diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 629858d9a31..9472dd06d68 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -67,6 +67,7 @@ class nsIStyleSheet; class nsIStyleRule; class nsIViewManager; class nsIScriptGlobalObject; +class nsPIDOMWindow; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; @@ -472,6 +473,11 @@ public: virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0; virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0; + /** + * Return the window containing the document (the outer window). + */ + virtual nsPIDOMWindow *GetWindow() = 0; + /** * Get the script loader for this document */ diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 8191c90c3f2..cb99c63e81e 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -697,6 +697,12 @@ NS_IMPL_RELEASE_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument) // NOTE! nsDocument::operator new() zeroes out all members, so don't // bother initializing members to 0. +nsDocument::nsDocument() + : nsIDocument(), + mVisible(PR_TRUE) +{ +} + nsDocument::~nsDocument() { mInDestructor = PR_TRUE; @@ -2043,6 +2049,15 @@ nsDocument::GetScriptGlobalObject() const void nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) { +#ifdef DEBUG + { + nsCOMPtr win(do_QueryInterface(aScriptGlobalObject)); + + NS_ASSERTION(!win || win->IsInnerWindow(), + "Script global object must be an inner window!"); + } +#endif + if (mScriptGlobalObject && !aScriptGlobalObject) { // We're detaching from the window. We need to grab a pointer to // our layout history state now. @@ -2057,6 +2072,18 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) } } +nsPIDOMWindow * +nsDocument::GetWindow() +{ + nsCOMPtr win(do_QueryInterface(GetScriptGlobalObject())); + + if (!win) { + return nsnull; + } + + return win->GetOuterWindow(); +} + nsIScriptLoader * nsDocument::GetScriptLoader() { @@ -3037,11 +3064,14 @@ nsDocument::GetDefaultView(nsIDOMAbstractView** aDefaultView) if (win) { // The default view is our outer window. - if (!win->IsInnerWindow()) { - return NS_ERROR_UNEXPECTED; + nsPIDOMWindow *outer = win->GetOuterWindow(); + + if (outer) { + return CallQueryInterface(outer, aDefaultView); } - return CallQueryInterface(win->GetOuterWindow(), aDefaultView); + // Fall through here and return null in case our window no longer + // has an outer window. } return NS_OK; diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index edebf76e592..4534f676c1a 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -450,6 +450,11 @@ public: virtual nsIScriptGlobalObject* GetScriptGlobalObject() const; virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject); + /** + * Return the window containing the document (the outer window). + */ + virtual nsPIDOMWindow *GetWindow(); + /** * Get the script loader for this document */ @@ -678,7 +683,7 @@ protected: return kNameSpaceID_None; }; - nsDocument() : nsIDocument(), mVisible(PR_TRUE) {} + nsDocument(); virtual ~nsDocument(); nsCString mReferrer; diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index eba883ac63d..04d04eac079 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -518,7 +518,7 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget) { nsCOMPtr win = do_QueryInterface(aTarget); - NS_ASSERTION(!win || win == win->GetOuterWindow(), + NS_ASSERTION(!win || !win->IsInnerWindow(), "Uh, inner window set as event target!"); } #endif @@ -533,7 +533,7 @@ NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget) { nsCOMPtr win = do_QueryInterface(aCurrentTarget); - NS_ASSERTION(!win || win == win->GetOuterWindow(), + NS_ASSERTION(!win || !win->IsInnerWindow(), "Uh, inner window set as event target!"); } #endif @@ -548,7 +548,7 @@ NS_METHOD nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget) { nsCOMPtr win = do_QueryInterface(aOriginalTarget); - NS_ASSERTION(!win || win == win->GetOuterWindow(), + NS_ASSERTION(!win || !win->IsInnerWindow(), "Uh, inner window set as event target!"); } #endif diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 6ef1eac46f4..8c2eadbeb20 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -1184,9 +1184,12 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, scope = global->GetGlobalJSObject(); } } else { - nsCOMPtr win(do_QueryInterface(aObject)); + nsCOMPtr win(do_QueryInterface(aObject)); nsCOMPtr global; if (win) { + NS_ASSERTION(win->IsInnerWindow(), + "Event listener added to outer window!"); + nsCOMPtr domdoc; win->GetDocument(getter_AddRefs(domdoc)); doc = do_QueryInterface(domdoc); diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index d3da8cd5f50..e96db063b08 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -188,17 +188,14 @@ GetDocumentOuterWindow(nsIDocument *aDocument) } static nsIDocument * -GetInnerDocument(nsISupports *aWindow) +GetDocumentFromWindow(nsIDOMWindow *aWindow) { nsCOMPtr win = do_QueryInterface(aWindow); nsPIDOMWindow *innerWin; - nsIDocument *doc = nsnull; + nsCOMPtr doc; - if (win && (innerWin = win->GetCurrentInnerWindow())) { - nsCOMPtr tmp = - do_QueryInterface(innerWin->GetExtantDocument()); - - doc = tmp; + if (win) { + doc = do_QueryInterface(win->GetExtantDocument()); } return doc; @@ -830,7 +827,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, if (focusedWindow) { focusedWindow->Focus(); - nsCOMPtr document = GetInnerDocument(focusedWindow); + nsCOMPtr document = GetDocumentFromWindow(focusedWindow); if (document) { nsIPresShell *shell = document->GetShellAt(0); @@ -1637,7 +1634,7 @@ nsEventStateManager::ChangeTextSize(PRInt32 change) rootWindow->GetContent(getter_AddRefs(contentWindow)); if(!contentWindow) return NS_ERROR_FAILURE; - nsIDocument *doc = GetInnerDocument(contentWindow); + nsIDocument *doc = GetDocumentFromWindow(contentWindow); if(!doc) return NS_ERROR_FAILURE; nsIPresShell *presShell = doc->GetShellAt(0); diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 82e5c926ba1..1bde2b9afe1 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -3436,16 +3436,16 @@ nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow) nsCOMPtr doc_shell; mFrameLoader->GetDocShell(getter_AddRefs(doc_shell)); - nsCOMPtr win(do_GetInterface(doc_shell)); - nsCOMPtr piwin(do_QueryInterface(win)); + nsCOMPtr win(do_GetInterface(doc_shell)); - if (piwin && piwin->IsInnerWindow()) { - // We got an inner window here somehow, this just should not happen. - - return NS_ERROR_UNEXPECTED; + if (!win) { + return NS_OK; } - return CallQueryInterface(piwin->GetOuterWindow(), aContentWindow); + NS_ASSERTION(win->IsOuterWindow(), + "Uh, this window should always be an outer window!"); + + return CallQueryInterface(win, aContentWindow); } nsresult diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 7ed51caecf4..75c67b7c1eb 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -61,7 +61,7 @@ #include "nsIDOMComment.h" #include "nsIDOMDOMImplementation.h" #include "nsIDOMDocumentType.h" -#include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIDOMHTMLFormElement.h" #include "nsDOMString.h" #include "nsIStreamListener.h" @@ -1915,7 +1915,7 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) nsCOMPtr kungFuDeathGrip = do_QueryInterface((nsIHTMLDocument*)this); - rv = mScriptGlobalObject->SetNewDocument(kungFuDeathGrip, PR_FALSE, + rv = mScriptGlobalObject->SetNewDocument((nsDocument *)this, PR_FALSE, PR_FALSE); if (NS_FAILED(rv)) { @@ -2774,7 +2774,7 @@ nsHTMLDocument::GetSelection(nsAString& aReturn) consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get()); } - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + nsIDOMWindow *window = GetWindow(); NS_ENSURE_TRUE(window, NS_OK); nsCOMPtr selection; @@ -3522,7 +3522,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode) if (!editSession) return NS_ERROR_FAILURE; - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + nsIDOMWindow *window = GetWindow(); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); if (aDesignMode.LowerCaseEqualsLiteral("on") && !mEditingIsOn) { @@ -3837,7 +3837,7 @@ nsHTMLDocument::ExecCommand(const nsAString & commandID, if (!cmdMgr) return NS_ERROR_FAILURE; - nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + nsIDOMWindow *window = GetWindow(); if (!window) return NS_ERROR_FAILURE; @@ -3908,7 +3908,7 @@ nsHTMLDocument::QueryCommandEnabled(const nsAString & commandID, if (!cmdMgr) return NS_ERROR_FAILURE; - nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + nsIDOMWindow *window = GetWindow(); if (!window) return NS_ERROR_FAILURE; @@ -3939,7 +3939,7 @@ nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID, if (!cmdMgr) return NS_ERROR_FAILURE; - nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + nsIDOMWindow *window = GetWindow(); if (!window) return NS_ERROR_FAILURE; @@ -3981,7 +3981,7 @@ nsHTMLDocument::QueryCommandState(const nsAString & commandID, PRBool *_retval) if (!cmdMgr) return NS_ERROR_FAILURE; - nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + nsIDOMWindow *window = GetWindow(); if (!window) return NS_ERROR_FAILURE; @@ -4071,7 +4071,7 @@ nsHTMLDocument::QueryCommandValue(const nsAString & commandID, if (!cmdMgr) return NS_ERROR_FAILURE; - nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + nsIDOMWindow *window = GetWindow(); if (!window) return NS_ERROR_FAILURE; diff --git a/mozilla/content/xbl/src/nsXBLProtoImpl.cpp b/mozilla/content/xbl/src/nsXBLProtoImpl.cpp index 3271a2c16bf..c287a97b4f5 100644 --- a/mozilla/content/xbl/src/nsXBLProtoImpl.cpp +++ b/mozilla/content/xbl/src/nsXBLProtoImpl.cpp @@ -141,7 +141,8 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding, // concrete base class. We need to alter the object so that our concrete class is interposed // between the object and its base class. We become the new base class of the object, and the // object's old base class becomes the new class' base class. - rv = aBinding->InitClass(mClassName, aContext, (void *) object, aTargetClassObject); + rv = aBinding->InitClass(mClassName, jscontext, global, object, + aTargetClassObject); if (NS_FAILED(rv)) return rv; @@ -172,10 +173,12 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding) nsIScriptContext *context = globalObject->GetContext(); NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY); + JSObject *global = globalObject->GetGlobalJSObject(); void* classObject; - nsresult rv = aBinding->InitClass(mClassName, context, - globalObject->GetGlobalJSObject(), + nsresult rv = aBinding->InitClass(mClassName, + (JSContext *)context->GetNativeContext(), + global, global, &classObject); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp index 656e4ed938d..01ce0fdfb1f 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -734,23 +734,16 @@ nsXBLPrototypeBinding::GetImmediateChild(nsIAtom* aTag) nsresult nsXBLPrototypeBinding::InitClass(const nsCString& aClassName, - nsIScriptContext * aContext, - void * aScriptObject, void ** aClassObject) + JSContext * aContext, JSObject * aGlobal, + JSObject * aScriptObject, + void ** aClassObject) { NS_ENSURE_ARG_POINTER(aClassObject); *aClassObject = nsnull; - JSContext* cx = (JSContext*)aContext->GetNativeContext(); - JSObject* scriptObject = (JSObject*) aScriptObject; - JSObject* tmp, *global = scriptObject; - - while ((tmp = ::JS_GetParent(cx, global))) { - global = tmp; - } - - return nsXBLBinding::DoInitJSClass(cx, global, scriptObject, aClassName, - aClassObject); + return nsXBLBinding::DoInitJSClass(aContext, aGlobal, aScriptObject, + aClassName, aClassObject); } nsIContent* diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.h b/mozilla/content/xbl/src/nsXBLPrototypeBinding.h index baf016f91a0..1bcfbc5d50b 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.h +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.h @@ -97,8 +97,10 @@ public: nsXBLProtoImplAnonymousMethod* GetDestructor(); nsresult SetDestructor(nsXBLProtoImplAnonymousMethod* aDestructor); - nsresult InitClass(const nsCString& aClassName, nsIScriptContext * aContext, void * aScriptObject, void ** aClassObject); - + nsresult InitClass(const nsCString& aClassName, JSContext * aContext, + JSObject * aGlobal, JSObject * aScriptObject, + void ** aClassObject); + nsresult ConstructInterfaceTable(const nsAString& aImpls); void SetImplementation(nsXBLProtoImpl* aImpl) { mImplementation = aImpl; } diff --git a/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp b/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp index db8c0b1821c..b0434492b3a 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -404,10 +404,13 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, // if the focused window was found get our script global object from // that. if (focusedWin) { + NS_ASSERTION(isXULKey, "We should only use the focused window for " + "XUL key handlers!"); nsCOMPtr piWin(do_QueryInterface(focusedWin)); - if (piWin && piWin->GetCurrentInnerWindow()) { + if (piWin) { piWin = piWin->GetCurrentInnerWindow(); + NS_ENSURE_TRUE(piWin, NS_ERROR_UNEXPECTED); } boundGlobal = do_QueryInterface(piWin->GetPrivateRoot()); diff --git a/mozilla/dom/public/base/nsPIDOMWindow.h b/mozilla/dom/public/base/nsPIDOMWindow.h index 1a36f266b72..d7e42fb11fb 100644 --- a/mozilla/dom/public/base/nsPIDOMWindow.h +++ b/mozilla/dom/public/base/nsPIDOMWindow.h @@ -100,9 +100,23 @@ public: PRBool HasMutationListeners(PRUint32 aMutationEventType) const { - const nsPIDOMWindow *win = GetCurrentInnerWindow(); + const nsPIDOMWindow *win; + + if (IsOuterWindow()) { + win = GetCurrentInnerWindow(); + + if (!win) { + NS_ERROR("No current inner window available!"); + + return PR_FALSE; + } + } else { + if (!mOuterWindow) { + NS_ERROR("HasMutationListeners() called on orphan inner window!"); + + return PR_FALSE; + } - if (!win) { win = this; } @@ -111,9 +125,23 @@ public: void SetMutationListeners(PRUint32 aType) { - nsPIDOMWindow *win = GetCurrentInnerWindow(); + nsPIDOMWindow *win; + + if (IsOuterWindow()) { + win = GetCurrentInnerWindow(); + + if (!win) { + NS_ERROR("No inner window available to set mutation bits on!"); + + return; + } + } else { + if (!mOuterWindow) { + NS_ERROR("HasMutationListeners() called on orphan inner window!"); + + return; + } - if (!win) { win = this; } @@ -133,20 +161,31 @@ public: // one doesn't for security reasons. nsIDOMElement* GetFrameElementInternal() const { - if (IsInnerWindow()) { + if (mOuterWindow) { return mOuterWindow->GetFrameElementInternal(); } + NS_ASSERTION(!IsInnerWindow(), + "GetFrameElementInternal() called on orphan inner window"); + return mFrameElement; } void SetFrameElementInternal(nsIDOMElement *aFrameElement) { - if (IsInnerWindow()) { - mOuterWindow->SetFrameElementInternal(aFrameElement); + if (IsOuterWindow()) { + mFrameElement = aFrameElement; + + return; } - mFrameElement = aFrameElement; + if (!mOuterWindow) { + NS_ERROR("frameElement set on inner window with no outer!"); + + return; + } + + mOuterWindow->SetFrameElementInternal(aFrameElement); } PRBool IsLoadingOrRunningTimeout() const @@ -163,9 +202,23 @@ public: // Check whether a document is currently loading PRBool IsLoading() const { - const nsPIDOMWindow *win = GetCurrentInnerWindow(); + const nsPIDOMWindow *win; + + if (IsOuterWindow()) { + win = GetCurrentInnerWindow(); + + if (!win) { + NS_ERROR("No current inner window available!"); + + return PR_FALSE; + } + } else { + if (!mOuterWindow) { + NS_ERROR("IsLoading() called on orphan inner window!"); + + return PR_FALSE; + } - if (!win) { win = this; } @@ -174,9 +227,23 @@ public: PRBool IsHandlingResizeEvent() const { - const nsPIDOMWindow *win = GetCurrentInnerWindow(); + const nsPIDOMWindow *win; + + if (IsOuterWindow()) { + win = GetCurrentInnerWindow(); + + if (!win) { + NS_ERROR("No current inner window available!"); + + return PR_FALSE; + } + } else { + if (!mOuterWindow) { + NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!"); + + return PR_FALSE; + } - if (!win) { win = this; } @@ -200,7 +267,7 @@ public: nsPIDOMWindow *GetOuterWindow() { - return mOuterWindow ? mOuterWindow : this; + return mIsInnerWindow ? mOuterWindow : this; } nsPIDOMWindow *GetCurrentInnerWindow() const @@ -210,7 +277,7 @@ public: PRBool IsInnerWindow() const { - return mOuterWindow != nsnull; + return mIsInnerWindow; } PRBool IsOuterWindow() const @@ -219,10 +286,15 @@ public: } protected: + // The nsPIDOMWindow constructor. The aOuterWindow argument should + // be null if and only if the created window itself is an outer + // window. In all other cases aOuterWindow should be the outer + // window for the inner window that is being created. nsPIDOMWindow(nsPIDOMWindow *aOuterWindow) : mFrameElement(nsnull), mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE), mIsHandlingResizeEvent(PR_FALSE), - mInnerWindow(nsnull), mOuterWindow(aOuterWindow) + mIsInnerWindow(aOuterWindow != nsnull), mInnerWindow(nsnull), + mOuterWindow(aOuterWindow) { } @@ -243,6 +315,7 @@ protected: PRPackedBool mIsDocumentLoaded; PRPackedBool mIsHandlingResizeEvent; + PRPackedBool mIsInnerWindow; // And these are the references between inner and outer windows. nsPIDOMWindow *mInnerWindow; diff --git a/mozilla/dom/public/nsIScriptContext.h b/mozilla/dom/public/nsIScriptContext.h index 8fb42726046..616c73d9045 100644 --- a/mozilla/dom/public/nsIScriptContext.h +++ b/mozilla/dom/public/nsIScriptContext.h @@ -337,7 +337,10 @@ public: virtual void SetGCOnDestruction(PRBool aGCOnDestruction) = 0; /** - * Initialize DOM classes on aGlobalObj + * Initialize DOM classes on aGlobalObj, always call + * WillInitializeContext() before calling InitContext(), and always + * call DidInitializeContext() when a context is fully + * (successfully) initialized. */ virtual nsresult InitClasses(JSObject *aGlobalObj) = 0; diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index fa5979f046e..a88b05afddc 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -394,6 +394,18 @@ static const char kDOMStringBundleURL[] = // NOTE: DEFAULT_SCRIPTABLE_FLAGS and DOM_DEFAULT_SCRIPTABLE_FLAGS // are defined in nsIDOMClassInfo.h. +#define WINDOW_SCRIPTABLE_FLAGS \ + (nsIXPCScriptable::WANT_GETPROPERTY | \ + nsIXPCScriptable::WANT_SETPROPERTY | \ + nsIXPCScriptable::WANT_PRECREATE | \ + nsIXPCScriptable::WANT_FINALIZE | \ + nsIXPCScriptable::WANT_ADDPROPERTY | \ + nsIXPCScriptable::WANT_DELPROPERTY | \ + nsIXPCScriptable::WANT_ENUMERATE | \ + nsIXPCScriptable::WANT_EQUALITY | \ + nsIXPCScriptable::WANT_OUTER_OBJECT | \ + nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE) + #define NODE_SCRIPTABLE_FLAGS \ ((DOM_DEFAULT_SCRIPTABLE_FLAGS | \ nsIXPCScriptable::WANT_PRECREATE | \ @@ -480,16 +492,7 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(Window, nsWindowSH, DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_GETPROPERTY | - nsIXPCScriptable::WANT_SETPROPERTY | - nsIXPCScriptable::WANT_PRECREATE | - nsIXPCScriptable::WANT_FINALIZE | - nsIXPCScriptable::WANT_ADDPROPERTY | - nsIXPCScriptable::WANT_DELPROPERTY | - nsIXPCScriptable::WANT_ENUMERATE | - nsIXPCScriptable::WANT_EQUALITY | - nsIXPCScriptable::WANT_OUTER_OBJECT | - nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE) + WINDOW_SCRIPTABLE_FLAGS) // Don't allow modifications to Location.prototype NS_DEFINE_CLASSINFO_DATA(Location, nsLocationSH, @@ -789,15 +792,7 @@ static nsDOMClassInfoData sClassInfoData[] = { // DOM Chrome Window class. NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH, DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_GETPROPERTY | - nsIXPCScriptable::WANT_SETPROPERTY | - nsIXPCScriptable::WANT_NEWRESOLVE | - nsIXPCScriptable::WANT_PRECREATE | - nsIXPCScriptable::WANT_FINALIZE | - nsIXPCScriptable::WANT_ADDPROPERTY | - nsIXPCScriptable::WANT_DELPROPERTY | - nsIXPCScriptable::WANT_ENUMERATE | - nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE) + WINDOW_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(CSSRGBColor, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1305,9 +1300,8 @@ nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED); nsCOMPtr holder; - - nsresult rv = sXPConnect->WrapNative(cx, scope, native, aIID, - getter_AddRefs(holder)); + nsresult rv = sXPConnect->WrapNative(cx, GetGlobalJSObject(cx, scope), + native, aIID, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); JSObject* obj = nsnull; @@ -3158,8 +3152,8 @@ nsDOMClassInfo::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if ((mode_type == JSACC_WATCH || mode_type == JSACC_PROTO || - mode_type == JSACC_PARENT) - && sSecMan) { + mode_type == JSACC_PARENT) && + sSecMan) { JSObject *real_obj = nsnull; nsresult rv = wrapper->GetJSObject(&real_obj); @@ -3683,8 +3677,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj, if (result) { jsval v; - nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), result, - NS_GET_IID(nsISupports), &v); + nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), &v); NS_ENSURE_SUCCESS(rv, rv); if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(jsstr), @@ -3863,7 +3856,14 @@ nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // child frame, wrap the child frame without doing a security // check and return. - rv = WrapNative(cx, obj, frame, NS_GET_IID(nsIDOMWindow), vp); + nsGlobalWindow *frameWin = (nsGlobalWindow *)frame.get(); + nsGlobalWindow *frameInnerWin = + frameWin->GetCurrentInnerWindowInternal(); + + NS_ASSERTION(frameInnerWin, "No inner window in frame window!"); + + rv = WrapNative(cx, frameInnerWin->GetGlobalJSObject(), frame, + NS_GET_IID(nsIDOMWindow), vp); } return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; @@ -4111,7 +4111,7 @@ nsWindowSH::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *innerObj; if (innerWin && (innerObj = innerWin->GetGlobalJSObject())) { #ifdef DEBUG_SH_FORWARDING - printf(" --- Forwarding add to inner window %p\n", (void *)innerWin); + printf(" --- Forwarding del to inner window %p\n", (void *)innerWin); #endif // Forward the del to the inner object @@ -4194,8 +4194,8 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx, return rv; } - rv = nsDOMGenericSH::WrapNative(cx, GetGlobalJSObject(cx, obj), native, - NS_GET_IID(nsISupports), rval); + rv = nsDOMGenericSH::WrapNative(cx, obj, native, NS_GET_IID(nsISupports), + rval); return NS_SUCCEEDED(rv) ? JS_TRUE : JS_FALSE; } @@ -4918,7 +4918,7 @@ NS_DOMClassInfo_PreserveWrapper(nsIXPConnectWrappedNative *aWrapper) // static nsresult -nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx, +nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, JSObject *obj, JSString *str, PRUint32 flags, PRBool *did_resolve) { @@ -5239,7 +5239,18 @@ nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx, prop_val = OBJECT_TO_JSVAL(prop_obj); } else { - rv = WrapNative(cx, obj, native, NS_GET_IID(nsISupports), &prop_val); + JSObject *scope; + + if (aWin->IsOuterWindow()) { + nsGlobalWindow *inner = aWin->GetCurrentInnerWindowInternal(); + NS_ENSURE_TRUE(inner, NS_ERROR_UNEXPECTED); + + scope = inner->GetGlobalJSObject(); + } else { + scope = aWin->GetGlobalJSObject(); + } + + rv = WrapNative(cx, scope, native, NS_GET_IID(nsISupports), &prop_val); } NS_ENSURE_SUCCESS(rv, rv); @@ -5258,7 +5269,7 @@ nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx, do_CreateInstance(name_struct->mCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsIScriptContext *context = global->GetContext(); + nsIScriptContext *context = aWin->GetContext(); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); rv = nameset->InitializeNameSet(context); @@ -5310,9 +5321,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // 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 while the - // document before the document load stated will be visible to - // the document once it's loaded, assuming same origin etc. + // 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()) { @@ -5321,6 +5332,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // Grab the new inner window. innerWin = win->GetCurrentInnerWindowInternal(); + + if (!innerWin) { + return NS_ERROR_OUT_OF_MEMORY; + } } } @@ -5602,12 +5617,11 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, } if (!scope) { - scope = obj; + wrapper->GetJSObject(&scope); } jsval v; - rv = WrapNative(cx, GetGlobalJSObject(cx, scope), location, - NS_GET_IID(nsIDOMLocation), &v); + rv = WrapNative(cx, scope, location, NS_GET_IID(nsIDOMLocation), &v); NS_ENSURE_SUCCESS(rv, rv); sDoSecurityCheckInAddProperty = PR_FALSE; @@ -5677,13 +5691,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, rv = WrapNative(cx, obj, document, NS_GET_IID(nsIDOMDocument), &v); NS_ENSURE_SUCCESS(rv, rv); - if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str), - ::JS_GetStringLength(str), v, nsnull, - nsnull, JSPROP_READONLY | JSPROP_ENUMERATE)) { - return NS_ERROR_FAILURE; - } - - *objp = obj; + // The PostCreate hook for the document will handle defining the + // property *objp = obj; return NS_OK; } @@ -5691,6 +5700,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if (id == sWindow_id) { // window should *always* be the outer window object. win = win->GetOuterWindowInternal(); + NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str), ::JS_GetStringLength(str), @@ -5763,9 +5773,15 @@ nsWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx, nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper); + NS_ASSERTION(win->IsOuterWindow(), + "Inner window detected in Equality hook!"); + nsCOMPtr other = do_QueryWrappedNative(other_wrapper); if (other) { + NS_ASSERTION(other->IsOuterWindow(), + "Inner window detected in Equality hook!"); + *bp = win->GetOuterWindow() == other->GetOuterWindow(); } @@ -5776,10 +5792,22 @@ NS_IMETHODIMP nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, JSObject * *_retval) { - nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper); + nsGlobalWindow *win = + nsGlobalWindow::FromWrapper(wrapper)->GetOuterWindowInternal(); - // Always return the outer window. - *_retval = win->GetOuterWindowInternal()->GetGlobalJSObject(); + if (win) { + // Return the outer window. + + *_retval = win->GetGlobalJSObject(); + } else { + // If we no longer have an outer window. No code should ever be + // running on a window w/o an outer, which means this hook should + // never be called when we have no outer. But just in case, return + // null to prevent leaking an inner window to code in a different + // window. + + *_retval = nsnull; + } return NS_OK; } @@ -5839,8 +5867,6 @@ NS_IMETHODIMP nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj) { - // XXXjst: Add code that asserts the the scope is an inner window - nsCOMPtr content(do_QueryInterface(nativeObj)); nsCOMPtr doc; @@ -6401,8 +6427,7 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, NS_ENSURE_SUCCESS(rv, rv); if (array_item) { - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), array_item, - NS_GET_IID(nsISupports), vp); + rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp); NS_ENSURE_SUCCESS(rv, rv); rv = NS_SUCCESS_I_DID_SOMETHING; @@ -6440,8 +6465,7 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, NS_ENSURE_SUCCESS(rv, rv); if (item) { - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), item, - NS_GET_IID(nsISupports), vp); + rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp); NS_ENSURE_SUCCESS(rv, rv); rv = NS_SUCCESS_I_DID_SOMETHING; @@ -6701,8 +6725,7 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, jsval v; - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), location, - NS_GET_IID(nsIDOMLocation), &v); + rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), &v); NS_ENSURE_SUCCESS(rv, rv); sDoSecurityCheckInAddProperty = PR_FALSE; @@ -6809,8 +6832,7 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, rv = location->SetHref(nsDependentJSString(val)); NS_ENSURE_SUCCESS(rv, rv); - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), location, - NS_GET_IID(nsIDOMLocation), vp); + rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp); return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; } } @@ -6854,8 +6876,7 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if (SameCOMIdentity(doc, currentDoc)) { jsval winVal; - nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), win, - NS_GET_IID(nsIDOMWindow), &winVal); + nsresult rv = WrapNative(cx, obj, win, NS_GET_IID(nsIDOMWindow), &winVal); NS_ENSURE_SUCCESS(rv, rv); NS_NAMED_LITERAL_STRING(doc_str, "document"); @@ -6956,8 +6977,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc, return JS_FALSE; } - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), retval, - NS_GET_IID(nsIDOMDocument), rval); + rv = WrapNative(cx, obj, retval, NS_GET_IID(nsIDOMDocument), rval); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!"); return NS_SUCCEEDED(rv); @@ -7701,8 +7721,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper, if (result) { // Wrap result, result can be either an element or a list of // elements - nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), result, - NS_GET_IID(nsISupports), vp); + nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp); return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; } @@ -7716,8 +7735,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper, form->GetElementAt(n, getter_AddRefs(control)); if (control) { - nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), control, - NS_GET_IID(nsISupports), vp); + nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp); return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; } } @@ -7822,8 +7840,7 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper, options->Item(n, getter_AddRefs(node)); - rv = WrapNative(cx, GetGlobalJSObject(cx, obj), node, - NS_GET_IID(nsIDOMNode), vp); + rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp); if (NS_SUCCEEDED(rv)) { rv = NS_SUCCESS_I_DID_SOMETHING; } @@ -8417,8 +8434,7 @@ nsHTMLPluginObjElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, } nsCOMPtr holder; - rv = sXPConnect->WrapNative(cx, GetGlobalJSObject(cx, obj), pi, *iid, - getter_AddRefs(holder)); + rv = sXPConnect->WrapNative(cx, obj, pi, *iid, getter_AddRefs(holder)); if (NS_SUCCEEDED(rv)) { JSObject* ifaceObj; diff --git a/mozilla/dom/src/base/nsDOMClassInfo.h b/mozilla/dom/src/base/nsDOMClassInfo.h index a2164f0d546..0ef99cb43e5 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.h +++ b/mozilla/dom/src/base/nsDOMClassInfo.h @@ -53,6 +53,7 @@ class nsIDOMNode; class nsIDOMNodeList; class nsIDOMDocument; class nsIHTMLDocument; +class nsGlobalWindow; struct nsDOMClassInfoData; @@ -412,7 +413,7 @@ protected: { } - static nsresult GlobalResolve(nsIScriptGlobalObject *aGlobal, JSContext *cx, + static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, JSObject *obj, JSString *str, PRUint32 flags, PRBool *did_resolve); diff --git a/mozilla/dom/src/base/nsFocusController.cpp b/mozilla/dom/src/base/nsFocusController.cpp index c5cbfd84f7b..f0a7655374d 100644 --- a/mozilla/dom/src/base/nsFocusController.cpp +++ b/mozilla/dom/src/base/nsFocusController.cpp @@ -409,13 +409,13 @@ nsFocusController::GetControllerForCommand(const char * aCommand, *_retval = nsnull; nsCOMPtr controllers; + nsCOMPtr controller; + GetControllers(getter_AddRefs(controllers)); if(controllers) { - nsCOMPtr controller; controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller)); if(controller) { - *_retval = controller; - NS_ADDREF(*_retval); + controller.swap(*_retval); return NS_OK; } } @@ -441,12 +441,10 @@ nsFocusController::GetControllerForCommand(const char * aCommand, nsCOMPtr controllers2; domWindow->GetControllers(getter_AddRefs(controllers2)); if(controllers2) { - nsCOMPtr controller; controllers2->GetControllerForCommand(aCommand, getter_AddRefs(controller)); if(controller) { - *_retval = controller; - NS_ADDREF(*_retval); + controller.swap(*_retval); return NS_OK; } } diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index cc88a0e103a..b540ecd4d9a 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -180,38 +180,61 @@ PRInt32 gTimeoutCnt = 0; #define DOM_MIN_TIMEOUT_VALUE 10 // 10ms -#define FORWARD_TO_OUTER(method, args) \ +#define FORWARD_TO_OUTER(method, args, err_rval) \ PR_BEGIN_MACRO \ if (IsInnerWindow()) { \ - return GetOuterWindowInternal()->method args; \ + nsGlobalWindow *outer = GetOuterWindowInternal(); \ + if (!outer) { \ + NS_WARNING("No outer window available!"); \ + return err_rval; \ + } \ + return outer->method args; \ } \ PR_END_MACRO #define FORWARD_TO_OUTER_VOID(method, args) \ PR_BEGIN_MACRO \ if (IsInnerWindow()) { \ - GetOuterWindowInternal()->method args; \ + nsGlobalWindow *outer = GetOuterWindowInternal(); \ + if (!outer) { \ + NS_WARNING("No outer window available!"); \ + return; \ + } \ + outer->method args; \ return; \ } \ PR_END_MACRO -#define FORWARD_TO_OUTER_CHROME(method, args) \ +#define FORWARD_TO_OUTER_CHROME(method, args, err_rval) \ PR_BEGIN_MACRO \ if (IsInnerWindow()) { \ - return ((nsGlobalChromeWindow *)mOuterWindow)->method args; \ + nsGlobalWindow *outer = GetOuterWindowInternal(); \ + if (!outer) { \ + NS_WARNING("No outer window available!"); \ + return err_rval; \ + } \ + return ((nsGlobalChromeWindow *)outer)->method args; \ } \ PR_END_MACRO -#define FORWARD_TO_INNER(method, args) \ +#define FORWARD_TO_INNER(method, args, err_rval) \ PR_BEGIN_MACRO \ - if (mInnerWindow) { \ + if (IsOuterWindow()) { \ + if (!mInnerWindow) { \ + NS_WARNING("No inner window available!"); \ + return err_rval; \ + } \ return GetCurrentInnerWindowInternal()->method args; \ } \ PR_END_MACRO #define FORWARD_TO_INNER_VOID(method, args) \ PR_BEGIN_MACRO \ - if (mInnerWindow) { \ + if (IsOuterWindow()) { \ + if (!mInnerWindow) { \ + NS_WARNING("No inner window available!"); \ + return; \ + } \ GetCurrentInnerWindowInternal()->method args; \ return; \ } \ @@ -258,13 +281,13 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) mGlobalObjectOwner(nsnull), mDocShell(nsnull) { - // Window object's are also PRCList's, the list is for keeping all - // innter windows reachable from the outer so that the proper - // cleanup can be done on shutdown. + // Initialize the PRCList (this). PR_INIT_CLIST(this); if (aOuterWindow) { - PR_INSERT_AFTER(aOuterWindow, this); + // |this| is an inner window, add this inner window to the outer + // |window list of inners. + PR_INSERT_AFTER(this, aOuterWindow); } // We could have failed the first time through trying @@ -291,19 +314,13 @@ nsGlobalWindow::~nsGlobalWindow() printf("--DOMWINDOW == %d\n", gRefCnt); #endif - nsGlobalWindow *outer = GetOuterWindowInternal(); - if (outer->mInnerWindow == this) { - outer->mInnerWindow = nsnull; - } - - if (IsOuterWindow() && !PR_CLIST_IS_EMPTY(this)) { - // An outer window is destroyed with inner windows still alive, - // iterate through the inner windows and null out their back - // pointer to this outer, and pull them out of the list of inner - // windows. - - nsGlobalWindow *w = (nsGlobalWindow *)PR_LIST_HEAD(this); + if (IsOuterWindow()) { + // An outer window is destroyed with inner windows still possibly + // alive, iterate through the inner windows and null out their + // back pointer to this outer, and pull them out of the list of + // inner windows. + nsGlobalWindow *w; while ((w = (nsGlobalWindow *)PR_LIST_HEAD(this)) != this) { NS_ASSERTION(w->mOuterWindow == this, "Uh, bad outer window pointer?"); @@ -316,10 +333,19 @@ nsGlobalWindow::~nsGlobalWindow() // list if inner windows. PR_REMOVE_LINK(this); + + // If our outer window's inner window is this window, null out the + // outer window's reference to this window that's being deleted. + nsGlobalWindow *outer = GetOuterWindowInternal(); + if (outer && outer->mInnerWindow == this) { + outer->mInnerWindow = nsnull; + } } mDocument = nsnull; // Forces Release + NS_ASSERTION(!mArguments, "mArguments wasn't cleaned up properly!"); + CleanUp(); } @@ -429,6 +455,7 @@ void nsGlobalWindow::SetContext(nsIScriptContext* aContext) { NS_ASSERTION(IsOuterWindow(), "Uh, SetContext() called on inner window!"); + NS_ASSERTION(!aContext || !mContext, "Bad call to SetContext()!"); // if setting the context to null, then we won't get to clean up the // named reference, so do it now @@ -460,7 +487,7 @@ nsGlobalWindow::SetContext(nsIScriptContext* aContext) nsIScriptContext * nsGlobalWindow::GetContext() { - FORWARD_TO_OUTER(GetContext, ()); + FORWARD_TO_OUTER(GetContext, (), nsnull); return mContext; } @@ -529,6 +556,10 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument, "mDocumentPrincipal prematurely set!"); if (!aIsInternalCall && IsInnerWindow()) { + if (!mOuterWindow) { + return NS_ERROR_NOT_INITIALIZED; + } + return GetOuterWindowInternal()->SetNewDocument(aDocument, aRemoveEventListeners, aClearScopeHint, PR_TRUE); @@ -599,20 +630,17 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument, } } - /* No mDocShell means we've either an inner window or we're already + /* No mDocShell means we're either an inner window or we're already been partially closed down. When that happens, setting status isn't a big requirement, so don't. (Doesn't happen under normal circumstances, but bug 49615 describes a case.) */ - /* We only want to do this when we're setting a new document rather - than going away. See bug 61840. */ - if (mDocShell) { - SetStatus(EmptyString()); - SetDefaultStatus(EmptyString()); - } + SetStatus(EmptyString()); + SetDefaultStatus(EmptyString()); - // If we're in the middle of shutdown, nsContentUtils may have - // already been notified of shutdown and may return null here. + // This code should not be called during shutdown any more (now that + // we don't ever call SetNewDocument(nsnull), so no need to null + // check xpc here. nsIXPConnect *xpc = nsContentUtils::XPConnect(); PRBool reUseInnerWindow = PR_FALSE; @@ -714,7 +742,7 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument, scx->WillInitializeContext(); } - if (xpc && IsOuterWindow()) { + if (IsOuterWindow()) { nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal(); // In case we're not removing event listeners, move the event @@ -868,8 +896,9 @@ nsGlobalWindow::SetNewDocument(nsIDOMDocument* aDocument, JSObject *nav; navigatorHolder->GetJSObject(&nav); - jsval navVal = OBJECT_TO_JSVAL(nav); - ::JS_SetProperty(cx, newInnerWindow->mJSObject, "navigator", &navVal); + ::JS_DefineProperty(cx, newInnerWindow->mJSObject, "navigator", + OBJECT_TO_JSVAL(nav), nsnull, nsnull, + JSPROP_ENUMERATE); } newInnerWindow->mListenerManager = listenerManager; @@ -919,7 +948,7 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell) // finalized by the JS GC). if (!aDocShell && mContext) { - ClearAllTimeouts(); + NS_ASSERTION(!mTimeouts, "Uh, outer window holds timeouts!"); JSContext *cx = (JSContext *)mContext->GetNativeContext(); @@ -949,18 +978,21 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell) currentInner->mDocumentPrincipal = doc->GetPrincipal(); } - // Release the current inner window's document references. - currentInner->mDocument = nsnull; + // Release the current inner window's document reference + // through the global scope polluter. nsWindowSH::InvalidateGlobalScopePolluter(cx, currentInner->mJSObject); } + // Release the current inner window's document references. + currentInner->mDocument = nsnull; + nsCOMPtr doc = do_QueryInterface(mDocument); // Remember the document's principal. mDocumentPrincipal = doc->GetPrincipal(); - // Release the our document reference + // Release our document reference mDocument = nsnull; if (mJSObject) { @@ -1084,7 +1116,7 @@ nsGlobalWindow::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) nsIScriptGlobalObjectOwner * nsGlobalWindow::GetGlobalObjectOwner() { - FORWARD_TO_OUTER(GetGlobalObjectOwner, ()); + FORWARD_TO_OUTER(GetGlobalObjectOwner, (), nsnull); return mGlobalObjectOwner; } @@ -1095,7 +1127,8 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, nsEventStatus* aEventStatus) { FORWARD_TO_INNER(HandleDOMEvent, - (aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus)); + (aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus), + NS_ERROR_NOT_INITIALIZED); nsGlobalWindow *outer = GetOuterWindowInternal(); @@ -1142,7 +1175,7 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, // if the window is deactivated while in full screen mode, // restore OS chrome, and hide it again upon re-activation - if (outer->mFullScreen && (NS_EVENT_FLAG_BUBBLE & aFlags)) { + if (outer && outer->mFullScreen && (NS_EVENT_FLAG_BUBBLE & aFlags)) { if (aEvent->message == NS_DEACTIVATE || aEvent->message == NS_ACTIVATE) { nsCOMPtr fullScreen = do_GetService("@mozilla.org/browser/fullscreen;1"); @@ -1170,7 +1203,8 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, // Execute bindingdetached handlers before we tear ourselves // down. - if (aEvent->message == NS_PAGE_UNLOAD && mDocument && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) { + if (aEvent->message == NS_PAGE_UNLOAD && mDocument && + !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) { nsCOMPtr doc(do_QueryInterface(mDocument)); doc->BindingManager()->ExecuteDetachedHandlers(); } @@ -1196,13 +1230,14 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, } // Local handling stage - if ((aEvent->message != NS_BLUR_CONTENT || !GetBlurSuppression()) && + if (outer && (aEvent->message != NS_BLUR_CONTENT || !GetBlurSuppression()) && mListenerManager && - !(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags))) { + !((NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags) && + (NS_EVENT_FLAG_BUBBLE & aFlags) && + !(NS_EVENT_FLAG_INIT & aFlags))) { aEvent->flags |= aFlags; mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, - GetOuterWindowInternal(), aFlags, - aEventStatus); + outer, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -1225,7 +1260,8 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, (aEvent->message != NS_FOCUS_CONTENT) && (aEvent->message != NS_BLUR_CONTENT)) { mChromeEventHandler->HandleChromeEvent(aPresContext, aEvent, - aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK, + aDOMEvent, + aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus); } } @@ -1321,7 +1357,7 @@ nsGlobalWindow::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) nsresult nsGlobalWindow::SetNewArguments(JSObject *aArguments) { - FORWARD_TO_OUTER(SetNewArguments, (aArguments)); + FORWARD_TO_OUTER(SetNewArguments, (aArguments), NS_ERROR_NOT_INITIALIZED); JSContext *cx; NS_ENSURE_TRUE(aArguments && mContext && @@ -1388,6 +1424,11 @@ nsGlobalWindow::GetPrincipal() NS_IMETHODIMP nsGlobalWindow::GetDocument(nsIDOMDocument** aDocument) { + // This method *should* forward calls to the outer window, but since + // there's nothing here that *depends* on anything in the outer + // (GetDocShellInternal() eliminates that dependency), we won't do + // that to avoid the extra virtual function call. + // lazily instantiate an about:blank document if necessary, and if // we have what it takes to do so. Note that domdoc here is the same // thing as our mDocument, but we don't have to explicitly set the @@ -1409,7 +1450,7 @@ nsGlobalWindow::GetDocument(nsIDOMDocument** aDocument) NS_IMETHODIMP nsGlobalWindow::GetWindow(nsIDOMWindowInternal** aWindow) { - FORWARD_TO_OUTER(GetWindow, (aWindow)); + FORWARD_TO_OUTER(GetWindow, (aWindow), NS_ERROR_NOT_INITIALIZED); *aWindow = NS_STATIC_CAST(nsIDOMWindowInternal *, this); NS_ADDREF(*aWindow); @@ -1419,7 +1460,7 @@ nsGlobalWindow::GetWindow(nsIDOMWindowInternal** aWindow) NS_IMETHODIMP nsGlobalWindow::GetSelf(nsIDOMWindowInternal** aWindow) { - FORWARD_TO_OUTER(GetSelf, (aWindow)); + FORWARD_TO_OUTER(GetSelf, (aWindow), NS_ERROR_NOT_INITIALIZED); *aWindow = NS_STATIC_CAST(nsIDOMWindowInternal *, this); NS_ADDREF(*aWindow); @@ -1429,7 +1470,7 @@ nsGlobalWindow::GetSelf(nsIDOMWindowInternal** aWindow) NS_IMETHODIMP nsGlobalWindow::GetNavigator(nsIDOMNavigator** aNavigator) { - FORWARD_TO_OUTER(GetNavigator, (aNavigator)); + FORWARD_TO_OUTER(GetNavigator, (aNavigator), NS_ERROR_NOT_INITIALIZED); *aNavigator = nsnull; @@ -1448,7 +1489,7 @@ nsGlobalWindow::GetNavigator(nsIDOMNavigator** aNavigator) NS_IMETHODIMP nsGlobalWindow::GetScreen(nsIDOMScreen** aScreen) { - FORWARD_TO_OUTER(GetScreen, (aScreen)); + FORWARD_TO_OUTER(GetScreen, (aScreen), NS_ERROR_NOT_INITIALIZED); *aScreen = nsnull; @@ -1467,7 +1508,7 @@ nsGlobalWindow::GetScreen(nsIDOMScreen** aScreen) NS_IMETHODIMP nsGlobalWindow::GetHistory(nsIDOMHistory** aHistory) { - FORWARD_TO_OUTER(GetHistory, (aHistory)); + FORWARD_TO_OUTER(GetHistory, (aHistory), NS_ERROR_NOT_INITIALIZED); *aHistory = nsnull; @@ -1485,7 +1526,7 @@ nsGlobalWindow::GetHistory(nsIDOMHistory** aHistory) NS_IMETHODIMP nsGlobalWindow::GetParent(nsIDOMWindow** aParent) { - FORWARD_TO_OUTER(GetParent, (aParent)); + FORWARD_TO_OUTER(GetParent, (aParent), NS_ERROR_NOT_INITIALIZED); *aParent = nsnull; if (!mDocShell) @@ -1512,7 +1553,7 @@ nsGlobalWindow::GetParent(nsIDOMWindow** aParent) NS_IMETHODIMP nsGlobalWindow::GetTop(nsIDOMWindow** aTop) { - FORWARD_TO_OUTER(GetTop, (aTop)); + FORWARD_TO_OUTER(GetTop, (aTop), NS_ERROR_NOT_INITIALIZED); nsresult ret = NS_OK; @@ -1534,7 +1575,7 @@ nsGlobalWindow::GetTop(nsIDOMWindow** aTop) NS_IMETHODIMP nsGlobalWindow::GetContent(nsIDOMWindow** aContent) { - FORWARD_TO_OUTER(GetContent, (aContent)); + FORWARD_TO_OUTER(GetContent, (aContent), NS_ERROR_NOT_INITIALIZED); *aContent = nsnull; @@ -1576,7 +1617,7 @@ nsGlobalWindow::GetContent(nsIDOMWindow** aContent) NS_IMETHODIMP nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt) { - FORWARD_TO_OUTER(GetPrompter, (aPrompt)); + FORWARD_TO_OUTER(GetPrompter, (aPrompt), NS_ERROR_NOT_INITIALIZED); if (!mDocShell) return NS_ERROR_FAILURE; @@ -1591,7 +1632,7 @@ nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt) NS_IMETHODIMP nsGlobalWindow::GetMenubar(nsIDOMBarProp** aMenubar) { - FORWARD_TO_OUTER(GetMenubar, (aMenubar)); + FORWARD_TO_OUTER(GetMenubar, (aMenubar), NS_ERROR_NOT_INITIALIZED); *aMenubar = nsnull; @@ -1615,7 +1656,7 @@ nsGlobalWindow::GetMenubar(nsIDOMBarProp** aMenubar) NS_IMETHODIMP nsGlobalWindow::GetToolbar(nsIDOMBarProp** aToolbar) { - FORWARD_TO_OUTER(GetToolbar, (aToolbar)); + FORWARD_TO_OUTER(GetToolbar, (aToolbar), NS_ERROR_NOT_INITIALIZED); *aToolbar = nsnull; @@ -1639,7 +1680,7 @@ nsGlobalWindow::GetToolbar(nsIDOMBarProp** aToolbar) NS_IMETHODIMP nsGlobalWindow::GetLocationbar(nsIDOMBarProp** aLocationbar) { - FORWARD_TO_OUTER(GetLocationbar, (aLocationbar)); + FORWARD_TO_OUTER(GetLocationbar, (aLocationbar), NS_ERROR_NOT_INITIALIZED); *aLocationbar = nsnull; @@ -1663,7 +1704,7 @@ nsGlobalWindow::GetLocationbar(nsIDOMBarProp** aLocationbar) NS_IMETHODIMP nsGlobalWindow::GetPersonalbar(nsIDOMBarProp** aPersonalbar) { - FORWARD_TO_OUTER(GetPersonalbar, (aPersonalbar)); + FORWARD_TO_OUTER(GetPersonalbar, (aPersonalbar), NS_ERROR_NOT_INITIALIZED); *aPersonalbar = nsnull; @@ -1687,7 +1728,7 @@ nsGlobalWindow::GetPersonalbar(nsIDOMBarProp** aPersonalbar) NS_IMETHODIMP nsGlobalWindow::GetStatusbar(nsIDOMBarProp** aStatusbar) { - FORWARD_TO_OUTER(GetStatusbar, (aStatusbar)); + FORWARD_TO_OUTER(GetStatusbar, (aStatusbar), NS_ERROR_NOT_INITIALIZED); *aStatusbar = nsnull; @@ -1711,7 +1752,7 @@ nsGlobalWindow::GetStatusbar(nsIDOMBarProp** aStatusbar) NS_IMETHODIMP nsGlobalWindow::GetScrollbars(nsIDOMBarProp** aScrollbars) { - FORWARD_TO_OUTER(GetScrollbars, (aScrollbars)); + FORWARD_TO_OUTER(GetScrollbars, (aScrollbars), NS_ERROR_NOT_INITIALIZED); *aScrollbars = nsnull; @@ -1741,7 +1782,7 @@ nsGlobalWindow::GetDirectories(nsIDOMBarProp** aDirectories) NS_IMETHODIMP nsGlobalWindow::GetClosed(PRBool* aClosed) { - FORWARD_TO_OUTER(GetClosed, (aClosed)); + FORWARD_TO_OUTER(GetClosed, (aClosed), NS_ERROR_NOT_INITIALIZED); // If someone called close(), or if we don't have a docshell, we're // closed. @@ -1753,7 +1794,7 @@ nsGlobalWindow::GetClosed(PRBool* aClosed) NS_IMETHODIMP nsGlobalWindow::GetFrames(nsIDOMWindowCollection** aFrames) { - FORWARD_TO_OUTER(GetFrames, (aFrames)); + FORWARD_TO_OUTER(GetFrames, (aFrames), NS_ERROR_NOT_INITIALIZED); *aFrames = nsnull; @@ -1772,7 +1813,7 @@ nsGlobalWindow::GetFrames(nsIDOMWindowCollection** aFrames) NS_IMETHODIMP nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto) { - FORWARD_TO_OUTER(GetCrypto, (aCrypto)); + FORWARD_TO_OUTER(GetCrypto, (aCrypto), NS_ERROR_NOT_INITIALIZED); if (!mCrypto) { mCrypto = do_CreateInstance(kCryptoContractID); @@ -1786,7 +1827,7 @@ nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto) NS_IMETHODIMP nsGlobalWindow::GetPkcs11(nsIDOMPkcs11** aPkcs11) { - FORWARD_TO_OUTER(GetPkcs11, (aPkcs11)); + FORWARD_TO_OUTER(GetPkcs11, (aPkcs11), NS_ERROR_NOT_INITIALIZED); if (!mPkcs11) { mPkcs11 = do_CreateInstance(kPkcs11ContractID); @@ -1800,7 +1841,7 @@ nsGlobalWindow::GetPkcs11(nsIDOMPkcs11** aPkcs11) NS_IMETHODIMP nsGlobalWindow::GetControllers(nsIControllers** aResult) { - FORWARD_TO_OUTER(GetControllers, (aResult)); + FORWARD_TO_OUTER(GetControllers, (aResult), NS_ERROR_NOT_INITIALIZED); if (!mControllers) { nsresult rv; @@ -1827,7 +1868,7 @@ nsGlobalWindow::GetControllers(nsIControllers** aResult) NS_IMETHODIMP nsGlobalWindow::GetOpener(nsIDOMWindowInternal** aOpener) { - FORWARD_TO_OUTER(GetOpener, (aOpener)); + FORWARD_TO_OUTER(GetOpener, (aOpener), NS_ERROR_NOT_INITIALIZED); *aOpener = nsnull; // First, check if we were called from a privileged chrome script @@ -1866,7 +1907,7 @@ nsGlobalWindow::GetOpener(nsIDOMWindowInternal** aOpener) NS_IMETHODIMP nsGlobalWindow::SetOpener(nsIDOMWindowInternal* aOpener) { - FORWARD_TO_OUTER(SetOpener, (aOpener)); + FORWARD_TO_OUTER(SetOpener, (aOpener), NS_ERROR_NOT_INITIALIZED); // check if we were called from a privileged chrome script. // If not, opener is settable only to null. @@ -1884,7 +1925,7 @@ nsGlobalWindow::SetOpener(nsIDOMWindowInternal* aOpener) NS_IMETHODIMP nsGlobalWindow::GetStatus(nsAString& aStatus) { - FORWARD_TO_OUTER(GetStatus, (aStatus)); + FORWARD_TO_OUTER(GetStatus, (aStatus), NS_ERROR_NOT_INITIALIZED); aStatus = mStatus; return NS_OK; @@ -1893,7 +1934,7 @@ nsGlobalWindow::GetStatus(nsAString& aStatus) NS_IMETHODIMP nsGlobalWindow::SetStatus(const nsAString& aStatus) { - FORWARD_TO_OUTER(SetStatus, (aStatus)); + FORWARD_TO_OUTER(SetStatus, (aStatus), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_status_change is true, @@ -1919,7 +1960,8 @@ nsGlobalWindow::SetStatus(const nsAString& aStatus) NS_IMETHODIMP nsGlobalWindow::GetDefaultStatus(nsAString& aDefaultStatus) { - FORWARD_TO_OUTER(GetDefaultStatus, (aDefaultStatus)); + FORWARD_TO_OUTER(GetDefaultStatus, (aDefaultStatus), + NS_ERROR_NOT_INITIALIZED); aDefaultStatus = mDefaultStatus; return NS_OK; @@ -1928,7 +1970,8 @@ nsGlobalWindow::GetDefaultStatus(nsAString& aDefaultStatus) NS_IMETHODIMP nsGlobalWindow::SetDefaultStatus(const nsAString& aDefaultStatus) { - FORWARD_TO_OUTER(SetDefaultStatus, (aDefaultStatus)); + FORWARD_TO_OUTER(SetDefaultStatus, (aDefaultStatus), + NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_status_change is true, @@ -1954,7 +1997,7 @@ nsGlobalWindow::SetDefaultStatus(const nsAString& aDefaultStatus) NS_IMETHODIMP nsGlobalWindow::GetName(nsAString& aName) { - FORWARD_TO_OUTER(GetName, (aName)); + FORWARD_TO_OUTER(GetName, (aName), NS_ERROR_NOT_INITIALIZED); nsXPIDLString name; nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); @@ -1968,7 +2011,7 @@ nsGlobalWindow::GetName(nsAString& aName) NS_IMETHODIMP nsGlobalWindow::SetName(const nsAString& aName) { - FORWARD_TO_OUTER(SetName, (aName)); + FORWARD_TO_OUTER(SetName, (aName), NS_ERROR_NOT_INITIALIZED); nsresult result = NS_OK; nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); @@ -1980,7 +2023,7 @@ nsGlobalWindow::SetName(const nsAString& aName) NS_IMETHODIMP nsGlobalWindow::GetInnerWidth(PRInt32* aInnerWidth) { - FORWARD_TO_OUTER(GetInnerWidth, (aInnerWidth)); + FORWARD_TO_OUTER(GetInnerWidth, (aInnerWidth), NS_ERROR_NOT_INITIALIZED); EnsureSizeUpToDate(); @@ -1996,7 +2039,7 @@ nsGlobalWindow::GetInnerWidth(PRInt32* aInnerWidth) NS_IMETHODIMP nsGlobalWindow::SetInnerWidth(PRInt32 aInnerWidth) { - FORWARD_TO_OUTER(SetInnerWidth, (aInnerWidth)); + FORWARD_TO_OUTER(SetInnerWidth, (aInnerWidth), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2028,7 +2071,7 @@ nsGlobalWindow::SetInnerWidth(PRInt32 aInnerWidth) NS_IMETHODIMP nsGlobalWindow::GetInnerHeight(PRInt32* aInnerHeight) { - FORWARD_TO_OUTER(GetInnerHeight, (aInnerHeight)); + FORWARD_TO_OUTER(GetInnerHeight, (aInnerHeight), NS_ERROR_NOT_INITIALIZED); EnsureSizeUpToDate(); @@ -2044,7 +2087,7 @@ nsGlobalWindow::GetInnerHeight(PRInt32* aInnerHeight) NS_IMETHODIMP nsGlobalWindow::SetInnerHeight(PRInt32 aInnerHeight) { - FORWARD_TO_OUTER(SetInnerHeight, (aInnerHeight)); + FORWARD_TO_OUTER(SetInnerHeight, (aInnerHeight), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2077,7 +2120,7 @@ nsGlobalWindow::SetInnerHeight(PRInt32 aInnerHeight) NS_IMETHODIMP nsGlobalWindow::GetOuterWidth(PRInt32* aOuterWidth) { - FORWARD_TO_OUTER(GetOuterWidth, (aOuterWidth)); + FORWARD_TO_OUTER(GetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED); nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); @@ -2098,7 +2141,7 @@ nsGlobalWindow::GetOuterWidth(PRInt32* aOuterWidth) NS_IMETHODIMP nsGlobalWindow::SetOuterWidth(PRInt32 aOuterWidth) { - FORWARD_TO_OUTER(SetOuterWidth, (aOuterWidth)); + FORWARD_TO_OUTER(SetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2128,7 +2171,7 @@ nsGlobalWindow::SetOuterWidth(PRInt32 aOuterWidth) NS_IMETHODIMP nsGlobalWindow::GetOuterHeight(PRInt32* aOuterHeight) { - FORWARD_TO_OUTER(GetOuterHeight, (aOuterHeight)); + FORWARD_TO_OUTER(GetOuterHeight, (aOuterHeight), NS_ERROR_NOT_INITIALIZED); nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); @@ -2150,7 +2193,7 @@ nsGlobalWindow::GetOuterHeight(PRInt32* aOuterHeight) NS_IMETHODIMP nsGlobalWindow::SetOuterHeight(PRInt32 aOuterHeight) { - FORWARD_TO_OUTER(SetOuterHeight, (aOuterHeight)); + FORWARD_TO_OUTER(SetOuterHeight, (aOuterHeight), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2180,7 +2223,7 @@ nsGlobalWindow::SetOuterHeight(PRInt32 aOuterHeight) NS_IMETHODIMP nsGlobalWindow::GetScreenX(PRInt32* aScreenX) { - FORWARD_TO_OUTER(GetScreenX, (aScreenX)); + FORWARD_TO_OUTER(GetScreenX, (aScreenX), NS_ERROR_NOT_INITIALIZED); nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); @@ -2197,7 +2240,7 @@ nsGlobalWindow::GetScreenX(PRInt32* aScreenX) NS_IMETHODIMP nsGlobalWindow::SetScreenX(PRInt32 aScreenX) { - FORWARD_TO_OUTER(SetScreenX, (aScreenX)); + FORWARD_TO_OUTER(SetScreenX, (aScreenX), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2228,7 +2271,7 @@ nsGlobalWindow::SetScreenX(PRInt32 aScreenX) NS_IMETHODIMP nsGlobalWindow::GetScreenY(PRInt32* aScreenY) { - FORWARD_TO_OUTER(GetScreenY, (aScreenY)); + FORWARD_TO_OUTER(GetScreenY, (aScreenY), NS_ERROR_NOT_INITIALIZED); nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); @@ -2245,7 +2288,7 @@ nsGlobalWindow::GetScreenY(PRInt32* aScreenY) NS_IMETHODIMP nsGlobalWindow::SetScreenY(PRInt32 aScreenY) { - FORWARD_TO_OUTER(SetScreenY, (aScreenY)); + FORWARD_TO_OUTER(SetScreenY, (aScreenY), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_move_resize is true, @@ -2393,7 +2436,8 @@ nsGlobalWindow::GetPageYOffset(PRInt32* aPageYOffset) nsresult nsGlobalWindow::GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY) { - FORWARD_TO_OUTER(GetScrollMaxXY, (aScrollMaxX, aScrollMaxY)); + FORWARD_TO_OUTER(GetScrollMaxXY, (aScrollMaxX, aScrollMaxY), + NS_ERROR_NOT_INITIALIZED); nsresult rv; nsIScrollableView *view = nsnull; // no addref/release for views @@ -2440,7 +2484,8 @@ nsresult nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY, PRBool aDoFlush) { - FORWARD_TO_OUTER(GetScrollXY, (aScrollX, aScrollY, aDoFlush)); + FORWARD_TO_OUTER(GetScrollXY, (aScrollX, aScrollY, aDoFlush), + NS_ERROR_NOT_INITIALIZED); nsresult rv; nsIScrollableView *view = nsnull; // no addref/release for views @@ -2609,7 +2654,7 @@ nsGlobalWindow::GetMainWidget() NS_IMETHODIMP nsGlobalWindow::SetFullScreen(PRBool aFullScreen) { - FORWARD_TO_OUTER(SetFullScreen, (aFullScreen)); + FORWARD_TO_OUTER(SetFullScreen, (aFullScreen), NS_ERROR_NOT_INITIALIZED); // Only chrome can change our fullScreen mode. if (aFullScreen == mFullScreen || !IsCallerChrome()) { @@ -2655,7 +2700,7 @@ nsGlobalWindow::SetFullScreen(PRBool aFullScreen) NS_IMETHODIMP nsGlobalWindow::GetFullScreen(PRBool* aFullScreen) { - FORWARD_TO_OUTER(GetFullScreen, (aFullScreen)); + FORWARD_TO_OUTER(GetFullScreen, (aFullScreen), NS_ERROR_NOT_INITIALIZED); *aFullScreen = mFullScreen; return NS_OK; @@ -2726,7 +2771,7 @@ nsGlobalWindow::EnsureReflowFlushAndPaint() NS_IMETHODIMP nsGlobalWindow::GetTextZoom(float *aZoom) { - FORWARD_TO_OUTER(GetTextZoom, (aZoom)); + FORWARD_TO_OUTER(GetTextZoom, (aZoom), NS_ERROR_NOT_INITIALIZED); if (mDocShell) { nsCOMPtr contentViewer; @@ -2743,7 +2788,7 @@ nsGlobalWindow::GetTextZoom(float *aZoom) NS_IMETHODIMP nsGlobalWindow::SetTextZoom(float aZoom) { - FORWARD_TO_OUTER(SetTextZoom, (aZoom)); + FORWARD_TO_OUTER(SetTextZoom, (aZoom), NS_ERROR_NOT_INITIALIZED); if (mDocShell) { nsCOMPtr contentViewer; @@ -2860,7 +2905,7 @@ nsGlobalWindow::MakeScriptDialogTitle(const nsAString &aInTitle, NS_IMETHODIMP nsGlobalWindow::Alert(const nsAString& aString) { - FORWARD_TO_OUTER(Alert, (aString)); + FORWARD_TO_OUTER(Alert, (aString), NS_ERROR_NOT_INITIALIZED); nsCOMPtr prompter(do_GetInterface(mDocShell)); NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); @@ -2899,7 +2944,7 @@ nsGlobalWindow::Alert(const nsAString& aString) NS_IMETHODIMP nsGlobalWindow::Confirm(const nsAString& aString, PRBool* aReturn) { - FORWARD_TO_OUTER(Confirm, (aString, aReturn)); + FORWARD_TO_OUTER(Confirm, (aString, aReturn), NS_ERROR_NOT_INITIALIZED); nsCOMPtr prompter(do_GetInterface(mDocShell)); NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); @@ -2983,7 +3028,7 @@ nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial, NS_IMETHODIMP nsGlobalWindow::Prompt(nsAString& aReturn) { - FORWARD_TO_OUTER(Prompt, (aReturn)); + FORWARD_TO_OUTER(Prompt, (aReturn), NS_ERROR_NOT_INITIALIZED); NS_ENSURE_STATE(mDocShell); @@ -3034,7 +3079,7 @@ nsGlobalWindow::Prompt(nsAString& aReturn) NS_IMETHODIMP nsGlobalWindow::Focus() { - FORWARD_TO_OUTER(Focus, ()); + FORWARD_TO_OUTER(Focus, (), NS_ERROR_NOT_INITIALIZED); /* * If caller is not chrome and dom.disable_window_flip is true, @@ -3090,7 +3135,7 @@ nsGlobalWindow::Focus() NS_IMETHODIMP nsGlobalWindow::Blur() { - FORWARD_TO_OUTER(Blur, ()); + FORWARD_TO_OUTER(Blur, (), NS_ERROR_NOT_INITIALIZED); nsresult rv = NS_ERROR_FAILURE; @@ -3109,7 +3154,7 @@ nsGlobalWindow::Blur() NS_IMETHODIMP nsGlobalWindow::Back() { - FORWARD_TO_OUTER(Back, ()); + FORWARD_TO_OUTER(Back, (), NS_ERROR_NOT_INITIALIZED); nsCOMPtr webNav(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); @@ -3120,7 +3165,7 @@ nsGlobalWindow::Back() NS_IMETHODIMP nsGlobalWindow::Forward() { - FORWARD_TO_OUTER(Forward, ()); + FORWARD_TO_OUTER(Forward, (), NS_ERROR_NOT_INITIALIZED); nsCOMPtr webNav(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); @@ -3131,7 +3176,7 @@ nsGlobalWindow::Forward() NS_IMETHODIMP nsGlobalWindow::Home() { - FORWARD_TO_OUTER(Home, ()); + FORWARD_TO_OUTER(Home, (), NS_ERROR_NOT_INITIALIZED); if (!mDocShell) return NS_OK; @@ -3162,7 +3207,7 @@ nsGlobalWindow::Home() NS_IMETHODIMP nsGlobalWindow::Stop() { - FORWARD_TO_OUTER(Stop, ()); + FORWARD_TO_OUTER(Stop, (), NS_ERROR_NOT_INITIALIZED); nsCOMPtr webNav(do_QueryInterface(mDocShell)); return webNav->Stop(nsIWebNavigation::STOP_ALL); @@ -3171,6 +3216,8 @@ nsGlobalWindow::Stop() NS_IMETHODIMP nsGlobalWindow::Print() { + FORWARD_TO_OUTER(Print, (), NS_ERROR_NOT_INITIALIZED); + nsCOMPtr webBrowserPrint; if (NS_SUCCEEDED(GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(webBrowserPrint)))) { @@ -3218,6 +3265,8 @@ nsGlobalWindow::Print() NS_IMETHODIMP nsGlobalWindow::MoveTo(PRInt32 aXPos, PRInt32 aYPos) { + FORWARD_TO_OUTER(MoveTo, (aXPos, aYPos), NS_ERROR_NOT_INITIALIZED); + /* * If caller is not chrome and dom.disable_window_move_resize is true, * prevent window.moveTo() by exiting early @@ -3243,6 +3292,8 @@ nsGlobalWindow::MoveTo(PRInt32 aXPos, PRInt32 aYPos) NS_IMETHODIMP nsGlobalWindow::MoveBy(PRInt32 aXDif, PRInt32 aYDif) { + FORWARD_TO_OUTER(MoveBy, (aXDif, aYDif), NS_ERROR_NOT_INITIALIZED); + /* * If caller is not chrome and dom.disable_window_move_resize is true, * prevent window.moveBy() by exiting early @@ -3272,6 +3323,8 @@ nsGlobalWindow::MoveBy(PRInt32 aXDif, PRInt32 aYDif) NS_IMETHODIMP nsGlobalWindow::ResizeTo(PRInt32 aWidth, PRInt32 aHeight) { + FORWARD_TO_OUTER(ResizeTo, (aWidth, aHeight), NS_ERROR_NOT_INITIALIZED); + /* * If caller is not chrome and dom.disable_window_move_resize is true, * prevent window.resizeTo() by exiting early @@ -3297,6 +3350,8 @@ nsGlobalWindow::ResizeTo(PRInt32 aWidth, PRInt32 aHeight) NS_IMETHODIMP nsGlobalWindow::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif) { + FORWARD_TO_OUTER(ResizeBy, (aWidthDif, aHeightDif), NS_ERROR_NOT_INITIALIZED); + /* * If caller is not chrome and dom.disable_window_move_resize is true, * prevent window.resizeBy() by exiting early @@ -3327,7 +3382,7 @@ nsGlobalWindow::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif) NS_IMETHODIMP nsGlobalWindow::SizeToContent() { - FORWARD_TO_OUTER(SizeToContent, ()); + FORWARD_TO_OUTER(SizeToContent, (), NS_ERROR_NOT_INITIALIZED); if (!mDocShell) { return NS_OK; @@ -3633,7 +3688,7 @@ nsGlobalWindow::CanSetProperty(const char *aPrefName) PopupControlState nsGlobalWindow::CheckForAbusePoint() { - FORWARD_TO_OUTER(CheckForAbusePoint, ()); + FORWARD_TO_OUTER(CheckForAbusePoint, (), openAbused); nsCOMPtr item(do_QueryInterface(mDocShell)); @@ -3942,7 +3997,7 @@ nsGlobalWindow::OpenDialog(nsIDOMWindow** _retval) NS_IMETHODIMP nsGlobalWindow::GetFrames(nsIDOMWindow** aFrames) { - FORWARD_TO_OUTER(GetFrames, (aFrames)); + FORWARD_TO_OUTER(GetFrames, (aFrames), NS_ERROR_NOT_INITIALIZED); *aFrames = this; NS_ADDREF(*aFrames); @@ -3997,7 +4052,7 @@ nsCloseEvent::PostCloseEvent() NS_IMETHODIMP nsGlobalWindow::Close() { - FORWARD_TO_OUTER(Close, ()); + FORWARD_TO_OUTER(Close, (), NS_ERROR_NOT_INITIALIZED); if (IsFrame() || !mDocShell) { // window.close() is called on a frame in a frameset, or on a @@ -4178,7 +4233,8 @@ nsGlobalWindow::ReallyCloseWindow() that closes the window). */ PRBool isTab = PR_FALSE; if (rootWin == this || - !bwin || (bwin->IsTabContentWindow(this, &isTab), isTab)) + !bwin || (bwin->IsTabContentWindow(GetOuterWindowInternal(), + &isTab), isTab)) treeOwnerAsWin->Destroy(); } } @@ -4190,7 +4246,7 @@ nsGlobalWindow::ReallyCloseWindow() NS_IMETHODIMP nsGlobalWindow::GetFrameElement(nsIDOMElement** aFrameElement) { - FORWARD_TO_OUTER(GetFrameElement, (aFrameElement)); + FORWARD_TO_OUTER(GetFrameElement, (aFrameElement), NS_ERROR_NOT_INITIALIZED); *aFrameElement = nsnull; @@ -4312,7 +4368,7 @@ nsGlobalWindow::GetBlurSuppression() NS_IMETHODIMP nsGlobalWindow::GetSelection(nsISelection** aSelection) { - FORWARD_TO_OUTER(GetSelection, (aSelection)); + FORWARD_TO_OUTER(GetSelection, (aSelection), NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(aSelection); *aSelection = nsnull; @@ -4429,7 +4485,7 @@ nsGlobalWindow::FindInternal(const nsAString& aStr, PRBool caseSensitive, { FORWARD_TO_OUTER(FindInternal, (aStr, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog, - aDidFind)); + aDidFind), NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(aDidFind); nsresult rv = NS_OK; @@ -4601,7 +4657,8 @@ nsGlobalWindow::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) { - FORWARD_TO_INNER(AddEventListener, (aType, aListener, aUseCapture)); + FORWARD_TO_INNER(AddEventListener, (aType, aListener, aUseCapture), + NS_ERROR_NOT_INITIALIZED); nsCOMPtr doc(do_QueryInterface(mDocument)); @@ -4620,7 +4677,7 @@ nsGlobalWindow::RemoveEventListener(const nsAString& aType, NS_IMETHODIMP nsGlobalWindow::DispatchEvent(nsIDOMEvent* aEvent, PRBool* _retval) { - FORWARD_TO_INNER(DispatchEvent, (aEvent, _retval)); + FORWARD_TO_INNER(DispatchEvent, (aEvent, _retval), NS_ERROR_NOT_INITIALIZED); nsCOMPtr doc(do_QueryInterface(mDocument)); if (!doc) { @@ -4650,7 +4707,8 @@ nsGlobalWindow::AddGroupedEventListener(const nsAString & aType, nsIDOMEventGroup *aEvtGrp) { FORWARD_TO_INNER(AddGroupedEventListener, - (aType, aListener, aUseCapture, aEvtGrp)); + (aType, aListener, aUseCapture, aEvtGrp), + NS_ERROR_NOT_INITIALIZED); nsCOMPtr manager; @@ -4670,7 +4728,8 @@ nsGlobalWindow::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventGroup *aEvtGrp) { FORWARD_TO_INNER(RemoveGroupedEventListener, - (aType, aListener, aUseCapture, aEvtGrp)); + (aType, aListener, aUseCapture, aEvtGrp), + NS_ERROR_NOT_INITIALIZED); if (mListenerManager) { PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; @@ -4734,7 +4793,8 @@ NS_IMETHODIMP nsGlobalWindow::RemoveEventListenerByIID(nsIDOMEventListener* aListener, const nsIID& aIID) { - FORWARD_TO_INNER(RemoveEventListenerByIID, (aListener, aIID)); + FORWARD_TO_INNER(RemoveEventListenerByIID, (aListener, aIID), + NS_ERROR_NOT_INITIALIZED); if (mListenerManager) { mListenerManager->RemoveEventListenerByIID(aListener, aIID, @@ -4747,7 +4807,7 @@ nsGlobalWindow::RemoveEventListenerByIID(nsIDOMEventListener* aListener, NS_IMETHODIMP nsGlobalWindow::GetListenerManager(nsIEventListenerManager **aResult) { - FORWARD_TO_INNER(GetListenerManager, (aResult)); + FORWARD_TO_INNER(GetListenerManager, (aResult), NS_ERROR_NOT_INITIALIZED); if (!mListenerManager) { static NS_DEFINE_CID(kEventListenerManagerCID, @@ -4787,7 +4847,7 @@ nsGlobalWindow::GetSystemEventGroup(nsIDOMEventGroup **aGroup) nsPIDOMWindow* nsGlobalWindow::GetPrivateParent() { - FORWARD_TO_OUTER(GetPrivateParent, ()); + FORWARD_TO_OUTER(GetPrivateParent, (), nsnull); nsCOMPtr parent; GetParent(getter_AddRefs(parent)); @@ -4819,7 +4879,7 @@ nsGlobalWindow::GetPrivateParent() nsPIDOMWindow* nsGlobalWindow::GetPrivateRoot() { - FORWARD_TO_OUTER(GetPrivateRoot, ()); + FORWARD_TO_OUTER(GetPrivateRoot, (), nsnull); nsCOMPtr parent; GetTop(getter_AddRefs(parent)); @@ -4858,7 +4918,7 @@ nsGlobalWindow::GetPrivateRoot() NS_IMETHODIMP nsGlobalWindow::GetLocation(nsIDOMLocation ** aLocation) { - FORWARD_TO_OUTER(GetLocation, (aLocation)); + FORWARD_TO_OUTER(GetLocation, (aLocation), NS_ERROR_NOT_INITIALIZED); *aLocation = nsnull; @@ -4870,7 +4930,7 @@ nsGlobalWindow::GetLocation(nsIDOMLocation ** aLocation) } NS_IF_ADDREF(*aLocation = mLocation); - + return NS_OK; } @@ -4878,7 +4938,8 @@ nsresult nsGlobalWindow::GetObjectProperty(const PRUnichar *aProperty, nsISupports ** aObject) { - FORWARD_TO_INNER(GetObjectProperty, (aProperty, aObject)); + FORWARD_TO_INNER(GetObjectProperty, (aProperty, aObject), + NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mJSObject, NS_ERROR_NOT_AVAILABLE); @@ -4913,7 +4974,7 @@ nsGlobalWindow::GetObjectProperty(const PRUnichar *aProperty, nsresult nsGlobalWindow::Activate() { - FORWARD_TO_OUTER(Activate, ()); + FORWARD_TO_OUTER(Activate, (), NS_ERROR_NOT_INITIALIZED); /* nsCOMPtr treeOwnerAsWin; @@ -4979,7 +5040,7 @@ nsGlobalWindow::Activate() nsresult nsGlobalWindow::Deactivate() { - FORWARD_TO_OUTER(Deactivate, ()); + FORWARD_TO_OUTER(Deactivate, (), NS_ERROR_NOT_INITIALIZED); nsCOMPtr presShell; mDocShell->GetPresShell(getter_AddRefs(presShell)); @@ -5035,7 +5096,8 @@ nsGlobalWindow::GetComputedStyle(nsIDOMElement* aElt, const nsAString& aPseudoElt, nsIDOMCSSStyleDeclaration** aReturn) { - FORWARD_TO_OUTER(GetComputedStyle, (aElt, aPseudoElt, aReturn)); + FORWARD_TO_OUTER(GetComputedStyle, (aElt, aPseudoElt, aReturn), + NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; @@ -5112,7 +5174,7 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) *aSink = nsnull; if (aIID.Equals(NS_GET_IID(nsIDocCharset))) { - FORWARD_TO_OUTER(GetInterface, (aIID, aSink)); + FORWARD_TO_OUTER(GetInterface, (aIID, aSink), NS_ERROR_NOT_INITIALIZED); if (mDocShell) { nsCOMPtr docCharset(do_QueryInterface(mDocShell)); @@ -5123,7 +5185,7 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) } } else if (aIID.Equals(NS_GET_IID(nsIWebNavigation))) { - FORWARD_TO_OUTER(GetInterface, (aIID, aSink)); + FORWARD_TO_OUTER(GetInterface, (aIID, aSink), NS_ERROR_NOT_INITIALIZED); if (mDocShell) { nsCOMPtr webNav(do_QueryInterface(mDocShell)); @@ -5134,7 +5196,7 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) } } else if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { - FORWARD_TO_OUTER(GetInterface, (aIID, aSink)); + FORWARD_TO_OUTER(GetInterface, (aIID, aSink), NS_ERROR_NOT_INITIALIZED); if (mDocShell) { nsCOMPtr viewer; @@ -5159,7 +5221,7 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) } } else if (aIID.Equals(NS_GET_IID(nsIDOMWindowUtils))) { - FORWARD_TO_OUTER(GetInterface, (aIID, aSink)); + FORWARD_TO_OUTER(GetInterface, (aIID, aSink), NS_ERROR_NOT_INITIALIZED); nsCOMPtr utils(do_QueryReferent(mWindowUtils)); if (utils) { @@ -5190,7 +5252,7 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) nsIDOMWindowInternal * nsGlobalWindow::GetParentInternal() { - FORWARD_TO_OUTER(GetParentInternal, ()); + FORWARD_TO_OUTER(GetParentInternal, (), nsnull); nsIDOMWindowInternal *parentInternal = nsnull; @@ -5215,7 +5277,8 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName, nsIDOMWindow **aReturn) { FORWARD_TO_OUTER(OpenInternal, (aUrl, aName, aOptions, aDialog, argv, argc, - aExtraArgument, aReturn)); + aExtraArgument, aReturn), + NS_ERROR_NOT_INITIALIZED); nsXPIDLCString url; nsresult rv = NS_OK; @@ -5450,7 +5513,8 @@ static const char kSetTimeoutStr[] = "setTimeout"; nsresult nsGlobalWindow::SetTimeoutOrInterval(PRBool aIsInterval, PRInt32 *aReturn) { - FORWARD_TO_INNER(SetTimeoutOrInterval, (aIsInterval, aReturn)); + FORWARD_TO_INNER(SetTimeoutOrInterval, (aIsInterval, aReturn), + NS_ERROR_NOT_INITIALIZED); nsIScriptContext *scx = GetContextInternal(); @@ -6033,7 +6097,7 @@ nsTimeout::AddRef() nsresult nsGlobalWindow::ClearTimeoutOrInterval() { - FORWARD_TO_INNER(ClearTimeoutOrInterval, ()); + FORWARD_TO_INNER(ClearTimeoutOrInterval, (), NS_ERROR_NOT_INITIALIZED); nsresult rv = NS_OK; nsCOMPtr ncc; @@ -6189,7 +6253,7 @@ nsGlobalWindow::TimerCallback(nsITimer *aTimer, void *aClosure) nsresult nsGlobalWindow::GetTreeOwner(nsIDocShellTreeOwner **aTreeOwner) { - FORWARD_TO_OUTER(GetTreeOwner, (aTreeOwner)); + FORWARD_TO_OUTER(GetTreeOwner, (aTreeOwner), NS_ERROR_NOT_INITIALIZED); nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); @@ -6208,7 +6272,7 @@ nsGlobalWindow::GetTreeOwner(nsIDocShellTreeOwner **aTreeOwner) nsresult nsGlobalWindow::GetTreeOwner(nsIBaseWindow **aTreeOwner) { - FORWARD_TO_OUTER(GetTreeOwner, (aTreeOwner)); + FORWARD_TO_OUTER(GetTreeOwner, (aTreeOwner), NS_ERROR_NOT_INITIALIZED); nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); nsCOMPtr treeOwner; @@ -6244,7 +6308,8 @@ nsresult nsGlobalWindow::GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T, float *aT2P) { - FORWARD_TO_OUTER(GetScrollInfo, (aScrollableView, aP2T, aT2P)); + FORWARD_TO_OUTER(GetScrollInfo, (aScrollableView, aP2T, aT2P), + NS_ERROR_NOT_INITIALIZED); *aScrollableView = nsnull; *aP2T = 0.0f; @@ -6599,7 +6664,7 @@ nsGlobalWindow::SaveWindowState(nsISupports **aState) return NS_OK; } - FORWARD_TO_INNER(SaveWindowState, (aState)); + FORWARD_TO_INNER(SaveWindowState, (aState), NS_ERROR_NOT_INITIALIZED); JSContext *cx = NS_STATIC_CAST(JSContext*, GetContextInternal()->GetNativeContext()); @@ -6626,14 +6691,14 @@ nsresult nsGlobalWindow::RestoreWindowState(nsISupports *aState) { // SetNewDocument() has already been called so we should have a - // new clean inner window to restore stat into here. + // new clean inner window to restore state into here. if (IsOuterWindow() && (!mContext || !mJSObject)) { // The window may be getting torn down; don't bother restoring state. return NS_OK; } - FORWARD_TO_INNER(RestoreWindowState, (aState)); + FORWARD_TO_INNER(RestoreWindowState, (aState), NS_ERROR_NOT_INITIALIZED); JSContext *cx = NS_STATIC_CAST(JSContext*, GetContextInternal()->GetNativeContext()); @@ -6727,7 +6792,8 @@ nsGlobalWindow::SuspendTimeouts() } // Suspend our children as well. - nsCOMPtr node = do_QueryInterface(mDocShell); + nsCOMPtr node = + do_QueryInterface(GetDocShellInternal()); if (node) { PRInt32 childCount = 0; node->GetChildCount(&childCount); @@ -6752,7 +6818,7 @@ nsGlobalWindow::SuspendTimeouts() nsresult nsGlobalWindow::ResumeTimeouts() { - FORWARD_TO_INNER(ResumeTimeouts, ()); + FORWARD_TO_INNER(ResumeTimeouts, (), NS_ERROR_NOT_INITIALIZED); // Restore all of the timeouts, using the stored time remaining. @@ -6772,7 +6838,8 @@ nsGlobalWindow::ResumeTimeouts() } // Resume our children as well. - nsCOMPtr node = do_QueryInterface(mDocShell); + nsCOMPtr node = + do_QueryInterface(GetDocShellInternal()); if (node) { PRInt32 childCount = 0; node->GetChildCount(&childCount); @@ -6941,7 +7008,7 @@ nsGlobalChromeWindow::GetAttentionWithCycleCount(PRInt32 aCycleCount) NS_IMETHODIMP nsGlobalChromeWindow::SetCursor(const nsAString& aCursor) { - FORWARD_TO_OUTER_CHROME(SetCursor, (aCursor)); + FORWARD_TO_OUTER_CHROME(SetCursor, (aCursor), NS_ERROR_NOT_INITIALIZED); nsresult rv = NS_OK; PRInt32 cursor; @@ -7002,7 +7069,8 @@ nsGlobalChromeWindow::SetCursor(const nsAString& aCursor) NS_IMETHODIMP nsGlobalChromeWindow::GetBrowserDOMWindow(nsIBrowserDOMWindow **aBrowserWindow) { - FORWARD_TO_OUTER_CHROME(GetBrowserDOMWindow, (aBrowserWindow)); + FORWARD_TO_OUTER_CHROME(GetBrowserDOMWindow, (aBrowserWindow), + NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(aBrowserWindow); @@ -7014,7 +7082,8 @@ nsGlobalChromeWindow::GetBrowserDOMWindow(nsIBrowserDOMWindow **aBrowserWindow) NS_IMETHODIMP nsGlobalChromeWindow::SetBrowserDOMWindow(nsIBrowserDOMWindow *aBrowserWindow) { - FORWARD_TO_OUTER_CHROME(SetBrowserDOMWindow, (aBrowserWindow)); + FORWARD_TO_OUTER_CHROME(SetBrowserDOMWindow, (aBrowserWindow), + NS_ERROR_NOT_INITIALIZED); mBrowserDOMWindow = aBrowserWindow; return NS_OK; diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index d3dafc931aa..01311da408c 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -118,6 +118,15 @@ class WindowStateHolder; // doing. Security wise this is very sensitive code. -- // jst@netscape.com +// nsGlobalWindow inherits PRCList for maintaining a list of all inner +// widows still in memory for any given outer window. This list is +// needed to ensure that mOuterWindow doesn't end up dangling. The +// nature of PRCList means that the window itself is always in the +// list, and an outer window's list will also contain all inner window +// objects that are still in memory (and in reality all inner window +// object's lists also contain its outer and all other inner windows +// belonging to the same outer window, but that's an unimportant +// side effect of inheriting PRCList). class nsGlobalWindow : public nsPIDOMWindow, public nsIScriptGlobalObject, @@ -231,7 +240,7 @@ public: nsIScriptContext *GetContextInternal() { - if (IsInnerWindow()) { + if (mOuterWindow) { return GetOuterWindowInternal()->mContext; } @@ -250,7 +259,11 @@ public: nsIDocShell *GetDocShellInternal() { - return GetOuterWindowInternal()->mDocShell; + if (mOuterWindow) { + return GetOuterWindowInternal()->mDocShell; + } + + return mDocShell; } static void ShutDown(); @@ -275,11 +288,21 @@ protected: // popup tracking PRBool IsPopupSpamWindow() { + if (IsInnerWindow() && !mOuterWindow) { + return PR_FALSE; + } + return GetOuterWindowInternal()->mIsPopupSpam; } void SetPopupSpamWindow(PRBool aPopup) { + if (IsInnerWindow() && !mOuterWindow) { + NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!"); + + return; + } + GetOuterWindowInternal()->mIsPopupSpam = aPopup; } @@ -377,7 +400,6 @@ protected: nsCOMPtr mContext; nsCOMPtr mOpener; nsCOMPtr mControllers; - JSObject* mJSObject; JSObject* mArguments; nsRefPtr mNavigator; nsRefPtr mScreen; @@ -391,10 +413,6 @@ protected: nsRefPtr mStatusbar; nsRefPtr mScrollbars; nsCOMPtr mWindowUtils; - nsTimeout* mTimeouts; - nsTimeout** mTimeoutInsertionPoint; - PRUint32 mTimeoutPublicIdCounter; - PRUint32 mTimeoutFiringDepth; nsString mStatus; nsString mDefaultStatus; @@ -405,11 +423,16 @@ protected: nsCOMPtr mInnerWindowHolder; - // This member variable is used only on the inner window. + // These member variable are used only on inner windows. nsCOMPtr mListenerManager; + nsTimeout* mTimeouts; + nsTimeout** mTimeoutInsertionPoint; + PRUint32 mTimeoutPublicIdCounter; + PRUint32 mTimeoutFiringDepth; - // This member variable is used on both inner and the outer windows. + // These member variables are used on both inner and the outer windows. nsCOMPtr mDocumentPrincipal; + JSObject* mJSObject; friend class nsDOMScriptableHelper; friend class nsDOMWindowUtils; diff --git a/mozilla/dom/src/jsurl/Makefile.in b/mozilla/dom/src/jsurl/Makefile.in index 816df925267..85a9862c788 100644 --- a/mozilla/dom/src/jsurl/Makefile.in +++ b/mozilla/dom/src/jsurl/Makefile.in @@ -53,6 +53,7 @@ REQUIRES = xpcom \ string \ js \ dom \ + layout \ necko \ caps \ widget \ diff --git a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp index 7cc594c271b..734a8ce8959 100644 --- a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -58,7 +58,7 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsIStringStream.h" #include "nsIWindowMediator.h" -#include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsIJSConsoleService.h" #include "nsIConsoleService.h" @@ -147,7 +147,16 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel) return NS_ERROR_FAILURE; } - JSObject *globalJSObject = global->GetGlobalJSObject(); + nsCOMPtr win(do_QueryInterface(global)); + nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow(); + + if (!innerWin) { + return NS_ERROR_UNEXPECTED; + } + + nsCOMPtr innerGlobal = do_QueryInterface(innerWin); + + JSObject *globalJSObject = innerGlobal->GetGlobalJSObject(); nsCOMPtr domWindow(do_QueryInterface(global, &rv)); if (NS_FAILED(rv)) { diff --git a/mozilla/embedding/components/windowwatcher/src/nsPrompt.cpp b/mozilla/embedding/components/windowwatcher/src/nsPrompt.cpp index 6afb4118aed..a1f44e7c550 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsPrompt.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsPrompt.cpp @@ -109,6 +109,14 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsPrompt, nsIPrompt, nsIAuthPrompt) nsPrompt::nsPrompt(nsIDOMWindow *aParent) : mParent(aParent) { +#ifdef DEBUG + { + nsCOMPtr win(do_QueryInterface(aParent)); + + NS_ASSERTION(!win || win->IsOuterWindow(), + "Inner window passed as nsPrompt parent!"); + } +#endif } nsresult diff --git a/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp b/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp index f5e36be9967..b683bfc1176 100644 --- a/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp +++ b/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp @@ -1098,10 +1098,24 @@ XPC_NW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp) return JS_TRUE; } - JSObject *other = JSVAL_TO_OBJECT(v); + XPCWrappedNative *wrappedNative = + XPCNativeWrapper::GetWrappedNative(cx, obj); - *bp = (obj == other || - GetIdentityObject(cx, obj) == GetIdentityObject(cx, other)); + if (wrappedNative && wrappedNative->IsValid() && + NATIVE_HAS_FLAG(wrappedNative, WantEquality)) { + // Forward the call to the wrapped native's Equality() hook. + nsresult rv = wrappedNative->GetScriptableCallback()-> + Equality(wrappedNative, cx, obj, v, bp); + + if (NS_FAILED(rv)) { + return ThrowException(rv, cx); + } + } else { + JSObject *other = JSVAL_TO_OBJECT(v); + + *bp = (obj == other || + GetIdentityObject(cx, obj) == GetIdentityObject(cx, other)); + } return JS_TRUE; } diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index af1a5f3fec7..b33c68d45e1 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -2718,10 +2718,9 @@ static void CheckForFocus(nsPIDOMWindow* aOurWindow, } while (curDoc) { - nsCOMPtr curWin = - do_QueryInterface(curDoc->GetScriptGlobalObject()); + nsPIDOMWindow *curWin = curDoc->GetWindow(); - if (!curWin || curWin->GetOuterWindow() == ourWin) + if (!curWin || curWin == ourWin) break; curDoc = curDoc->GetParentDocument(); @@ -4362,15 +4361,14 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } // Selection is at anchor. // Now focus the document itself if focus is on an element within it. - nsCOMPtr win = - do_QueryInterface(mDocument->GetScriptGlobalObject()); + nsPIDOMWindow *win = mDocument->GetWindow(); if (win) { nsCOMPtr focusController = win->GetRootFocusController(); if (focusController) { nsCOMPtr focusedWin; focusController->GetFocusedWindow(getter_AddRefs(focusedWin)); - if (SameCOMIdentity(win->GetOuterWindow(), focusedWin)) { + if (SameCOMIdentity(win, focusedWin)) { esm->ChangeFocusWith(nsnull, nsIEventStateManager::eEventFocusedByApplication); } } diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 5270d6d7ddc..33ec4a91baf 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -2158,7 +2158,7 @@ nsObjectFrame::NotifyContentObjectWrapper() nsCOMPtr wrapper; nsContentUtils::XPConnect()-> - GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), mContent, + GetWrappedNativeOfNativeObject(cx, sgo->GetGlobalJSObject(), mContent, NS_GET_IID(nsISupports), getter_AddRefs(wrapper)); diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index 71fec551af1..6cbedb524fa 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -1335,6 +1335,9 @@ _getwindowobject(NPP npp) JSContext *cx = GetJSContextFromNPP(npp); NS_ENSURE_TRUE(cx, nsnull); + // Using ::JS_GetGlobalObject(cx) is ok here since the window we + // want to return here is the outer window, *not* the inner (since + // we don't know what the plugin will do with it). return nsJSObjWrapper::GetNewOrUsed(npp, cx, ::JS_GetGlobalObject(cx)); } diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp index fbf5951059a..f698af27395 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -52,6 +52,7 @@ #include "nsIServiceManager.h" #include "nsIDocument.h" +#include "nsPIDOMWindow.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" #include "nsIDirectoryService.h" @@ -781,8 +782,9 @@ nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow) rv = mOwner->GetDocument(getter_AddRefs(document)); if (NS_SUCCEEDED(rv) && document) { - nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); + nsPIDOMWindow *win = document->GetWindow(); + nsCOMPtr global = do_QueryInterface(win); if(global) { *outJSWindow = global->GetGlobalJSObject(); } diff --git a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index a4354b82750..6ad6aa6410a 100644 --- a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -63,7 +63,7 @@ #include "nsIDocumentViewer.h" #include "nsIDocument.h" #include "nsIDOMElement.h" -#include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIContent.h" #include "nsIWebProgress.h" #include "nsIChannel.h" @@ -353,8 +353,9 @@ nsSecureBrowserUIImpl::Notify(nsIContent* formNode, nsIURI *formURL = document->GetBaseURI(); - nsCOMPtr postingWindow(do_QueryInterface(document->GetScriptGlobalObject())); - + nsCOMPtr postingWindow = + do_QueryInterface(document->GetWindow()); + PRBool isChild; IsChildOfDomWindow(mWindow, postingWindow, &isChild);