mshtml: Added begining implementation of IPersistStreamInit::Save.

This commit is contained in:
Jacek Caban 2006-10-02 20:33:08 +02:00 committed by Alexandre Julliard
parent e947b948a1
commit 1a4c366f11
4 changed files with 209 additions and 3 deletions

View File

@ -318,6 +318,7 @@ void nsAString_Finish(nsAString*);
nsIInputStream *create_nsstream(const char*,PRInt32); nsIInputStream *create_nsstream(const char*,PRInt32);
nsICommandParams *create_nscommand_params(void); nsICommandParams *create_nscommand_params(void);
void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
BSCallback *create_bscallback(IMoniker*); BSCallback *create_bscallback(IMoniker*);
HRESULT start_binding(BSCallback*); HRESULT start_binding(BSCallback*);

View File

@ -41,6 +41,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1" #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
#define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1" #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
#define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1" #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
#define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
#define APPSTARTUP_TOPIC "app-startup" #define APPSTARTUP_TOPIC "app-startup"
@ -464,6 +465,103 @@ nsICommandParams *create_nscommand_params(void)
return ret; return ret;
} }
static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
{
nsIDOMNodeList *node_list = NULL;
PRBool has_children = FALSE;
PRUint16 type;
nsresult nsres;
nsIDOMNode_HasChildNodes(nsnode, &has_children);
nsres = nsIDOMNode_GetNodeType(nsnode, &type);
if(NS_FAILED(nsres)) {
ERR("GetType failed: %08lx\n", nsres);
return;
}
switch(type) {
case ELEMENT_NODE: {
nsIDOMElement *nselem;
nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
nsIDOMElement_Release(nselem);
break;
}
case TEXT_NODE: {
nsIDOMText *nstext;
nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
nsIDOMText_Release(nstext);
break;
}
case DOCUMENT_NODE: {
nsIDOMDocument *nsdoc;
nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
nsIDOMDocument_Release(nsdoc);
}
default:
FIXME("Unhandled type %u\n", type);
}
if(has_children) {
PRUint32 child_cnt, i;
nsIDOMNode *child_node;
nsIDOMNode_GetChildNodes(nsnode, &node_list);
nsIDOMNodeList_GetLength(node_list, &child_cnt);
for(i=0; i<child_cnt; i++) {
nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
if(NS_SUCCEEDED(nsres)) {
nsnode_to_nsstring_rec(serializer, child_node, str);
nsIDOMNode_Release(child_node);
}else {
ERR("Item failed: %08lx\n", nsres);
}
}
nsIDOMNodeList_Release(node_list);
}
if(type == ELEMENT_NODE) {
nsIDOMElement *nselem;
nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
nsIDOMElement_Release(nselem);
}
}
void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
{
nsIContentSerializer *serializer;
nsIDOMNode *nsnode;
nsresult nsres;
nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
(void**)&serializer);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIContentSerializer: %08lx\n", nsres);
return;
}
nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
if(NS_FAILED(nsres))
ERR("Init failed: %08lx\n", nsres);
nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
nsnode_to_nsstring_rec(serializer, nsnode, str);
nsIDOMNode_Release(nsnode);
nsres = nsIContentSerializer_Flush(serializer, str);
if(NS_FAILED(nsres))
ERR("Flush failed: %08lx\n", nsres);
nsIContentSerializer_Release(serializer);
}
void close_gecko() void close_gecko()
{ {
TRACE("()\n"); TRACE("()\n");

View File

@ -100,7 +100,6 @@ typedef nsISupports nsIDOMAttr;
typedef nsISupports nsIDOMDocumentType; typedef nsISupports nsIDOMDocumentType;
typedef nsISupports nsIDOMDOMImplementation; typedef nsISupports nsIDOMDOMImplementation;
typedef nsISupports nsIDOMDocumentFragment; typedef nsISupports nsIDOMDocumentFragment;
typedef nsISupports nsIDOMText;
typedef nsISupports nsIDOMComment; typedef nsISupports nsIDOMComment;
typedef nsISupports nsIDOMCDATASection; typedef nsISupports nsIDOMCDATASection;
typedef nsISupports nsIDOMProcessingInstruction; typedef nsISupports nsIDOMProcessingInstruction;
@ -110,6 +109,7 @@ typedef nsISupports nsIDOMHTMLOptionsCollection;
typedef nsISupports nsIDOMHTMLCollection; typedef nsISupports nsIDOMHTMLCollection;
typedef nsISupports nsIDOMRange; typedef nsISupports nsIDOMRange;
typedef nsISupports nsIEditor; typedef nsISupports nsIEditor;
typedef nsISupports nsIWebProgressListener;
[ [
object, object,
@ -391,6 +391,21 @@ interface nsIDOMNodeList : nsISupports
] ]
interface nsIDOMNode : nsISupports interface nsIDOMNode : nsISupports
{ {
enum NSNODETYPE {
ELEMENT_NODE = 1,
ATTRIBUTE_NODE = 2,
TEXT_NODE = 3,
CDATA_SELECTION_NODE = 4,
ENTITY_REFERENCE_NODE = 5,
ENTITY_NODE = 6,
PROCESSING_INSTRUCTION_NODE = 7,
COMMENT_NODE = 8,
DOCUMENT_NODE = 9,
DOCUMENT_TYPE_NODE = 10,
DOCUMENT_FRAGMENT_NODE = 11,
NOTATION_NODE = 12
};
nsresult GetNodeName(nsAString *aNodeName); nsresult GetNodeName(nsAString *aNodeName);
nsresult GetNodeValue(nsAString *aNodeValue); nsresult GetNodeValue(nsAString *aNodeValue);
nsresult SetNodeValue(const nsAString *aNodeValue); nsresult SetNodeValue(const nsAString *aNodeValue);
@ -491,6 +506,31 @@ interface nsIDOMNSHTMLElement : nsISupports
nsresult ScrollIntoView(PRBool top); nsresult ScrollIntoView(PRBool top);
} }
[
object,
uuid(a6cf9072-15b3-11d2-932e-00805f8add32)
]
interface nsIDOMCharacterData : nsIDOMNode
{
nsresult GetData(nsAString *aData);
nsresult SetData(const nsAString *aData);
nsresult GetLength(PRUint32 *aLength);
nsresult SubstringData(PRUint32 offset, PRUint32 count, nsAString *_retval);
nsresult AppendData(const nsAString *arg);
nsresult InsertData(PRUint32 offset, const nsAString *arg);
nsresult DeleteData(PRUint32 offset, PRUint32 count);
nsresult ReplaceData(PRUint32 offset, PRUint32 count, const nsAString *arg);
}
[
object,
uuid(a6cf9082-15b3-11d2-932e-00805f8add32)
]
interface nsIDOMText : nsIDOMCharacterData
{
nsresult SplitText(PRUint32 offset, nsIDOMText **_retval);
}
[ [
object, object,
uuid(a6cf9075-15b3-11d2-932e-00805f8add32) uuid(a6cf9075-15b3-11d2-932e-00805f8add32)
@ -1216,6 +1256,27 @@ interface nsICommandManager : nsISupports
nsIDOMWindow *aTargetWindow); nsIDOMWindow *aTargetWindow);
} }
[
object,
uuid(d650439a-ca29-410d-a906-b0557fb62fcd)
]
interface nsIContentSerializer : nsISupports
{
nsresult Init(PRUint32 flags, PRUint32 aWrapColumn, const char* aCharSet, PRBool aIsCopying);
nsresult AppendText(nsIDOMText *aText, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString *aStr);
nsresult AppendCDATASection(nsIDOMCDATASection *aCDATASection, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString *aStr);
nsresult AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString *aStr);
nsresult AppendComment(nsIDOMComment *aComment, PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAString *aStr);
nsresult AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString *aStr);
nsresult AppendElementStart(nsIDOMElement *aElement, PRBool aHasChildren, nsAString *aStr);
nsresult AppendElementEnd(nsIDOMElement *aElement, nsAString *aStr);
nsresult Flush(nsAString *aStr);
nsresult AppendDocumentStart(nsIDOMDocument *aDocument, nsAString *aStr);
}
/* /*
* NOTE: * NOTE:
* This is a private Wine interface that is implemented by our implementation * This is a private Wine interface that is implemented by our implementation

View File

@ -464,8 +464,54 @@ static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM
BOOL fClearDirty) BOOL fClearDirty)
{ {
HTMLDocument *This = PERSTRINIT_THIS(iface); HTMLDocument *This = PERSTRINIT_THIS(iface);
FIXME("(%p)->(%p %x)\n", This, pStm, fClearDirty); nsIDOMDocument *nsdoc;
return E_NOTIMPL; nsIDOMNode *nsnode;
nsAString nsstr;
LPCWSTR strw;
char *str;
DWORD len, written=0;
nsresult nsres;
HRESULT hres;
WARN("(%p)->(%p %x) needs more work\n", This, pStm, fClearDirty);
if(!This->nscontainer)
return S_OK;
nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, &nsdoc);
if(NS_FAILED(nsres)) {
ERR("GetDocument failed: %08lx\n", nsres);
return E_FAIL;
}
nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
nsIDOMDocument_Release(nsdoc);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMNode failed: %08lx\n", nsres);
return E_FAIL;
}
nsAString_Init(&nsstr, NULL);
nsnode_to_nsstring(nsnode, &nsstr);
nsIDOMNode_Release(nsnode);
nsAString_GetData(&nsstr, &strw, NULL);
len = WideCharToMultiByte(CP_ACP, 0, strw, -1, NULL, 0, NULL, NULL);
str = mshtml_alloc(len);
WideCharToMultiByte(CP_ACP, 0, strw, -1, str, len, NULL, NULL);
nsAString_Finish(&nsstr);
ERR("%s\n", debugstr_a(str));
hres = IStream_Write(pStm, str, len, &written);
if(FAILED(hres))
FIXME("Write failed: %08lx\n", hres);
mshtml_free(str);
return S_OK;
} }
static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface, static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,