From a32d399c43d7c9c3f12c332f6fa3cfbc4eccbb21 Mon Sep 17 00:00:00 2001 From: Jonas Sicking Date: Tue, 23 Nov 2010 00:50:56 -0800 Subject: [PATCH] Bug 608669: Make chrome-document-global-created be properly dispatched on newly opened windows. r=jst a=blocker --- docshell/test/chrome/Makefile.in | 2 + docshell/test/chrome/bug608669.xul | 6 ++ docshell/test/chrome/test_bug608669.xul | 120 ++++++++++++++++++++++++ dom/base/nsGlobalWindow.cpp | 22 ++++- dom/base/nsPIDOMWindow.h | 4 + 5 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 docshell/test/chrome/bug608669.xul create mode 100644 docshell/test/chrome/test_bug608669.xul diff --git a/docshell/test/chrome/Makefile.in b/docshell/test/chrome/Makefile.in index 60ced9c878e..9f41478819a 100644 --- a/docshell/test/chrome/Makefile.in +++ b/docshell/test/chrome/Makefile.in @@ -100,6 +100,8 @@ _TEST_FILES = \ test_bug582176.xul \ bug582176_window.xul \ test_bug428288.html \ + test_bug608669.xul \ + bug608669.xul \ test_bug449778.xul \ bug449778_window.xul \ test_bug449780.xul \ diff --git a/docshell/test/chrome/bug608669.xul b/docshell/test/chrome/bug608669.xul new file mode 100644 index 00000000000..1ab012c14ef --- /dev/null +++ b/docshell/test/chrome/bug608669.xul @@ -0,0 +1,6 @@ + + + + + diff --git a/docshell/test/chrome/test_bug608669.xul b/docshell/test/chrome/test_bug608669.xul new file mode 100644 index 00000000000..c7dead12609 --- /dev/null +++ b/docshell/test/chrome/test_bug608669.xul @@ -0,0 +1,120 @@ + + + + + + + + + + + Mozilla Bug 608669 + + + + + + Below will an iframe be added + + diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3326718721c..b2485b85530 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -737,7 +737,7 @@ nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow) mMayHaveAudioAvailableEventListener(PR_FALSE), mIsModalContentWindow(PR_FALSE), mIsActive(PR_FALSE), mInnerWindow(nsnull), mOuterWindow(aOuterWindow), // Make sure no actual window ends up with mWindowID == 0 - mWindowID(++gNextWindowID) + mWindowID(++gNextWindowID), mHasNotifiedGlobalCreated(PR_FALSE) {} nsPIDOMWindow::~nsPIDOMWindow() {} @@ -2205,9 +2205,23 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, mContext->GC(); mContext->DidInitializeContext(); - if (!aState && !reUseInnerWindow) { - nsContentUtils::AddScriptRunner( - NS_NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated)); + if (newInnerWindow && !newInnerWindow->mHasNotifiedGlobalCreated && mDoc) { + // We should probably notify. However if this is the, arguably bad, + // situation when we're creating a temporary non-chrome-about-blank + // document in a chrome docshell, don't notify just yet. Instead wait + // until we have a real chrome doc. + nsCOMPtr treeItem(do_QueryInterface(mDocShell)); + PRInt32 itemType = nsIDocShellTreeItem::typeContent; + if (treeItem) { + treeItem->GetItemType(&itemType); + } + + if (itemType != nsIDocShellTreeItem::typeChrome || + nsContentUtils::IsSystemPrincipal(mDoc->NodePrincipal())) { + newInnerWindow->mHasNotifiedGlobalCreated = PR_TRUE; + nsContentUtils::AddScriptRunner( + NS_NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated)); + } } return NS_OK; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index f871b528aed..430d7c670a0 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -620,6 +620,10 @@ protected: // A unique (as long as our 64-bit counter doesn't roll over) id for // this window. PRUint64 mWindowID; + + // This is only used by the inner window. Set to true once we've sent + // the (chrome|content)-document-global-created notification. + PRPackedBool mHasNotifiedGlobalCreated; };