diff --git a/mozilla/content/base/src/nsDocumentFragment.cpp b/mozilla/content/base/src/nsDocumentFragment.cpp index 5b8feeff5dd..0e0e3e57f0c 100644 --- a/mozilla/content/base/src/nsDocumentFragment.cpp +++ b/mozilla/content/base/src/nsDocumentFragment.cpp @@ -47,6 +47,7 @@ #include "nsIDOMDocument.h" #include "nsDOMError.h" #include "nsIDOM3Node.h" +#include "nsLayoutAtoms.h" class nsDocumentFragment : public nsGenericContainerElement, @@ -174,23 +175,14 @@ nsresult NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, nsIDocument* aOwnerDocument) { - NS_ENSURE_ARG_POINTER(aInstancePtrResult); + NS_ENSURE_ARG(aOwnerDocument); + + nsINodeInfoManager *nimgr = aOwnerDocument->GetNodeInfoManager(); - nsCOMPtr nimgr; nsCOMPtr nodeInfo; - - nsresult rv; - - if (aOwnerDocument) { - nimgr = aOwnerDocument->GetNodeInfoManager(); - } else { - rv = nsNodeInfoManager::GetAnonymousManager(getter_AddRefs(nimgr)); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = nimgr->GetNodeInfo(NS_LITERAL_CSTRING("#document-fragment"), - nsnull, kNameSpaceID_None, - getter_AddRefs(nodeInfo)); + nsresult rv = nimgr->GetNodeInfo(nsLayoutAtoms::documentFragmentNodeName, + nsnull, kNameSpaceID_None, + getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); nsDocumentFragment* it = new nsDocumentFragment(aOwnerDocument); diff --git a/mozilla/content/base/src/nsNodeInfoManager.cpp b/mozilla/content/base/src/nsNodeInfoManager.cpp index 71e5da2dd63..b24466de877 100644 --- a/mozilla/content/base/src/nsNodeInfoManager.cpp +++ b/mozilla/content/base/src/nsNodeInfoManager.cpp @@ -48,7 +48,6 @@ #include "nsContentUtils.h" #include "nsReadableUtils.h" -nsNodeInfoManager* nsNodeInfoManager::gAnonymousNodeInfoManager; PRUint32 nsNodeInfoManager::gNodeManagerCount; @@ -96,19 +95,7 @@ nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2) nsNodeInfoManager::nsNodeInfoManager() { - - if (gNodeManagerCount == 1 && gAnonymousNodeInfoManager) { - /* - * If we get here the global nodeinfo manager was the first one created, - * in that case we're not holding a strong reference to the global nodeinfo - * manager. Now we're creating one more nodeinfo manager so we'll grab - * a strong reference to the global nodeinfo manager so that it's - * lifetime will be longer than the lifetime of the other node managers. - */ - NS_ADDREF(gAnonymousNodeInfoManager); - } - - gNodeManagerCount++; + ++gNodeManagerCount; mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue, NodeInfoInnerKeyCompare, @@ -122,17 +109,7 @@ nsNodeInfoManager::nsNodeInfoManager() nsNodeInfoManager::~nsNodeInfoManager() { - gNodeManagerCount--; - - if (gNodeManagerCount == 1 && gAnonymousNodeInfoManager) { - NS_RELEASE(gAnonymousNodeInfoManager); - } else if (!gNodeManagerCount) { - /* - * Here we just make sure that we don't leave a dangling pointer to - * the global nodeinfo manager after it's deleted. - */ - gAnonymousNodeInfoManager = nsnull; - } + --gNodeManagerCount; if (mNodeInfoHash) PL_HashTableDestroy(mNodeInfoHash); @@ -166,7 +143,6 @@ nsNodeInfoManager::Init(nsIDocument *aDocument) return NS_OK; } - void nsNodeInfoManager::DropDocumentReference() { @@ -360,31 +336,3 @@ nsNodeInfoManager::RemoveNodeInfo(nsNodeInfo *aNodeInfo) NS_WARN_IF_FALSE(ret, "Can't find nsINodeInfo to remove!!!"); } } - - -nsresult -nsNodeInfoManager::GetAnonymousManager(nsINodeInfoManager** aNodeInfoManager) -{ - if (!gAnonymousNodeInfoManager) { - gAnonymousNodeInfoManager = new nsNodeInfoManager; - - if (!gAnonymousNodeInfoManager) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(gAnonymousNodeInfoManager); - } - - *aNodeInfoManager = gAnonymousNodeInfoManager; - - /* - * If the only nodeinfo manager is the global one we don't hold a ref - * since the global nodeinfo manager should be destroyed when it's released, - * even if it's the last one arround. - */ - if (gNodeManagerCount > 1) { - NS_ADDREF(*aNodeInfoManager); - } - - return NS_OK; -} - diff --git a/mozilla/content/base/src/nsNodeInfoManager.h b/mozilla/content/base/src/nsNodeInfoManager.h index 2318d0183a8..d8f8f1afc3f 100644 --- a/mozilla/content/base/src/nsNodeInfoManager.h +++ b/mozilla/content/base/src/nsNodeInfoManager.h @@ -77,8 +77,6 @@ public: void RemoveNodeInfo(nsNodeInfo *aNodeInfo); - static nsresult GetAnonymousManager(nsINodeInfoManager** aNodeInfoManager); - private: static PRIntn PR_CALLBACK NodeInfoInnerKeyCompare(const void *key1, const void *key2); @@ -91,19 +89,6 @@ private: PLHashTable *mNodeInfoHash; nsCOMPtr mPrincipal; - /* - * gAnonymousNodeInfoManager is a global nodeinfo manager used for nodes - * that are no longer part of a document and for nodes that are created - * where no document is accessible. - * - * gAnonymousNodeInfoManager is allocated when requested for the first time - * and once the last nodeinfo manager (appart from gAnonymousNodeInfoManager) - * is destroyed gAnonymousNodeInfoManager is destroyed. If the global - * nodeinfo manager is the only nodeinfo manager used it can be deleted - * and later reallocated if all users of the nodeinfo manager drops the - * referernces to it. - */ - static nsNodeInfoManager *gAnonymousNodeInfoManager; static PRUint32 gNodeManagerCount; }; diff --git a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp index 225586a99b2..e52ecc2bbb4 100644 --- a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -155,6 +155,7 @@ public: nsString mBaseHREF; nsString mBaseTarget; + nsCOMPtr mTargetDocument; nsCOMPtr mNodeInfoManager; }; @@ -245,8 +246,10 @@ nsHTMLFragmentContentSink::WillBuildModel(void) return NS_OK; } + NS_ASSERTION(mTargetDocument, "Need a document!"); + nsCOMPtr frag; - nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), nsnull); + nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mTargetDocument); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(frag, &mRoot); @@ -697,18 +700,18 @@ nsHTMLFragmentContentSink::GetFragment(nsIDOMDocumentFragment** aFragment) NS_IMETHODIMP nsHTMLFragmentContentSink::SetTargetDocument(nsIDocument* aTargetDocument) { - if (aTargetDocument) { - mNodeInfoManager = aTargetDocument->GetNodeInfoManager(); - } + NS_ENSURE_ARG_POINTER(aTargetDocument); + mTargetDocument = aTargetDocument; + mNodeInfoManager = aTargetDocument->GetNodeInfoManager(); if (mNodeInfoManager) { return NS_OK; } nsresult rv = NS_NewNodeInfoManager(getter_AddRefs(mNodeInfoManager)); NS_ENSURE_SUCCESS(rv, rv); - - rv = mNodeInfoManager->Init(nsnull); + + rv = mNodeInfoManager->Init(aTargetDocument); if (NS_FAILED(rv)) { mNodeInfoManager = nsnull; } diff --git a/mozilla/content/shared/public/nsLayoutAtomList.h b/mozilla/content/shared/public/nsLayoutAtomList.h index 14a7007d0e8..e68994cec9f 100644 --- a/mozilla/content/shared/public/nsLayoutAtomList.h +++ b/mozilla/content/shared/public/nsLayoutAtomList.h @@ -88,6 +88,7 @@ LAYOUT_ATOM(popupList, "Popup-list") LAYOUT_ATOM(commentTagName, "__moz_comment") LAYOUT_ATOM(textTagName, "__moz_text") LAYOUT_ATOM(processingInstructionTagName, "__moz_pi") +LAYOUT_ATOM(documentFragmentNodeName, "#document-fragment") // Alphabetical list of frame types LAYOUT_ATOM(areaFrame, "AreaFrame") diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index f9f7ac6ebf6..784c6ea3807 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -1094,15 +1094,15 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable if (insertAsImage) { stuffToPaste.Assign(NS_LITERAL_STRING("\"\"")); } else /* insert as link */ { stuffToPaste.Assign(NS_LITERAL_STRING("")); - stuffToPaste.Append(NS_ConvertUTF8toUCS2(urltext)); + AppendUTF8toUTF16(urltext, stuffToPaste); stuffToPaste.Append(NS_LITERAL_STRING("")); } nsAutoEditBatch beginBatching(this); @@ -2151,15 +2151,11 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(const nsAString &aInputString, nsCOMPtr contextAsNode, tmp; nsresult res = NS_OK; - nsCOMPtr rootElement; - GetRootElement(getter_AddRefs(rootElement)); + nsCOMPtr domDoc; + GetDocument(getter_AddRefs(domDoc)); - nsCOMPtr doc; - if (rootElement) { - nsCOMPtr domDoc; - rootElement->GetOwnerDocument(getter_AddRefs(domDoc)); - doc = do_QueryInterface(domDoc); - } + nsCOMPtr doc = do_QueryInterface(domDoc); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); // if we have context info, create a fragment for that nsVoidArray tagStack; diff --git a/mozilla/layout/base/nsLayoutAtomList.h b/mozilla/layout/base/nsLayoutAtomList.h index 14a7007d0e8..e68994cec9f 100644 --- a/mozilla/layout/base/nsLayoutAtomList.h +++ b/mozilla/layout/base/nsLayoutAtomList.h @@ -88,6 +88,7 @@ LAYOUT_ATOM(popupList, "Popup-list") LAYOUT_ATOM(commentTagName, "__moz_comment") LAYOUT_ATOM(textTagName, "__moz_text") LAYOUT_ATOM(processingInstructionTagName, "__moz_pi") +LAYOUT_ATOM(documentFragmentNodeName, "#document-fragment") // Alphabetical list of frame types LAYOUT_ATOM(areaFrame, "AreaFrame")