Fix for bug 230439 (Remove anonymous nodeinfomanager and other cleanup). r=caillon, sr=jst.
git-svn-id: svn://10.0.0.236/trunk@151500 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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<nsINodeInfoManager> nimgr;
|
||||
nsCOMPtr<nsINodeInfo> 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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<nsIPrincipal> 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;
|
||||
};
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ public:
|
||||
nsString mBaseHREF;
|
||||
nsString mBaseTarget;
|
||||
|
||||
nsCOMPtr<nsIDocument> mTargetDocument;
|
||||
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
|
||||
};
|
||||
|
||||
@@ -245,8 +246,10 @@ nsHTMLFragmentContentSink::WillBuildModel(void)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ASSERTION(mTargetDocument, "Need a document!");
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentFragment> 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;
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -1094,15 +1094,15 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
|
||||
if (insertAsImage)
|
||||
{
|
||||
stuffToPaste.Assign(NS_LITERAL_STRING("<IMG src=\""));
|
||||
stuffToPaste.Append(NS_ConvertUTF8toUCS2(urltext));
|
||||
AppendUTF8toUTF16(urltext, stuffToPaste);
|
||||
stuffToPaste.Append(NS_LITERAL_STRING("\" alt=\"\" >"));
|
||||
}
|
||||
else /* insert as link */
|
||||
{
|
||||
stuffToPaste.Assign(NS_LITERAL_STRING("<A href=\""));
|
||||
stuffToPaste.Append(NS_ConvertUTF8toUCS2(urltext));
|
||||
AppendUTF8toUTF16(urltext, stuffToPaste);
|
||||
stuffToPaste.Append(NS_LITERAL_STRING("\">"));
|
||||
stuffToPaste.Append(NS_ConvertUTF8toUCS2(urltext));
|
||||
AppendUTF8toUTF16(urltext, stuffToPaste);
|
||||
stuffToPaste.Append(NS_LITERAL_STRING("</A>"));
|
||||
}
|
||||
nsAutoEditBatch beginBatching(this);
|
||||
@@ -2151,15 +2151,11 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(const nsAString &aInputString,
|
||||
nsCOMPtr<nsIDOMNode> contextAsNode, tmp;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> rootElement;
|
||||
GetRootElement(getter_AddRefs(rootElement));
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
GetDocument(getter_AddRefs(domDoc));
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (rootElement) {
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rootElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
doc = do_QueryInterface(domDoc);
|
||||
}
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
||||
|
||||
// if we have context info, create a fragment for that
|
||||
nsVoidArray tagStack;
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user