diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index a74da5d17a3..13de83abef8 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -102,8 +102,7 @@ Navigator::Init() Navigator::Navigator(nsPIDOMWindow* aWindow) : mWindow(aWindow) { - NS_ASSERTION(aWindow->IsInnerWindow(), - "Navigator must get an inner window!"); + MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!"); SetIsDOMBinding(); } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 55edf6b181b..a88cba24757 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2871,6 +2871,8 @@ nsGlobalWindow::UpdateParentTarget() bool nsGlobalWindow::GetIsTabModalPromptAllowed() { + MOZ_ASSERT(IsOuterWindow()); + bool allowTabModal = true; if (mDocShell) { nsCOMPtr cv; @@ -2964,6 +2966,8 @@ nsGlobalWindow::PreHandleEvent(nsEventChainPreVisitor& aVisitor) bool nsGlobalWindow::ShouldPromptToBlockDialogs() { + MOZ_ASSERT(IsOuterWindow()); + nsGlobalWindow *topWindow = GetScriptableTop(); if (!topWindow) { NS_ASSERTION(!mDocShell, "ShouldPromptToBlockDialogs() called without a top window?"); @@ -3011,6 +3015,7 @@ nsGlobalWindow::AreDialogsEnabled() bool nsGlobalWindow::DialogsAreBeingAbused() { + MOZ_ASSERT(IsInnerWindow()); NS_ASSERTION(GetScriptableTop() && GetScriptableTop()->GetCurrentInnerWindowInternal() == this, "DialogsAreBeingAbused called with invalid window"); @@ -4590,7 +4595,7 @@ nsGlobalWindow::SetInnerHeight(int32_t aInnerHeight) nsIntSize nsGlobalWindow::GetOuterSize(ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(GetOuterSize, (aError), aError, nsIntSize(0, 0)); + MOZ_ASSERT(IsOuterWindow()); nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { @@ -4616,6 +4621,7 @@ nsGlobalWindow::GetOuterSize(ErrorResult& aError) int32_t nsGlobalWindow::GetOuterWidth(ErrorResult& aError) { + FORWARD_TO_OUTER_OR_THROW(GetOuterWidth, (aError), aError, 0); return GetOuterSize(aError).width; } @@ -4631,6 +4637,7 @@ nsGlobalWindow::GetOuterWidth(int32_t* aOuterWidth) int32_t nsGlobalWindow::GetOuterHeight(ErrorResult& aError) { + FORWARD_TO_OUTER_OR_THROW(GetOuterHeight, (aError), aError, 0); return GetOuterSize(aError).height; } @@ -4647,6 +4654,8 @@ void nsGlobalWindow::SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth, ErrorResult& aError) { + MOZ_ASSERT(IsOuterWindow()); + /* * If caller is not chrome and the user has not explicitly exempted the site, * prevent setting window.outerWidth by exiting early @@ -4748,6 +4757,8 @@ nsGlobalWindow::GetScreenX(int32_t* aScreenX) nsRect nsGlobalWindow::GetInnerScreenRect() { + MOZ_ASSERT(IsOuterWindow()); + if (!mDocShell) { return nsRect(); } @@ -5138,6 +5149,8 @@ nsGlobalWindow::SetScreenY(int32_t aScreenY) void nsGlobalWindow::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight) { + MOZ_ASSERT(IsOuterWindow()); + #ifdef MOZ_XUL if (!nsContentUtils::IsCallerChrome()) { // if attempting to resize the window, hide any open popups @@ -5165,6 +5178,8 @@ nsGlobalWindow::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight) nsresult nsGlobalWindow::SetDocShellWidthAndHeight(int32_t aInnerWidth, int32_t aInnerHeight) { + MOZ_ASSERT(IsOuterWindow()); + NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); nsCOMPtr treeOwner; @@ -5181,6 +5196,8 @@ nsGlobalWindow::SetDocShellWidthAndHeight(int32_t aInnerWidth, int32_t aInnerHei void nsGlobalWindow::SetCSSViewportWidthAndHeight(nscoord aInnerWidth, nscoord aInnerHeight) { + MOZ_ASSERT(IsOuterWindow()); + nsRefPtr presContext; mDocShell->GetPresContext(getter_AddRefs(presContext)); @@ -5196,6 +5213,8 @@ nsGlobalWindow::SetCSSViewportWidthAndHeight(nscoord aInnerWidth, nscoord aInner void nsGlobalWindow::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop) { + MOZ_ASSERT(IsOuterWindow()); + // This one is harder. We have to get the screen size and window dimensions. // Check security state for use in determing window dimensions @@ -5733,8 +5752,7 @@ nsGlobalWindow::Dump(const nsAString& aStr) void nsGlobalWindow::EnsureReflowFlushAndPaint() { - NS_ASSERTION(IsOuterWindow(), "EnsureReflowFlushAndPaint() must be called on" - "the outer window"); + MOZ_ASSERT(IsOuterWindow()); NS_ASSERTION(mDocShell, "EnsureReflowFlushAndPaint() called with no " "docshell!"); @@ -5865,6 +5883,8 @@ nsGlobalWindow::MakeScriptDialogTitle(nsAString &aOutTitle) bool nsGlobalWindow::CanMoveResizeWindows() { + MOZ_ASSERT(IsOuterWindow()); + // When called from chrome, we can avoid the following checks. if (!nsContentUtils::IsCallerChrome()) { // Don't allow scripts to move or resize windows that were not opened by a @@ -9190,6 +9210,8 @@ nsGlobalWindow::GetLocation(nsIDOMLocation ** aLocation) void nsGlobalWindow::ActivateOrDeactivate(bool aActivate) { + MOZ_ASSERT(IsOuterWindow()); + // Set / unset mIsActive on the top level window, which is used for the // :-moz-window-inactive pseudoclass, and its sheet (if any). nsCOMPtr mainWidget = GetMainWidget(); @@ -9249,6 +9271,8 @@ nsGlobalWindow::SetActive(bool aActive) void nsGlobalWindow::SetIsBackground(bool aIsBackground) { + MOZ_ASSERT(IsOuterWindow()); + bool resetTimers = (!aIsBackground && IsBackground()); nsPIDOMWindow::SetIsBackground(aIsBackground); if (resetTimers) { @@ -9554,6 +9578,8 @@ public: nsGlobalWindow* aWindow) : mWindow(aWindow) { + MOZ_ASSERT(mWindow); + MOZ_ASSERT(mWindow->IsInnerWindow()); mOldURL.Assign(aOldURL); mNewURL.Assign(aNewURL); } @@ -9600,7 +9626,7 @@ nsresult nsGlobalWindow::FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL) { - NS_ENSURE_TRUE(IsInnerWindow(), NS_ERROR_FAILURE); + MOZ_ASSERT(IsInnerWindow()); // Don't do anything if the window is frozen. if (IsFrozen()) @@ -9725,6 +9751,8 @@ static nsCanvasFrame* FindCanvasFrame(nsIFrame* aFrame) void nsGlobalWindow::UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent) { + MOZ_ASSERT(IsInnerWindow()); + // this is called from the inner window so use GetDocShell nsIDocShell* docShell = GetDocShell(); if (!docShell) @@ -10549,6 +10577,7 @@ nsGlobalWindow::ShowSlowScriptDialog() uint32_t nsGlobalWindow::FindInsertionIndex(IdleObserverHolder* aIdleObserver) { + MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(aIdleObserver, "Idle observer not instantiated."); uint32_t i = 0; @@ -10755,6 +10784,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, mNotifyIdleObserversActiveOnThaw = true; mNotifyIdleObserversIdleOnThaw = false; } else if (IsCurrentInnerWindow()) { + MOZ_ASSERT(IsInnerWindow()); ScheduleActiveTimerCallback(); } return NS_OK; @@ -11017,6 +11047,7 @@ nsGlobalWindow::GetParentInternal() void nsGlobalWindow::UnblockScriptedClosing() { + MOZ_ASSERT(IsOuterWindow()); mBlockScriptedClosingFlag = false; } @@ -11025,12 +11056,17 @@ class AutoUnblockScriptClosing private: nsRefPtr mWin; public: - AutoUnblockScriptClosing(nsGlobalWindow *aWin) : mWin(aWin) {}; + AutoUnblockScriptClosing(nsGlobalWindow* aWin) + : mWin(aWin) + { + MOZ_ASSERT(mWin); + MOZ_ASSERT(mWin->IsOuterWindow()); + } ~AutoUnblockScriptClosing() { void (nsGlobalWindow::*run)() = &nsGlobalWindow::UnblockScriptedClosing; NS_DispatchToCurrentThread(NS_NewRunnableMethod(mWin, run)); - }; + } }; nsresult @@ -12534,6 +12570,8 @@ nsGlobalWindow::TimeoutSuspendCount() void nsGlobalWindow::EnableDeviceSensor(uint32_t aType) { + MOZ_ASSERT(IsInnerWindow()); + bool alreadyEnabled = false; for (uint32_t i = 0; i < mEnabledSensors.Length(); i++) { if (mEnabledSensors[i] == aType) { @@ -12557,6 +12595,8 @@ nsGlobalWindow::EnableDeviceSensor(uint32_t aType) void nsGlobalWindow::DisableDeviceSensor(uint32_t aType) { + MOZ_ASSERT(IsInnerWindow()); + int32_t doomedElement = -1; int32_t listenerCount = 0; for (uint32_t i = 0; i < mEnabledSensors.Length(); i++) { @@ -13085,6 +13125,8 @@ nsGlobalModalWindow::SetReturnValue(nsIVariant *aRetVal) void nsGlobalWindow::SetHasAudioAvailableEventListeners() { + MOZ_ASSERT(IsInnerWindow()); + if (mDoc) { mDoc->NotifyAudioAvailableListener(); } @@ -13094,6 +13136,8 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners() void nsGlobalWindow::EnableNetworkEvent(uint32_t aType) { + MOZ_ASSERT(IsInnerWindow()); + nsCOMPtr permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); if (!permMgr) { @@ -13134,6 +13178,8 @@ nsGlobalWindow::EnableNetworkEvent(uint32_t aType) void nsGlobalWindow::DisableNetworkEvent(uint32_t aType) { + MOZ_ASSERT(IsInnerWindow()); + nsCOMPtr os = mozilla::services::GetObserverService(); if (!os) { return; diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index ccd0d449405..fec72ace0d3 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -411,9 +411,12 @@ public: // nsPIDOMWindow virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot(); + + // Outer windows only. virtual NS_HIDDEN_(void) ActivateOrDeactivate(bool aActivate); virtual NS_HIDDEN_(void) SetActive(bool aActive); virtual NS_HIDDEN_(void) SetIsBackground(bool aIsBackground); + virtual NS_HIDDEN_(void) SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler); virtual NS_HIDDEN_(void) SetInitialPrincipalToSubject(); @@ -445,6 +448,7 @@ public: void DispatchDOMWindowCreated(); virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindow* aOpener, bool aOriginalOpener); + // Outer windows only. virtual NS_HIDDEN_(void) EnsureSizeUpToDate(); @@ -520,7 +524,9 @@ public: // ShouldPromptToBlockDialogs is implemented in terms of // DialogsAreBeingAbused, and will get the scriptable top inner window // automatically. + // Outer windows only. bool ShouldPromptToBlockDialogs(); + // Inner windows only. bool DialogsAreBeingAbused(); // Ask the user if further dialogs should be blocked, if dialogs are currently @@ -534,6 +540,7 @@ public: void DisableDialogs(); bool AreDialogsEnabled(); + // Inner windows only. virtual void SetHasAudioAvailableEventListeners(); nsIScriptContext *GetContextInternal() @@ -588,6 +595,7 @@ public: nsresult Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData); + // Outer windows only. void UnblockScriptedClosing(); static void Init(); @@ -616,6 +624,7 @@ public: virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI); virtual nsresult DispatchSyncPopState(); + // Inner windows only. virtual void EnableDeviceSensor(uint32_t aType); virtual void DisableDeviceSensor(uint32_t aType); @@ -623,6 +632,7 @@ public: virtual void DisableTimeChangeNotifications(); #ifdef MOZ_B2G + // Inner windows only. virtual void EnableNetworkEvent(uint32_t aType); virtual void DisableNetworkEvent(uint32_t aType); #endif // MOZ_B2G @@ -1136,6 +1146,7 @@ protected: const nsAString &aPopupWindowFeatures); void FireOfflineStatusEvent(); + // Inner windows only. nsresult ScheduleNextIdleObserverCallback(); uint32_t GetFuzzTimeMS(); nsresult ScheduleActiveTimerCallback(); @@ -1145,13 +1156,17 @@ protected: int32_t* aRemoveElementIndex); virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserverPtr); + // Inner windows only. nsresult FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL); void FlushPendingNotifications(mozFlushType aType); + + // Outer windows only. void EnsureReflowFlushAndPaint(); void CheckSecurityWidthAndHeight(int32_t* width, int32_t* height); void CheckSecurityLeftAndTop(int32_t* left, int32_t* top); + // Outer windows only. // Arguments to this function should have values in app units void SetCSSViewportWidthAndHeight(nscoord width, nscoord height); // Arguments to this function should have values in device pixels @@ -1161,10 +1176,9 @@ protected: static void MakeScriptDialogTitle(nsAString &aOutTitle); + // Outer windows only. bool CanMoveResizeWindows(); - bool GetBlurSuppression(); - // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to // just flush our parent and only flush ourselves if we think we need to. mozilla::CSSIntPoint GetScrollXY(bool aDoFlush, mozilla::ErrorResult& aError); @@ -1174,7 +1188,6 @@ protected: // Outer windows only. nsresult GetInnerSize(mozilla::CSSIntSize& aSize); - nsIntSize GetOuterSize(mozilla::ErrorResult& aError); void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth, mozilla::ErrorResult& aError); @@ -1187,6 +1200,7 @@ protected: return GetParentInternal() != nullptr; } + // Outer windows only. // If aLookForCallerOnJSStack is true, this method will look at the JS stack // to determine who the caller is. If it's false, it'll use |this| as the // caller. @@ -1231,6 +1245,7 @@ protected: virtual void GetKeyboardIndicators(bool* aShowAccelerators, bool* aShowFocusRings); + // Inner windows only. void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent); public: @@ -1247,6 +1262,7 @@ protected: virtual void UpdateParentTarget(); + // Outer windows only. bool GetIsTabModalPromptAllowed(); inline int32_t DOMMinTimeoutValue() const; @@ -1398,7 +1414,7 @@ protected: nsRefPtr mWindowUtils; nsString mStatus; nsString mDefaultStatus; - nsGlobalWindowObserver* mObserver; + nsGlobalWindowObserver* mObserver; // Inner windows only. nsCOMPtr mCrypto; nsCOMPtr mLocalStorage; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 151cab42175..723ea5ca0b0 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -70,39 +70,37 @@ public: virtual nsPIDOMWindow* GetPrivateRoot() = 0; + // Outer windows only. virtual void ActivateOrDeactivate(bool aActivate) = 0; // this is called GetTopWindowRoot to avoid conflicts with nsIDOMWindow::GetWindowRoot virtual already_AddRefed GetTopWindowRoot() = 0; - virtual void SetActive(bool aActive) - { - NS_PRECONDITION(IsOuterWindow(), - "active state is only maintained on outer windows"); - mIsActive = aActive; - } - + // Inner windows only. virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0; virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0; + // Outer windows only. + virtual void SetActive(bool aActive) + { + MOZ_ASSERT(IsOuterWindow()); + mIsActive = aActive; + } bool IsActive() { - NS_PRECONDITION(IsOuterWindow(), - "active state is only maintained on outer windows"); + MOZ_ASSERT(IsOuterWindow()); return mIsActive; } + // Outer windows only. virtual void SetIsBackground(bool aIsBackground) { - NS_PRECONDITION(IsOuterWindow(), - "background state is only maintained on outer windows"); + MOZ_ASSERT(IsOuterWindow()); mIsBackground = aIsBackground; } - bool IsBackground() { - NS_PRECONDITION(IsOuterWindow(), - "background state is only maintained on outer windows"); + MOZ_ASSERT(IsOuterWindow()); return mIsBackground; } @@ -566,12 +564,18 @@ public: virtual nsresult DispatchSyncPopState() = 0; /** - * Tell this window that it should listen for sensor changes of the given type. + * Tell this window that it should listen for sensor changes of the given + * type. + * + * Inner windows only. */ virtual void EnableDeviceSensor(uint32_t aType) = 0; /** - * Tell this window that it should remove itself from sensor change notifications. + * Tell this window that it should remove itself from sensor change + * notifications. + * + * Inner windows only. */ virtual void DisableDeviceSensor(uint32_t aType) = 0; @@ -582,12 +586,16 @@ public: /** * Tell the window that it should start to listen to the network event of the * given aType. + * + * Inner windows only. */ virtual void EnableNetworkEvent(uint32_t aType) = 0; /** * Tell the window that it should stop to listen to the network event of the * given aType. + * + * Inner windows only. */ virtual void DisableNetworkEvent(uint32_t aType) = 0; #endif // MOZ_B2G