diff --git a/dom/public/base/nsPIDOMWindow.h b/dom/public/base/nsPIDOMWindow.h index 9fd139c5f574..9c73fa4379aa 100644 --- a/dom/public/base/nsPIDOMWindow.h +++ b/dom/public/base/nsPIDOMWindow.h @@ -77,8 +77,8 @@ class nsIDocument; struct nsTimeout; #define NS_PIDOMWINDOW_IID \ -{ 0x207fe64a, 0x7123, 0x43d0, \ - { 0x91, 0x1d, 0x51, 0x19, 0x35, 0x9a, 0xb5, 0x77 } } +{ 0xabb217ba, 0x2528, 0x467e, \ + { 0xaa, 0x29, 0xdd, 0x84, 0x2d, 0x97, 0x3c, 0x78 } } class nsPIDOMWindow : public nsIDOMWindowInternal { @@ -280,6 +280,15 @@ public: return mInnerWindow; } + nsPIDOMWindow *EnsureInnerWindow() + { + NS_ASSERTION(IsOuterWindow(), "EnsureInnerWindow called on inner window"); + // GetDocument forces inner window creation if there isn't one already + nsCOMPtr doc; + GetDocument(getter_AddRefs(doc)); + return GetCurrentInnerWindow(); + } + PRBool IsInnerWindow() const { return mIsInnerWindow; diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 9e3785016a3c..c6a5b600fc93 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -5627,22 +5627,18 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // We're resolving a property on an outer window for which there // is no inner window yet, and the window is not frozen // (i.e. we're not in the middle of initializing XPConnect - // classes on it). If the context is already initalized, trigger - // creation of a new inner window by calling GetDocument() on - // the outer window. This will create a synthetic about:blank - // document, and an inner window which may be reused by the - // actual document being loaded into this outer window. This way - // properties defined on the window before the document load - // started will be visible to the document once it's loaded, - // assuming same origin etc. + // classes on it). If the context is already initalized, force + // creation of a new inner window. This will create a synthetic + // about:blank document, and an inner window which may be reused + // by the actual document being loaded into this outer + // window. This way properties defined on the window before the + // document load started will be visible to the document once + // it's loaded, assuming same origin etc. nsIScriptContext *scx = win->GetContextInternal(); if (scx && scx->IsContextInitialized()) { - nsCOMPtr doc; - win->GetDocument(getter_AddRefs(doc)); - // Grab the new inner window. - innerWin = win->GetCurrentInnerWindowInternal(); + innerWin = win->EnsureInnerWindowInternal(); if (!innerWin) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 7451617e282e..2e8c34d9ed36 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -266,6 +266,11 @@ public: return NS_STATIC_CAST(nsGlobalWindow *, mInnerWindow); } + nsGlobalWindow *EnsureInnerWindowInternal() + { + return NS_STATIC_CAST(nsGlobalWindow *, EnsureInnerWindow()); + } + PRBool IsFrozen() const { return mIsFrozen; diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index a16e943fdfeb..89abf76461ed 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -150,12 +150,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel) nsCOMPtr win(do_QueryInterface(global)); - // Get the document out of the window to make sure we create a new - // inner window if one doesn't already exist (see bug 306630). - nsCOMPtr doc; - win->GetDocument(getter_AddRefs(doc)); - - nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow(); + // Make sure we create a new inner window if one doesn't already exist (see + // bug 306630). + nsPIDOMWindow *innerWin = win->EnsureInnerWindow(); if (!innerWin) { return NS_ERROR_UNEXPECTED; @@ -178,15 +175,6 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel) return NS_ERROR_DOM_RETVAL_UNDEFINED; } - // Now get the DOM Document. Accessing the document will create one - // if necessary. So, basically, this call ensures that a document gets - // created -- if necessary. - rv = domWindow->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc, "No DOMDocument!"); - if (NS_FAILED(rv)) { - return NS_ERROR_FAILURE; - } - nsCOMPtr scriptContext = global->GetContext(); if (!scriptContext) return NS_ERROR_FAILURE;