diff --git a/.cron.yml b/.cron.yml index 2c19c2b7d6df..e610ea687b4b 100644 --- a/.cron.yml +++ b/.cron.yml @@ -98,6 +98,18 @@ jobs: mozilla-central: [{hour: 10, minute: 0}] # No default + - name: searchfox-index + job: + type: decision-task + treeherder-symbol: Searchfox + target-tasks-method: searchfox_index + run-on-projects: + - mozilla-central + when: + by-project: + mozilla-central: [{hour: 10, minute: 30}] + # No default + - name: periodic-update job: type: decision-task diff --git a/browser/base/content/browser-pageActions.js b/browser/base/content/browser-pageActions.js index 06e5aadae44e..985ece77096a 100644 --- a/browser/base/content/browser-pageActions.js +++ b/browser/base/content/browser-pageActions.js @@ -20,7 +20,7 @@ var BrowserPageActions = { }, /** - * The photonmultiview node in the main page action panel (DOM node) + * The panelmultiview node in the main page action panel (DOM node) */ get multiViewNode() { delete this.multiViewNode; @@ -234,7 +234,7 @@ var BrowserPageActions = { let iframeNode = null; if (action.subview) { - let multiViewNode = document.createElement("photonpanelmultiview"); + let multiViewNode = document.createElement("panelmultiview"); panelViewNode = this._makePanelViewNodeForAction(action, true); multiViewNode.appendChild(panelViewNode); panelNode.appendChild(multiViewNode); diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index b200c3fa624d..4bcb59e34c56 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -71,32 +71,17 @@ panelmultiview { -moz-binding: url("chrome://browser/content/customizableui/panelUI.xml#panelmultiview"); } -photonpanelmultiview { - -moz-binding: url("chrome://browser/content/customizableui/panelUI.xml#photonpanelmultiview"); -} - panelview { -moz-binding: url("chrome://browser/content/customizableui/panelUI.xml#panelview"); -moz-box-orient: vertical; } panel[hidden] panelmultiview, -panel[hidden] photonpanelmultiview, panel[hidden] panelview { -moz-binding: none; } -.panel-mainview { - transition: transform var(--panelui-subview-transition-duration); -} - -panelview:not([mainview]):not([current]):not([in-transition]) { - transition: visibility 0s linear var(--panelui-subview-transition-duration); - visibility: collapse; -} - -photonpanelmultiview panelview:not([current]):not([in-transition]) { - transition: none; +panelview:not([current]):not([in-transition]) { visibility: collapse; } @@ -1070,12 +1055,6 @@ notification[value="translation"] { -moz-binding: url("chrome://browser/content/translation-infobar.xml#translationbar"); } -/** See bug 872317 for why the following rule is necessary. */ - -#downloads-button { - -moz-binding: url("chrome://browser/content/downloads/download.xml#download-toolbarbutton"); -} - /*** Visibility of downloads indicator controls ***/ /* Bug 924050: If we've loaded the indicator, for now we hide it in the menu panel, diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 7d7ac9f655b8..596c34e4ad7e 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -417,15 +417,15 @@ emailLink-title="&emailPageCmd.label;" sendToDevice-title="&pageAction.sendTabToDevice.label;" sendToDevice-notReadyTitle="&sendToDevice.syncNotReady.label;"> - + - + - + @@ -184,5 +184,5 @@ - + diff --git a/browser/components/customizableui/CustomizableUI.jsm b/browser/components/customizableui/CustomizableUI.jsm index 9dee4807cade..e579e753b0db 100644 --- a/browser/components/customizableui/CustomizableUI.jsm +++ b/browser/components/customizableui/CustomizableUI.jsm @@ -1620,7 +1620,7 @@ var CustomizableUIInternal = { if (areaType != CustomizableUI.TYPE_MENU_PANEL) { let wrapper = this.wrapWidget(aWidget.id).forWindow(ownerWindow); - let hasMultiView = !!aNode.closest("photonpanelmultiview,panelmultiview"); + let hasMultiView = !!aNode.closest("panelmultiview"); if (wrapper && !hasMultiView && wrapper.anchor) { this.hidePanelForNode(aNode); anchor = wrapper.anchor; @@ -1804,13 +1804,9 @@ var CustomizableUIInternal = { if (closemenu == "single") { let panel = this._getPanelForNode(target); - let multiview = panel.querySelector("photonpanelmultiview,panelmultiview"); + let multiview = panel.querySelector("panelmultiview"); if (multiview.showingSubView) { - if (multiview.instance.panelViews) { - multiview.goBack(); - } else { - multiview.showMainView(); - } + multiview.goBack(); return; } } @@ -4303,15 +4299,10 @@ OverflowableToolbar.prototype = { return new Promise(resolve => { let doc = this._panel.ownerDocument; this._panel.hidden = false; - let photonView = this._panel.querySelector("photonpanelmultiview"); - let contextMenu; - if (photonView) { - let mainViewId = photonView.getAttribute("mainViewId"); - let mainView = doc.getElementById(mainViewId); - contextMenu = doc.getElementById(mainView.getAttribute("context")); - } else { - contextMenu = doc.getElementById(this._panel.getAttribute("context")); - } + let multiview = this._panel.querySelector("panelmultiview"); + let mainViewId = multiview.getAttribute("mainViewId"); + let mainView = doc.getElementById(mainViewId); + let contextMenu = doc.getElementById(mainView.getAttribute("context")); gELS.addSystemEventListener(contextMenu, "command", this, true); let anchor = doc.getAnonymousElementByAttribute(this._chevron, "class", "toolbarbutton-icon"); // Ensure we update the gEditUIVisible flag when opening the popup, in diff --git a/browser/components/customizableui/PanelMultiView.jsm b/browser/components/customizableui/PanelMultiView.jsm index a8710fd95fae..7e97380b7217 100644 --- a/browser/components/customizableui/PanelMultiView.jsm +++ b/browser/components/customizableui/PanelMultiView.jsm @@ -166,7 +166,7 @@ this.PanelMultiView = class { } get showingSubView() { - return this.node.getAttribute("viewtype") == "subview"; + return this._showingSubView; } get _mainViewId() { return this.node.getAttribute("mainViewId"); @@ -201,11 +201,6 @@ this.PanelMultiView = class { } get panelViews() { - // If there's a dedicated subViews container, we're not in the right binding - // to use SlidingPanelViews. - if (this._subViews) - return null; - if (this._panelViews) return this._panelViews; @@ -234,14 +229,10 @@ this.PanelMultiView = class { return this._viewShowing || this._currentSubView; } get _currentSubView() { - return this.panelViews ? this.panelViews.currentView : this.__currentSubView; + return this.panelViews.currentView; } set _currentSubView(panel) { - if (this.panelViews) - this.panelViews.currentView = panel; - else - this.__currentSubView = panel; - return panel; + this.panelViews.currentView = panel; } /** * @return {Promise} showSubView() returns a promise, which is kept here for @@ -268,20 +259,14 @@ this.PanelMultiView = class { if (testMode) return; - this._currentSubView = this._anchorElement = this._subViewObserver = null; + this._currentSubView = this._subViewObserver = null; this._mainViewHeight = 0; - this.__transitioning = this._ignoreMutations = false; + this.__transitioning = this._ignoreMutations = this._showingSubView = false; const {document, window} = this; - this._clickCapturer = - document.getAnonymousElementByAttribute(this.node, "anonid", "clickCapturer"); this._viewContainer = document.getAnonymousElementByAttribute(this.node, "anonid", "viewContainer"); - this._mainViewContainer = - document.getAnonymousElementByAttribute(this.node, "anonid", "mainViewContainer"); - this._subViews = - document.getAnonymousElementByAttribute(this.node, "anonid", "subViews"); this._viewStack = document.getAnonymousElementByAttribute(this.node, "anonid", "viewStack"); this._offscreenViewStack = @@ -296,24 +281,14 @@ this.PanelMultiView = class { this._panel.addEventListener("popuppositioned", this); this._panel.addEventListener("popuphidden", this); this._panel.addEventListener("popupshown", this); - if (this.panelViews) { - let cs = window.getComputedStyle(document.documentElement); - // Set CSS-determined attributes now to prevent a layout flush when we do - // it when transitioning between panels. - this._dir = cs.direction; - this.setMainView(this.panelViews.currentView); - this.showMainView(); - } else { - this._clickCapturer.addEventListener("click", this); + let cs = window.getComputedStyle(document.documentElement); + // Set CSS-determined attributes now to prevent a layout flush when we do + // it when transitioning between panels. + this._dir = cs.direction; + this.setMainView(this.panelViews.currentView); + this.showMainView(); - this._mainViewContainer.setAttribute("panelid", this._panel.id); - - if (this._mainView) { - this.setMainView(this._mainView); - } - } - - this.node.setAttribute("viewtype", "main"); + this._showingSubView = false; // Proxy these public properties and methods, as used elsewhere by various // parts of the browser, to this instance. @@ -354,24 +329,17 @@ this.PanelMultiView = class { this._panelViewCache.appendChild(mainView); mainView.removeAttribute("mainview"); } - if (this._subViews) - this._moveOutKids(this._subViews); - if (this.panelViews) { - this._moveOutKids(this._viewStack); - this.panelViews.clear(); - } else { - this._clickCapturer.removeEventListener("click", this); - } + this._moveOutKids(this._viewStack); + this.panelViews.clear(); this._panel.removeEventListener("mousemove", this); this._panel.removeEventListener("popupshowing", this); this._panel.removeEventListener("popuppositioned", this); this._panel.removeEventListener("popupshown", this); this._panel.removeEventListener("popuphidden", this); this.window.removeEventListener("keydown", this); - this.node = this._clickCapturer = this._viewContainer = this._mainViewContainer = - this._subViews = this._viewStack = this.__dwu = this._panelViewCache = - this._transitionDetails = null; + this.node = this._viewContainer = this._viewStack = this.__dwu = + this._panelViewCache = this._transitionDetails = null; } /** @@ -395,13 +363,9 @@ this.PanelMultiView = class { } _placeSubView(viewNode) { - if (this.panelViews) { - this._viewStack.appendChild(viewNode); - if (!this.panelViews.includes(viewNode)) - this.panelViews.push(viewNode); - } else { - this._subViews.appendChild(viewNode); - } + this._viewStack.appendChild(viewNode); + if (!this.panelViews.includes(viewNode)) + this.panelViews.push(viewNode); } goBack(target) { @@ -425,20 +389,15 @@ this.PanelMultiView = class { return; if (this._mainView) { - if (!this.panelViews) - this._subViews.appendChild(this._mainView); this._mainView.removeAttribute("mainview"); } this._mainViewId = aNewMainView.id; aNewMainView.setAttribute("mainview", "true"); - if (this.panelViews) { - // If the new main view is not yet in the zeroth position, make sure it's - // inserted there. - if (aNewMainView.parentNode != this._viewStack && this._viewStack.firstChild != aNewMainView) { - this._viewStack.insertBefore(aNewMainView, this._viewStack.firstChild); - } - } else { - this._mainViewContainer.appendChild(aNewMainView); + // If the new main view is not yet in the zeroth position, make sure it's + // inserted there. + if (aNewMainView.parentNode != this._viewStack && + this._viewStack.firstChild != aNewMainView) { + this._viewStack.insertBefore(aNewMainView, this._viewStack.firstChild); } } @@ -446,21 +405,7 @@ this.PanelMultiView = class { if (!this._mainViewId) return Promise.resolve(); - if (this.panelViews) - return this.showSubView(this._mainView); - - if (this.showingSubView) { - let viewNode = this._currentSubView; - this._dispatchViewEvent(viewNode, "ViewHiding"); - this._transitionHeight(() => { - viewNode.removeAttribute("current"); - this._currentSubView = null; - this.node.setAttribute("viewtype", "main"); - }); - } - - this._shiftMainView(); - return Promise.resolve(); + return this.showSubView(this._mainView); } /** @@ -491,7 +436,7 @@ this.PanelMultiView = class { this.descriptionHeightWorkaround(theOne); this._dispatchViewEvent(theOne, "ViewShown"); } - this.node.setAttribute("viewtype", (theOne.id == this._mainViewId) ? "main" : "subview"); + this._showingSubView = theOne.id != this._mainViewId; } showSubView(aViewId, aAnchor, aPreviousView) { @@ -517,26 +462,21 @@ this.PanelMultiView = class { let playTransition = (!!previousViewNode && !showingSameView && this._panel.state == "open"); let isMainView = viewNode.id == this._mainViewId; - let dwu, previousRect; - if (playTransition || this.panelViews) { - dwu = this._dwu; - previousRect = previousViewNode.__lastKnownBoundingRect = + let dwu = this._dwu; + let previousRect = previousViewNode.__lastKnownBoundingRect = dwu.getBoundsWithoutFlushing(previousViewNode); - if (this.panelViews) { - // Cache the measures that have the same caching lifetime as the width - // or height of the main view, i.e. whilst the panel is shown and/ or - // visible. - if (!this._mainViewWidth) { - this._mainViewWidth = previousRect.width; - let top = dwu.getBoundsWithoutFlushing(previousViewNode.firstChild || previousViewNode).top; - let bottom = dwu.getBoundsWithoutFlushing(previousViewNode.lastChild || previousViewNode).bottom; - this._viewVerticalPadding = previousRect.height - (bottom - top); - } - if (!this._mainViewHeight) { - this._mainViewHeight = previousRect.height; - this._viewContainer.style.minHeight = this._mainViewHeight + "px"; - } - } + // Cache the measures that have the same caching lifetime as the width + // or height of the main view, i.e. whilst the panel is shown and/ or + // visible. + if (!this._mainViewWidth) { + this._mainViewWidth = previousRect.width; + let top = dwu.getBoundsWithoutFlushing(previousViewNode.firstChild || previousViewNode).top; + let bottom = dwu.getBoundsWithoutFlushing(previousViewNode.lastChild || previousViewNode).bottom; + this._viewVerticalPadding = previousRect.height - (bottom - top); + } + if (!this._mainViewHeight) { + this._mainViewHeight = previousRect.height; + this._viewContainer.style.minHeight = this._mainViewHeight + "px"; } this._viewShowing = viewNode; @@ -549,12 +489,12 @@ this.PanelMultiView = class { viewNode.removeAttribute("mainview"); // Make sure that new panels always have a title set. - if (this.panelViews && aAnchor) { + if (aAnchor) { if (!viewNode.hasAttribute("title")) viewNode.setAttribute("title", aAnchor.getAttribute("label")); viewNode.classList.add("PanelUI-subView"); } - if (this.panelViews && !isMainView && this._mainViewWidth) + if (!isMainView && this._mainViewWidth) viewNode.style.maxWidth = viewNode.style.minWidth = this._mainViewWidth + "px"; if (!showingSameView || !viewNode.hasAttribute("current")) { @@ -584,31 +524,14 @@ this.PanelMultiView = class { } } - // Now we have to transition the panel. - if (this.panelViews) { - // If we've got an older transition still running, make sure to clean it up. - await this._cleanupTransitionPhase(); - if (playTransition) { - await this._transitionViews(previousViewNode, viewNode, reverse, previousRect, aAnchor); - this._updateKeyboardFocus(viewNode); - } else { - this.hideAllViewsExcept(viewNode); - } + // Now we have to transition the panel. If we've got an older transition + // still running, make sure to clean it up. + await this._cleanupTransitionPhase(); + if (playTransition) { + await this._transitionViews(previousViewNode, viewNode, reverse, previousRect, aAnchor); + this._updateKeyboardFocus(viewNode); } else { - this._currentSubView = viewNode; - this._transitionHeight(() => { - viewNode.setAttribute("current", true); - if (viewNode.id == this._mainViewId) { - this.node.setAttribute("viewtype", "main"); - } else { - this.node.setAttribute("viewtype", "subview"); - } - // Now that the subview is visible, we can check the height of the - // description elements it contains. - this.descriptionHeightWorkaround(viewNode); - this._dispatchViewEvent(viewNode, "ViewShown"); - }); - this._shiftMainView(aAnchor); + this.hideAllViewsExcept(viewNode); } })().catch(e => Cu.reportError(e)); return this._currentShowPromise; @@ -901,123 +824,12 @@ this.PanelMultiView = class { return maxHeight; } - /** - * Applies the height transition for which is designed. - * - * The height transition involves two elements, the viewContainer and its only - * immediate child the viewStack. In order for this to work correctly, the - * viewContainer must have "overflow: hidden;" and the two elements must have - * no margins or padding. This means that the height of the viewStack is never - * limited by the viewContainer, but when the height of the container is not - * constrained it matches the height of the viewStack. - * - * @param changeFn - * This synchronous function is called to make the DOM changes - * that will result in a new height of the viewStack. - */ - _transitionHeight(changeFn) { - if (this._panel.state != "open") { - changeFn(); - return; - } - - // Lock the dimensions of the window that hosts the popup panel. This - // in turn constrains the height of the viewContainer. - let rect = this._panel.popupBoxObject.getOuterScreenRect(); - this._panel.setAttribute("width", rect.width); - this._panel.setAttribute("height", rect.height); - - // Read the current height of the viewStack. If we are in the middle - // of a transition, this is the actual height of the element at this - // point in time. - let oldHeight = this._dwu.getBoundsWithoutFlushing(this._viewStack).height; - - // Make the necessary DOM changes, and remove the "height" property of the - // viewStack to ensure that we read its final value even if we are in the - // middle of a transition. To avoid flickering, we have to prevent the panel - // from being painted in this temporary state, which requires a synchronous - // layout when reading the new height. - this._viewStack.style.removeProperty("height"); - changeFn(); - let newHeight = this._viewStack.getBoundingClientRect().height; - - // Now we can allow the popup panel to resize again. This must occur - // in the same tick as the code below, but we can do this before - // setting the starting height in case the transition is not needed. - this._panel.removeAttribute("width"); - this._panel.removeAttribute("height"); - - if (oldHeight != newHeight) { - // Height transitions can only occur between two numeric values, and - // cannot start if the height is not set. In case a transition is - // needed, we have to set the height to the old value, then force a - // synchronous layout so the panel won't resize unexpectedly. - this._viewStack.style.height = oldHeight + "px"; - this._viewStack.getBoundingClientRect().height; - - // We can now set the new height to start the transition, but - // before doing that we set up a listener to reset the height to - // "auto" at the end, so that DOM changes made after the - // transition ends are still reflected by the height of the panel. - let onTransitionEnd = event => { - if (event.target != this._viewStack) { - return; - } - this._viewStack.removeEventListener("transitionend", onTransitionEnd); - this._viewStack.style.removeProperty("height"); - }; - this._viewStack.addEventListener("transitionend", onTransitionEnd); - this._viewStack.style.height = newHeight + "px"; - } - } - - _shiftMainView(aAnchor) { - if (aAnchor) { - // We need to find the edge of the anchor, relative to the main panel. - // Then we need to add half the width of the anchor. This is the target - // that we need to transition to. - let anchorRect = aAnchor.getBoundingClientRect(); - let mainViewRect = this._mainViewContainer.getBoundingClientRect(); - let center = aAnchor.clientWidth / 2; - let direction = aAnchor.ownerGlobal.getComputedStyle(aAnchor).direction; - let edge; - if (direction == "ltr") { - edge = anchorRect.left - mainViewRect.left; - } else { - edge = mainViewRect.right - anchorRect.right; - } - - // If the anchor is an element on the far end of the mainView we - // don't want to shift the mainView too far, we would reveal empty - // space otherwise. - let cstyle = this.window.getComputedStyle(this.document.documentElement); - let exitSubViewGutterWidth = - cstyle.getPropertyValue("--panel-ui-exit-subview-gutter-width"); - let maxShift = mainViewRect.width - parseInt(exitSubViewGutterWidth); - let target = Math.min(maxShift, edge + center); - - let neg = direction == "ltr" ? "-" : ""; - this._mainViewContainer.style.transform = `translateX(${neg}${target}px)`; - aAnchor.setAttribute("panel-multiview-anchor", true); - } else { - this._mainViewContainer.style.transform = ""; - if (this.anchorElement) - this.anchorElement.removeAttribute("panel-multiview-anchor"); - } - this.anchorElement = aAnchor; - } - handleEvent(aEvent) { if (aEvent.type.startsWith("popup") && aEvent.target != this._panel) { // Shouldn't act on e.g. context menus being shown from within the panel. return; } switch (aEvent.type) { - case "click": - if (aEvent.originalTarget == this._clickCapturer) { - this.showMainView(); - } - break; case "keydown": this._keyNavigation(aEvent); break; @@ -1060,27 +872,25 @@ this.PanelMultiView = class { this._transitioning = false; this.node.removeAttribute("panelopen"); this.showMainView(); - if (this.panelViews) { - for (let panelView of this._viewStack.children) { - if (panelView.nodeName != "children") { - panelView.__lastKnownBoundingRect = null; - panelView.style.removeProperty("min-width"); - panelView.style.removeProperty("max-width"); - } + for (let panelView of this._viewStack.children) { + if (panelView.nodeName != "children") { + panelView.__lastKnownBoundingRect = null; + panelView.style.removeProperty("min-width"); + panelView.style.removeProperty("max-width"); } - this.window.removeEventListener("keydown", this); - this._panel.removeEventListener("mousemove", this); - this._resetKeyNavigation(); - - // Clear the main view size caches. The dimensions could be different - // when the popup is opened again, e.g. through touch mode sizing. - this._mainViewHeight = 0; - this._mainViewWidth = 0; - this._viewContainer.style.removeProperty("min-height"); - this._viewStack.style.removeProperty("max-height"); - this._viewContainer.style.removeProperty("min-width"); - this._viewContainer.style.removeProperty("max-width"); } + this.window.removeEventListener("keydown", this); + this._panel.removeEventListener("mousemove", this); + this._resetKeyNavigation(); + + // Clear the main view size caches. The dimensions could be different + // when the popup is opened again, e.g. through touch mode sizing. + this._mainViewHeight = 0; + this._mainViewWidth = 0; + this._viewContainer.style.removeProperty("min-height"); + this._viewStack.style.removeProperty("max-height"); + this._viewContainer.style.removeProperty("min-width"); + this._viewContainer.style.removeProperty("max-width"); this._dispatchViewEvent(this.node, "PanelMultiViewHidden"); break; diff --git a/browser/components/customizableui/content/panelUI.css b/browser/components/customizableui/content/panelUI.css index 147c4964ac2a..5e64dcd09d41 100644 --- a/browser/components/customizableui/content/panelUI.css +++ b/browser/components/customizableui/content/panelUI.css @@ -2,45 +2,23 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -.panel-viewstack[viewtype="main"] > .panel-clickcapturer { - pointer-events: none; -} - .panel-viewcontainer { overflow: hidden; } .panel-viewstack { + overflow: visible; transition: height var(--panelui-subview-transition-duration); } -.panel-subviews { - -moz-stack-sizing: ignore-horizontal; - transform: translateX(0); -} - -.panel-viewstack[viewtype="main"] > .panel-subviews { - -moz-stack-sizing: ignore; -} - -.panel-subviews[panelopen] { - transition: transform var(--panelui-subview-transition-duration); -} - -.panel-viewcontainer[panelopen]:-moz-any(:not([viewtype="main"]),[transitioning]) { +.panel-viewcontainer[panelopen] { transition-property: height; transition-timing-function: var(--animation-easing-function); transition-duration: var(--panelui-subview-transition-duration); will-change: height; } -/* START photon adjustments */ - -photonpanelmultiview > .panel-viewcontainer > .panel-viewstack { - overflow: visible; -} - -photonpanelmultiview[transitioning] { +panelmultiview[transitioning] { pointer-events: none; } @@ -55,5 +33,3 @@ photonpanelmultiview[transitioning] { margin: 0; padding: 0; } - -/* END photon adjustments */ diff --git a/browser/components/customizableui/content/panelUI.inc.xul b/browser/components/customizableui/content/panelUI.inc.xul index bc7954ce55e7..25c322b0afa8 100644 --- a/browser/components/customizableui/content/panelUI.inc.xul +++ b/browser/components/customizableui/content/panelUI.inc.xul @@ -9,7 +9,7 @@ position="bottomcenter topright" photon="true" hidden="true"> - + @@ -24,7 +24,7 @@ accesskey="&overflowCustomizeToolbar.accesskey;" label="&overflowCustomizeToolbar.label;"/> - + @@ -164,8 +164,8 @@ flip="slide" position="bottomcenter topright" noautofocus="true"> - + @@ -667,7 +667,7 @@ label-checked="&hideBookmarksToolbar.label;"/> - + viewShown = true; viewNode.addEventListener("ViewShown", listener, {once: true}); - let multiView = document.createElement("photonpanelmultiview"); + let multiView = document.createElement("panelmultiview"); multiView.setAttribute("id", "customizationui-widget-multiview"); multiView.setAttribute("viewCacheId", "appMenu-viewCache"); multiView.setAttribute("mainViewId", viewNode.id); diff --git a/browser/components/customizableui/content/panelUI.xml b/browser/components/customizableui/content/panelUI.xml index d9189eb27bd8..872d5cbed211 100644 --- a/browser/components/customizableui/content/panelUI.xml +++ b/browser/components/customizableui/content/panelUI.xml @@ -18,26 +18,14 @@ - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - diff --git a/browser/components/customizableui/test/browser_967000_button_charEncoding.js b/browser/components/customizableui/test/browser_967000_button_charEncoding.js index c84dd9731816..9b02be4c7bac 100644 --- a/browser/components/customizableui/test/browser_967000_button_charEncoding.js +++ b/browser/components/customizableui/test/browser_967000_button_charEncoding.js @@ -46,7 +46,7 @@ add_task(async function() { let checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); is(checkedButtons.length, 2, "There should be 2 checked items (1 charset, 1 detector)."); - is(checkedButtons[0].getAttribute("label"), "Unicode", "The unicode encoding is correctly selected"); + is(checkedButtons[0].getAttribute("label"), "Western", "The western encoding is correctly selected"); is(characterEncodingView.querySelectorAll("#PanelUI-characterEncodingView-autodetect toolbarbutton[checked='true']").length, 1, "There should be 1 checked detector."); diff --git a/browser/components/customizableui/test/browser_987640_charEncoding.js b/browser/components/customizableui/test/browser_987640_charEncoding.js index 635cfdb37ac0..c08e4ceb9e2f 100644 --- a/browser/components/customizableui/test/browser_987640_charEncoding.js +++ b/browser/components/customizableui/test/browser_987640_charEncoding.js @@ -26,32 +26,34 @@ add_task(async function() { let checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); let initialEncoding = checkedButtons[0]; - is(initialEncoding.getAttribute("label"), "Unicode", "The unicode encoding is initially selected"); + is(initialEncoding.getAttribute("label"), "Western", "The western encoding is initially selected"); // change the encoding let encodings = characterEncodingView.querySelectorAll("toolbarbutton"); let newEncoding = encodings[0].hasAttribute("checked") ? encodings[1] : encodings[0]; - let tabLoadPromise = promiseTabLoadEvent(gBrowser.selectedTab, TEST_PAGE); + let browserStopPromise = BrowserTestUtils.browserStopped(gBrowser, TEST_PAGE); newEncoding.click(); - await tabLoadPromise; + await browserStopPromise; + is(gBrowser.selectedBrowser.characterSet, "UTF-8", "The encoding should be changed to UTF-8"); + ok(!gBrowser.selectedBrowser.mayEnableCharacterEncodingMenu, "The encoding menu should be disabled"); // check that the new encodng is applied await document.getElementById("nav-bar").overflowable.show(); charEncodingButton.click(); checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); let selectedEncodingName = checkedButtons[0].getAttribute("label"); - ok(selectedEncodingName != "Unicode", "The encoding was changed to " + selectedEncodingName); + ok(selectedEncodingName == "Unicode", "The encoding was changed to " + selectedEncodingName); - // reset the initial encoding + CustomizableUI.removeWidgetFromArea("characterencoding-button"); + CustomizableUI.addWidgetToArea("characterencoding-button", + CustomizableUI.AREA_FIXED_OVERFLOW_PANEL); + await waitForOverflowButtonShown(); await document.getElementById("nav-bar").overflowable.show(); - charEncodingButton.click(); - tabLoadPromise = promiseTabLoadEvent(gBrowser.selectedTab, TEST_PAGE); - initialEncoding.click(); - await tabLoadPromise; - await document.getElementById("nav-bar").overflowable.show(); - charEncodingButton.click(); - checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); - is(checkedButtons[0].getAttribute("label"), "Unicode", "The encoding was reset to Unicode"); + charEncodingButton = document.getElementById("characterencoding-button"); + + // check the encoding menu again + is(charEncodingButton.getAttribute("disabled"), "true", "We should disable the encoding menu"); + await BrowserTestUtils.removeTab(newTab); }); diff --git a/browser/components/customizableui/test/browser_overflow_use_subviews.js b/browser/components/customizableui/test/browser_overflow_use_subviews.js index a3c4b48b692c..3b95e583ef5d 100644 --- a/browser/components/customizableui/test/browser_overflow_use_subviews.js +++ b/browser/components/customizableui/test/browser_overflow_use_subviews.js @@ -39,7 +39,7 @@ add_task(async function check_developer_subview_in_overflow() { let subviewShownPromise = subviewShown(developerView); button.click(); await subviewShownPromise; - let hasSubviews = !!kOverflowPanel.querySelector("photonpanelmultiview,panelmultiview"); + let hasSubviews = !!kOverflowPanel.querySelector("panelmultiview"); let expectedPanel = hasSubviews ? kOverflowPanel : document.getElementById("customizationui-widget-panel"); is(developerView.closest("panel"), expectedPanel, "Should be inside the panel"); expectedPanel.hidePopup(); diff --git a/browser/components/customizableui/test/support/test_967000_charEncoding_page.html b/browser/components/customizableui/test/support/test_967000_charEncoding_page.html index addfd041cda6..c664885288c7 100644 --- a/browser/components/customizableui/test/support/test_967000_charEncoding_page.html +++ b/browser/components/customizableui/test/support/test_967000_charEncoding_page.html @@ -1,7 +1,7 @@ - + Test page diff --git a/browser/components/downloads/content/download.xml b/browser/components/downloads/content/download.xml index 93e797fe4053..bb5ba02aaa13 100644 --- a/browser/components/downloads/content/download.xml +++ b/browser/components/downloads/content/download.xml @@ -110,21 +110,6 @@ - - - - - - - - - - - - diff --git a/browser/components/downloads/content/downloads.css b/browser/components/downloads/content/downloads.css index 2def6b2b80f8..bd9564f7ec2f 100644 --- a/browser/components/downloads/content/downloads.css +++ b/browser/components/downloads/content/downloads.css @@ -198,8 +198,7 @@ richlistitem.download button { /* Make the panel wide enough to show the download list items without improperly truncating them. */ #downloadsPanel-multiView > .panel-viewcontainer, -#downloadsPanel-multiView > .panel-viewcontainer > .panel-viewstack, -#downloadsPanel-multiView > .panel-viewcontainer > .panel-viewstack > .panel-mainview { +#downloadsPanel-multiView > .panel-viewcontainer > .panel-viewstack { max-width: unset; } diff --git a/browser/components/downloads/content/downloadsOverlay.xul b/browser/components/downloads/content/downloadsOverlay.xul index 0224cd7ad996..46fe3d2f8bff 100644 --- a/browser/components/downloads/content/downloadsOverlay.xul +++ b/browser/components/downloads/content/downloadsOverlay.xul @@ -109,8 +109,8 @@ label="&cmd.clearDownloads.label;"/> - + @@ -207,7 +207,7 @@ oncommand="BrowserDownloadsUI(); CustomizableUI.hidePanelForNode(this);"/> - + diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index debc930ec6ef..ee8a6e03f4c1 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -2204,7 +2204,7 @@ BrowserGlue.prototype = { let defaultEngine = Services.search.originalDefaultEngine; defaultEngine.hidden = false; Services.search.currentEngine = defaultEngine; - Services.prefs.setIntPref("browser.search.reset.status", "silent"); + Services.prefs.setCharPref("browser.search.reset.status", "silent"); } }); } diff --git a/browser/components/search/content/searchReset.xhtml b/browser/components/search/content/searchReset.xhtml index 62f89f61e658..62e36847063b 100644 --- a/browser/components/search/content/searchReset.xhtml +++ b/browser/components/search/content/searchReset.xhtml @@ -41,7 +41,7 @@

&searchreset.pageInfo1;

&searchreset.selector.label;

-

&searchreset.beforelink.pageInfo2;&searchreset.link.pageInfo2;&searchreset.afterlink.pageInfo2;

+

&searchreset.beforelink.pageInfo2;&searchreset.link.pageInfo2;&searchreset.afterlink.pageInfo2;

diff --git a/browser/components/search/test/browser_aboutSearchReset.js b/browser/components/search/test/browser_aboutSearchReset.js index 53d9dd1dd1ed..f748c22111ca 100644 --- a/browser/components/search/test/browser_aboutSearchReset.js +++ b/browser/components/search/test/browser_aboutSearchReset.js @@ -115,7 +115,7 @@ var gTests = [ Services.prefs.setCharPref(kStatusPref, "pending"); let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, - "about:preferences"); + "about:preferences#search"); // eslint-disable-next-line mozilla/no-cpows-in-tests gBrowser.contentDocument.getElementById("linkSettingsPage").click(); await loadPromise; diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index f238c23459aa..c7648cf7b66d 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -219,7 +219,7 @@ skip-if = true # Needs to be rewritten as Marionette test, bug 995916 [browser_739531.js] [browser_739805.js] [browser_819510_perwindowpb.js] -skip-if = (os == 'win' && bits == 64) || (os == "mac") # Win: Bug 1284312, Mac: Bug 1341980 +skip-if = (os == 'win' && bits == 64) || (os == "mac") || (os == "linux") # Win: Bug 1284312, Mac: Bug 1341980, Linux: bug 1381451 [browser_not_collect_when_idle.js] # Disabled for frequent intermittent failures diff --git a/browser/config/mozconfigs/linux64/debug-searchfox-clang b/browser/config/mozconfigs/linux64/debug-searchfox-clang new file mode 100644 index 000000000000..da12067c770e --- /dev/null +++ b/browser/config/mozconfigs/linux64/debug-searchfox-clang @@ -0,0 +1,25 @@ +MOZ_AUTOMATION_BUILD_SYMBOLS=0 +MOZ_AUTOMATION_PACKAGE_TESTS=0 +MOZ_AUTOMATION_L10N_CHECK=0 + +. "$topsrcdir/build/mozconfig.common" + +ac_add_options --enable-debug +ac_add_options --enable-dmd + +. $topsrcdir/build/mozconfig.stylo + +# Use Clang as specified in manifest +export CC="$topsrcdir/clang/bin/clang" +export CXX="$topsrcdir/clang/bin/clang++" + +# Add the static checker +ac_add_options --enable-clang-plugin +ac_add_options --enable-mozsearch-plugin + +. "$topsrcdir/build/unix/mozconfig.stdcxx" + +export PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig:/usr/share/pkgconfig +. $topsrcdir/build/unix/mozconfig.gtk + +. "$topsrcdir/build/mozconfig.common.override" diff --git a/browser/config/mozconfigs/macosx64/debug-searchfox b/browser/config/mozconfigs/macosx64/debug-searchfox new file mode 100644 index 000000000000..526fd941f330 --- /dev/null +++ b/browser/config/mozconfigs/macosx64/debug-searchfox @@ -0,0 +1,13 @@ +MOZ_AUTOMATION_BUILD_SYMBOLS=0 +MOZ_AUTOMATION_PACKAGE_TESTS=0 +MOZ_AUTOMATION_L10N_CHECK=0 + +. $topsrcdir/build/macosx/mozconfig.common + +ac_add_options --enable-debug +ac_add_options --enable-dmd + +ac_add_options --enable-clang-plugin +ac_add_options --enable-mozsearch-plugin + +. "$topsrcdir/build/mozconfig.common.override" diff --git a/browser/config/mozconfigs/win32/debug-searchfox b/browser/config/mozconfigs/win32/debug-searchfox new file mode 100644 index 000000000000..c7d71470d608 --- /dev/null +++ b/browser/config/mozconfigs/win32/debug-searchfox @@ -0,0 +1,17 @@ +MOZ_AUTOMATION_BUILD_SYMBOLS=0 +MOZ_AUTOMATION_PACKAGE_TESTS=0 +MOZ_AUTOMATION_L10N_CHECK=0 + +. "$topsrcdir/build/mozconfig.win-common" +. "$topsrcdir/browser/config/mozconfigs/common" + +ac_add_options --enable-optimize +ac_add_options --enable-debug + +ac_add_options --enable-clang-plugin +ac_add_options --enable-mozsearch-plugin + +. $topsrcdir/build/win32/mozconfig.vs-latest + +. "$topsrcdir/build/mozconfig.common.override" +. "$topsrcdir/build/mozconfig.clang-cl" diff --git a/browser/themes/linux/customizableui/panelUI.css b/browser/themes/linux/customizableui/panelUI.css index 835c2526ba9f..8492aa812612 100644 --- a/browser/themes/linux/customizableui/panelUI.css +++ b/browser/themes/linux/customizableui/panelUI.css @@ -4,10 +4,6 @@ %include ../../shared/customizableui/panelUI.inc.css -.panel-subviews { - background-color: var(--arrowpanel-background); -} - #BMB_bookmarksPopup > menuitem[type="checkbox"] { -moz-appearance: none !important; /* important, to override toolkit rule */ } diff --git a/browser/themes/osx/controlcenter/panel.css b/browser/themes/osx/controlcenter/panel.css index 541119cf85b5..df25e4e8137f 100644 --- a/browser/themes/osx/controlcenter/panel.css +++ b/browser/themes/osx/controlcenter/panel.css @@ -10,15 +10,6 @@ box-shadow: var(--focus-ring-box-shadow); } -#identity-popup-multiView > .panel-viewcontainer > .panel-viewstack > .panel-subviews { - border-bottom-right-radius: 3.5px; -} - -#identity-popup-multiView > .panel-viewcontainer > .panel-viewstack > .panel-subviews:-moz-locale-dir(rtl) { - border-bottom-right-radius: 0; - border-bottom-left-radius: 3.5px; -} - #tracking-action-block, #tracking-action-unblock, #tracking-action-unblock-private, diff --git a/browser/themes/osx/customizableui/panelUI.css b/browser/themes/osx/customizableui/panelUI.css index fe6b2b65e810..70f95bd45252 100644 --- a/browser/themes/osx/customizableui/panelUI.css +++ b/browser/themes/osx/customizableui/panelUI.css @@ -4,10 +4,6 @@ %include ../../shared/customizableui/panelUI.inc.css -.panel-subviews { - background-color: hsla(0,0%,100%,.97); -} - .restoreallitem > .toolbarbutton-icon { display: none; } @@ -20,7 +16,7 @@ padding-inline-start: 14px; } -photonpanelmultiview .toolbaritem-combined-buttons > spacer { +panelmultiview .toolbaritem-combined-buttons > spacer { width: 42px; /* 18px toolbarbutton padding + 16px icon + 8px label padding start */ } diff --git a/browser/themes/shared/controlcenter/panel.inc.css b/browser/themes/shared/controlcenter/panel.inc.css index e97887cc7603..973b36e2d695 100644 --- a/browser/themes/shared/controlcenter/panel.inc.css +++ b/browser/themes/shared/controlcenter/panel.inc.css @@ -68,20 +68,6 @@ max-width: 30em; } -#identity-popup-multiView > .panel-viewcontainer > .panel-viewstack[viewtype="main"] > .panel-subviews { - transform: translateX(100%); - box-shadow: none; -} - -#identity-popup-multiView > .panel-viewcontainer > .panel-viewstack[viewtype="main"] > .panel-subviews:-moz-locale-dir(rtl) { - transform: translateX(-100%); -} - -#identity-popup-multiView > .panel-viewcontainer > .panel-viewstack > .panel-subviews { - background: var(--arrowpanel-background); - padding: 0; -} - .identity-popup-section:not(:first-child) { border-top: 1px solid var(--panel-separator-color); } @@ -164,7 +150,7 @@ .identity-popup-host { word-wrap: break-word; /* 1em + 2em + 24px is .identity-popup-security-content padding - * 30em is .panel-mainview width */ + * 30em is the panel width */ max-width: calc(30rem - 3rem - 24px - @identityPopupExpanderWidth@); } diff --git a/browser/themes/shared/customizableui/panelUI.inc.css b/browser/themes/shared/customizableui/panelUI.inc.css index 0b0099a0dbe7..4f17fe2ee3a3 100644 --- a/browser/themes/shared/customizableui/panelUI.inc.css +++ b/browser/themes/shared/customizableui/panelUI.inc.css @@ -22,7 +22,6 @@ %define panelPaletteIconSize 16px :root { - --panel-ui-exit-subview-gutter-width: 38px; --appmenu-yellow-warning-border-color: hsl(45, 100%, 77%); --appmenu-yellow-warning-color: #FFEFBF; --appmenu-yellow-warning-hover-color: #FFE8A2; @@ -114,26 +113,11 @@ background: #FFBF00 url(chrome://browser/skin/update-badge-failed.svg) no-repeat center; } -.panel-subviews { - padding: 4px; - background-clip: padding-box; - border-left: 1px solid var(--arrowpanel-border-color); - box-shadow: 0 3px 5px hsla(210,4%,10%,.1), - 0 0 7px hsla(210,4%,10%,.1); - margin-inline-start: var(--panel-ui-exit-subview-gutter-width); -} - -.panel-viewstack[viewtype="main"] > .panel-subviews { - transform: translateX(@menuPanelWidth@); -} - -.panel-viewstack[viewtype="main"] > .panel-subviews:-moz-locale-dir(rtl) { - transform: translateX(-@menuPanelWidth@); -} - panelview { -moz-box-orient: vertical; -moz-box-flex: 1; + background: var(--arrowpanel-background); + padding: 0; } /* This section is to anchor all the drop down panels at the same height, shift the @@ -200,6 +184,7 @@ panelview { overflow-y: auto; overflow-x: hidden; -moz-box-flex: 1; + padding: 6px 0; } .panel-view-body-unscrollable { @@ -242,8 +227,7 @@ panel[photon] > .panel-arrowcontainer > .panel-arrowcontent { margin-inline-start: 0; } -#BMB_bookmarksPopup, -.panel-mainview { +#BMB_bookmarksPopup { max-width: @standaloneSubviewWidth@; } @@ -323,11 +307,6 @@ panel[photon] > .panel-arrowcontainer > .panel-arrowcontent { opacity: 1; } -/* Give WebExtension stand-alone panels extra width for Chrome compatibility */ -.cui-widget-panel[viewId^=PanelUI-webext-] .panel-mainview { - max-width: 800px; -} - .cui-widget-panel[viewId^=PanelUI-webext-] > .panel-arrowcontainer > .panel-arrowcontent { padding: 0; } @@ -347,18 +326,11 @@ panelview:not([mainview]) .toolbarbutton-text, padding: 4px 0; } -/* START photonpanelview adjustments */ - #appMenu-popup > .panel-arrowcontainer > .panel-arrowcontent, panel[photon] > .panel-arrowcontainer > .panel-arrowcontent { padding: 0; } -photonpanelmultiview panelview { - background: var(--arrowpanel-background); - padding: 0; -} - #appMenu-popup panelview, #customizationui-widget-multiview panelview:not([extension]) { min-width: @menuPanelWidth@; @@ -377,12 +349,6 @@ photonpanelmultiview panelview { min-width: calc(@menuPanelWidth@ + 32px); } -photonpanelmultiview .panel-subview-body { - padding: 6px 0; -} - -/* END photonpanelview adjustments */ - .cui-widget-panel.cui-widget-panelWithFooter > .panel-arrowcontainer > .panel-arrowcontent { padding-bottom: 0; } @@ -461,7 +427,8 @@ toolbarbutton[constrain-size="true"][cui-areatype="menu-panel"] > .toolbarbutton content: ""; width: 16px; height: 16px; - margin-inline-end: 16.5px; + margin-inline-start: 10px; + margin-inline-end: 12px; display: -moz-box; } @@ -904,25 +871,9 @@ panelview .toolbarbutton-1, color: inherit; } -/* START photon adjustments */ - .subviewbutton[checked="true"] { - background: url(chrome://browser/skin/check.svg) center left 7px / 11px 11px no-repeat transparent; - fill: currentColor; -} - -.subviewbutton[checked="true"]:-moz-locale-dir(rtl) { - background-position: center right 7px; -} - -photonpanelmultiview .subviewbutton[checked="true"] { - background: none; list-style-image: url(chrome://browser/skin/check.svg); -} - -photonpanelmultiview .subviewbutton > .menu-iconic-left { - -moz-appearance: none; - margin-inline-end: 0; + fill: currentColor; } #appMenu-popup .toolbaritem-combined-buttons { @@ -933,22 +884,22 @@ photonpanelmultiview .subviewbutton > .menu-iconic-left { margin-inline-end: 8px; } -photonpanelmultiview .toolbaritem-combined-buttons > label { +panelmultiview .toolbaritem-combined-buttons > label { -moz-box-flex: 1; font: menu; margin: 0; } -photonpanelmultiview .toolbaritem-combined-buttons > spacer.before-label { +panelmultiview .toolbaritem-combined-buttons > spacer.before-label { width: 36px; /* 12px toolbarbutton padding + 16px icon + 8px label padding start */ } -photonpanelmultiview .toolbaritem-combined-buttons > spacer.after-label { +panelmultiview .toolbaritem-combined-buttons > spacer.after-label { -moz-box-flex: 1; width: 20px; /* a little bigger than the width of the scrollbar */ } -photonpanelmultiview .PanelUI-subView .toolbaritem-combined-buttons > .subviewbutton { +.PanelUI-subView .toolbaritem-combined-buttons > .subviewbutton { -moz-box-flex: 0; height: auto; margin-inline-start: 18px; @@ -975,44 +926,33 @@ photonpanelmultiview .PanelUI-subView .toolbaritem-combined-buttons > .subviewbu margin-inline-start: 0; } -photonpanelmultiview .PanelUI-subView .toolbaritem-combined-buttons > - .subviewbutton-iconic > .toolbarbutton-text, -photonpanelmultiview .PanelUI-subView .toolbaritem-combined-buttons > - .subviewbutton:not(.subviewbutton-iconic) > .toolbarbutton-icon { +.PanelUI-subView .toolbaritem-combined-buttons > .subviewbutton-iconic > .toolbarbutton-text, +.PanelUI-subView .toolbaritem-combined-buttons > .subviewbutton:not(.subviewbutton-iconic) > .toolbarbutton-icon { display: none; } /* Using this selector, because this way the hover and active selectors will apply properly. */ -photonpanelmultiview .PanelUI-subView .toolbaritem-combined-buttons > - .subviewbutton:not(.subviewbutton-iconic) { +.PanelUI-subView .toolbaritem-combined-buttons > .subviewbutton:not(.subviewbutton-iconic) { background-color: #f9f9f9; border: 1px solid #e1e1e1; border-radius: 10000px; padding: 1px 8px; } -photonpanelmultiview .toolbaritem-combined-buttons > .subviewbutton:not(.subviewbutton-iconic) > .toolbarbutton-text { +.toolbaritem-combined-buttons > .subviewbutton:not(.subviewbutton-iconic) > .toolbarbutton-text { font-size: 1em; padding-inline-start: 0; } -photonpanelmultiview .addon-banner-item::after, -photonpanelmultiview .panel-banner-item::after { - margin-inline-end: 12px; - margin-inline-start: 10px; -} - -photonpanelmultiview .subview-subheader { +.subview-subheader { color: GrayText; } -photonpanelmultiview .subview-subheader, -photonpanelmultiview .panel-subview-footer { +.subview-subheader, +.panel-subview-footer { font: menu; } -/* END photon adjustments */ - panelview .toolbarbutton-1 { margin-top: 6px; } @@ -1108,12 +1048,16 @@ menuitem.panel-subview-footer@menuStateActive@, padding: 0; } -.PanelUI-subView menuseparator, -.PanelUI-subView toolbarseparator { +.PanelUI-subView menuseparator { margin-inline-start: -5px; margin-inline-end: -4px; } +.PanelUI-subView toolbarseparator { + margin-inline-start: 0; + margin-inline-end: 0; +} + .PanelUI-subView menuseparator.small-separator, .PanelUI-subView toolbarseparator.small-separator { margin-left: 5px; @@ -1240,7 +1184,6 @@ toolbarpaletteitem[place=panel] > .toolbaritem-combined-buttons > toolbarbutton padding: 0; } -.cui-widget-panelview, #widget-overflow-mainView .panel-subview-body { overflow-y: auto; overflow-x: hidden; @@ -1293,14 +1236,13 @@ toolbarpaletteitem[place=panel] > .subviewbutton-nav::after { .subviewbutton > .menu-iconic-left { -moz-appearance: none; - margin-inline-end: 3px; + margin-inline-end: 0; } menuitem[checked="true"].subviewbutton > .menu-iconic-left { visibility: hidden; } -.panel-mainview[panelid=customizationui-widget-panel], #PanelUI-panicView > .panel-subview-body, #PanelUI-panicView { overflow: visible; @@ -1493,8 +1435,6 @@ menuitem[checked="true"].subviewbutton > .menu-iconic-left { } } -/* START photon adjustments */ - .panel-header { align-items: center; border-bottom: 1px solid var(--panel-separator-color); @@ -1514,7 +1454,7 @@ menuitem[checked="true"].subviewbutton > .menu-iconic-left { text-align: center; } -photonpanelmultiview .PanelUI-subView .panel-header > .subviewbutton-back { +.PanelUI-subView .panel-header > .subviewbutton-back { -moz-context-properties: fill; fill: var(--arrowpanel-color); list-style-image: url(chrome://browser/skin/arrow-left.svg); @@ -1531,18 +1471,7 @@ photonpanelmultiview .PanelUI-subView .panel-header > .subviewbutton-back { display: none !important; } -photonpanelmultiview .PanelUI-subView toolbarseparator { - margin-inline-start: 0; - margin-inline-end: 0; -} - -/* This is explicitly overriding the overflow properties set above. */ -photonpanelmultiview .cui-widget-panelview { - overflow-x: visible; - overflow-y: visible; -} - -photonpanelmultiview #panelMenu_pocket { +#panelMenu_pocket { display: none; } @@ -1597,5 +1526,3 @@ photonpanelmultiview #panelMenu_pocket { .subviewbutton.download:-moz-any([openLabel],[retryLabel]) > .action-button@buttonStateActive@ { background-color: var(--arrowpanel-dimmed-even-further); } - -/* END photon adjustments */ diff --git a/browser/themes/shared/downloads/downloads.inc.css b/browser/themes/shared/downloads/downloads.inc.css index 3fd5c204d369..44459676bb3d 100644 --- a/browser/themes/shared/downloads/downloads.inc.css +++ b/browser/themes/shared/downloads/downloads.inc.css @@ -15,10 +15,6 @@ #downloadsPanel > .panel-arrowcontainer > .panel-arrowcontent { overflow: hidden; -} - -#downloadsPanel > .panel-arrowcontainer > .panel-arrowcontent, -#downloadsPanel-multiView > .panel-viewcontainer > .panel-viewstack > .panel-subviews { padding: 0; } diff --git a/browser/themes/windows/customizableui/panelUI.css b/browser/themes/windows/customizableui/panelUI.css index b29cc035da3c..1871bec1e3c0 100644 --- a/browser/themes/windows/customizableui/panelUI.css +++ b/browser/themes/windows/customizableui/panelUI.css @@ -4,10 +4,6 @@ %include ../../shared/customizableui/panelUI.inc.css -.panel-subviews { - background-color: var(--arrowpanel-background); -} - /* bookmark panel submenus */ #BMB_bookmarksPopup menupopup[placespopup=true] { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index e0622aa74844..96859c2f5468 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3864,7 +3864,6 @@ ItemIsActive(nsIDocShellTreeItem* aItem) { if (nsCOMPtr window = aItem->GetWindow()) { auto* win = nsGlobalWindowOuter::Cast(window); - MOZ_ASSERT(win->IsOuterWindow()); if (!win->GetClosedOuter()) { return true; } diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index 667ef7d72be4..f9531c68627b 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -1,5 +1,3 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -77,8 +75,6 @@ AudioChannelAgent::InitWithWeakCallback(mozIDOMWindow* aWindow, nsresult AudioChannelAgent::FindCorrectWindow(nsPIDOMWindowInner* aWindow) { - MOZ_ASSERT(aWindow->IsInnerWindow()); - mWindow = aWindow->GetScriptableTop(); if (NS_WARN_IF(!mWindow)) { return NS_OK; @@ -142,7 +138,6 @@ AudioChannelAgent::InitInternal(nsPIDOMWindowInner* aWindow, return NS_ERROR_FAILURE; } - MOZ_ASSERT(aWindow->IsInnerWindow()); mInnerWindowID = aWindow->WindowID(); nsresult rv = FindCorrectWindow(aWindow); diff --git a/dom/audiochannel/AudioChannelService.cpp b/dom/audiochannel/AudioChannelService.cpp index 1aa7bf0515d9..d548ef894a59 100644 --- a/dom/audiochannel/AudioChannelService.cpp +++ b/dom/audiochannel/AudioChannelService.cpp @@ -345,12 +345,10 @@ AudioChannelService::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) AudioPlaybackConfig AudioChannelService::GetMediaConfig(nsPIDOMWindowOuter* aWindow) const { - MOZ_ASSERT(!aWindow || aWindow->IsOuterWindow()); - AudioPlaybackConfig config(1.0, false, nsISuspendedTypes::NONE_SUSPENDED); - if (!aWindow || !aWindow->IsOuterWindow()) { + if (!aWindow) { config.SetConfig(0.0, true, nsISuspendedTypes::SUSPENDED_BLOCK); return config; @@ -452,7 +450,6 @@ AudioChannelService::RefreshAgents(nsPIDOMWindowOuter* aWindow, const std::function& aFunc) { MOZ_ASSERT(aWindow); - MOZ_ASSERT(aWindow->IsOuterWindow()); nsCOMPtr topWindow = aWindow->GetScriptableTop(); if (!topWindow) { @@ -495,7 +492,6 @@ AudioChannelService::SetWindowAudioCaptured(nsPIDOMWindowOuter* aWindow, { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aWindow); - MOZ_ASSERT(aWindow->IsOuterWindow()); MOZ_LOG(GetAudioChannelLog(), LogLevel::Debug, ("AudioChannelService, SetWindowAudioCaptured, window = %p, " @@ -532,7 +528,6 @@ AudioChannelService::GetOrCreateWindowData(nsPIDOMWindowOuter* aWindow) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aWindow); - MOZ_ASSERT(aWindow->IsOuterWindow()); AudioChannelWindow* winData = GetWindowData(aWindow->WindowID()); if (!winData) { @@ -595,7 +590,6 @@ void AudioChannelService::NotifyMediaResumedFromBlock(nsPIDOMWindowOuter* aWindow) { MOZ_ASSERT(aWindow); - MOZ_ASSERT(aWindow->IsOuterWindow()); nsCOMPtr topWindow = aWindow->GetScriptableTop(); if (!topWindow) { @@ -974,7 +968,6 @@ AudioChannelService::AudioChannelWindow::MaybeNotifyMediaBlockStart(AudioChannel return; } - MOZ_ASSERT(window->IsOuterWindow()); nsCOMPtr inner = window->GetCurrentInnerWindow(); if (!inner) { return; diff --git a/dom/base/BarProps.cpp b/dom/base/BarProps.cpp index d7367e29db48..7f6a448f2c60 100644 --- a/dom/base/BarProps.cpp +++ b/dom/base/BarProps.cpp @@ -21,7 +21,6 @@ namespace dom { BarProp::BarProp(nsGlobalWindowInner* aWindow) : mDOMWindow(aWindow) { - MOZ_ASSERT(aWindow->IsInnerWindow()); } BarProp::~BarProp() diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 5a9034eb40e0..ee421eb360f8 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -224,7 +224,6 @@ CustomElementRegistry::CustomElementRegistry(nsPIDOMWindowInner* aWindow) , mIsCustomDefinitionRunning(false) { MOZ_ASSERT(aWindow); - MOZ_ASSERT(aWindow->IsInnerWindow()); MOZ_ALWAYS_TRUE(mConstructors.init()); mozilla::HoldJSObjects(this); diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 92493a001337..220436a9c6e6 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -1965,8 +1965,7 @@ EventSource::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, nsCOMPtr ownerWindow = do_QueryInterface(aGlobal.GetAsSupports()); - MOZ_ASSERT(!NS_IsMainThread() || - (ownerWindow && ownerWindow->IsInnerWindow())); + MOZ_ASSERT(!NS_IsMainThread() || ownerWindow); RefPtr eventSource = new EventSource(ownerWindow, aEventSourceInitDict.mWithCredentials); diff --git a/dom/base/Location.cpp b/dom/base/Location.cpp index 3131b8541abc..47bc61056f7e 100644 --- a/dom/base/Location.cpp +++ b/dom/base/Location.cpp @@ -42,8 +42,6 @@ namespace dom { Location::Location(nsPIDOMWindowInner* aWindow, nsIDocShell *aDocShell) : mInnerWindow(aWindow) { - MOZ_ASSERT(mInnerWindow->IsInnerWindow()); - // aDocShell can be null if it gets called after nsDocShell::Destory(). mDocShell = do_GetWeakReference(aDocShell); } diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 19ca1f543215..35d9f61aadb4 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -168,7 +168,6 @@ Navigator::Init() Navigator::Navigator(nsPIDOMWindowInner* aWindow) : mWindow(aWindow) { - MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!"); } Navigator::~Navigator() @@ -1628,8 +1627,6 @@ Navigator::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const void Navigator::SetWindow(nsPIDOMWindowInner *aInnerWindow) { - NS_ASSERTION(aInnerWindow->IsInnerWindow(), - "Navigator must get an inner window!"); mWindow = aInnerWindow; } @@ -1712,7 +1709,6 @@ Navigator::GetWindowFromGlobal(JSObject* aGlobal) { nsCOMPtr win = do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal)); - MOZ_ASSERT(!win || win->IsInnerWindow()); return win.forget(); } diff --git a/dom/base/PostMessageEvent.cpp b/dom/base/PostMessageEvent.cpp index fd5b3e3ac52e..1a1c90e671a0 100644 --- a/dom/base/PostMessageEvent.cpp +++ b/dom/base/PostMessageEvent.cpp @@ -55,11 +55,6 @@ PostMessageEvent::~PostMessageEvent() NS_IMETHODIMP PostMessageEvent::Run() { - MOZ_ASSERT(mTargetWindow->IsOuterWindow(), - "should have been passed an outer window!"); - MOZ_ASSERT(!mSource || mSource->IsOuterWindow(), - "should have been passed an outer window!"); - // Note: We don't init this AutoJSAPI with targetWindow, because we do not // want exceptions during message deserialization to trigger error events on // targetWindow. @@ -82,8 +77,6 @@ PostMessageEvent::Run() targetWindow->IsClosedOrClosing()) return NS_OK; - MOZ_ASSERT(targetWindow->IsInnerWindow(), - "we ordered an inner window!"); JSAutoCompartment ac(cx, targetWindow->GetWrapper()); // Ensure that any origin which might have been provided is the origin of this diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp index 97f04a3720ec..72f0a9596834 100644 --- a/dom/base/TimeoutManager.cpp +++ b/dom/base/TimeoutManager.cpp @@ -410,8 +410,6 @@ TimeoutManager::TimeoutManager(nsGlobalWindowInner& aWindow) mThrottleTrackingTimeouts(false), mBudgetThrottleTimeouts(false) { - MOZ_DIAGNOSTIC_ASSERT(aWindow.IsInnerWindow()); - MOZ_LOG(gLog, LogLevel::Debug, ("TimeoutManager %p created, tracking bucketing %s\n", this, gAnnotateTrackingChannels ? "enabled" : "disabled")); @@ -587,7 +585,7 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler, } if (gRunningTimeoutDepth == 0 && - mWindow.GetPopupControlState() < openBlocked) { + nsContentUtils::GetPopupControlState() < openBlocked) { // This timeout is *not* set from another timeout and it's set // while popups are enabled. Propagate the state to the timeout if // its delay (interval) is equal to or less than what @@ -597,7 +595,7 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler, // because our lower bound for |realInterval| could be pretty high // in some cases. if (interval <= gDisableOpenClickDelay) { - timeout->mPopupState = mWindow.GetPopupControlState(); + timeout->mPopupState = nsContentUtils::GetPopupControlState(); } } @@ -1197,7 +1195,6 @@ public: explicit ThrottleTimeoutsCallback(nsGlobalWindowInner* aWindow) : mWindow(aWindow) { - MOZ_DIAGNOSTIC_ASSERT(aWindow->IsInnerWindow()); } NS_DECL_ISUPPORTS diff --git a/dom/base/WindowDestroyedEvent.cpp b/dom/base/WindowDestroyedEvent.cpp new file mode 100644 index 000000000000..424e5f34e93f --- /dev/null +++ b/dom/base/WindowDestroyedEvent.cpp @@ -0,0 +1,138 @@ +#include "WindowDestroyedEvent.h" + +#include "nsJSUtils.h" +#include "jsapi.h" // for JSAutoRequest +#include "jswrapper.h" +#include "nsIPrincipal.h" +#include "nsISupportsPrimitives.h" +#include "nsIAppStartup.h" +#include "nsToolkitCompsCID.h" +#include "nsCOMPtr.h" + +namespace mozilla { + +// Try to match compartments that are not web content by matching compartments +// with principals that are either the system principal or an expanded principal. +// This may not return true for all non-web-content compartments. +struct BrowserCompartmentMatcher : public js::CompartmentFilter { + bool match(JSCompartment* aC) const override + { + nsCOMPtr pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(aC)); + return nsContentUtils::IsSystemOrExpandedPrincipal(pc); + } +}; + +WindowDestroyedEvent::WindowDestroyedEvent(nsGlobalWindowInner* aWindow, + uint64_t aID, const char* aTopic) + : mozilla::Runnable("WindowDestroyedEvent") + , mID(aID) + , mPhase(Phase::Destroying) + , mTopic(aTopic) + , mIsInnerWindow(true) +{ + mWindow = do_GetWeakReference(aWindow); +} + +WindowDestroyedEvent::WindowDestroyedEvent(nsGlobalWindowOuter* aWindow, + uint64_t aID, const char* aTopic) + : mozilla::Runnable("WindowDestroyedEvent") + , mID(aID) + , mPhase(Phase::Destroying) + , mTopic(aTopic) + , mIsInnerWindow(false) +{ + mWindow = do_GetWeakReference(aWindow); +} + +NS_IMETHODIMP +WindowDestroyedEvent::Run() +{ + AUTO_PROFILER_LABEL("WindowDestroyedEvent::Run", OTHER); + + nsCOMPtr observerService = + services::GetObserverService(); + if (!observerService) { + return NS_OK; + } + + nsCOMPtr wrapper = + do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID); + if (wrapper) { + wrapper->SetData(mID); + observerService->NotifyObservers(wrapper, mTopic.get(), nullptr); + } + + switch (mPhase) { + case Phase::Destroying: + { + bool skipNukeCrossCompartment = false; +#ifndef DEBUG + nsCOMPtr appStartup = + do_GetService(NS_APPSTARTUP_CONTRACTID); + + if (appStartup) { + appStartup->GetShuttingDown(&skipNukeCrossCompartment); + } +#endif + + if (!skipNukeCrossCompartment) { + // The compartment nuking phase might be too expensive, so do that + // part off of idle dispatch. + + // For the compartment nuking phase, we dispatch either an + // inner-window-nuked or an outer-window-nuked notification. + // This will allow tests to wait for compartment nuking to happen. + if (mTopic.EqualsLiteral("inner-window-destroyed")) { + mTopic.AssignLiteral("inner-window-nuked"); + } else if (mTopic.EqualsLiteral("outer-window-destroyed")) { + mTopic.AssignLiteral("outer-window-nuked"); + } + mPhase = Phase::Nuking; + + nsCOMPtr copy(this); + NS_IdleDispatchToCurrentThread(copy.forget(), 1000); + } + } + break; + + case Phase::Nuking: + { + nsCOMPtr window = do_QueryReferent(mWindow); + if (window) { + nsGlobalWindowInner* currentInner; + if (mIsInnerWindow) { + currentInner = nsGlobalWindowInner::FromSupports(window); + } else { + nsGlobalWindowOuter* outer = nsGlobalWindowOuter::FromSupports(window); + currentInner = outer->GetCurrentInnerWindowInternal(); + } + NS_ENSURE_TRUE(currentInner, NS_OK); + + AutoSafeJSContext cx; + JS::Rooted obj(cx, currentInner->FastGetGlobalJSObject()); + if (obj && !js::IsSystemCompartment(js::GetObjectCompartment(obj))) { + JSCompartment* cpt = js::GetObjectCompartment(obj); + nsCOMPtr pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(cpt)); + + if (BasePrincipal::Cast(pc)->AddonPolicy()) { + // We want to nuke all references to the add-on compartment. + xpc::NukeAllWrappersForCompartment(cx, cpt, + mIsInnerWindow ? js::DontNukeWindowReferences + : js::NukeWindowReferences); + } else { + // We only want to nuke wrappers for the chrome->content case + js::NukeCrossCompartmentWrappers(cx, BrowserCompartmentMatcher(), cpt, + mIsInnerWindow ? js::DontNukeWindowReferences + : js::NukeWindowReferences, + js::NukeIncomingReferences); + } + } + } + } + break; + } + + return NS_OK; +} + +} // namespace mozilla diff --git a/dom/base/WindowDestroyedEvent.h b/dom/base/WindowDestroyedEvent.h new file mode 100644 index 000000000000..f62e9941790a --- /dev/null +++ b/dom/base/WindowDestroyedEvent.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WindowDestroyedEvent_h +#define WindowDestroyedEvent_h + +#include "nsGlobalWindow.h" +#include "nsThreadUtils.h" +#include "nsWeakPtr.h" +#include "nsString.h" + +namespace mozilla { + +class WindowDestroyedEvent final : public Runnable +{ +public: + WindowDestroyedEvent(nsGlobalWindowInner* aWindow, + uint64_t aID, const char* aTopic); + WindowDestroyedEvent(nsGlobalWindowOuter* aWindow, + uint64_t aID, const char* aTopic); + + enum class Phase + { + Destroying, + Nuking + }; + + NS_IMETHOD Run() override; + +private: + uint64_t mID; + Phase mPhase; + nsCString mTopic; + nsWeakPtr mWindow; + bool mIsInnerWindow; +}; + +} // namespace mozilla + +#endif // defined(WindowDestroyedEvent_h) diff --git a/dom/base/WindowOrientationObserver.cpp b/dom/base/WindowOrientationObserver.cpp index d4a2cbf177f0..ae55befb0eee 100644 --- a/dom/base/WindowOrientationObserver.cpp +++ b/dom/base/WindowOrientationObserver.cpp @@ -21,7 +21,7 @@ WindowOrientationObserver::WindowOrientationObserver( nsGlobalWindowInner* aGlobalWindow) : mWindow(aGlobalWindow) { - MOZ_ASSERT(aGlobalWindow && aGlobalWindow->IsInnerWindow()); + MOZ_ASSERT(aGlobalWindow); hal::RegisterScreenConfigurationObserver(this); hal::ScreenConfiguration config; diff --git a/dom/base/moz.build b/dom/base/moz.build index bf29a6979c17..52350018a2a7 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -363,6 +363,7 @@ UNIFIED_SOURCES += [ 'TimeoutManager.cpp', 'TreeWalker.cpp', 'WebKitCSSMatrix.cpp', + 'WindowDestroyedEvent.cpp', 'WindowNamedPropertiesHandler.cpp', 'WindowOrientationObserver.cpp', 'XPathGenerator.cpp', @@ -388,11 +389,9 @@ SOURCES += [ 'nsDOMWindowUtils.cpp', # Conflicts with windows.h's definition of SendMessage. 'nsFrameMessageManager.cpp', - # This file has a #error "Never include windows.h in this file!" - 'nsGlobalWindow.cpp', - # These files are included by nsGlobalWindow.cpp - # 'nsGlobalWindowInner.cpp', - # 'nsGlobalWindowOuter.cpp', + # These files have a #error "Never include windows.h in this file!" + 'nsGlobalWindowInner.cpp', + 'nsGlobalWindowOuter.cpp', # Conflicts with windows.h's definition of LoadImage. 'nsImageLoadingContent.cpp', # Because of OS X headers. diff --git a/dom/base/nsContentPermissionHelper.cpp b/dom/base/nsContentPermissionHelper.cpp index ec16fb357e80..e4485123138a 100644 --- a/dom/base/nsContentPermissionHelper.cpp +++ b/dom/base/nsContentPermissionHelper.cpp @@ -364,7 +364,6 @@ nsContentPermissionUtils::CreateContentPermissionRequestParent(const nsTArrayIsInnerWindow()); NS_ENSURE_STATE(aWindow && aWindow->IsCurrentInnerWindow()); // for content process diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index fafb75ed7062..ca9d89298fc1 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -343,6 +343,11 @@ bool nsContentUtils::sDoNotTrackEnabled = false; mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump"); +PopupControlState nsContentUtils::sPopupControlState = openAbused; + +int32_t nsContentUtils::sInnerOrOuterWindowCount = 0; +uint32_t nsContentUtils::sInnerOrOuterWindowSerialCounter = 0; + // Subset of http://www.whatwg.org/specs/web-apps/current-work/#autofill-field-name enum AutocompleteUnsupportedFieldName : uint8_t { @@ -9017,8 +9022,6 @@ nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel) nsContentUtils::StorageAccess nsContentUtils::StorageAllowedForWindow(nsPIDOMWindowInner* aWindow) { - MOZ_ASSERT(aWindow->IsInnerWindow()); - if (nsIDocument* document = aWindow->GetExtantDoc()) { nsCOMPtr principal = document->NodePrincipal(); return InternalStorageAllowedForPrincipal(principal, aWindow); @@ -9107,7 +9110,6 @@ nsContentUtils::InternalStorageAllowedForPrincipal(nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aWindow) { MOZ_ASSERT(aPrincipal); - MOZ_ASSERT(!aWindow || aWindow->IsInnerWindow()); StorageAccess access = StorageAccess::eAllow; @@ -10974,3 +10976,44 @@ nsContentUtils::DevToolsEnabled(JSContext* aCx) return workerPrivate->DevToolsEnabled(); } + +/* static */ bool +nsContentUtils::ContentIsLink(nsIContent* aContent) +{ + return aContent && (aContent->IsHTMLElement(nsGkAtoms::a) || + aContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type, + nsGkAtoms::simple, eCaseMatters)); +} + +/* static */ already_AddRefed +nsContentUtils::TryGetTabChildGlobalAsEventTarget(nsISupports* aFrom) +{ + nsCOMPtr frameLoaderOwner = do_QueryInterface(aFrom); + if (!frameLoaderOwner) { + return nullptr; + } + + RefPtr frameLoader = frameLoaderOwner->GetFrameLoader(); + if (!frameLoader) { + return nullptr; + } + + nsCOMPtr target = frameLoader->GetTabChildGlobalAsEventTarget(); + return target.forget(); +} + +/* static */ uint32_t +nsContentUtils::InnerOrOuterWindowCreated() +{ + MOZ_ASSERT(NS_IsMainThread()); + ++sInnerOrOuterWindowCount; + return ++sInnerOrOuterWindowSerialCounter; +} + +/* static */ void +nsContentUtils::InnerOrOuterWindowDestroyed() +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(sInnerOrOuterWindowCount > 0); + --sInnerOrOuterWindowCount; +} diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index de958d9c3014..72440e6d7ba6 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -3243,6 +3243,38 @@ public: static void AsyncPrecreateStringBundles(); + static bool ContentIsLink(nsIContent* aContent); + + static already_AddRefed + TryGetTabChildGlobalAsEventTarget(nsISupports* aFrom); + + static PopupControlState + PushPopupControlState(PopupControlState aState, bool aForce) + { + MOZ_ASSERT(NS_IsMainThread()); + PopupControlState old = sPopupControlState; + if (aState < old || aForce) { + sPopupControlState = aState; + } + return old; + } + + static void + PopPopupControlState(PopupControlState aState) + { + MOZ_ASSERT(NS_IsMainThread()); + sPopupControlState = aState; + } + + static PopupControlState GetPopupControlState() { return sPopupControlState; } + + // Get a serial number for a newly created inner or outer window. + static uint32_t InnerOrOuterWindowCreated(); + // Record that an inner or outer window has been destroyed. + static void InnerOrOuterWindowDestroyed(); + // Get the current number of inner or outer windows. + static int32_t GetCurrentInnerOrOuterWindowCount() { return sInnerOrOuterWindowCount; } + private: static bool InitializeEventTable(); @@ -3431,6 +3463,11 @@ private: #endif static bool sDoNotTrackEnabled; static mozilla::LazyLogModule sDOMDumpLog; + + static PopupControlState sPopupControlState; + + static int32_t sInnerOrOuterWindowCount; + static uint32_t sInnerOrOuterWindowSerialCounter; }; /* static */ inline diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 06bbdbecb62e..177970cefd37 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -229,7 +229,6 @@ static inline nsresult SetParentToWindow(nsGlobalWindowInner *win, JSObject **parent) { MOZ_ASSERT(win); - MOZ_ASSERT(win->IsInnerWindow()); *parent = win->FastGetGlobalJSObject(); if (MOZ_UNLIKELY(!*parent)) { @@ -1029,12 +1028,13 @@ nsDOMConstructor::Create(const char16_t* aName, nsPIDOMWindowOuter* outerWindow = aOwner->GetOuterWindow(); nsPIDOMWindowInner* currentInner = outerWindow ? outerWindow->GetCurrentInnerWindow() : aOwner; - if (!currentInner || - (aOwner != currentInner && - !nsContentUtils::CanCallerAccess(currentInner) && - !(currentInner = aOwner)->IsInnerWindow())) { + if (!currentInner) { return NS_ERROR_DOM_SECURITY_ERR; } + if (aOwner != currentInner && + !nsContentUtils::CanCallerAccess(currentInner)) { + currentInner = aOwner; + } bool constructable = aNameStruct && IsConstructable(aNameStruct); diff --git a/dom/base/nsDOMMutationObserver.cpp b/dom/base/nsDOMMutationObserver.cpp index 62c6f773d584..b44d0bc422aa 100644 --- a/dom/base/nsDOMMutationObserver.cpp +++ b/dom/base/nsDOMMutationObserver.cpp @@ -816,7 +816,6 @@ nsDOMMutationObserver::Constructor(const mozilla::dom::GlobalObject& aGlobal, aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - MOZ_ASSERT(window->IsInnerWindow()); bool isChrome = nsContentUtils::IsChromeDoc(window->GetExtantDoc()); RefPtr observer = new nsDOMMutationObserver(window.forget(), aCb, isChrome); diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 3cdebc755374..28701daa6572 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -212,7 +212,6 @@ nsDOMWindowUtils::nsDOMWindowUtils(nsGlobalWindowOuter *aWindow) { nsCOMPtr supports = do_QueryObject(aWindow); mWindow = do_GetWeakReference(supports); - NS_ASSERTION(aWindow->IsOuterWindow(), "How did that happen?"); } nsDOMWindowUtils::~nsDOMWindowUtils() @@ -2390,7 +2389,6 @@ nsDOMWindowUtils::GetOuterWindowID(uint64_t *aWindowID) nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_STATE(window); - NS_ASSERTION(window->IsOuterWindow(), "How did that happen?"); *aWindowID = window->WindowID(); return NS_OK; } @@ -2401,7 +2399,6 @@ nsDOMWindowUtils::GetCurrentInnerWindowID(uint64_t *aWindowID) nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_TRUE(window, NS_ERROR_NOT_AVAILABLE); - NS_ASSERTION(window->IsOuterWindow(), "How did that happen?"); nsGlobalWindowInner* inner = nsGlobalWindowOuter::Cast(window)->GetCurrentInnerWindowInternal(); if (!inner) { diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index bb14e4a3ebf8..c9eb620cf5e9 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1538,6 +1538,7 @@ nsIDocument::nsIDocument() mDidCallBeginLoad(false), mBufferingCSPViolations(false), mAllowPaymentRequest(false), + mEncodingMenuDisabled(false), mIsScopedStyleEnabled(eScopedStyle_Unknown), mCompatMode(eCompatibility_FullStandards), mReadyState(ReadyState::READYSTATE_UNINITIALIZED), @@ -5063,14 +5064,6 @@ nsIDocument::GetContainer() 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 MOZ_ASSERT(aScriptGlobalObject || !mAnimationController || mAnimationController->IsPausedByType( nsSMILTimeContainer::PAUSE_PAGEHIDE | @@ -10889,7 +10882,6 @@ nsIDocument::CreateTouch(nsGlobalWindowInner* aView, float aRotationAngle, float aForce) { - MOZ_ASSERT_IF(aView, aView->IsInnerWindow()); RefPtr touch = new Touch(aTarget, aIdentifier, aPageX, aPageY, @@ -14380,7 +14372,6 @@ nsIDocument::GetSelection(ErrorResult& aRv) return nullptr; } - NS_ASSERTION(window->IsInnerWindow(), "Should have inner window here!"); if (!window->IsCurrentInnerWindow()) { return nullptr; } diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index a4ba4d4f76cd..9dea3c90a16a 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1038,7 +1038,6 @@ nsFocusManager::WindowHidden(mozIDOMWindowProxy* aWindow) // not happen if nsIAppStartup::eForceQuit is used to quit, and can cause // a leak. So if the active window is being destroyed, call WindowLowered // directly. - NS_ASSERTION(mFocusedWindow->IsOuterWindow(), "outer window expected"); if (mActiveWindow == mFocusedWindow || mActiveWindow == window) WindowLowered(mActiveWindow); else diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp deleted file mode 100644 index d3686f08acbf..000000000000 --- a/dom/base/nsGlobalWindow.cpp +++ /dev/null @@ -1,832 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsGlobalWindow.h" - -#include - -#include "mozilla/MemoryReporting.h" - -// Local Includes -#include "Navigator.h" -#include "nsContentSecurityManager.h" -#include "nsScreen.h" -#include "nsHistory.h" -#include "nsDOMNavigationTiming.h" -#include "nsIDOMStorageManager.h" -#include "mozilla/dom/LocalStorage.h" -#include "mozilla/dom/Storage.h" -#include "mozilla/dom/IdleRequest.h" -#include "mozilla/dom/Performance.h" -#include "mozilla/dom/StorageEvent.h" -#include "mozilla/dom/StorageEventBinding.h" -#include "mozilla/dom/StorageNotifierService.h" -#include "mozilla/dom/StorageUtils.h" -#include "mozilla/dom/Timeout.h" -#include "mozilla/dom/TimeoutHandler.h" -#include "mozilla/dom/TimeoutManager.h" -#include "mozilla/IntegerPrintfMacros.h" -#if defined(MOZ_WIDGET_ANDROID) -#include "mozilla/dom/WindowOrientationObserver.h" -#endif -#include "nsDOMOfflineResourceList.h" -#include "nsError.h" -#include "nsIIdleService.h" -#include "nsISizeOfEventTarget.h" -#include "nsDOMJSUtils.h" -#include "nsArrayUtils.h" -#include "nsIDOMWindowCollection.h" -#include "nsDOMWindowList.h" -#include "mozilla/dom/WakeLock.h" -#include "mozilla/dom/power/PowerManagerService.h" -#include "nsIDocShellTreeOwner.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIPermissionManager.h" -#include "nsIScriptContext.h" -#include "nsIScriptTimeoutHandler.h" -#include "nsITimeoutHandler.h" -#include "nsIController.h" -#include "nsScriptNameSpaceManager.h" -#include "nsISlowScriptDebug.h" -#include "nsWindowMemoryReporter.h" -#include "nsWindowSizes.h" -#include "WindowNamedPropertiesHandler.h" -#include "nsFrameSelection.h" -#include "nsNetUtil.h" -#include "nsVariant.h" -#include "nsPrintfCString.h" -#include "mozilla/intl/LocaleService.h" - -// Helper Classes -#include "nsJSUtils.h" -#include "jsapi.h" // for JSAutoRequest -#include "jswrapper.h" -#include "nsCharSeparatedTokenizer.h" -#include "nsReadableUtils.h" -#include "nsDOMClassInfo.h" -#include "nsJSEnvironment.h" -#include "mozilla/dom/ScriptSettings.h" -#include "mozilla/Preferences.h" -#include "mozilla/Likely.h" -#include "mozilla/Sprintf.h" -#include "mozilla/Unused.h" - -// Other Classes -#include "mozilla/dom/BarProps.h" -#include "nsContentCID.h" -#include "nsLayoutStatics.h" -#include "nsCCUncollectableMarker.h" -#include "mozilla/dom/workers/Workers.h" -#include "mozilla/dom/ToJSValue.h" -#include "nsJSPrincipals.h" -#include "mozilla/Attributes.h" -#include "mozilla/Debug.h" -#include "mozilla/EventListenerManager.h" -#include "mozilla/EventStates.h" -#include "mozilla/MouseEvents.h" -#include "mozilla/ProcessHangMonitor.h" -#include "mozilla/ThrottledEventQueue.h" -#include "AudioChannelService.h" -#include "nsAboutProtocolUtils.h" -#include "nsCharTraits.h" // NS_IS_HIGH/LOW_SURROGATE -#include "PostMessageEvent.h" -#include "mozilla/dom/DocGroup.h" -#include "mozilla/dom/TabGroup.h" - -// Interfaces Needed -#include "nsIFrame.h" -#include "nsCanvasFrame.h" -#include "nsIWidget.h" -#include "nsIWidgetListener.h" -#include "nsIBaseWindow.h" -#include "nsIDeviceSensors.h" -#include "nsIContent.h" -#include "nsIDocShell.h" -#include "nsIDocCharset.h" -#include "nsIDocument.h" -#include "Crypto.h" -#include "nsIDOMDocument.h" -#include "nsIDOMElement.h" -#include "nsIDOMEvent.h" -#include "nsIDOMOfflineResourceList.h" -#include "nsDOMString.h" -#include "nsIEmbeddingSiteWindow.h" -#include "nsThreadUtils.h" -#include "nsILoadContext.h" -#include "nsIPresShell.h" -#include "nsIScrollableFrame.h" -#include "nsView.h" -#include "nsViewManager.h" -#include "nsISelectionController.h" -#include "nsISelection.h" -#include "nsIPrompt.h" -#include "nsIPromptService.h" -#include "nsIPromptFactory.h" -#include "nsIAddonPolicyService.h" -#include "nsIWritablePropertyBag2.h" -#include "nsIWebNavigation.h" -#include "nsIWebBrowserChrome.h" -#include "nsIWebBrowserFind.h" // For window.find() -#include "nsIWindowMediator.h" // For window.find() -#include "nsComputedDOMStyle.h" -#include "nsDOMCID.h" -#include "nsDOMWindowUtils.h" -#include "nsIWindowWatcher.h" -#include "nsPIWindowWatcher.h" -#include "nsIContentViewer.h" -#include "nsIScriptError.h" -#include "nsIControllers.h" -#include "nsIControllerContext.h" -#include "nsGlobalWindowCommands.h" -#include "nsQueryObject.h" -#include "nsContentUtils.h" -#include "nsCSSProps.h" -#include "nsIDOMFileList.h" -#include "nsIURIFixup.h" -#ifndef DEBUG -#include "nsIAppStartup.h" -#include "nsToolkitCompsCID.h" -#endif -#include "nsCDefaultURIFixup.h" -#include "mozilla/EventDispatcher.h" -#include "mozilla/EventStateManager.h" -#include "nsIObserverService.h" -#include "nsFocusManager.h" -#include "nsIXULWindow.h" -#include "nsITimedChannel.h" -#include "nsServiceManagerUtils.h" -#ifdef MOZ_XUL -#include "nsIDOMXULControlElement.h" -#include "nsMenuPopupFrame.h" -#endif -#include "mozilla/dom/CustomEvent.h" -#include "nsIJARChannel.h" -#include "nsIScreenManager.h" -#include "nsIEffectiveTLDService.h" - -#include "xpcprivate.h" - -#ifdef NS_PRINTING -#include "nsIPrintSettings.h" -#include "nsIPrintSettingsService.h" -#include "nsIWebBrowserPrint.h" -#endif - -#include "nsWindowRoot.h" -#include "nsNetCID.h" -#include "nsIArray.h" - -// XXX An unfortunate dependency exists here (two XUL files). -#include "nsIDOMXULDocument.h" -#include "nsIDOMXULCommandDispatcher.h" - -#include "nsBindingManager.h" -#include "nsXBLService.h" - -// used for popup blocking, needs to be converted to something -// belonging to the back-end like nsIContentPolicy -#include "nsIPopupWindowManager.h" - -#include "nsIDragService.h" -#include "mozilla/dom/Element.h" -#include "mozilla/dom/Selection.h" -#include "nsFrameLoader.h" -#include "nsISupportsPrimitives.h" -#include "nsXPCOMCID.h" -#include "mozilla/Logging.h" -#include "prenv.h" - -#include "mozilla/dom/IDBFactory.h" -#include "mozilla/dom/MessageChannel.h" -#include "mozilla/dom/Promise.h" - -#include "mozilla/dom/Gamepad.h" -#include "mozilla/dom/GamepadManager.h" - -#include "gfxVR.h" -#include "mozilla/dom/VRDisplay.h" -#include "mozilla/dom/VRDisplayEvent.h" -#include "mozilla/dom/VRDisplayEventBinding.h" -#include "mozilla/dom/VREventObserver.h" - -#include "nsRefreshDriver.h" -#include "Layers.h" - -#include "mozilla/AddonPathService.h" -#include "mozilla/BasePrincipal.h" -#include "mozilla/Services.h" -#include "mozilla/Telemetry.h" -#include "mozilla/dom/Location.h" -#include "nsHTMLDocument.h" -#include "nsWrapperCacheInlines.h" -#include "mozilla/DOMEventTargetHelper.h" -#include "prrng.h" -#include "nsSandboxFlags.h" -#include "TimeChangeObserver.h" -#include "mozilla/dom/AudioContext.h" -#include "mozilla/dom/BrowserElementDictionariesBinding.h" -#include "mozilla/dom/cache/CacheStorage.h" -#include "mozilla/dom/Console.h" -#include "mozilla/dom/Fetch.h" -#include "mozilla/dom/FunctionBinding.h" -#include "mozilla/dom/HashChangeEvent.h" -#include "mozilla/dom/IntlUtils.h" -#include "mozilla/dom/MozSelfSupportBinding.h" -#include "mozilla/dom/PopStateEvent.h" -#include "mozilla/dom/PopupBlockedEvent.h" -#include "mozilla/dom/PrimitiveConversions.h" -#include "mozilla/dom/WindowBinding.h" -#include "nsITabChild.h" -#include "mozilla/dom/MediaQueryList.h" -#include "mozilla/dom/ScriptSettings.h" -#include "mozilla/dom/NavigatorBinding.h" -#include "mozilla/dom/ImageBitmap.h" -#include "mozilla/dom/ImageBitmapBinding.h" -#include "mozilla/dom/ServiceWorkerRegistration.h" -#include "mozilla/dom/U2F.h" -#include "mozilla/dom/WebIDLGlobalNameHash.h" -#include "mozilla/dom/Worklet.h" -#ifdef HAVE_SIDEBAR -#include "mozilla/dom/ExternalBinding.h" -#endif - -#ifdef MOZ_WEBSPEECH -#include "mozilla/dom/SpeechSynthesis.h" -#endif - -// Apple system headers seem to have a check() macro. -#ifdef check -class nsIScriptTimeoutHandler; -#undef check -#endif // check -#include "AccessCheck.h" - -#ifdef ANDROID -#include -#endif - -#ifdef XP_WIN -#include -#define getpid _getpid -#else -#include // for getpid() -#endif - -static const char kStorageEnabled[] = "dom.storage.enabled"; - -using namespace mozilla; -using namespace mozilla::dom; -using namespace mozilla::dom::ipc; -using mozilla::BasePrincipal; -using mozilla::OriginAttributes; -using mozilla::TimeStamp; -using mozilla::TimeDuration; -using mozilla::dom::cache::CacheStorage; - -static LazyLogModule gDOMLeakPRLog("DOMLeak"); - -static int32_t gRefCnt = 0; -static int32_t gOpenPopupSpamCount = 0; -static PopupControlState gPopupControlState = openAbused; -static bool gMouseDown = false; -static bool gDragServiceDisabled = false; -static FILE *gDumpFile = nullptr; -static uint32_t gSerialCounter = 0; -static bool gIdleObserversAPIFuzzTimeDisabled = false; - -#ifdef DEBUG_jst -int32_t gTimeoutCnt = 0; -#endif - -#if defined(DEBUG_bryner) || defined(DEBUG_chb) -#define DEBUG_PAGE_CACHE -#endif - -#define DOM_TOUCH_LISTENER_ADDED "dom-touch-listener-added" - -#define MEMORY_PRESSURE_OBSERVER_TOPIC "memory-pressure" - -// The interval at which we execute idle callbacks -static uint32_t gThrottledIdlePeriodLength; - -#define DEFAULT_THROTTLED_IDLE_PERIOD_LENGTH 10000 - -// CIDs -static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); - -#define NETWORK_UPLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkupload") -#define NETWORK_DOWNLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkdownload") - -namespace mozilla { -namespace dom { -extern uint64_t -NextWindowID(); -} // namespace dom -} // namespace mozilla - -template -nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow) -: mFrameElement(nullptr), mDocShell(nullptr), mModalStateDepth(0), - mMutationBits(0), mActivePeerConnections(0), mIsDocumentLoaded(false), - mIsHandlingResizeEvent(false), mIsInnerWindow(aOuterWindow != nullptr), - mMayHavePaintEventListener(false), mMayHaveTouchEventListener(false), - mMayHaveSelectionChangeEventListener(false), - mMayHaveMouseEnterLeaveEventListener(false), - mMayHavePointerEnterLeaveEventListener(false), - mInnerObjectsFreed(false), - mIsActive(false), mIsBackground(false), - mMediaSuspend( - Preferences::GetBool("media.block-autoplay-until-in-foreground", true) && - Preferences::GetBool("media.autoplay.enabled", true) ? - nsISuspendedTypes::SUSPENDED_BLOCK : nsISuspendedTypes::NONE_SUSPENDED), - mAudioMuted(false), mAudioVolume(1.0), mAudioCaptured(false), - mDesktopModeViewport(false), mIsRootOuterWindow(false), mInnerWindow(nullptr), - mOuterWindow(aOuterWindow), - // Make sure no actual window ends up with mWindowID == 0 - mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false), - mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false), - mLargeAllocStatus(LargeAllocStatus::NONE), - mHasTriedToCacheTopInnerWindow(false), - mNumOfIndexedDBDatabases(0), - mNumOfOpenWebSockets(0) -{ - if (aOuterWindow) { - mTimeoutManager = - MakeUnique(*nsGlobalWindowInner::Cast(AsInner())); - } -} - -template -nsPIDOMWindow::~nsPIDOMWindow() {} - -PopupControlState -PushPopupControlState(PopupControlState aState, bool aForce) -{ - MOZ_ASSERT(NS_IsMainThread()); - - PopupControlState oldState = gPopupControlState; - - if (aState < gPopupControlState || aForce) { - gPopupControlState = aState; - } - - return oldState; -} - -void -PopPopupControlState(PopupControlState aState) -{ - MOZ_ASSERT(NS_IsMainThread()); - - gPopupControlState = aState; -} - -// We need certain special behavior for remote XUL whitelisted domains, but we -// don't want that behavior to take effect in automation, because we whitelist -// all the mochitest domains. So we need to check a pref here. -static bool -TreatAsRemoteXUL(nsIPrincipal* aPrincipal) -{ - MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(aPrincipal)); - return nsContentUtils::AllowXULXBLForPrincipal(aPrincipal) && - !Preferences::GetBool("dom.use_xbl_scopes_for_remote_xul", false); -} - -static bool -EnablePrivilege(JSContext* cx, unsigned argc, JS::Value* vp) -{ - Telemetry::Accumulate(Telemetry::ENABLE_PRIVILEGE_EVER_CALLED, true); - return xpc::EnableUniversalXPConnect(cx); -} - -static const JSFunctionSpec EnablePrivilegeSpec[] = { - JS_FN("enablePrivilege", EnablePrivilege, 1, 0), - JS_FS_END -}; - -static bool -InitializeLegacyNetscapeObject(JSContext* aCx, JS::Handle aGlobal) -{ - JSAutoCompartment ac(aCx, aGlobal); - - // Note: MathJax depends on window.netscape being exposed. See bug 791526. - JS::Rooted obj(aCx); - obj = JS_DefineObject(aCx, aGlobal, "netscape", nullptr); - NS_ENSURE_TRUE(obj, false); - - obj = JS_DefineObject(aCx, obj, "security", nullptr); - NS_ENSURE_TRUE(obj, false); - - // We hide enablePrivilege behind a pref because it has been altered in a - // way that makes it fundamentally insecure to use in production. Mozilla - // uses this pref during automated testing to support legacy test code that - // uses enablePrivilege. If you're not doing test automation, you _must_ not - // flip this pref, or you will be exposing all your users to security - // vulnerabilities. - if (!xpc::IsInAutomation()) { - return true; - } - - /* Define PrivilegeManager object with the necessary "static" methods. */ - obj = JS_DefineObject(aCx, obj, "PrivilegeManager", nullptr); - NS_ENSURE_TRUE(obj, false); - - return JS_DefineFunctions(aCx, obj, EnablePrivilegeSpec); -} - -static JS::CompartmentCreationOptions& -SelectZoneGroup(nsGlobalWindowInner* aNewInner, - JS::CompartmentCreationOptions& aOptions) -{ - JS::CompartmentCreationOptions options; - - if (aNewInner->GetOuterWindow()) { - nsGlobalWindowOuter *top = aNewInner->GetTopInternal(); - - // If we have a top-level window, use its zone (and zone group). - if (top && top->GetGlobalJSObject()) { - return aOptions.setExistingZone(top->GetGlobalJSObject()); - } - } - - // If we're in the parent process, don't bother with zone groups. - if (XRE_IsParentProcess()) { - return aOptions.setNewZoneInSystemZoneGroup(); - } - - // Otherwise, find a zone group from the TabGroup. Typically we only have to - // go through one iteration of this loop. - RefPtr tabGroup = aNewInner->TabGroup(); - for (nsPIDOMWindowOuter* outer : tabGroup->GetWindows()) { - nsGlobalWindowOuter* window = nsGlobalWindowOuter::Cast(outer); - if (JSObject* global = window->GetGlobalJSObject()) { - return aOptions.setNewZoneInExistingZoneGroup(global); - } - } - - return aOptions.setNewZoneInNewZoneGroup(); -} - -/** - * Create a new global object that will be used for an inner window. - * Return the native global and an nsISupports 'holder' that can be used - * to manage the lifetime of it. - */ -static nsresult -CreateNativeGlobalForInner(JSContext* aCx, - nsGlobalWindowInner* aNewInner, - nsIURI* aURI, - nsIPrincipal* aPrincipal, - JS::MutableHandle aGlobal, - bool aIsSecureContext) -{ - MOZ_ASSERT(aCx); - MOZ_ASSERT(aNewInner); - MOZ_ASSERT(aNewInner->IsInnerWindow()); - MOZ_ASSERT(aPrincipal); - - // DOMWindow with nsEP is not supported, we have to make sure - // no one creates one accidentally. - nsCOMPtr nsEP = do_QueryInterface(aPrincipal); - MOZ_RELEASE_ASSERT(!nsEP, "DOMWindow with nsEP is not supported"); - - JS::CompartmentOptions options; - - SelectZoneGroup(aNewInner, options.creationOptions()); - - // Sometimes add-ons load their own XUL windows, either as separate top-level - // windows or inside a browser element. In such cases we want to tag the - // window's compartment with the add-on ID. See bug 1092156. - if (nsContentUtils::IsSystemPrincipal(aPrincipal)) { - options.creationOptions().setAddonId(MapURIToAddonID(aURI)); - } - - options.creationOptions().setSecureContext(aIsSecureContext); - - xpc::InitGlobalObjectOptions(options, aPrincipal); - - // Determine if we need the Components object. - bool needComponents = nsContentUtils::IsSystemPrincipal(aPrincipal) || - TreatAsRemoteXUL(aPrincipal); - uint32_t flags = needComponents ? 0 : xpc::OMIT_COMPONENTS_OBJECT; - flags |= xpc::DONT_FIRE_ONNEWGLOBALHOOK; - - if (!WindowBinding::Wrap(aCx, aNewInner, aNewInner, options, - nsJSPrincipals::get(aPrincipal), false, aGlobal) || - !xpc::InitGlobalObject(aCx, aGlobal, flags)) { - return NS_ERROR_FAILURE; - } - - MOZ_ASSERT(aNewInner->GetWrapperPreserveColor() == aGlobal); - - // Set the location information for the new global, so that tools like - // about:memory may use that information - xpc::SetLocationForGlobal(aGlobal, aURI); - - if (!InitializeLegacyNetscapeObject(aCx, aGlobal)) { - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -static -already_AddRefed -TryGetTabChildGlobalAsEventTarget(nsISupports *aFrom) -{ - nsCOMPtr frameLoaderOwner = do_QueryInterface(aFrom); - if (!frameLoaderOwner) { - return nullptr; - } - - RefPtr frameLoader = frameLoaderOwner->GetFrameLoader(); - if (!frameLoader) { - return nullptr; - } - - nsCOMPtr target = frameLoader->GetTabChildGlobalAsEventTarget(); - return target.forget(); -} - -template -nsIURI* -nsPIDOMWindow::GetDocumentURI() const -{ - return mDoc ? mDoc->GetDocumentURI() : mDocumentURI.get(); -} - -template -nsIURI* -nsPIDOMWindow::GetDocBaseURI() const -{ - return mDoc ? mDoc->GetDocBaseURI() : mDocBaseURI.get(); -} - -template -void -nsPIDOMWindow::MaybeCreateDoc() -{ - MOZ_ASSERT(!mDoc); - if (nsIDocShell* docShell = GetDocShell()) { - // Note that |document| here is the same thing as our mDoc, but we - // don't have to explicitly set the member variable because the docshell - // has already called SetNewDocument(). - nsCOMPtr document = docShell->GetDocument(); - Unused << document; - } -} - -// Try to match compartments that are not web content by matching compartments -// with principals that are either the system principal or an expanded principal. -// This may not return true for all non-web-content compartments. -struct BrowserCompartmentMatcher : public js::CompartmentFilter { - bool match(JSCompartment* aC) const override - { - nsCOMPtr pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(aC)); - return nsContentUtils::IsSystemOrExpandedPrincipal(pc); - } -}; - -class WindowDestroyedEvent final : public Runnable -{ -public: - WindowDestroyedEvent(nsGlobalWindowInner* aWindow, uint64_t aID, const char* aTopic) - : mozilla::Runnable("WindowDestroyedEvent") - , mID(aID) - , mPhase(Phase::Destroying) - , mTopic(aTopic) - , mIsInnerWindow(true) - { - mWindow = do_GetWeakReference(aWindow); - } - WindowDestroyedEvent(nsGlobalWindowOuter* aWindow, uint64_t aID, const char* aTopic) - : mozilla::Runnable("WindowDestroyedEvent") - , mID(aID) - , mPhase(Phase::Destroying) - , mTopic(aTopic) - , mIsInnerWindow(false) - { - mWindow = do_GetWeakReference(aWindow); - } - - enum class Phase - { - Destroying, - Nuking - }; - - NS_IMETHOD Run() override - { - AUTO_PROFILER_LABEL("WindowDestroyedEvent::Run", OTHER); - - nsCOMPtr observerService = - services::GetObserverService(); - if (!observerService) { - return NS_OK; - } - - nsCOMPtr wrapper = - do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID); - if (wrapper) { - wrapper->SetData(mID); - observerService->NotifyObservers(wrapper, mTopic.get(), nullptr); - } - - switch (mPhase) { - case Phase::Destroying: - { - bool skipNukeCrossCompartment = false; -#ifndef DEBUG - nsCOMPtr appStartup = - do_GetService(NS_APPSTARTUP_CONTRACTID); - - if (appStartup) { - appStartup->GetShuttingDown(&skipNukeCrossCompartment); - } -#endif - - if (!skipNukeCrossCompartment) { - // The compartment nuking phase might be too expensive, so do that - // part off of idle dispatch. - - // For the compartment nuking phase, we dispatch either an - // inner-window-nuked or an outer-window-nuked notification. - // This will allow tests to wait for compartment nuking to happen. - if (mTopic.EqualsLiteral("inner-window-destroyed")) { - mTopic.AssignLiteral("inner-window-nuked"); - } else if (mTopic.EqualsLiteral("outer-window-destroyed")) { - mTopic.AssignLiteral("outer-window-nuked"); - } - mPhase = Phase::Nuking; - - nsCOMPtr copy(this); - NS_IdleDispatchToCurrentThread(copy.forget(), 1000); - } - } - break; - - case Phase::Nuking: - { - nsCOMPtr window = do_QueryReferent(mWindow); - if (window) { - nsGlobalWindowInner* currentInner; - if (mIsInnerWindow) { - currentInner = nsGlobalWindowInner::FromSupports(window); - } else { - nsGlobalWindowOuter* outer = nsGlobalWindowOuter::FromSupports(window); - currentInner = outer->GetCurrentInnerWindowInternal(); - } - NS_ENSURE_TRUE(currentInner, NS_OK); - - AutoSafeJSContext cx; - JS::Rooted obj(cx, currentInner->FastGetGlobalJSObject()); - if (obj && !js::IsSystemCompartment(js::GetObjectCompartment(obj))) { - JSCompartment* cpt = js::GetObjectCompartment(obj); - nsCOMPtr pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(cpt)); - - if (BasePrincipal::Cast(pc)->AddonPolicy()) { - // We want to nuke all references to the add-on compartment. - xpc::NukeAllWrappersForCompartment(cx, cpt, - mIsInnerWindow ? js::DontNukeWindowReferences - : js::NukeWindowReferences); - } else { - // We only want to nuke wrappers for the chrome->content case - js::NukeCrossCompartmentWrappers(cx, BrowserCompartmentMatcher(), cpt, - mIsInnerWindow ? js::DontNukeWindowReferences - : js::NukeWindowReferences, - js::NukeIncomingReferences); - } - } - } - } - break; - } - - return NS_OK; - } - -private: - uint64_t mID; - Phase mPhase; - nsCString mTopic; - nsWeakPtr mWindow; - bool mIsInnerWindow; -}; - -class ChildCommandDispatcher : public Runnable -{ -public: - ChildCommandDispatcher(nsPIWindowRoot* aRoot, - nsITabChild* aTabChild, - const nsAString& aAction) - : mozilla::Runnable("ChildCommandDispatcher") - , mRoot(aRoot) - , mTabChild(aTabChild) - , mAction(aAction) - { - } - - NS_IMETHOD Run() override - { - nsTArray enabledCommands, disabledCommands; - mRoot->GetEnabledDisabledCommands(enabledCommands, disabledCommands); - if (enabledCommands.Length() || disabledCommands.Length()) { - mTabChild->EnableDisableCommands(mAction, enabledCommands, disabledCommands); - } - - return NS_OK; - } - -private: - nsCOMPtr mRoot; - nsCOMPtr mTabChild; - nsString mAction; -}; - -class CommandDispatcher : public Runnable -{ -public: - CommandDispatcher(nsIDOMXULCommandDispatcher* aDispatcher, - const nsAString& aAction) - : mozilla::Runnable("CommandDispatcher") - , mDispatcher(aDispatcher) - , mAction(aAction) - { - } - - NS_IMETHOD Run() override - { - return mDispatcher->UpdateCommands(mAction); - } - - nsCOMPtr mDispatcher; - nsString mAction; -}; - -static bool IsLink(nsIContent* aContent) -{ - return aContent && (aContent->IsHTMLElement(nsGkAtoms::a) || - aContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type, - nsGkAtoms::simple, eCaseMatters)); -} - -static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode) -{ - if (!aNode) { - return true; - } - return !IsLink(aNode) && - !aNode->IsAnyOfHTMLElements(nsGkAtoms::video, nsGkAtoms::audio); -} - -static bool -IsInterval(const Optional& aTimeout, int32_t& aResultTimeout) -{ - if (aTimeout.WasPassed()) { - aResultTimeout = aTimeout.Value(); - return true; - } - - // If no interval was specified, treat this like a timeout, to avoid setting - // an interval of 0 milliseconds. - aResultTimeout = 0; - return false; -} - -template -mozilla::dom::DocGroup* -nsPIDOMWindow::GetDocGroup() const -{ - nsIDocument* doc = GetExtantDoc(); - if (doc) { - return doc->GetDocGroup(); - } - return nullptr; -} - -static void -EnsurePrefCaches() -{ - static bool sFirstTime = true; - if (sFirstTime) { - TimeoutManager::Initialize(); - Preferences::AddBoolVarCache(&gIdleObserversAPIFuzzTimeDisabled, - "dom.idle-observers-api.fuzz_time.disabled", - false); - - Preferences::AddUintVarCache(&gThrottledIdlePeriodLength, - "dom.idle_period.throttled_length", - DEFAULT_THROTTLED_IDLE_PERIOD_LENGTH); - sFirstTime = false; - } -} - -// Include the implementations for the inner and outer windows respectively. -#include "nsGlobalWindowOuter.cpp" -#include "nsGlobalWindowInner.cpp" - -template class nsPIDOMWindow; -template class nsPIDOMWindow; diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 918c9940aa1c..98407208d328 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -7,24 +7,6 @@ #ifndef nsGlobalWindow_h___ #define nsGlobalWindow_h___ -// XXX(nika): Figure out where to put this? -#define DEFAULT_HOME_PAGE "www.mozilla.org" -#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage" - -// Amount of time allowed between alert/prompt/confirm before enabling -// the stop dialog checkbox. -#define DEFAULT_SUCCESSIVE_DIALOG_TIME_LIMIT 3 // 3 sec - -// Maximum number of successive dialogs before we prompt users to disable -// dialogs for this window. -#define MAX_SUCCESSIVE_DIALOG_COUNT 5 - -// Idle fuzz time upper limit -#define MAX_IDLE_FUZZ_TIME_MS 90000 - -// Min idle notification time in seconds. -#define MIN_IDLE_NOTIFICATION_TIME_S 1 - // NOTE: This is so that I can rewrite the includes in a separate patch. // Specificially I don't think I want to change this until I've moved everything // to mozilla/dom/Window.h and mozilla/dom/WindowProxy.h. diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 2ece33e9581b..29c4c6870319 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -4,12 +4,290 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "nsGlobalWindow.h" + +#include + +#include "mozilla/MemoryReporting.h" + +// Local Includes +#include "Navigator.h" +#include "nsContentSecurityManager.h" +#include "nsScreen.h" +#include "nsHistory.h" +#include "nsDOMNavigationTiming.h" +#include "nsIDOMStorageManager.h" +#include "mozilla/dom/LocalStorage.h" +#include "mozilla/dom/Storage.h" +#include "mozilla/dom/IdleRequest.h" +#include "mozilla/dom/Performance.h" +#include "mozilla/dom/StorageEvent.h" +#include "mozilla/dom/StorageEventBinding.h" +#include "mozilla/dom/StorageNotifierService.h" +#include "mozilla/dom/StorageUtils.h" +#include "mozilla/dom/Timeout.h" +#include "mozilla/dom/TimeoutHandler.h" +#include "mozilla/dom/TimeoutManager.h" +#include "mozilla/IntegerPrintfMacros.h" +#if defined(MOZ_WIDGET_ANDROID) +#include "mozilla/dom/WindowOrientationObserver.h" +#endif +#include "nsDOMOfflineResourceList.h" +#include "nsError.h" +#include "nsIIdleService.h" +#include "nsISizeOfEventTarget.h" +#include "nsDOMJSUtils.h" +#include "nsArrayUtils.h" +#include "nsIDOMWindowCollection.h" +#include "nsDOMWindowList.h" +#include "mozilla/dom/WakeLock.h" +#include "mozilla/dom/power/PowerManagerService.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsIPermissionManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptTimeoutHandler.h" +#include "nsITimeoutHandler.h" +#include "nsIController.h" +#include "nsScriptNameSpaceManager.h" +#include "nsISlowScriptDebug.h" +#include "nsWindowMemoryReporter.h" +#include "nsWindowSizes.h" +#include "WindowNamedPropertiesHandler.h" +#include "nsFrameSelection.h" +#include "nsNetUtil.h" +#include "nsVariant.h" +#include "nsPrintfCString.h" +#include "mozilla/intl/LocaleService.h" +#include "WindowDestroyedEvent.h" + +// Helper Classes +#include "nsJSUtils.h" +#include "jsapi.h" // for JSAutoRequest +#include "jswrapper.h" +#include "nsCharSeparatedTokenizer.h" +#include "nsReadableUtils.h" +#include "nsDOMClassInfo.h" +#include "nsJSEnvironment.h" +#include "mozilla/dom/ScriptSettings.h" +#include "mozilla/Preferences.h" +#include "mozilla/Likely.h" +#include "mozilla/Sprintf.h" +#include "mozilla/Unused.h" + +// Other Classes +#include "mozilla/dom/BarProps.h" +#include "nsContentCID.h" +#include "nsLayoutStatics.h" +#include "nsCCUncollectableMarker.h" +#include "mozilla/dom/workers/Workers.h" +#include "mozilla/dom/ToJSValue.h" +#include "nsJSPrincipals.h" +#include "mozilla/Attributes.h" +#include "mozilla/Debug.h" +#include "mozilla/EventListenerManager.h" +#include "mozilla/EventStates.h" +#include "mozilla/MouseEvents.h" +#include "mozilla/ProcessHangMonitor.h" +#include "mozilla/ThrottledEventQueue.h" +#include "AudioChannelService.h" +#include "nsAboutProtocolUtils.h" +#include "nsCharTraits.h" // NS_IS_HIGH/LOW_SURROGATE +#include "PostMessageEvent.h" +#include "mozilla/dom/DocGroup.h" +#include "mozilla/dom/TabGroup.h" + +// Interfaces Needed +#include "nsIFrame.h" +#include "nsCanvasFrame.h" +#include "nsIWidget.h" +#include "nsIWidgetListener.h" +#include "nsIBaseWindow.h" +#include "nsIDeviceSensors.h" +#include "nsIContent.h" +#include "nsIDocShell.h" +#include "nsIDocCharset.h" +#include "nsIDocument.h" +#include "Crypto.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" +#include "nsIDOMEvent.h" +#include "nsIDOMOfflineResourceList.h" +#include "nsDOMString.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsThreadUtils.h" +#include "nsILoadContext.h" +#include "nsIPresShell.h" +#include "nsIScrollableFrame.h" +#include "nsView.h" +#include "nsViewManager.h" +#include "nsISelectionController.h" +#include "nsISelection.h" +#include "nsIPrompt.h" +#include "nsIPromptService.h" +#include "nsIPromptFactory.h" +#include "nsIAddonPolicyService.h" +#include "nsIWritablePropertyBag2.h" +#include "nsIWebNavigation.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWebBrowserFind.h" // For window.find() +#include "nsIWindowMediator.h" // For window.find() +#include "nsComputedDOMStyle.h" +#include "nsDOMCID.h" +#include "nsDOMWindowUtils.h" +#include "nsIWindowWatcher.h" +#include "nsPIWindowWatcher.h" +#include "nsIContentViewer.h" +#include "nsIScriptError.h" +#include "nsIControllers.h" +#include "nsIControllerContext.h" +#include "nsGlobalWindowCommands.h" +#include "nsQueryObject.h" +#include "nsContentUtils.h" +#include "nsCSSProps.h" +#include "nsIDOMFileList.h" +#include "nsIURIFixup.h" +#ifndef DEBUG +#include "nsIAppStartup.h" +#include "nsToolkitCompsCID.h" +#endif +#include "nsCDefaultURIFixup.h" +#include "mozilla/EventDispatcher.h" +#include "mozilla/EventStateManager.h" +#include "nsIObserverService.h" +#include "nsFocusManager.h" +#include "nsIXULWindow.h" +#include "nsITimedChannel.h" +#include "nsServiceManagerUtils.h" +#ifdef MOZ_XUL +#include "nsIDOMXULControlElement.h" +#include "nsMenuPopupFrame.h" +#endif +#include "mozilla/dom/CustomEvent.h" +#include "nsIJARChannel.h" +#include "nsIScreenManager.h" +#include "nsIEffectiveTLDService.h" + +#include "xpcprivate.h" + +#ifdef NS_PRINTING +#include "nsIPrintSettings.h" +#include "nsIPrintSettingsService.h" +#include "nsIWebBrowserPrint.h" +#endif + +#include "nsWindowRoot.h" +#include "nsNetCID.h" +#include "nsIArray.h" + +// XXX An unfortunate dependency exists here (two XUL files). +#include "nsIDOMXULDocument.h" +#include "nsIDOMXULCommandDispatcher.h" + +#include "nsBindingManager.h" +#include "nsXBLService.h" + +// used for popup blocking, needs to be converted to something +// belonging to the back-end like nsIContentPolicy +#include "nsIPopupWindowManager.h" + +#include "nsIDragService.h" +#include "mozilla/dom/Element.h" +#include "mozilla/dom/Selection.h" +#include "nsFrameLoader.h" +#include "nsISupportsPrimitives.h" +#include "nsXPCOMCID.h" +#include "mozilla/Logging.h" +#include "prenv.h" + +#include "mozilla/dom/IDBFactory.h" +#include "mozilla/dom/MessageChannel.h" +#include "mozilla/dom/Promise.h" + +#include "mozilla/dom/Gamepad.h" +#include "mozilla/dom/GamepadManager.h" + +#include "gfxVR.h" +#include "mozilla/dom/VRDisplay.h" +#include "mozilla/dom/VRDisplayEvent.h" +#include "mozilla/dom/VRDisplayEventBinding.h" +#include "mozilla/dom/VREventObserver.h" + +#include "nsRefreshDriver.h" +#include "Layers.h" + +#include "mozilla/AddonPathService.h" +#include "mozilla/BasePrincipal.h" +#include "mozilla/Services.h" +#include "mozilla/Telemetry.h" +#include "mozilla/dom/Location.h" +#include "nsHTMLDocument.h" +#include "nsWrapperCacheInlines.h" +#include "mozilla/DOMEventTargetHelper.h" +#include "prrng.h" +#include "nsSandboxFlags.h" +#include "TimeChangeObserver.h" +#include "mozilla/dom/AudioContext.h" +#include "mozilla/dom/BrowserElementDictionariesBinding.h" +#include "mozilla/dom/cache/CacheStorage.h" +#include "mozilla/dom/Console.h" +#include "mozilla/dom/Fetch.h" +#include "mozilla/dom/FunctionBinding.h" +#include "mozilla/dom/HashChangeEvent.h" +#include "mozilla/dom/IntlUtils.h" +#include "mozilla/dom/MozSelfSupportBinding.h" +#include "mozilla/dom/PopStateEvent.h" +#include "mozilla/dom/PopupBlockedEvent.h" +#include "mozilla/dom/PrimitiveConversions.h" +#include "mozilla/dom/WindowBinding.h" +#include "nsITabChild.h" +#include "mozilla/dom/MediaQueryList.h" +#include "mozilla/dom/ScriptSettings.h" +#include "mozilla/dom/NavigatorBinding.h" +#include "mozilla/dom/ImageBitmap.h" +#include "mozilla/dom/ImageBitmapBinding.h" +#include "mozilla/dom/ServiceWorkerRegistration.h" +#include "mozilla/dom/U2F.h" +#include "mozilla/dom/WebIDLGlobalNameHash.h" +#include "mozilla/dom/Worklet.h" +#ifdef HAVE_SIDEBAR +#include "mozilla/dom/ExternalBinding.h" +#endif + +#ifdef MOZ_WEBSPEECH +#include "mozilla/dom/SpeechSynthesis.h" +#endif + #include "mozilla/dom/ClientManager.h" #include "mozilla/dom/ClientSource.h" +// Apple system headers seem to have a check() macro. +#ifdef check +class nsIScriptTimeoutHandler; +#undef check +#endif // check +#include "AccessCheck.h" + +#ifdef ANDROID +#include +#endif + +#ifdef XP_WIN +#include +#define getpid _getpid +#else +#include // for getpid() +#endif + +using namespace mozilla; +using namespace mozilla::dom; +using namespace mozilla::dom::ipc; +using mozilla::TimeStamp; +using mozilla::TimeDuration; +using mozilla::dom::cache::CacheStorage; + #define FORWARD_TO_OUTER(method, args, err_rval) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsInnerWindow()); \ nsGlobalWindowOuter *outer = GetOuterWindowInternal(); \ if (!HasActiveDocument()) { \ NS_WARNING(outer ? \ @@ -22,7 +300,6 @@ #define FORWARD_TO_OUTER_OR_THROW(method, args, errorresult, err_rval) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsInnerWindow()); \ nsGlobalWindowOuter *outer = GetOuterWindowInternal(); \ if (MOZ_LIKELY(HasActiveDocument())) { \ return outer->method args; \ @@ -38,7 +315,6 @@ #define FORWARD_TO_OUTER_VOID(method, args) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsInnerWindow()); \ nsGlobalWindowOuter *outer = GetOuterWindowInternal(); \ if (!HasActiveDocument()) { \ NS_WARNING(outer ? \ @@ -50,9 +326,33 @@ return; \ PR_END_MACRO +#define DOM_TOUCH_LISTENER_ADDED "dom-touch-listener-added" +#define MEMORY_PRESSURE_OBSERVER_TOPIC "memory-pressure" + +// Amount of time allowed between alert/prompt/confirm before enabling +// the stop dialog checkbox. +#define DEFAULT_SUCCESSIVE_DIALOG_TIME_LIMIT 3 // 3 sec + +// Maximum number of successive dialogs before we prompt users to disable +// dialogs for this window. +#define MAX_SUCCESSIVE_DIALOG_COUNT 5 + +// Idle fuzz time upper limit +#define MAX_IDLE_FUZZ_TIME_MS 90000 + +// Min idle notification time in seconds. +#define MIN_IDLE_NOTIFICATION_TIME_S 1 + +static LazyLogModule gDOMLeakPRLogInner("DOMLeakInner"); + +static bool gIdleObserversAPIFuzzTimeDisabled = false; +static FILE *gDumpFile = nullptr; nsGlobalWindowInner::InnerWindowByIdTable *nsGlobalWindowInner::sInnerWindowsById = nullptr; +bool nsGlobalWindowInner::sDragServiceDisabled = false; +bool nsGlobalWindowInner::sMouseDown = false; + /** * An indirect observer object that means we don't have to implement nsIObserver * on nsGlobalWindow, where any script could see it. @@ -160,7 +460,6 @@ public: , mWindow(aWindow) { MOZ_DIAGNOSTIC_ASSERT(mWindow); - MOZ_DIAGNOSTIC_ASSERT(mWindow->IsInnerWindow()); mIdlePeriodLimit = { mDeadline, mWindow->LastIdleRequestHandle() }; mDelayedExecutorDispatcher = new IdleRequestExecutorTimeoutHandler(this); @@ -502,7 +801,6 @@ nsGlobalWindowInner::RequestIdleCallback(JSContext* aCx, const IdleRequestOptions& aOptions, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); AssertIsOnMainThread(); uint32_t handle = mIdleRequestCallbackCounter++; @@ -538,8 +836,6 @@ nsGlobalWindowInner::RequestIdleCallback(JSContext* aCx, void nsGlobalWindowInner::CancelIdleCallback(uint32_t aHandle) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - for (IdleRequest* r : mIdleRequestCallbacks) { if (r->Handle() == aHandle) { RemoveIdleCallback(r); @@ -578,20 +874,11 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) mIdleCallbackIndex(-1), mCurrentlyIdle(false), mAddActiveEventFuzzTime(true), - mFullScreen(false), - mFullscreenMode(false), - mIsClosed(false), - mInClose(false), - mHavePendingClose(false), - mHadOriginalOpener(false), - mOriginalOpenerWasSecureContext(false), - mIsPopupSpam(false), - mBlockScriptedClosingFlag(false), + mIsSecureContextIfOpenerIgnored(false), mWasOffline(false), mHasHadSlowScript(false), mNotifyIdleObserversIdleOnThaw(false), mNotifyIdleObserversActiveOnThaw(false), - mCreatingInnerWindow(false), mIsChrome(false), mCleanMessageManager(false), mNeedsFocus(true), @@ -602,26 +889,16 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) mHasVREvents(false), mHasVRDisplayActivateEvents(false), mHasSeenGamepadInput(false), - mNotifiedIDDestroyed(false), - mAllowScriptsToClose(false), - mTopLevelOuterContentWindow(false), mSuspendDepth(0), mFreezeDepth(0), mFocusMethod(0), mSerial(0), mIdleRequestCallbackCounter(1), mIdleRequestExecutor(nullptr), -#ifdef DEBUG - mSetOpenerWindowCalled(false), -#endif mCleanedUp(false), mDialogAbuseCount(0), mAreDialogsEnabled(true), -#ifdef DEBUG - mIsValidatingTabGroup(false), -#endif mCanSkipCCGeneration(0), - mAutoActivateVRDisplayID(0), mBeforeUnloadListenerCount(0) { AssertIsOnMainThread(); @@ -636,6 +913,9 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) // window list of inners. PR_INSERT_AFTER(this, aOuterWindow); + mTimeoutManager = + MakeUnique(*nsGlobalWindowInner::Cast(AsInner())); + mObserver = new nsGlobalWindowObserver(this); if (mObserver) { nsCOMPtr os = mozilla::services::GetObserverService(); @@ -674,9 +954,16 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) // to create the entropy collector, so we should // try to get one until we succeed. - gRefCnt++; + mSerial = nsContentUtils::InnerOrOuterWindowCreated(); - EnsurePrefCaches(); + static bool sFirstTime = true; + if (sFirstTime) { + sFirstTime = false; + TimeoutManager::Initialize(); + Preferences::AddBoolVarCache(&gIdleObserversAPIFuzzTimeDisabled, + "dom.idle-observers-api.fuzz_time.disabled", + false); + } if (gDumpFile == nullptr) { nsAutoCString fname; @@ -689,20 +976,18 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) } } - mSerial = ++gSerialCounter; - #ifdef DEBUG if (!PR_GetEnv("MOZ_QUIET")) { printf_stderr("++DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p]\n", - gRefCnt, + nsContentUtils::GetCurrentInnerOrOuterWindowCount(), static_cast(ToCanonicalSupports(this)), getpid(), - gSerialCounter, + mSerial, static_cast(ToCanonicalSupports(aOuterWindow))); } #endif - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("DOMWINDOW %p created outer=%p", this, aOuterWindow)); // Add ourselves to the inner windows list. @@ -732,7 +1017,7 @@ nsGlobalWindowInner::Init() { AssertIsOnMainThread(); - NS_ASSERTION(gDOMLeakPRLog, "gDOMLeakPRLog should have been initialized!"); + NS_ASSERTION(gDOMLeakPRLogInner, "gDOMLeakPRLogInner should have been initialized!"); sInnerWindowsById = new InnerWindowByIdTable(); } @@ -763,7 +1048,7 @@ nsGlobalWindowInner::~nsGlobalWindowInner() sInnerWindowsById->Remove(mWindowID); } - --gRefCnt; + nsContentUtils::InnerOrOuterWindowDestroyed(); #ifdef DEBUG if (!PR_GetEnv("MOZ_QUIET")) { @@ -780,7 +1065,7 @@ nsGlobalWindowInner::~nsGlobalWindowInner() nsGlobalWindowOuter* outer = nsGlobalWindowOuter::Cast(mOuterWindow); printf_stderr("--DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p] [url = %s]\n", - gRefCnt, + nsContentUtils::GetCurrentInnerOrOuterWindowCount(), static_cast(ToCanonicalSupports(this)), getpid(), mSerial, @@ -789,7 +1074,7 @@ nsGlobalWindowInner::~nsGlobalWindowInner() } #endif - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, ("DOMWINDOW %p destroyed", this)); + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("DOMWINDOW %p destroyed", this)); Telemetry::Accumulate(Telemetry::INNERWINDOWS_WITH_MUTATION_LISTENERS, mMutationBits ? 1 : 0); @@ -829,14 +1114,12 @@ nsGlobalWindowInner::~nsGlobalWindowInner() void nsGlobalWindowInner::AddEventTargetObject(DOMEventTargetHelper* aObject) { - MOZ_ASSERT(IsInnerWindow()); mEventTargetObjects.PutEntry(aObject); } void nsGlobalWindowInner::RemoveEventTargetObject(DOMEventTargetHelper* aObject) { - MOZ_ASSERT(IsInnerWindow()); mEventTargetObjects.RemoveEntry(aObject); } @@ -857,7 +1140,11 @@ nsGlobalWindowInner::ShutDown() { AssertIsOnMainThread(); - // nsGlobalWindowOuter::ShutDown() handles closing gDumpFile. + if (gDumpFile && gDumpFile != stdout) { + fclose(gDumpFile); + } + gDumpFile = nullptr; + delete sInnerWindowsById; sInnerWindowsById = nullptr; } @@ -921,8 +1208,6 @@ nsGlobalWindowInner::CleanUp() mScrollbars = nullptr; mHistory = nullptr; mCustomElements = nullptr; - mFrames = nullptr; - mWindowUtils = nullptr; mApplicationCache = nullptr; mIndexedDB = nullptr; @@ -945,12 +1230,6 @@ nsGlobalWindowInner::CleanUp() mOrientationChangeObserver = nullptr; #endif - ClearControllers(); - - mOpener = nullptr; // Forces Release - if (mContext) { - mContext = nullptr; // Forces Release - } mChromeEventHandler = nullptr; // Forces Release mParentTarget = nullptr; @@ -969,8 +1248,6 @@ nsGlobalWindowInner::CleanUp() } } - mArguments = nullptr; - CleanupCachedXBLHandlers(); for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) { @@ -988,31 +1265,9 @@ nsGlobalWindowInner::CleanUp() mIntlUtils = nullptr; } -void -nsGlobalWindowInner::ClearControllers() -{ - if (mControllers) { - uint32_t count; - mControllers->GetControllerCount(&count); - - while (count--) { - nsCOMPtr controller; - mControllers->GetControllerAt(count, getter_AddRefs(controller)); - - nsCOMPtr context = do_QueryInterface(controller); - if (context) - context->SetCommandContext(nullptr); - } - - mControllers = nullptr; - } -} - void nsGlobalWindowInner::FreeInnerObjects() { - NS_ASSERTION(IsInnerWindow(), "Don't free inner objects on an outer window"); - // Make sure that this is called before we null out the document and // other members that the window destroyed observers could // re-create. @@ -1131,7 +1386,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindowInner) if (aIID.Equals(NS_GET_IID(nsPIDOMWindowInner))) { foundInterface = static_cast(this); } else - if (aIID.Equals(NS_GET_IID(mozIDOMWindow)) && IsInnerWindow()) { + if (aIID.Equals(NS_GET_IID(mozIDOMWindow))) { foundInterface = static_cast(this); } else if (aIID.Equals(NS_GET_IID(nsIDOMChromeWindow)) && IsChromeWindow()) { @@ -1185,18 +1440,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner) if (tmp->mDoc && tmp->mDoc->GetDocumentURI()) { uri = tmp->mDoc->GetDocumentURI()->GetSpecOrDefault(); } - SprintfLiteral(name, "nsGlobalWindowInner # %" PRIu64 " %s %s", tmp->mWindowID, - tmp->IsInnerWindow() ? "inner" : "outer", uri.get()); + SprintfLiteral(name, "nsGlobalWindowInner # %" PRIu64 " inner %s", tmp->mWindowID, + uri.get()); cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name); } else { NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsGlobalWindowInner, tmp->mRefCnt.get()) } - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContext) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControllers) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mArguments) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReturnValue) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPerformance) @@ -1226,7 +1476,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocalStorage) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSessionStorage) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mApplicationCache) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTabChild) @@ -1248,7 +1497,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner) // Traverse stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMenubar) @@ -1266,24 +1514,15 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMozSelfSupport) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIntlUtils) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocShell) - tmp->TraverseHostObjectURIs(cb); - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mBrowserDOMWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mMessageManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mGroupMessageManagers) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mOpenerForInitialContentBrowser) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) tmp->CleanupCachedXBLHandlers(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mContext) - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mControllers) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mArguments) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mReturnValue) NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPerformance) @@ -1317,7 +1556,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) static_cast(tmp->mApplicationCache.get())->Disconnect(); NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplicationCache) } - NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTabChild) @@ -1333,7 +1571,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) // Unlink stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameElement) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode) NS_IMPL_CYCLE_COLLECTION_UNLINK(mMenubar) @@ -1351,8 +1588,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) NS_IMPL_CYCLE_COLLECTION_UNLINK(mMozSelfSupport) NS_IMPL_CYCLE_COLLECTION_UNLINK(mIntlUtils) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell) - tmp->UnlinkHostObjectURIs(); NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleRequestExecutor) @@ -1361,7 +1596,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) tmp->mClientSource.reset(); if (tmp->IsChromeWindow()) { - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mBrowserDOMWindow) if (tmp->mChromeFields.mMessageManager) { static_cast( tmp->mChromeFields.mMessageManager.get())->Disconnect(); @@ -1369,7 +1603,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) } tmp->DisconnectAndClearGroupMessageManagers(); NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mGroupMessageManagers) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mOpenerForInitialContentBrowser) } NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER @@ -1446,30 +1679,10 @@ nsGlobalWindowInner::TraceGlobalJSObject(JSTracer* aTrc) TraceWrapper(aTrc, "active window global"); } -void -nsGlobalWindowInner::SetInitialPrincipalToSubject() -{ - MOZ_CRASH("Virtual outer window only function"); -} - -PopupControlState -nsGlobalWindowInner::PushPopupControlState(PopupControlState aState, - bool aForce) const -{ - MOZ_CRASH("Virtual outer window only function"); -} - -void -nsGlobalWindowInner::PopPopupControlState(PopupControlState aState) const -{ - MOZ_CRASH("Virtual outer window only function"); -} - PopupControlState nsGlobalWindowInner::GetPopupControlState() const { - MOZ_ASSERT(NS_IsMainThread()); - return gPopupControlState; + return nsContentUtils::GetPopupControlState(); } nsresult @@ -1498,12 +1711,11 @@ nsGlobalWindowInner::SetNewDocument(nsIDocument* aDocument, void nsGlobalWindowInner::InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument) { - NS_PRECONDITION(IsInnerWindow(), "Must only be called on inner windows"); MOZ_ASSERT(aDocument); - if (MOZ_LOG_TEST(gDOMLeakPRLog, LogLevel::Debug)) { + if (MOZ_LOG_TEST(gDOMLeakPRLogInner, LogLevel::Debug)) { nsIURI *uri = aDocument->GetDocumentURI(); - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("DOMWINDOW %p SetNewDocument %s", this, uri ? uri->GetSpecOrDefault().get() : "")); } @@ -1621,18 +1833,20 @@ nsGlobalWindowInner::UpdateParentTarget() nsCOMPtr frameElement = GetOuterWindow()->GetFrameElementInternal(); nsCOMPtr eventTarget = - TryGetTabChildGlobalAsEventTarget(frameElement); + nsContentUtils::TryGetTabChildGlobalAsEventTarget(frameElement); if (!eventTarget) { nsGlobalWindowOuter* topWin = GetScriptableTopInternal(); if (topWin) { frameElement = topWin->AsOuter()->GetFrameElementInternal(); - eventTarget = TryGetTabChildGlobalAsEventTarget(frameElement); + eventTarget = + nsContentUtils::TryGetTabChildGlobalAsEventTarget(frameElement); } } if (!eventTarget) { - eventTarget = TryGetTabChildGlobalAsEventTarget(mChromeEventHandler); + eventTarget = + nsContentUtils::TryGetTabChildGlobalAsEventTarget(mChromeEventHandler); } if (!eventTarget) { @@ -1663,8 +1877,6 @@ nsGlobalWindowInner::WillHandleEvent(EventChainPostVisitor& aVisitor) nsresult nsGlobalWindowInner::GetEventTargetParent(EventChainPreVisitor& aVisitor) { - NS_PRECONDITION(IsInnerWindow(), - "GetEventTargetParent is used on outer window!?"); EventMessage msg = aVisitor.mEvent->mMessage; aVisitor.mCanHandle = true; @@ -1678,15 +1890,15 @@ nsGlobalWindowInner::GetEventTargetParent(EventChainPreVisitor& aVisitor) mIsHandlingResizeEvent = true; } } else if (msg == eMouseDown && aVisitor.mEvent->IsTrusted()) { - gMouseDown = true; + sMouseDown = true; } else if ((msg == eMouseUp || msg == eDragEnd) && aVisitor.mEvent->IsTrusted()) { - gMouseDown = false; - if (gDragServiceDisabled) { + sMouseDown = false; + if (sDragServiceDisabled) { nsCOMPtr ds = do_GetService("@mozilla.org/widget/dragservice;1"); if (ds) { - gDragServiceDisabled = false; + sDragServiceDisabled = false; ds->Unsuppress(); } } @@ -1708,7 +1920,6 @@ nsGlobalWindowInner::GetEventTargetParent(EventChainPreVisitor& aVisitor) bool nsGlobalWindowInner::DialogsAreBeingAbused() { - MOZ_ASSERT(IsInnerWindow()); NS_ASSERTION(GetScriptableTopInternal() && GetScriptableTopInternal()->GetCurrentInnerWindowInternal() == this, "DialogsAreBeingAbused called with invalid window"); @@ -1749,8 +1960,6 @@ nsGlobalWindowInner::EnableDialogs() nsresult nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) { - NS_PRECONDITION(IsInnerWindow(), "PostHandleEvent is used on outer window!?"); - // Return early if there is nothing to do. switch (aVisitor.mEvent->mMessage) { case eResize: @@ -1843,17 +2052,9 @@ nsGlobalWindowInner::PostHandleEvent(EventChainPostVisitor& aVisitor) return NS_OK; } -nsresult -nsGlobalWindowInner::SetArguments(nsIArray *aArguments) -{ - MOZ_CRASH("Virtual outer window only function"); -} - nsresult nsGlobalWindowInner::DefineArgumentsProperty(nsIArray *aArguments) { - MOZ_ASSERT(IsInnerWindow()); - nsIScriptContext *ctx = GetOuterWindowInternal()->mContext; NS_ENSURE_TRUE(aArguments && ctx, NS_ERROR_NOT_INITIALIZED); @@ -1900,8 +2101,6 @@ nsGlobalWindowInner::GetPrincipal() bool nsPIDOMWindowInner::AddAudioContext(AudioContext* aAudioContext) { - MOZ_ASSERT(IsInnerWindow()); - mAudioContexts.AppendElement(aAudioContext); // Return true if the context should be muted and false if not. @@ -1912,16 +2111,12 @@ nsPIDOMWindowInner::AddAudioContext(AudioContext* aAudioContext) void nsPIDOMWindowInner::RemoveAudioContext(AudioContext* aAudioContext) { - MOZ_ASSERT(IsInnerWindow()); - mAudioContexts.RemoveElement(aAudioContext); } void nsPIDOMWindowInner::MuteAudioContexts() { - MOZ_ASSERT(IsInnerWindow()); - for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) { if (!mAudioContexts[i]->IsOffline()) { mAudioContexts[i]->Mute(); @@ -1932,8 +2127,6 @@ nsPIDOMWindowInner::MuteAudioContexts() void nsPIDOMWindowInner::UnmuteAudioContexts() { - MOZ_ASSERT(IsInnerWindow()); - for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) { if (!mAudioContexts[i]->IsOffline()) { mAudioContexts[i]->Unmute(); @@ -1956,8 +2149,6 @@ nsGlobalWindowInner::Self() Navigator* nsGlobalWindowInner::Navigator() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mNavigator) { mNavigator = new mozilla::dom::Navigator(this); } @@ -1974,8 +2165,6 @@ nsGlobalWindowInner::GetNavigator() nsScreen* nsGlobalWindowInner::GetScreen(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mScreen) { mScreen = nsScreen::Create(this); if (!mScreen) { @@ -1999,8 +2188,6 @@ nsGlobalWindowInner::GetScreen() nsHistory* nsGlobalWindowInner::GetHistory(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mHistory) { mHistory = new nsHistory(this); } @@ -2011,8 +2198,6 @@ nsGlobalWindowInner::GetHistory(ErrorResult& aError) CustomElementRegistry* nsGlobalWindowInner::CustomElements() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mCustomElements) { mCustomElements = new CustomElementRegistry(this); } @@ -2023,7 +2208,6 @@ nsGlobalWindowInner::CustomElements() Performance* nsPIDOMWindowInner::GetPerformance() { - MOZ_ASSERT(IsInnerWindow()); CreatePerformanceObjectIfNeeded(); return mPerformance; } @@ -2031,8 +2215,6 @@ nsPIDOMWindowInner::GetPerformance() void nsPIDOMWindowInner::CreatePerformanceObjectIfNeeded() { - MOZ_ASSERT(IsInnerWindow()); - if (mPerformance || !mDoc) { return; } @@ -2100,7 +2282,7 @@ nsPIDOMWindowInner::GetClientInfo() const void nsGlobalWindowInner::UpdateTopInnerWindow() { - if (!IsInnerWindow() || IsTopInnerWindow() || !mTopInnerWindow) { + if (IsTopInnerWindow() || !mTopInnerWindow) { return; } @@ -2111,7 +2293,6 @@ void nsPIDOMWindowInner::AddPeerConnection() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(IsInnerWindow()); mTopInnerWindow ? mTopInnerWindow->mActivePeerConnections++ : mActivePeerConnections++; } @@ -2120,7 +2301,6 @@ void nsPIDOMWindowInner::RemovePeerConnection() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(mTopInnerWindow ? mTopInnerWindow->mActivePeerConnections : mActivePeerConnections); @@ -2132,7 +2312,6 @@ bool nsPIDOMWindowInner::HasActivePeerConnections() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(IsInnerWindow()); return mTopInnerWindow ? mTopInnerWindow->mActivePeerConnections : mActivePeerConnections; } @@ -2268,15 +2447,12 @@ nsPIDOMWindowInner::HasOpenWebSockets() const bool nsPIDOMWindowInner::GetAudioCaptured() const { - MOZ_ASSERT(IsInnerWindow()); return mAudioCaptured; } nsresult nsPIDOMWindowInner::SetAudioCapture(bool aCapture) { - MOZ_ASSERT(IsInnerWindow()); - mAudioCaptured = aCapture; RefPtr service = AudioChannelService::GetOrCreate(); @@ -2293,8 +2469,6 @@ nsPIDOMWindowInner::SetAudioCapture(bool aCapture) SpeechSynthesis* nsGlobalWindowInner::GetSpeechSynthesis(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mSpeechSynthesis) { mSpeechSynthesis = new SpeechSynthesis(this); } @@ -2305,8 +2479,6 @@ nsGlobalWindowInner::GetSpeechSynthesis(ErrorResult& aError) bool nsGlobalWindowInner::HasActiveSpeechSynthesis() { - MOZ_ASSERT(IsInnerWindow()); - if (mSpeechSynthesis) { return !mSpeechSynthesis->HasEmptyQueue(); } @@ -2345,16 +2517,6 @@ nsGlobalWindowInner::GetScriptableParentOrNull() FORWARD_TO_OUTER(GetScriptableParentOrNull, (), nullptr); } -/** - * nsPIDOMWindow::GetParent (when called from C++) is just a wrapper around - * GetRealParent. - */ -already_AddRefed -nsGlobalWindowInner::GetParent() -{ - MOZ_CRASH("Virtual outer window only function"); -} - /** * GetScriptableTop is called when script reads window.top. * @@ -2368,12 +2530,6 @@ nsGlobalWindowInner::GetScriptableTop() FORWARD_TO_OUTER(GetScriptableTop, (), nullptr); } -already_AddRefed -nsGlobalWindowInner::GetTop() -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::GetContent(JSContext* aCx, JS::MutableHandle aRetval, @@ -2387,8 +2543,6 @@ nsGlobalWindowInner::GetContent(JSContext* aCx, MozSelfSupport* nsGlobalWindowInner::GetMozSelfSupport(ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - if (mMozSelfSupport) { return mMozSelfSupport; } @@ -2401,22 +2555,9 @@ nsGlobalWindowInner::GetMozSelfSupport(ErrorResult& aError) return mMozSelfSupport; } -nsresult -nsGlobalWindowInner::GetPrompter(nsIPrompt** aPrompt) -{ - nsGlobalWindowOuter* outer = GetOuterWindowInternal(); - if (!outer) { - NS_WARNING("No outer window available!"); - return NS_ERROR_NOT_INITIALIZED; - } - return outer->GetPrompter(aPrompt); -} - BarProp* nsGlobalWindowInner::GetMenubar(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mMenubar) { mMenubar = new MenubarProp(this); } @@ -2427,8 +2568,6 @@ nsGlobalWindowInner::GetMenubar(ErrorResult& aError) BarProp* nsGlobalWindowInner::GetToolbar(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mToolbar) { mToolbar = new ToolbarProp(this); } @@ -2439,8 +2578,6 @@ nsGlobalWindowInner::GetToolbar(ErrorResult& aError) BarProp* nsGlobalWindowInner::GetLocationbar(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mLocationbar) { mLocationbar = new LocationbarProp(this); } @@ -2450,8 +2587,6 @@ nsGlobalWindowInner::GetLocationbar(ErrorResult& aError) BarProp* nsGlobalWindowInner::GetPersonalbar(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mPersonalbar) { mPersonalbar = new PersonalbarProp(this); } @@ -2461,8 +2596,6 @@ nsGlobalWindowInner::GetPersonalbar(ErrorResult& aError) BarProp* nsGlobalWindowInner::GetStatusbar(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mStatusbar) { mStatusbar = new StatusbarProp(this); } @@ -2472,8 +2605,6 @@ nsGlobalWindowInner::GetStatusbar(ErrorResult& aError) BarProp* nsGlobalWindowInner::GetScrollbars(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mScrollbars) { mScrollbars = new ScrollbarsProp(this); } @@ -2487,12 +2618,6 @@ nsGlobalWindowInner::GetClosed(ErrorResult& aError) FORWARD_TO_OUTER_OR_THROW(GetClosedOuter, (), aError, false); } -bool -nsGlobalWindowInner::Closed() -{ - MOZ_CRASH("Virtual outer window only function"); -} - already_AddRefed nsGlobalWindowInner::GetFrames() { @@ -2510,8 +2635,6 @@ nsGlobalWindowInner::DoResolve(JSContext* aCx, JS::Handle aObj, JS::Handle aId, JS::MutableHandle aDesc) { - MOZ_ASSERT(IsInnerWindow()); - // Note: Keep this in sync with MayResolve. // Note: The infallibleInit call in GlobalResolve depends on this check. @@ -2591,7 +2714,6 @@ nsGlobalWindowInner::GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aName return; } - MOZ_ASSERT(IsInnerWindow()); // "Components" is marked as enumerable but only resolved on demand :-/. //aNames.AppendElement(NS_LITERAL_STRING("Components")); @@ -2654,8 +2776,6 @@ nsGlobalWindowInner::IsRequestIdleCallbackEnabled(JSContext* aCx, JSObject* aObj nsIDOMOfflineResourceList* nsGlobalWindowInner::GetApplicationCache(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mApplicationCache) { nsCOMPtr webNav(do_QueryInterface(GetDocShell())); if (!webNav || !mDoc) { @@ -2697,8 +2817,6 @@ nsGlobalWindowInner::GetApplicationCache() Crypto* nsGlobalWindowInner::GetCrypto(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mCrypto) { mCrypto = new Crypto(); mCrypto->Init(this); @@ -2709,8 +2827,6 @@ nsGlobalWindowInner::GetCrypto(ErrorResult& aError) mozilla::dom::U2F* nsGlobalWindowInner::GetU2f(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mU2F) { RefPtr u2f = new U2F(this); u2f->Init(aError); @@ -2749,8 +2865,6 @@ void nsGlobalWindowInner::GetOpener(JSContext* aCx, JS::MutableHandle aRetval, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - nsCOMPtr opener = GetOpenerWindow(aError); if (aError.Failed() || !opener) { aRetval.setNull(); @@ -2760,12 +2874,6 @@ nsGlobalWindowInner::GetOpener(JSContext* aCx, JS::MutableHandle aRet aError = nsContentUtils::WrapNative(aCx, opener, aRetval); } -already_AddRefed -nsGlobalWindowInner::GetOpener() -{ - FORWARD_TO_OUTER(GetOpener, (), nullptr); -} - void nsGlobalWindowInner::SetOpener(JSContext* aCx, JS::Handle aOpener, ErrorResult& aError) @@ -3050,8 +3158,6 @@ int32_t nsGlobalWindowInner::RequestAnimationFrame(FrameRequestCallback& aCallback, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mDoc) { return 0; } @@ -3068,8 +3174,6 @@ nsGlobalWindowInner::RequestAnimationFrame(FrameRequestCallback& aCallback, void nsGlobalWindowInner::CancelAnimationFrame(int32_t aHandle, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mDoc) { return; } @@ -3142,28 +3246,24 @@ nsGlobalWindowInner::SetScreenY(JSContext* aCx, JS::Handle aValue, int32_t nsGlobalWindowInner::GetScrollMinX(ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); FORWARD_TO_OUTER_OR_THROW(GetScrollBoundaryOuter, (eSideLeft), aError, 0); } int32_t nsGlobalWindowInner::GetScrollMinY(ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); FORWARD_TO_OUTER_OR_THROW(GetScrollBoundaryOuter, (eSideTop), aError, 0); } int32_t nsGlobalWindowInner::GetScrollMaxX(ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); FORWARD_TO_OUTER_OR_THROW(GetScrollBoundaryOuter, (eSideRight), aError, 0); } int32_t nsGlobalWindowInner::GetScrollMaxY(ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); FORWARD_TO_OUTER_OR_THROW(GetScrollBoundaryOuter, (eSideBottom), aError, 0); } @@ -3200,17 +3300,9 @@ nsGlobalWindowInner::GetChildWindow(const nsAString& aName) return nullptr; } -bool -nsGlobalWindowInner::DispatchCustomEvent(const nsAString& aEventName) -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::RefreshCompartmentPrincipal() { - MOZ_ASSERT(IsInnerWindow()); - JS_SetCompartmentPrincipals(js::GetObjectCompartment(GetWrapperPreserveColor()), nsJSPrincipals::get(mDoc->NodePrincipal())); } @@ -3236,31 +3328,6 @@ nsGlobalWindowInner::SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aErro FORWARD_TO_OUTER_OR_THROW(SetFullScreenOuter, (aFullScreen, aError), aError, /* void */); } -nsresult -nsGlobalWindowInner::SetFullScreen(bool aFullScreen) -{ - FORWARD_TO_OUTER(SetFullScreen, (aFullScreen), NS_ERROR_NOT_INITIALIZED); -} - -nsresult -nsGlobalWindowInner::SetFullscreenInternal(FullscreenReason aReason, - bool aFullScreen) -{ - MOZ_CRASH("Virtual outer window only function"); -} - -/* virtual */ void -nsGlobalWindowInner::FullscreenWillChange(bool aIsFullscreen) -{ - MOZ_CRASH("Virtual outer window only function"); -} - -/* virtual */ void -nsGlobalWindowInner::FinishFullscreenChange(bool aIsFullscreen) -{ - MOZ_CRASH("Virtual outer window only function"); -} - bool nsGlobalWindowInner::GetFullScreen(ErrorResult& aError) { @@ -3314,7 +3381,6 @@ void nsGlobalWindowInner::Alert(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); Alert(EmptyString(), aSubjectPrincipal, aError); } @@ -3436,12 +3502,6 @@ nsGlobalWindowInner::MoveBy(int32_t aXDif, int32_t aYDif, (aXDif, aYDif, aCallerType, aError), aError, ); } -nsresult -nsGlobalWindowInner::MoveBy(int32_t aXDif, int32_t aYDif) -{ - FORWARD_TO_OUTER(MoveBy, (aXDif, aYDif), NS_ERROR_UNEXPECTED); -} - void nsGlobalWindowInner::ResizeTo(int32_t aWidth, int32_t aHeight, CallerType aCallerType, ErrorResult& aError) @@ -3469,13 +3529,11 @@ nsGlobalWindowInner::SizeToContent(CallerType aCallerType, ErrorResult& aError) already_AddRefed nsGlobalWindowInner::GetTopWindowRoot() { - nsPIDOMWindowOuter* piWin = GetPrivateRoot(); - if (!piWin) { + nsGlobalWindowOuter* outer = GetOuterWindowInternal(); + if (!outer) { return nullptr; } - - nsCOMPtr window = do_QueryInterface(piWin->GetChromeEventHandler()); - return window.forget(); + return outer->GetTopWindowRoot(); } void @@ -3610,8 +3668,6 @@ void nsGlobalWindowInner::ScrollByLines(int32_t numLines, const ScrollOptions& aOptions) { - MOZ_ASSERT(IsInnerWindow()); - FlushPendingNotifications(FlushType::Layout); nsIScrollableFrame *sf = GetScrollFrame(); if (sf) { @@ -3631,8 +3687,6 @@ void nsGlobalWindowInner::ScrollByPages(int32_t numPages, const ScrollOptions& aOptions) { - MOZ_ASSERT(IsInnerWindow()); - FlushPendingNotifications(FlushType::Layout); nsIScrollableFrame *sf = GetScrollFrame(); if (sf) { @@ -3651,8 +3705,6 @@ nsGlobalWindowInner::ScrollByPages(int32_t numPages, void nsGlobalWindowInner::MozScrollSnap() { - MOZ_ASSERT(IsInnerWindow()); - FlushPendingNotifications(FlushType::Layout); nsIScrollableFrame *sf = GetScrollFrame(); if (sf) { @@ -3663,8 +3715,6 @@ nsGlobalWindowInner::MozScrollSnap() void nsGlobalWindowInner::ClearTimeout(int32_t aHandle) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (aHandle > 0) { mTimeoutManager->ClearTimeout(aHandle, Timeout::Reason::eTimeoutOrInterval); } @@ -3673,8 +3723,6 @@ nsGlobalWindowInner::ClearTimeout(int32_t aHandle) void nsGlobalWindowInner::ClearInterval(int32_t aHandle) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (aHandle > 0) { mTimeoutManager->ClearTimeout(aHandle, Timeout::Reason::eTimeoutOrInterval); } @@ -3702,15 +3750,6 @@ nsGlobalWindowInner::ReleaseEvents() } } -void -nsGlobalWindowInner::FirePopupBlockedEvent(nsIDocument* aDoc, - nsIURI* aPopupURI, - const nsAString& aPopupWindowName, - const nsAString& aPopupWindowFeatures) -{ - MOZ_CRASH("Virtual outer window only function"); -} - already_AddRefed nsGlobalWindowInner::Open(const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions, ErrorResult& aError) @@ -3719,37 +3758,6 @@ nsGlobalWindowInner::Open(const nsAString& aUrl, const nsAString& aName, nullptr); } -nsresult -nsGlobalWindowInner::Open(const nsAString& aUrl, const nsAString& aName, - const nsAString& aOptions, nsIDocShellLoadInfo* aLoadInfo, - bool aForceNoOpener, nsPIDOMWindowOuter **_retval) -{ - FORWARD_TO_OUTER(Open, (aUrl, aName, aOptions, aLoadInfo, aForceNoOpener, - _retval), - NS_ERROR_NOT_INITIALIZED); -} - -// like Open, but attaches to the new window any extra parameters past -// [features] as a JS property named "arguments" -nsresult -nsGlobalWindowInner::OpenDialog(const nsAString& aUrl, const nsAString& aName, - const nsAString& aOptions, - nsISupports* aExtraArgument, - nsPIDOMWindowOuter** _retval) -{ - MOZ_CRASH("Virtual outer window only function"); -} - -// Like Open, but passes aNavigate=false. -/* virtual */ nsresult -nsGlobalWindowInner::OpenNoNavigate(const nsAString& aUrl, - const nsAString& aName, - const nsAString& aOptions, - nsPIDOMWindowOuter **_retval) -{ - MOZ_CRASH("Virtual outer window only function"); -} - already_AddRefed nsGlobalWindowInner::OpenDialog(JSContext* aCx, const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions, @@ -3834,12 +3842,6 @@ nsGlobalWindowInner::PostMessageMoz(JSContext* aCx, JS::Handle aMessa aSubjectPrincipal, aRv); } -bool -nsGlobalWindowInner::CanClose() -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::Close(ErrorResult& aError) { @@ -3852,30 +3854,12 @@ nsGlobalWindowInner::Close() FORWARD_TO_OUTER(Close, (), NS_ERROR_UNEXPECTED); } -void -nsGlobalWindowInner::ForceClose() -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::ReallyCloseWindow() { FORWARD_TO_OUTER_VOID(ReallyCloseWindow, ()); } -void -nsGlobalWindowInner::EnterModalState() -{ - MOZ_CRASH("Virtual outer window only function"); -} - -void -nsGlobalWindowInner::LeaveModalState() -{ - MOZ_CRASH("Virtual outer window only function"); -} - bool nsGlobalWindowInner::IsInModalState() { @@ -3900,10 +3884,7 @@ nsGlobalWindowInner::NotifyWindowIDDestroyed(const char* aTopic) { nsCOMPtr runnable = new WindowDestroyedEvent(this, mWindowID, aTopic); - nsresult rv = Dispatch(TaskCategory::Other, runnable.forget()); - if (NS_SUCCEEDED(rv)) { - mNotifiedIDDestroyed = true; - } + Dispatch(TaskCategory::Other, runnable.forget()); } // static @@ -4128,12 +4109,6 @@ nsGlobalWindowInner::GetSelection(ErrorResult& aError) FORWARD_TO_OUTER_OR_THROW(GetSelectionOuter, (), aError, nullptr); } -already_AddRefed -nsGlobalWindowInner::GetSelection() -{ - MOZ_CRASH("Virtual outer window only function"); -} - bool nsGlobalWindowInner::Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards, bool aWrapAround, bool aWholeWord, @@ -4149,7 +4124,6 @@ nsGlobalWindowInner::Find(const nsAString& aString, bool aCaseSensitive, void nsGlobalWindowInner::GetOrigin(nsAString& aOrigin) { - MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow()); nsContentUtils::GetUTFOrigin(GetPrincipal(), aOrigin); } @@ -4157,7 +4131,6 @@ void nsGlobalWindowInner::Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); aError = nsContentUtils::Atob(aAsciiBase64String, aBinaryData); } @@ -4165,7 +4138,6 @@ void nsGlobalWindowInner::Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); aError = nsContentUtils::Btoa(aBinaryData, aAsciiBase64String); } @@ -4329,8 +4301,6 @@ nsGlobalWindowInner::GetPrivateRoot() Location* nsGlobalWindowInner::GetLocation() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mLocation) { mLocation = new dom::Location(this, GetDocShell()); } @@ -4338,18 +4308,6 @@ nsGlobalWindowInner::GetLocation() return mLocation; } -void -nsGlobalWindowInner::ActivateOrDeactivate(bool aActivate) -{ - MOZ_CRASH("Virtual outer window only function"); -} - -void -nsGlobalWindowInner::SetActive(bool aActive) -{ - MOZ_CRASH("Virtual outer window only function"); -} - bool nsGlobalWindowInner::IsTopLevelWindowActive() { @@ -4359,12 +4317,6 @@ nsGlobalWindowInner::IsTopLevelWindowActive() return false; } -void -nsGlobalWindowInner::SetIsBackground(bool aIsBackground) -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::MaybeUpdateTouchState() { @@ -4383,8 +4335,6 @@ nsGlobalWindowInner::MaybeUpdateTouchState() void nsGlobalWindowInner::EnableGamepadUpdates() { - MOZ_ASSERT(IsInnerWindow()); - if (mHasGamepad) { RefPtr gamepadManager(GamepadManager::GetService()); if (gamepadManager) { @@ -4396,8 +4346,6 @@ nsGlobalWindowInner::EnableGamepadUpdates() void nsGlobalWindowInner::DisableGamepadUpdates() { - MOZ_ASSERT(IsInnerWindow()); - if (mHasGamepad) { RefPtr gamepadManager(GamepadManager::GetService()); if (gamepadManager) { @@ -4409,8 +4357,6 @@ nsGlobalWindowInner::DisableGamepadUpdates() void nsGlobalWindowInner::EnableVRUpdates() { - MOZ_ASSERT(IsInnerWindow()); - if (mHasVREvents && !mVREventObserver) { mVREventObserver = new VREventObserver(this); } @@ -4419,7 +4365,6 @@ nsGlobalWindowInner::EnableVRUpdates() void nsGlobalWindowInner::DisableVRUpdates() { - MOZ_ASSERT(IsInnerWindow()); if (mVREventObserver) { mVREventObserver->DisconnectFromOwner(); mVREventObserver = nullptr; @@ -4434,10 +4379,13 @@ nsGlobalWindowInner::ResetVRTelemetry(bool aUpdate) } } -void -nsGlobalWindowInner::SetChromeEventHandler(EventTarget* aChromeEventHandler) +static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode) { - MOZ_CRASH("Virtual outer window only function"); + if (!aNode) { + return true; + } + return !nsContentUtils::ContentIsLink(aNode) && + !aNode->IsAnyOfHTMLElements(nsGkAtoms::video, nsGkAtoms::audio); } void @@ -4502,13 +4450,6 @@ nsGlobalWindowInner::ShouldShowFocusRing() return root ? root->ShowFocusRings() : false; } -void -nsGlobalWindowInner::SetKeyboardIndicators(UIStateChangeType aShowAccelerators, - UIStateChangeType aShowFocusRings) -{ - MOZ_CRASH("Virtual outer window only function"); -} - bool nsGlobalWindowInner::TakeFocus(bool aFocus, uint32_t aFocusMethod) { @@ -4575,7 +4516,6 @@ public: , mWindow(aWindow) { MOZ_ASSERT(mWindow); - MOZ_ASSERT(mWindow->IsInnerWindow()); mOldURL.Assign(aOldURL); mNewURL.Assign(aNewURL); } @@ -4595,8 +4535,6 @@ private: nsresult nsGlobalWindowInner::DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - // Make sure that aOldURI and aNewURI are identical up to the '#', and that // their hashes are different. bool equal = false; @@ -4627,8 +4565,6 @@ nsresult nsGlobalWindowInner::FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL) { - MOZ_ASSERT(IsInnerWindow()); - // Don't do anything if the window is frozen. if (IsFrozen()) { return NS_OK; @@ -4662,7 +4598,6 @@ nsGlobalWindowInner::FireHashchange(const nsAString &aOldURL, nsresult nsGlobalWindowInner::DispatchSyncPopState() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Must be safe to run script here."); @@ -4737,8 +4672,6 @@ FindCanvasFrame(nsIFrame* aFrame) void nsGlobalWindowInner::UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent) { - MOZ_ASSERT(IsInnerWindow()); - // this is called from the inner window so use GetDocShell nsIDocShell* docShell = GetDocShell(); if (!docShell) @@ -4782,7 +4715,6 @@ already_AddRefed nsGlobalWindowInner::GetComputedStyle(Element& aElt, const nsAString& aPseudoElt, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); return GetComputedStyleHelper(aElt, aPseudoElt, false, aError); } @@ -4791,7 +4723,6 @@ nsGlobalWindowInner::GetDefaultComputedStyle(Element& aElt, const nsAString& aPseudoElt, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); return GetComputedStyleHelper(aElt, aPseudoElt, true, aError); } @@ -4801,8 +4732,6 @@ nsGlobalWindowInner::GetComputedStyleHelper(nsIDOMElement* aElt, bool aDefaultStylesOnly, nsIDOMCSSStyleDeclaration** aReturn) { - MOZ_ASSERT(IsInnerWindow()); - NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nullptr; @@ -4833,17 +4762,15 @@ nsGlobalWindowInner::GetComputedStyleHelper(Element& aElt, Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - nsIPrincipal *principal = GetPrincipal(); nsIDocShell* docShell = GetDocShell(); - if (!principal || !docShell || !Preferences::GetBool(kStorageEnabled)) { + if (!principal || !docShell || !Storage::StoragePrefIsEnabled()) { return nullptr; } if (mSessionStorage) { - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("nsGlobalWindowInner %p has %p sessionStorage", this, mSessionStorage.get())); bool canAccess = principal->Subsumes(mSessionStorage->Principal()); NS_ASSERTION(canAccess, @@ -4894,7 +4821,7 @@ nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) mSessionStorage = static_cast(storage.get()); MOZ_ASSERT(mSessionStorage); - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("nsGlobalWindowInner %p tried to get a new sessionStorage %p", this, mSessionStorage.get())); if (!mSessionStorage) { @@ -4903,7 +4830,7 @@ nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) } } - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("nsGlobalWindowInner %p returns %p sessionStorage", this, mSessionStorage.get())); return mSessionStorage; @@ -4912,9 +4839,7 @@ nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - - if (!Preferences::GetBool(kStorageEnabled)) { + if (!Storage::StoragePrefIsEnabled()) { return nullptr; } @@ -4964,7 +4889,6 @@ nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) IDBFactory* nsGlobalWindowInner::GetIndexedDB(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); if (!mIndexedDB) { // This may keep mIndexedDB null without setting an error. aError = IDBFactory::CreateForWindow(this, @@ -4996,15 +4920,12 @@ nsGlobalWindowInner::GetInterface(JSContext* aCx, nsIJSID* aIID, JS::MutableHandle aRetval, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); dom::GetInterface(aCx, this, aIID, aRetval, aError); } already_AddRefed nsGlobalWindowInner::GetCaches(ErrorResult& aRv) { - MOZ_ASSERT(IsInnerWindow()); - if (!mCacheStorage) { bool forceTrustedOrigin = GetOuterWindow()->GetServiceWorkersTestingEnabled(); @@ -5117,7 +5038,6 @@ void nsGlobalWindowInner::NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder, bool aCallOnidle) { - MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(aIdleObserverHolder); aIdleObserverHolder->mPrevNotificationIdle = aCallOnidle; @@ -5168,7 +5088,6 @@ IdleObserverTimerCallback(nsITimer* aTimer, void* aClosure) void nsGlobalWindowInner::HandleIdleObserverCallback() { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); MOZ_ASSERT(static_cast(mIdleCallbackIndex) < mIdleObservers.Length(), "Idle callback index exceeds array bounds!"); IdleObserverHolder& idleObserver = mIdleObservers.ElementAt(mIdleCallbackIndex); @@ -5182,7 +5101,6 @@ nsGlobalWindowInner::HandleIdleObserverCallback() nsresult nsGlobalWindowInner::ScheduleNextIdleObserverCallback() { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); MOZ_ASSERT(mIdleService, "No idle service!"); if (mIdleCallbackIndex < 0 || @@ -5217,8 +5135,6 @@ nsGlobalWindowInner::ScheduleNextIdleObserverCallback() uint32_t nsGlobalWindowInner::GetFuzzTimeMS() { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); - if (gIdleObserversAPIFuzzTimeDisabled) { return 0; } @@ -5240,8 +5156,6 @@ nsGlobalWindowInner::GetFuzzTimeMS() nsresult nsGlobalWindowInner::ScheduleActiveTimerCallback() { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); - if (!mAddActiveEventFuzzTime) { return HandleIdleActiveEvent(); } @@ -5263,8 +5177,6 @@ nsGlobalWindowInner::ScheduleActiveTimerCallback() nsresult nsGlobalWindowInner::HandleIdleActiveEvent() { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); - if (mCurrentlyIdle) { mIdleCallbackIndex = 0; mIdleFuzzFactor = GetFuzzTimeMS(); @@ -5290,8 +5202,6 @@ nsGlobalWindowInner::HandleIdleActiveEvent() nsGlobalWindowInner::SlowScriptResponse nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) { - MOZ_ASSERT(IsInnerWindow()); - nsresult rv; AutoJSContext cx; @@ -5525,7 +5435,6 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) uint32_t nsGlobalWindowInner::FindInsertionIndex(IdleObserverHolder* aIdleObserver) { - MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(aIdleObserver, "Idle observer not instantiated."); uint32_t i = 0; @@ -5545,8 +5454,6 @@ nsGlobalWindowInner::FindInsertionIndex(IdleObserverHolder* aIdleObserver) nsresult nsGlobalWindowInner::RegisterIdleObserver(nsIIdleObserver* aIdleObserver) { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); - nsresult rv; if (mIdleObservers.IsEmpty()) { mIdleService = do_GetService("@mozilla.org/widget/idleservice;1", &rv); @@ -5617,7 +5524,6 @@ nsresult nsGlobalWindowInner::FindIndexOfElementToRemove(nsIIdleObserver* aIdleObserver, int32_t* aRemoveElementIndex) { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); MOZ_ASSERT(aIdleObserver, "Idle observer not instantiated."); *aRemoveElementIndex = 0; @@ -5646,8 +5552,6 @@ nsGlobalWindowInner::FindIndexOfElementToRemove(nsIIdleObserver* aIdleObserver, nsresult nsGlobalWindowInner::UnregisterIdleObserver(nsIIdleObserver* aIdleObserver) { - MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!"); - int32_t removeElementIndex; nsresult rv = FindIndexOfElementToRemove(aIdleObserver, &removeElementIndex); if (NS_FAILED(rv)) { @@ -5736,7 +5640,6 @@ nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic, mNotifyIdleObserversActiveOnThaw = true; mNotifyIdleObserversIdleOnThaw = false; } else if (IsCurrentInnerWindow()) { - MOZ_ASSERT(IsInnerWindow()); ScheduleActiveTimerCallback(); } return NS_OK; @@ -5759,7 +5662,6 @@ nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic, if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { MOZ_ASSERT(!NS_strcmp(aData, u"intl.accept_languages")); - MOZ_ASSERT(IsInnerWindow()); // The user preferred languages have changed, we need to fire an event on // Window object and invalidate the cache for navigator.languages. It is @@ -5808,7 +5710,7 @@ nsGlobalWindowInner::ObserveStorageNotification(StorageEvent* aEvent, // generate events on frozen or otherwise-navigated-away from windows. // (Actually, this code used to try and buffer events for frozen windows, // but it never worked, so we've removed it. See bug 1285898.) - if (!IsInnerWindow() || !IsCurrentInnerWindow() || IsFrozen()) { + if (!IsCurrentInnerWindow() || IsFrozen()) { return; } @@ -5842,7 +5744,7 @@ nsGlobalWindowInner::ObserveStorageNotification(StorageEvent* aEvent, return; } - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, ("nsGlobalWindowInner %p with sessionStorage %p passing event from %p", this, mSessionStorage.get(), changingStorage.get())); @@ -5890,8 +5792,6 @@ nsGlobalWindowInner::CloneStorageEvent(const nsAString& aType, const RefPtr& aEvent, ErrorResult& aRv) { - MOZ_ASSERT(IsInnerWindow()); - StorageEventInit dict; dict.mBubbles = aEvent->Bubbles(); @@ -5942,7 +5842,6 @@ void nsGlobalWindowInner::Suspend() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow()); // We can only safely suspend windows that are the current inner window. If // its not the current inner, then we are in one of two different cases. @@ -5991,7 +5890,6 @@ void nsGlobalWindowInner::Resume() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow()); // We can only safely resume a window if its the current inner window. If // its not the current inner, then we are in one of two different cases. @@ -6059,7 +5957,6 @@ void nsGlobalWindowInner::FreezeInternal() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow()); MOZ_DIAGNOSTIC_ASSERT(IsCurrentInnerWindow()); MOZ_DIAGNOSTIC_ASSERT(IsSuspended()); @@ -6078,9 +5975,7 @@ nsGlobalWindowInner::FreezeInternal() mClientSource->Freeze(); } - if (IsInnerWindow()) { - NotifyDOMWindowFrozen(this); - } + NotifyDOMWindowFrozen(this); } void @@ -6095,7 +5990,6 @@ void nsGlobalWindowInner::ThawInternal() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow()); MOZ_DIAGNOSTIC_ASSERT(IsCurrentInnerWindow()); MOZ_DIAGNOSTIC_ASSERT(IsSuspended()); @@ -6115,9 +6009,7 @@ nsGlobalWindowInner::ThawInternal() mozilla::dom::workers::ThawWorkersForWindow(this); - if (IsInnerWindow()) { - NotifyDOMWindowThawed(this); - } + NotifyDOMWindowThawed(this); } bool @@ -6134,7 +6026,6 @@ nsGlobalWindowInner::SyncStateFromParentWindow() { // This method should only be called on an inner window that has been // assigned to an outer window already. - MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(IsCurrentInnerWindow()); nsPIDOMWindowOuter* outer = GetOuterWindow(); MOZ_ASSERT(outer); @@ -6179,7 +6070,6 @@ void nsGlobalWindowInner::CallOnChildren(Method aMethod) { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(IsInnerWindow()); MOZ_ASSERT(IsCurrentInnerWindow()); nsCOMPtr docShell = GetDocShell(); @@ -6315,6 +6205,20 @@ nsGlobalWindowInner::SetTimeout(JSContext* aCx, const nsAString& aHandler, return SetTimeoutOrInterval(aCx, aHandler, aTimeout, false, aError); } +static bool +IsInterval(const Optional& aTimeout, int32_t& aResultTimeout) +{ + if (aTimeout.WasPassed()) { + aResultTimeout = aTimeout.Value(); + return true; + } + + // If no interval was specified, treat this like a timeout, to avoid setting + // an interval of 0 milliseconds. + aResultTimeout = 0; + return false; +} + int32_t nsGlobalWindowInner::SetInterval(JSContext* aCx, Function& aFunction, const Optional& aTimeout, @@ -6399,8 +6303,6 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout, nsIScriptContext* aScx) { - MOZ_ASSERT(IsInnerWindow()); - // Hold on to the timeout in case mExpr or mFunObj releases its // doc. RefPtr timeout = aTimeout; @@ -6555,29 +6457,9 @@ nsGlobalWindowInner::FlushPendingNotifications(FlushType aType) } } -void -nsGlobalWindowInner::EnsureSizeAndPositionUpToDate() -{ - MOZ_CRASH("Virtual outer window only function"); -} - -already_AddRefed -nsGlobalWindowInner::SaveWindowState() -{ - MOZ_CRASH("Virtual outer window only function"); -} - -nsresult -nsGlobalWindowInner::RestoreWindowState(nsISupports *aState) -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::EnableDeviceSensor(uint32_t aType) { - MOZ_ASSERT(IsInnerWindow()); - bool alreadyEnabled = false; for (uint32_t i = 0; i < mEnabledSensors.Length(); i++) { if (mEnabledSensors[i] == aType) { @@ -6601,8 +6483,6 @@ nsGlobalWindowInner::EnableDeviceSensor(uint32_t aType) void nsGlobalWindowInner::DisableDeviceSensor(uint32_t aType) { - MOZ_ASSERT(IsInnerWindow()); - int32_t doomedElement = -1; int32_t listenerCount = 0; for (uint32_t i = 0; i < mEnabledSensors.Length(); i++) { @@ -6632,8 +6512,9 @@ nsGlobalWindowInner::DisableDeviceSensor(uint32_t aType) void nsGlobalWindowInner::EnableOrientationChangeListener() { - MOZ_ASSERT(IsInnerWindow()); - if (!nsContentUtils::ShouldResistFingerprinting(mDocShell) && + // XXX: mDocShell is never set on the inner window? + nsIDocShell* docShell = nullptr; + if (!nsContentUtils::ShouldResistFingerprinting(docShell) && !mOrientationChangeObserver) { mOrientationChangeObserver = MakeUnique(this); @@ -6643,8 +6524,6 @@ nsGlobalWindowInner::EnableOrientationChangeListener() void nsGlobalWindowInner::DisableOrientationChangeListener() { - MOZ_ASSERT(IsInnerWindow()); - mOrientationChangeObserver = nullptr; } #endif @@ -6652,7 +6531,6 @@ nsGlobalWindowInner::DisableOrientationChangeListener() void nsGlobalWindowInner::SetHasGamepadEventListener(bool aHasGamepad/* = true*/) { - MOZ_ASSERT(IsInnerWindow()); mHasGamepad = aHasGamepad; if (aHasGamepad) { EnableGamepadUpdates(); @@ -6678,7 +6556,6 @@ nsGlobalWindowInner::EventListenerAdded(nsAtom* aType) if (aType == nsGkAtoms::onbeforeunload && mTabChild && (!mDoc || !(mDoc->GetSandboxFlags() & SANDBOXED_MODALS))) { - MOZ_ASSERT(IsInnerWindow()); mBeforeUnloadListenerCount++; MOZ_ASSERT(mBeforeUnloadListenerCount > 0); mTabChild->BeforeUnloadAdded(); @@ -6698,7 +6575,6 @@ nsGlobalWindowInner::EventListenerRemoved(nsAtom* aType) if (aType == nsGkAtoms::onbeforeunload && mTabChild && (!mDoc || !(mDoc->GetSandboxFlags() & SANDBOXED_MODALS))) { - MOZ_ASSERT(IsInnerWindow()); mBeforeUnloadListenerCount--; MOZ_ASSERT(mBeforeUnloadListenerCount >= 0); mTabChild->BeforeUnloadRemoved(); @@ -6708,7 +6584,6 @@ nsGlobalWindowInner::EventListenerRemoved(nsAtom* aType) void nsGlobalWindowInner::NotifyVREventListenerAdded() { - MOZ_ASSERT(IsInnerWindow()); mHasVREvents = true; EnableVRUpdates(); } @@ -6716,8 +6591,6 @@ nsGlobalWindowInner::NotifyVREventListenerAdded() bool nsGlobalWindowInner::HasUsedVR() const { - MOZ_ASSERT(IsInnerWindow()); - // Returns true only if any WebVR API call or related event // has been used return mHasVREvents; @@ -6726,8 +6599,6 @@ nsGlobalWindowInner::HasUsedVR() const bool nsGlobalWindowInner::IsVRContentDetected() const { - MOZ_ASSERT(IsInnerWindow()); - // Returns true only if the content will respond to // the VRDisplayActivate event. return mHasVRDisplayActivateEvents; @@ -6810,7 +6681,6 @@ nsGlobalWindowInner::AddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const void nsGlobalWindowInner::AddGamepad(uint32_t aIndex, Gamepad* aGamepad) { - MOZ_ASSERT(IsInnerWindow()); // Create the index we will present to content based on which indices are // already taken, as required by the spec. // https://w3c.github.io/gamepad/gamepad.html#widl-Gamepad-index @@ -6826,7 +6696,6 @@ nsGlobalWindowInner::AddGamepad(uint32_t aIndex, Gamepad* aGamepad) void nsGlobalWindowInner::RemoveGamepad(uint32_t aIndex) { - MOZ_ASSERT(IsInnerWindow()); RefPtr gamepad; if (!mGamepads.Get(aIndex, getter_AddRefs(gamepad))) { return; @@ -6839,7 +6708,6 @@ nsGlobalWindowInner::RemoveGamepad(uint32_t aIndex) void nsGlobalWindowInner::GetGamepads(nsTArray >& aGamepads) { - MOZ_ASSERT(IsInnerWindow()); aGamepads.Clear(); // navigator.getGamepads() always returns an empty array when @@ -6860,7 +6728,6 @@ nsGlobalWindowInner::GetGamepads(nsTArray >& aGamepads) already_AddRefed nsGlobalWindowInner::GetGamepad(uint32_t aIndex) { - MOZ_ASSERT(IsInnerWindow()); RefPtr gamepad; if (mGamepads.Get(aIndex, getter_AddRefs(gamepad))) { @@ -6873,21 +6740,18 @@ nsGlobalWindowInner::GetGamepad(uint32_t aIndex) void nsGlobalWindowInner::SetHasSeenGamepadInput(bool aHasSeen) { - MOZ_ASSERT(IsInnerWindow()); mHasSeenGamepadInput = aHasSeen; } bool nsGlobalWindowInner::HasSeenGamepadInput() { - MOZ_ASSERT(IsInnerWindow()); return mHasSeenGamepadInput; } void nsGlobalWindowInner::SyncGamepadState() { - MOZ_ASSERT(IsInnerWindow()); if (mHasSeenGamepadInput) { RefPtr gamepadManager(GamepadManager::GetService()); for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) { @@ -6899,7 +6763,6 @@ nsGlobalWindowInner::SyncGamepadState() void nsGlobalWindowInner::StopGamepadHaptics() { - MOZ_ASSERT(IsInnerWindow()); if (mHasSeenGamepadInput) { RefPtr gamepadManager(GamepadManager::GetService()); gamepadManager->StopHaptics(); @@ -6917,8 +6780,6 @@ nsGlobalWindowInner::UpdateVRDisplays(nsTArray>& void nsGlobalWindowInner::NotifyActiveVRDisplaysChanged() { - MOZ_ASSERT(IsInnerWindow()); - if (mNavigator) { mNavigator->NotifyActiveVRDisplaysChanged(); } @@ -7093,7 +6954,6 @@ enum WindowState { uint16_t nsGlobalWindowInner::WindowState() { - MOZ_ASSERT(IsInnerWindow()); nsCOMPtr widget = GetMainWidget(); int32_t mode = widget ? widget->SizeMode() : 0; @@ -7118,8 +6978,6 @@ nsGlobalWindowInner::WindowState() bool nsGlobalWindowInner::IsFullyOccluded() { - MOZ_ASSERT(IsInnerWindow()); - nsCOMPtr widget = GetMainWidget(); return widget && widget->IsFullyOccluded(); } @@ -7127,8 +6985,6 @@ nsGlobalWindowInner::IsFullyOccluded() void nsGlobalWindowInner::Maximize() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - nsCOMPtr widget = GetMainWidget(); if (widget) { @@ -7139,8 +6995,6 @@ nsGlobalWindowInner::Maximize() void nsGlobalWindowInner::Minimize() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - nsCOMPtr widget = GetMainWidget(); if (widget) { @@ -7151,8 +7005,6 @@ nsGlobalWindowInner::Minimize() void nsGlobalWindowInner::Restore() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - nsCOMPtr widget = GetMainWidget(); if (widget) { @@ -7163,7 +7015,6 @@ nsGlobalWindowInner::Restore() void nsGlobalWindowInner::GetAttention(ErrorResult& aResult) { - MOZ_ASSERT(IsInnerWindow()); return GetAttentionWithCycleCount(-1, aResult); } @@ -7171,8 +7022,6 @@ void nsGlobalWindowInner::GetAttentionWithCycleCount(int32_t aCycleCount, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - nsCOMPtr widget = GetMainWidget(); if (widget) { @@ -7184,8 +7033,6 @@ void nsGlobalWindowInner::BeginWindowMove(Event& aMouseDownEvent, Element* aPanel, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - nsCOMPtr widget; // if a panel was supplied, use its widget instead. @@ -7258,7 +7105,6 @@ void nsGlobalWindowInner::NotifyDefaultButtonLoaded(Element& aDefaultButton, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); #ifdef MOZ_XUL // Don't snap to a disabled button. nsCOMPtr xulControl = @@ -7315,7 +7161,6 @@ nsIMessageBroadcaster* nsGlobalWindowInner::GetMessageManager(ErrorResult& aError) { MOZ_ASSERT(IsChromeWindow()); - MOZ_RELEASE_ASSERT(IsInnerWindow()); if (!mChromeFields.mMessageManager) { nsCOMPtr globalMM = do_GetService("@mozilla.org/globalmessagemanager;1"); @@ -7342,7 +7187,6 @@ nsGlobalWindowInner::GetGroupMessageManager(const nsAString& aGroup, ErrorResult& aError) { MOZ_ASSERT(IsChromeWindow()); - MOZ_RELEASE_ASSERT(IsInnerWindow()); nsCOMPtr messageManager = mChromeFields.mGroupMessageManagers.LookupForAdd(aGroup).OrInsert( @@ -7357,18 +7201,6 @@ nsGlobalWindowInner::GetGroupMessageManager(const nsAString& aGroup, return messageManager; } -nsresult -nsGlobalWindowInner::SetOpenerForInitialContentBrowser(mozIDOMWindowProxy* aOpenerWindow) -{ - MOZ_CRASH("Virtual outer window only function"); -} - -nsresult -nsGlobalWindowInner::TakeOpenerForInitialContentBrowser(mozIDOMWindowProxy** aOpenerWindow) -{ - MOZ_CRASH("Virtual outer window only function"); -} - void nsGlobalWindowInner::InitWasOffline() { @@ -7387,8 +7219,6 @@ nsGlobalWindowInner::Orientation(CallerType aCallerType) const Console* nsGlobalWindowInner::GetConsole(ErrorResult& aRv) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mConsole) { mConsole = Console::Create(this, aRv); if (NS_WARN_IF(aRv.Failed())) { @@ -7402,24 +7232,18 @@ nsGlobalWindowInner::GetConsole(ErrorResult& aRv) bool nsGlobalWindowInner::IsSecureContext() const { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - return JS_GetIsSecureContext(js::GetObjectCompartment(GetWrapperPreserveColor())); } bool nsGlobalWindowInner::IsSecureContextIfOpenerIgnored() const { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - return mIsSecureContextIfOpenerIgnored; } already_AddRefed nsGlobalWindowInner::GetExternal(ErrorResult& aRv) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - #ifdef HAVE_SIDEBAR if (!mExternal) { AutoJSContext cx; @@ -7443,8 +7267,6 @@ void nsGlobalWindowInner::GetSidebar(OwningExternalOrWindowProxy& aResult, ErrorResult& aRv) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - #ifdef HAVE_SIDEBAR // First check for a named frame named "sidebar" nsCOMPtr domWindow = GetChildWindow(NS_LITERAL_STRING("sidebar")); @@ -7465,8 +7287,6 @@ nsGlobalWindowInner::GetSidebar(OwningExternalOrWindowProxy& aResult, void nsGlobalWindowInner::ClearDocumentDependentSlots(JSContext* aCx) { - MOZ_ASSERT(IsInnerWindow()); - // If JSAPI OOMs here, there is basically nothing we can do to recover safely. if (!WindowBinding::ClearCachedDocumentValue(aCx, this) || !WindowBinding::ClearCachedPerformanceValue(aCx, this)) { @@ -7513,8 +7333,6 @@ nsGlobalWindowInner::GetReplaceableWindowCoord(JSContext* aCx, CallerType aCallerType, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - int32_t coord = (this->*aGetter)(aCallerType, aError); if (!aError.Failed() && !ToJSValue(aCx, coord, aRetval)) { @@ -7530,8 +7348,6 @@ nsGlobalWindowInner::SetReplaceableWindowCoord(JSContext* aCx, CallerType aCallerType, ErrorResult& aError) { - MOZ_ASSERT(IsInnerWindow()); - /* * If caller is not chrome and the user has not explicitly exempted the site, * just treat this the way we would an IDL replaceable property. @@ -7651,8 +7467,6 @@ nsGlobalWindowInner::SetReplaceableWindowCoord(JSContext* aCx, void nsGlobalWindowInner::FireOnNewGlobalObject() { - MOZ_ASSERT(IsInnerWindow()); - // AutoEntryScript required to invoke debugger hook, which is a // Gecko-specific concept at present. AutoEntryScript aes(this, "nsGlobalWindowInner report new global"); @@ -7714,8 +7528,6 @@ nsGlobalWindowInner::CreateImageBitmap(JSContext* aCx, mozilla::dom::TabGroup* nsGlobalWindowInner::TabGroupInner() { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - // If we don't have a TabGroup yet, try to get it from the outer window and // cache it. if (!mTabGroup) { @@ -7775,8 +7587,6 @@ nsGlobalWindowInner::AbstractMainThreadFor(TaskCategory aCategory) Worklet* nsGlobalWindowInner::GetAudioWorklet(ErrorResult& aRv) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mAudioWorklet) { nsIPrincipal* principal = GetPrincipal(); if (!principal) { @@ -7793,8 +7603,6 @@ nsGlobalWindowInner::GetAudioWorklet(ErrorResult& aRv) Worklet* nsGlobalWindowInner::GetPaintWorklet(ErrorResult& aRv) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mPaintWorklet) { nsIPrincipal* principal = GetPrincipal(); if (!principal) { @@ -7822,8 +7630,6 @@ nsGlobalWindowInner::GetRegionalPrefsLocales(nsTArray& aLocales) IntlUtils* nsGlobalWindowInner::GetIntlUtils(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsInnerWindow()); - if (!mIntlUtils) { mIntlUtils = new IntlUtils(this); } @@ -7850,6 +7656,72 @@ nsGlobalWindowInner::Create(nsGlobalWindowOuter *aOuterWindow, bool aIsChrome) return window.forget(); } +nsIURI* +nsPIDOMWindowInner::GetDocumentURI() const +{ + return mDoc ? mDoc->GetDocumentURI() : mDocumentURI.get(); +} + +nsIURI* +nsPIDOMWindowInner::GetDocBaseURI() const +{ + return mDoc ? mDoc->GetDocBaseURI() : mDocBaseURI.get(); +} + +void +nsPIDOMWindowInner::MaybeCreateDoc() +{ + // XXX: Forward to outer? + MOZ_ASSERT(!mDoc); + if (nsIDocShell* docShell = GetDocShell()) { + // Note that |document| here is the same thing as our mDoc, but we + // don't have to explicitly set the member variable because the docshell + // has already called SetNewDocument(). + nsCOMPtr document = docShell->GetDocument(); + Unused << document; + } +} + +mozilla::dom::DocGroup* +nsPIDOMWindowInner::GetDocGroup() const +{ + nsIDocument* doc = GetExtantDoc(); + if (doc) { + return doc->GetDocGroup(); + } + return nullptr; +} + +// XXX: Can we define this in a header instead of here? +namespace mozilla { +namespace dom { +extern uint64_t +NextWindowID(); +} // namespace dom +} // namespace mozilla + +nsPIDOMWindowInner::nsPIDOMWindowInner(nsPIDOMWindowOuter *aOuterWindow) +: mMutationBits(0), mActivePeerConnections(0), mIsDocumentLoaded(false), + mIsHandlingResizeEvent(false), + mMayHavePaintEventListener(false), mMayHaveTouchEventListener(false), + mMayHaveSelectionChangeEventListener(false), + mMayHaveMouseEnterLeaveEventListener(false), + mMayHavePointerEnterLeaveEventListener(false), + mInnerObjectsFreed(false), + mAudioCaptured(false), + mOuterWindow(aOuterWindow), + // Make sure no actual window ends up with mWindowID == 0 + mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false), + mMarkedCCGeneration(0), + mHasTriedToCacheTopInnerWindow(false), + mNumOfIndexedDBDatabases(0), + mNumOfOpenWebSockets(0) +{ + MOZ_ASSERT(aOuterWindow); +} + +nsPIDOMWindowInner::~nsPIDOMWindowInner() {} + #undef FORWARD_TO_OUTER #undef FORWARD_TO_OUTER_OR_THROW #undef FORWARD_TO_OUTER_VOID diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 39e89261e2d1..fd200e19b314 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -192,27 +192,17 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, CycleCollectionNoteChild(aCallback, aField.mIdleObserver.get(), aName, aFlags); } -// NOTE: Currently this file, despite being named mozilla/dom/Window.h, exports -// the class nsGlobalWindowInner. It will be renamed in the future to -// mozilla::dom::Window. - //***************************************************************************** -// nsGlobalWindow: Global Object for Scripting +// nsGlobalWindowInner: Global Object for Scripting //***************************************************************************** -// Beware that all scriptable interfaces implemented by -// nsGlobalWindow will be reachable from JS, if you make this class -// implement new interfaces you better know what you're -// doing. Security wise this is very sensitive code. -- -// jst@netscape.com -// nsGlobalWindow inherits PRCList for maintaining a list of all inner -// windows 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 +// nsGlobalWindowInner inherits PRCList for maintaining a list of all inner +// windows 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 nsGlobalWindowInner : public mozilla::dom::EventTarget, @@ -262,8 +252,6 @@ public: nsGlobalWindowInner* innerWindow = sInnerWindowsById->Get(aInnerWindowID); - MOZ_ASSERT(!innerWindow || innerWindow->IsInnerWindow(), - "Outer window in sInnerWindowsById?"); return innerWindow; } @@ -291,7 +279,7 @@ public: // nsWrapperCache virtual JSObject *WrapObject(JSContext *cx, JS::Handle aGivenProto) override { - return IsInnerWindow() || AsOuter()->EnsureInnerWindow() ? GetWrapper() : nullptr; + return GetWrapper(); } // nsIGlobalJSObjectHolder @@ -348,22 +336,10 @@ public: virtual nsPIDOMWindowOuter* GetPrivateRoot() override; // Outer windows only. - virtual void ActivateOrDeactivate(bool aActivate) override; - virtual void SetActive(bool aActive) override; virtual bool IsTopLevelWindowActive() override; - virtual void SetIsBackground(bool aIsBackground) override; - virtual void SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler) override; - // Outer windows only. - virtual void SetInitialPrincipalToSubject() override; - - virtual PopupControlState PushPopupControlState(PopupControlState state, bool aForce) const override; - virtual void PopPopupControlState(PopupControlState state) const override; virtual PopupControlState GetPopupControlState() const override; - virtual already_AddRefed SaveWindowState() override; - virtual nsresult RestoreWindowState(nsISupports *aState) override; - void Suspend(); void Resume(); virtual bool IsSuspended() const override; @@ -383,33 +359,14 @@ public: virtual void SetOpenerWindow(nsPIDOMWindowOuter* aOpener, bool aOriginalOpener) override; - // Outer windows only. - virtual void EnsureSizeAndPositionUpToDate() override; - - virtual void EnterModalState() override; - virtual void LeaveModalState() override; - - // Outer windows only. - virtual bool CanClose() override; - virtual void ForceClose() override; - virtual void MaybeUpdateTouchState() override; - // Outer windows only. - virtual bool DispatchCustomEvent(const nsAString& aEventName) override; - // Inner windows only. void RefreshCompartmentPrincipal(); // For accessing protected field mFullScreen friend class FullscreenTransitionTask; - // Outer windows only. - virtual nsresult SetFullscreenInternal( - FullscreenReason aReason, bool aIsFullscreen) override final; - virtual void FullscreenWillChange(bool aIsFullscreen) override final; - virtual void FinishFullscreenChange(bool aIsFullscreen) override final; - // Inner windows only. virtual void SetHasGamepadEventListener(bool aHasGamepad = true) override; void NotifyVREventListenerAdded(); @@ -444,7 +401,6 @@ public: void GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames, bool aEnumerableOnly, mozilla::ErrorResult& aRv); - already_AddRefed GetTop() override; nsPIDOMWindowOuter* GetScriptableTop() override; inline nsGlobalWindowOuter *GetTopInternal(); @@ -475,11 +431,6 @@ public: nsGlobalWindowOuter *GetOuterWindowInternal() const; - bool IsCreatingInnerWindow() const - { - return mCreatingInnerWindow; - } - bool IsChromeWindow() const { return mIsChrome; @@ -538,13 +489,8 @@ public: virtual void EnableTimeChangeNotifications() override; virtual void DisableTimeChangeNotifications() override; - virtual nsresult SetArguments(nsIArray* aArguments) override; - bool IsClosedOrClosing() { - return (mIsClosed || - mInClose || - mHavePendingClose || - mCleanedUp); + return mCleanedUp; } bool @@ -553,12 +499,6 @@ public: return mCleanedUp; } - virtual void - FirePopupBlockedEvent(nsIDocument* aDoc, - nsIURI* aPopupURI, - const nsAString& aPopupWindowName, - const nsAString& aPopupWindowFeatures) override; - virtual uint32_t GetSerial() override { return mSerial; } @@ -575,11 +515,6 @@ public: bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, uint32_t timeInS); void HandleIdleObserverCallback(); - void AllowScriptsToClose() - { - mAllowScriptsToClose = true; - } - enum SlowScriptResponse { ContinueSlowScript = 0, ContinueSlowScriptAndKeepNotifying, @@ -707,7 +642,6 @@ public: void Close(mozilla::ErrorResult& aError); nsresult Close() override; bool GetClosed(mozilla::ErrorResult& aError); - bool Closed() override; void Stop(mozilla::ErrorResult& aError); void Focus(mozilla::ErrorResult& aError); nsresult Focus() override; @@ -716,8 +650,6 @@ public: already_AddRefed GetFrames(mozilla::ErrorResult& aError); uint32_t Length(); already_AddRefed GetTop(mozilla::ErrorResult& aError); - - nsresult GetPrompter(nsIPrompt** aPrompt) override; protected: explicit nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow); // Initializes the mWasOffline member variable @@ -726,11 +658,9 @@ public: nsPIDOMWindowOuter* GetOpenerWindow(mozilla::ErrorResult& aError); void GetOpener(JSContext* aCx, JS::MutableHandle aRetval, mozilla::ErrorResult& aError); - already_AddRefed GetOpener() override; void SetOpener(JSContext* aCx, JS::Handle aOpener, mozilla::ErrorResult& aError); already_AddRefed GetParent(mozilla::ErrorResult& aError); - already_AddRefed GetParent() override; nsPIDOMWindowOuter* GetScriptableParent() override; nsPIDOMWindowOuter* GetScriptableParentOrNull() override; mozilla::dom::Element* @@ -742,11 +672,6 @@ public: const nsAString& aName, const nsAString& aOptions, mozilla::ErrorResult& aError); - nsresult Open(const nsAString& aUrl, const nsAString& aName, - const nsAString& aOptions, - nsIDocShellLoadInfo* aLoadInfo, - bool aForceNoOpener, - nsPIDOMWindowOuter **_retval) override; mozilla::dom::Navigator* Navigator(); nsIDOMNavigator* GetNavigator() override; nsIDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError); @@ -836,7 +761,6 @@ public: mozilla::dom::Storage* GetLocalStorage(mozilla::ErrorResult& aError); mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError); - already_AddRefed GetSelection() override; mozilla::dom::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError); already_AddRefed GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt, @@ -853,7 +777,6 @@ public: void MoveBy(int32_t aXDif, int32_t aYDif, mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError); - nsresult MoveBy(int32_t aXDif, int32_t aYDif) override; void ResizeTo(int32_t aWidth, int32_t aHeight, mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError); @@ -956,7 +879,6 @@ public: bool GetFullScreen(mozilla::ErrorResult& aError); bool GetFullScreen() override; void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError); - nsresult SetFullScreen(bool aFullScreen) override; void Back(mozilla::ErrorResult& aError); void Forward(mozilla::ErrorResult& aError); void Home(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError); @@ -976,10 +898,6 @@ public: const nsAString& aOptions, const mozilla::dom::Sequence& aExtraArgument, mozilla::ErrorResult& aError); - nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName, - const nsAString& aOptions, - nsISupports* aExtraArgument, - nsPIDOMWindowOuter** _retval) override; nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) override; void GetContent(JSContext* aCx, @@ -1157,9 +1075,6 @@ protected: // Object Management virtual ~nsGlobalWindowInner(); void CleanUp(); - void ClearControllers(); - - inline void MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner); void FreeInnerObjects(); nsGlobalWindowInner *CallerInnerWindow(); @@ -1181,16 +1096,6 @@ public: // popup tracking bool IsPopupSpamWindow(); -protected: - // Window Control Functions - - // Outer windows only. - virtual nsresult - OpenNoNavigate(const nsAString& aUrl, - const nsAString& aName, - const nsAString& aOptions, - nsPIDOMWindowOuter** _retval) override; - private: template void CallOnChildren(Method aMethod); @@ -1256,9 +1161,6 @@ public: virtual bool ShouldShowFocusRing() override; - virtual void SetKeyboardIndicators(UIStateChangeType aShowAccelerators, - UIStateChangeType aShowFocusRings) override; - // Inner windows only. void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent); @@ -1310,10 +1212,7 @@ private: void DisconnectEventTargetObjects(); - // nsPIDOMWindow should be able to see these helper methods. - friend class nsPIDOMWindow; - friend class nsPIDOMWindow; - friend class nsPIDOMWindow; + // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods. friend class nsPIDOMWindowInner; friend class nsPIDOMWindowOuter; @@ -1360,23 +1259,7 @@ public: void RemoveIdleCallback(mozilla::dom::IdleRequest* aRequest); protected: - // These members are only used on outer window objects. Make sure - // you never set any of these on an inner object! - bool mFullScreen : 1; - bool mFullscreenMode : 1; - bool mIsClosed : 1; - bool mInClose : 1; - // mHavePendingClose means we've got a termination function set to - // close us when the JS stops executing or that we have a close - // event posted. If this is set, just ignore window.close() calls. - bool mHavePendingClose : 1; - bool mHadOriginalOpener : 1; - bool mOriginalOpenerWasSecureContext : 1; bool mIsSecureContextIfOpenerIgnored : 1; - bool mIsPopupSpam : 1; - - // Indicates whether scripts are allowed to close this window. - bool mBlockScriptedClosingFlag : 1; // Window offline status. Checked to see if we need to fire offline event bool mWasOffline : 1; @@ -1390,10 +1273,6 @@ protected: bool mNotifyIdleObserversIdleOnThaw : 1; bool mNotifyIdleObserversActiveOnThaw : 1; - // Indicates whether we're in the middle of creating an initializing - // a new inner window object. - bool mCreatingInnerWindow : 1; - // Fast way to tell if this is a chrome window (without having to QI). bool mIsChrome : 1; @@ -1415,53 +1294,29 @@ protected: // should be displayed. bool mFocusByKeyOccurred : 1; - // Inner windows only. // Indicates whether this window wants gamepad input events bool mHasGamepad : 1; - // Inner windows only. // Indicates whether this window wants VR events bool mHasVREvents : 1; - // Inner windows only. // Indicates whether this window wants VRDisplayActivate events bool mHasVRDisplayActivateEvents : 1; nsCheapSet mGamepadIndexSet; nsRefPtrHashtable mGamepads; bool mHasSeenGamepadInput; - // whether we've sent the destroy notification for our window id - bool mNotifiedIDDestroyed : 1; - // whether scripts may close the window, - // even if "dom.allow_scripts_to_close_windows" is false. - bool mAllowScriptsToClose : 1; - - bool mTopLevelOuterContentWindow : 1; - - nsCOMPtr mContext; - nsWeakPtr mOpener; - nsCOMPtr mControllers; - - // For |window.arguments|, via |openDialog|. - nsCOMPtr mArguments; - - // Only used in the outer. - RefPtr mReturnValue; - RefPtr mNavigator; RefPtr mScreen; - RefPtr mFrames; - // All BarProps are inner window only. + RefPtr mMenubar; RefPtr mToolbar; RefPtr mLocationbar; RefPtr mPersonalbar; RefPtr mStatusbar; RefPtr mScrollbars; - RefPtr mWindowUtils; - nsString mStatus; - nsString mDefaultStatus; - RefPtr mObserver; // Inner windows only. + + RefPtr mObserver; RefPtr mCrypto; RefPtr mU2F; RefPtr mCacheStorage; @@ -1479,13 +1334,11 @@ protected: RefPtr mLocalStorage; RefPtr mSessionStorage; - // These member variable are used only on inner windows. RefPtr mListenerManager; RefPtr mLocation; RefPtr mHistory; RefPtr mCustomElements; - // These member variables are used on both inner and the outer windows. nsCOMPtr mDocumentPrincipal; // mTabChild is only ever populated in the content process. nsCOMPtr mTabChild; @@ -1504,7 +1357,6 @@ protected: RefPtr mIdleRequestExecutor; #ifdef DEBUG - bool mSetOpenerWindowCalled; nsCOMPtr mLastOpenedURI; #endif @@ -1515,14 +1367,6 @@ protected: using XBLPrototypeHandlerTable = nsJSThingHashtable, JSObject*>; mozilla::UniquePtr mCachedXBLPrototypeHandlers; - // mSuspendedDoc is only set on outer windows. It's useful when we get matched - // EnterModalState/LeaveModalState calls, in which case the outer window is - // responsible for unsuspending events on the document. If we don't (for - // example, if the outer window is closed before the LeaveModalState call), - // then the inner window whose mDoc is our mSuspendedDoc is responsible for - // unsuspending it. - nsCOMPtr mSuspendedDoc; - RefPtr mIndexedDB; // This counts the number of windows that have been opened in rapid succession @@ -1550,16 +1394,9 @@ protected: #endif #ifdef MOZ_WEBSPEECH - // mSpeechSynthesis is only used on inner windows. RefPtr mSpeechSynthesis; #endif -#ifdef DEBUG - // This member is used in the debug only assertions in TabGroup() - // to catch cyclic parent/opener trees and not overflow the stack. - bool mIsValidatingTabGroup; -#endif - // This is the CC generation the last time we called CanSkip. uint32_t mCanSkipCCGeneration; @@ -1568,11 +1405,7 @@ protected: RefPtr mVREventObserver; - // When non-zero, the document should receive a vrdisplayactivate event - // after loading. The value is the ID of the VRDisplay that content should - // begin presentation on. - uint32_t mAutoActivateVRDisplayID; // Outer windows only - int64_t mBeforeUnloadListenerCount; // Inner windows only + int64_t mBeforeUnloadListenerCount; RefPtr mIntlUtils; @@ -1587,16 +1420,15 @@ protected: : mGroupMessageManagers(1) {} - nsCOMPtr mBrowserDOMWindow; nsCOMPtr mMessageManager; nsInterfaceHashtable mGroupMessageManagers; - // A weak pointer to the nsPresShell that we are doing fullscreen for. - // The pointer being set indicates we've set the IsInFullscreenChange - // flag on this pres shell. - nsWeakPtr mFullscreenPresShell; - nsCOMPtr mOpenerForInitialContentBrowser; } mChromeFields; + // These fields are used by the inner and outer windows to prevent + // programatically moving the window while the mouse is down. + static bool sMouseDown; + static bool sDragServiceDisabled; + friend class nsDOMScriptableHelper; friend class nsDOMWindowUtils; friend class mozilla::dom::PostMessageEvent; @@ -1652,7 +1484,7 @@ nsGlobalWindowInner::GetContextInternal() return GetOuterWindowInternal()->mContext; } - return mContext; + return nullptr; } inline nsGlobalWindowOuter* @@ -1664,7 +1496,7 @@ nsGlobalWindowInner::GetOuterWindowInternal() const inline bool nsGlobalWindowInner::IsPopupSpamWindow() { - if (IsInnerWindow() && !mOuterWindow) { + if (!mOuterWindow) { return false; } @@ -1677,12 +1509,4 @@ nsGlobalWindowInner::IsFrame() return GetParentInternal() != nullptr; } -inline void -nsGlobalWindowInner::MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner) -{ - if(mInnerWindow == aExpectedInner->AsInner()) { - mInnerWindow = nullptr; - } -} - #endif /* nsGlobalWindowInner_h___ */ diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 59ddbbcca657..634a1d6e4072 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -4,9 +4,287 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "nsGlobalWindow.h" + +#include + +#include "mozilla/MemoryReporting.h" + +// Local Includes +#include "Navigator.h" +#include "nsContentSecurityManager.h" +#include "nsScreen.h" +#include "nsHistory.h" +#include "nsDOMNavigationTiming.h" +#include "nsIDOMStorageManager.h" +#include "mozilla/dom/LocalStorage.h" +#include "mozilla/dom/Storage.h" +#include "mozilla/dom/IdleRequest.h" +#include "mozilla/dom/Performance.h" +#include "mozilla/dom/StorageEvent.h" +#include "mozilla/dom/StorageEventBinding.h" +#include "mozilla/dom/StorageNotifierService.h" +#include "mozilla/dom/StorageUtils.h" +#include "mozilla/dom/Timeout.h" +#include "mozilla/dom/TimeoutHandler.h" +#include "mozilla/dom/TimeoutManager.h" +#include "mozilla/IntegerPrintfMacros.h" +#if defined(MOZ_WIDGET_ANDROID) +#include "mozilla/dom/WindowOrientationObserver.h" +#endif +#include "nsDOMOfflineResourceList.h" +#include "nsError.h" +#include "nsIIdleService.h" +#include "nsISizeOfEventTarget.h" +#include "nsDOMJSUtils.h" +#include "nsArrayUtils.h" +#include "nsIDOMWindowCollection.h" +#include "nsDOMWindowList.h" +#include "mozilla/dom/WakeLock.h" +#include "mozilla/dom/power/PowerManagerService.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsIPermissionManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptTimeoutHandler.h" +#include "nsITimeoutHandler.h" +#include "nsIController.h" +#include "nsScriptNameSpaceManager.h" +#include "nsISlowScriptDebug.h" +#include "nsWindowMemoryReporter.h" +#include "nsWindowSizes.h" +#include "WindowNamedPropertiesHandler.h" +#include "nsFrameSelection.h" +#include "nsNetUtil.h" +#include "nsVariant.h" +#include "nsPrintfCString.h" +#include "mozilla/intl/LocaleService.h" +#include "WindowDestroyedEvent.h" + +// Helper Classes +#include "nsJSUtils.h" +#include "jsapi.h" // for JSAutoRequest +#include "jswrapper.h" +#include "nsCharSeparatedTokenizer.h" +#include "nsReadableUtils.h" +#include "nsDOMClassInfo.h" +#include "nsJSEnvironment.h" +#include "mozilla/dom/ScriptSettings.h" +#include "mozilla/Preferences.h" +#include "mozilla/Likely.h" +#include "mozilla/Sprintf.h" +#include "mozilla/Unused.h" + +// Other Classes +#include "mozilla/dom/BarProps.h" +#include "nsContentCID.h" +#include "nsLayoutStatics.h" +#include "nsCCUncollectableMarker.h" +#include "mozilla/dom/workers/Workers.h" +#include "mozilla/dom/ToJSValue.h" +#include "nsJSPrincipals.h" +#include "mozilla/Attributes.h" +#include "mozilla/Debug.h" +#include "mozilla/EventListenerManager.h" +#include "mozilla/EventStates.h" +#include "mozilla/MouseEvents.h" +#include "mozilla/ProcessHangMonitor.h" +#include "mozilla/ThrottledEventQueue.h" +#include "AudioChannelService.h" +#include "nsAboutProtocolUtils.h" +#include "nsCharTraits.h" // NS_IS_HIGH/LOW_SURROGATE +#include "PostMessageEvent.h" +#include "mozilla/dom/DocGroup.h" +#include "mozilla/dom/TabGroup.h" + +// Interfaces Needed +#include "nsIFrame.h" +#include "nsCanvasFrame.h" +#include "nsIWidget.h" +#include "nsIWidgetListener.h" +#include "nsIBaseWindow.h" +#include "nsIDeviceSensors.h" +#include "nsIContent.h" +#include "nsIDocShell.h" +#include "nsIDocCharset.h" +#include "nsIDocument.h" +#include "Crypto.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" +#include "nsIDOMEvent.h" +#include "nsIDOMOfflineResourceList.h" +#include "nsDOMString.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsThreadUtils.h" +#include "nsILoadContext.h" +#include "nsIPresShell.h" +#include "nsIScrollableFrame.h" +#include "nsView.h" +#include "nsViewManager.h" +#include "nsISelectionController.h" +#include "nsISelection.h" +#include "nsIPrompt.h" +#include "nsIPromptService.h" +#include "nsIPromptFactory.h" +#include "nsIAddonPolicyService.h" +#include "nsIWritablePropertyBag2.h" +#include "nsIWebNavigation.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWebBrowserFind.h" // For window.find() +#include "nsIWindowMediator.h" // For window.find() +#include "nsComputedDOMStyle.h" +#include "nsDOMCID.h" +#include "nsDOMWindowUtils.h" +#include "nsIWindowWatcher.h" +#include "nsPIWindowWatcher.h" +#include "nsIContentViewer.h" +#include "nsIScriptError.h" +#include "nsIControllers.h" +#include "nsIControllerContext.h" +#include "nsGlobalWindowCommands.h" +#include "nsQueryObject.h" +#include "nsContentUtils.h" +#include "nsCSSProps.h" +#include "nsIDOMFileList.h" +#include "nsIURIFixup.h" +#ifndef DEBUG +#include "nsIAppStartup.h" +#include "nsToolkitCompsCID.h" +#endif +#include "nsCDefaultURIFixup.h" +#include "mozilla/EventDispatcher.h" +#include "mozilla/EventStateManager.h" +#include "nsIObserverService.h" +#include "nsFocusManager.h" +#include "nsIXULWindow.h" +#include "nsITimedChannel.h" +#include "nsServiceManagerUtils.h" +#ifdef MOZ_XUL +#include "nsIDOMXULControlElement.h" +#include "nsMenuPopupFrame.h" +#endif +#include "mozilla/dom/CustomEvent.h" +#include "nsIJARChannel.h" +#include "nsIScreenManager.h" +#include "nsIEffectiveTLDService.h" + +#include "xpcprivate.h" + +#ifdef NS_PRINTING +#include "nsIPrintSettings.h" +#include "nsIPrintSettingsService.h" +#include "nsIWebBrowserPrint.h" +#endif + +#include "nsWindowRoot.h" +#include "nsNetCID.h" +#include "nsIArray.h" + +// XXX An unfortunate dependency exists here (two XUL files). +#include "nsIDOMXULDocument.h" +#include "nsIDOMXULCommandDispatcher.h" + +#include "nsBindingManager.h" +#include "nsXBLService.h" + +// used for popup blocking, needs to be converted to something +// belonging to the back-end like nsIContentPolicy +#include "nsIPopupWindowManager.h" + +#include "nsIDragService.h" +#include "mozilla/dom/Element.h" +#include "mozilla/dom/Selection.h" +#include "nsFrameLoader.h" +#include "nsISupportsPrimitives.h" +#include "nsXPCOMCID.h" +#include "mozilla/Logging.h" +#include "prenv.h" + +#include "mozilla/dom/IDBFactory.h" +#include "mozilla/dom/MessageChannel.h" +#include "mozilla/dom/Promise.h" + +#include "mozilla/dom/Gamepad.h" +#include "mozilla/dom/GamepadManager.h" + +#include "gfxVR.h" +#include "mozilla/dom/VRDisplay.h" +#include "mozilla/dom/VRDisplayEvent.h" +#include "mozilla/dom/VRDisplayEventBinding.h" +#include "mozilla/dom/VREventObserver.h" + +#include "nsRefreshDriver.h" +#include "Layers.h" + +#include "mozilla/AddonPathService.h" +#include "mozilla/BasePrincipal.h" +#include "mozilla/Services.h" +#include "mozilla/Telemetry.h" +#include "mozilla/dom/Location.h" +#include "nsHTMLDocument.h" +#include "nsWrapperCacheInlines.h" +#include "mozilla/DOMEventTargetHelper.h" +#include "prrng.h" +#include "nsSandboxFlags.h" +#include "TimeChangeObserver.h" +#include "mozilla/dom/AudioContext.h" +#include "mozilla/dom/BrowserElementDictionariesBinding.h" +#include "mozilla/dom/cache/CacheStorage.h" +#include "mozilla/dom/Console.h" +#include "mozilla/dom/Fetch.h" +#include "mozilla/dom/FunctionBinding.h" +#include "mozilla/dom/HashChangeEvent.h" +#include "mozilla/dom/IntlUtils.h" +#include "mozilla/dom/MozSelfSupportBinding.h" +#include "mozilla/dom/PopStateEvent.h" +#include "mozilla/dom/PopupBlockedEvent.h" +#include "mozilla/dom/PrimitiveConversions.h" +#include "mozilla/dom/WindowBinding.h" +#include "nsITabChild.h" +#include "mozilla/dom/MediaQueryList.h" +#include "mozilla/dom/ScriptSettings.h" +#include "mozilla/dom/NavigatorBinding.h" +#include "mozilla/dom/ImageBitmap.h" +#include "mozilla/dom/ImageBitmapBinding.h" +#include "mozilla/dom/ServiceWorkerRegistration.h" +#include "mozilla/dom/U2F.h" +#include "mozilla/dom/WebIDLGlobalNameHash.h" +#include "mozilla/dom/Worklet.h" +#ifdef HAVE_SIDEBAR +#include "mozilla/dom/ExternalBinding.h" +#endif + +#ifdef MOZ_WEBSPEECH +#include "mozilla/dom/SpeechSynthesis.h" +#endif + +// Apple system headers seem to have a check() macro. +#ifdef check +class nsIScriptTimeoutHandler; +#undef check +#endif // check +#include "AccessCheck.h" + +#ifdef ANDROID +#include +#endif + +#ifdef XP_WIN +#include +#define getpid _getpid +#else +#include // for getpid() +#endif + +using namespace mozilla; +using namespace mozilla::dom; +using namespace mozilla::dom::ipc; +using mozilla::BasePrincipal; +using mozilla::OriginAttributes; +using mozilla::TimeStamp; + #define FORWARD_TO_INNER(method, args, err_rval) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsOuterWindow()); \ if (!mInnerWindow) { \ NS_WARNING("No inner window available!"); \ return err_rval; \ @@ -16,7 +294,6 @@ #define FORWARD_TO_INNER_VOID(method, args) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsOuterWindow()); \ if (!mInnerWindow) { \ NS_WARNING("No inner window available!"); \ return; \ @@ -29,7 +306,6 @@ // inner doesn't already exists. #define FORWARD_TO_INNER_CREATE(method, args, err_rval) \ PR_BEGIN_MACRO \ - MOZ_RELEASE_ASSERT(IsOuterWindow()); \ if (!mInnerWindow) { \ if (mIsClosed) { \ return err_rval; \ @@ -43,72 +319,17 @@ return GetCurrentInnerWindowInternal()->method args; \ PR_END_MACRO +#define DEFAULT_HOME_PAGE "www.mozilla.org" +#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage" + +static LazyLogModule gDOMLeakPRLogOuter("DOMLeakOuter"); + +static int32_t gOpenPopupSpamCount = 0; + nsGlobalWindowOuter::OuterWindowByIdTable *nsGlobalWindowOuter::sOuterWindowsById = nullptr; -static already_AddRefed -CreateVoidVariant() -{ - RefPtr writable = new nsVariantCC(); - writable->SetAsVoid(); - return writable.forget(); -} - -nsresult -DialogValueHolder::Get(nsIPrincipal* aSubject, nsIVariant** aResult) -{ - nsCOMPtr result; - if (aSubject->SubsumesConsideringDomain(mOrigin)) { - result = mValue; - } else { - result = CreateVoidVariant(); - } - result.forget(aResult); - return NS_OK; -} - -void -DialogValueHolder::Get(JSContext* aCx, JS::Handle aScope, - nsIPrincipal* aSubject, - JS::MutableHandle aResult, - mozilla::ErrorResult& aError) -{ - if (aSubject->Subsumes(mOrigin)) { - aError = nsContentUtils::XPConnect()->VariantToJS(aCx, aScope, - mValue, aResult); - } else { - aResult.setUndefined(); - } -} -void -nsGlobalWindowOuter::RemoveIdleCallback(mozilla::dom::IdleRequest* aRequest) -{ - AssertIsOnMainThread(); - - if (aRequest->HasTimeout()) { - mTimeoutManager->ClearTimeout(aRequest->GetTimeoutHandle(), - Timeout::Reason::eIdleCallbackTimeout); - } - - aRequest->removeFrom(mIdleRequestCallbacks); - aRequest->Release(); -} - -nsresult -nsGlobalWindowOuter::RunIdleRequest(IdleRequest* aRequest, - DOMHighResTimeStamp aDeadline, - bool aDidTimeout) -{ - AssertIsOnMainThread(); - RefPtr request(aRequest); - RemoveIdleCallback(request); - return request->IdleRun(AsInner(), aDeadline, aDidTimeout); -} - -bool -nsGlobalWindowOuter::IsBackgroundInternal() const -{ - return !mOuterWindow || mOuterWindow->IsBackground(); -} +// CIDs +static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); /* static */ nsPIDOMWindowOuter* @@ -126,16 +347,6 @@ nsPIDOMWindowOuter::GetFromCurrentInner(nsPIDOMWindowInner* aInner) return outer; } -// DialogValueHolder CC goop. -NS_IMPL_CYCLE_COLLECTION(DialogValueHolder, mValue) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DialogValueHolder) - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -NS_IMPL_CYCLE_COLLECTING_ADDREF(DialogValueHolder) -NS_IMPL_CYCLE_COLLECTING_RELEASE(DialogValueHolder) - //***************************************************************************** // nsOuterWindowProxy: Outer Window Proxy //***************************************************************************** @@ -219,7 +430,6 @@ protected: { nsGlobalWindowOuter* outerWindow = nsGlobalWindowOuter::FromSupports( static_cast(js::GetProxyReservedSlot(proxy, 0).toPrivate())); - MOZ_ASSERT_IF(outerWindow, outerWindow->IsOuterWindow()); return outerWindow; } @@ -538,7 +748,6 @@ nsOuterWindowProxy::GetSubframeWindow(JSContext *cx, } nsGlobalWindowOuter* win = GetOuterWindow(proxy); - MOZ_ASSERT(win->IsOuterWindow()); return win->IndexedGetterOuter(index); } @@ -632,41 +841,20 @@ nsGlobalWindowOuter::nsGlobalWindowOuter() mIsPopupSpam(false), mBlockScriptedClosingFlag(false), mWasOffline(false), - mHasHadSlowScript(false), - mNotifyIdleObserversIdleOnThaw(false), - mNotifyIdleObserversActiveOnThaw(false), mCreatingInnerWindow(false), mIsChrome(false), - mCleanMessageManager(false), - mNeedsFocus(true), - mHasFocus(false), - mShowFocusRingForContent(false), - mFocusByKeyOccurred(false), - mHasGamepad(false), - mHasVREvents(false), - mHasVRDisplayActivateEvents(false), - mHasSeenGamepadInput(false), - mNotifiedIDDestroyed(false), mAllowScriptsToClose(false), mTopLevelOuterContentWindow(false), - mSuspendDepth(0), - mFreezeDepth(0), - mFocusMethod(0), mSerial(0), - mIdleRequestCallbackCounter(1), - mIdleRequestExecutor(nullptr), #ifdef DEBUG mSetOpenerWindowCalled(false), #endif mCleanedUp(false), - mDialogAbuseCount(0), - mAreDialogsEnabled(true), #ifdef DEBUG mIsValidatingTabGroup(false), #endif mCanSkipCCGeneration(0), - mAutoActivateVRDisplayID(0), - mBeforeUnloadListenerCount(0) + mAutoActivateVRDisplayID(0) { AssertIsOnMainThread(); @@ -690,35 +878,20 @@ nsGlobalWindowOuter::nsGlobalWindowOuter() // to create the entropy collector, so we should // try to get one until we succeed. - gRefCnt++; - - EnsurePrefCaches(); - - if (gDumpFile == nullptr) { - nsAutoCString fname; - Preferences::GetCString("browser.dom.window.dump.file", fname); - if (!fname.IsEmpty()) { - // If this fails to open, Dump() knows to just go to stdout on null. - gDumpFile = fopen(fname.get(), "wb+"); - } else { - gDumpFile = stdout; - } - } - - mSerial = ++gSerialCounter; + mSerial = nsContentUtils::InnerOrOuterWindowCreated(); #ifdef DEBUG if (!PR_GetEnv("MOZ_QUIET")) { printf_stderr("++DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p]\n", - gRefCnt, + nsContentUtils::GetCurrentInnerOrOuterWindowCount(), static_cast(ToCanonicalSupports(this)), getpid(), - gSerialCounter, + mSerial, nullptr); } #endif - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, + MOZ_LOG(gDOMLeakPRLogOuter, LogLevel::Debug, ("DOMWINDOW %p created outer=nullptr", this)); // Add ourselves to the outer windows list. @@ -750,7 +923,7 @@ nsGlobalWindowOuter::Init() { AssertIsOnMainThread(); - NS_ASSERTION(gDOMLeakPRLog, "gDOMLeakPRLog should have been initialized!"); + NS_ASSERTION(gDOMLeakPRLogOuter, "gDOMLeakPRLogOuter should have been initialized!"); sOuterWindowsById = new OuterWindowByIdTable(); } @@ -759,27 +932,13 @@ nsGlobalWindowOuter::~nsGlobalWindowOuter() { AssertIsOnMainThread(); - if (IsChromeWindow()) { - MOZ_ASSERT(mCleanMessageManager, - "chrome windows may always disconnect the msg manager"); - - DisconnectAndClearGroupMessageManagers(); - - if (mChromeFields.mMessageManager) { - static_cast( - mChromeFields.mMessageManager.get())->Disconnect(); - } - - mCleanMessageManager = false; - } - if (sOuterWindowsById) { MOZ_ASSERT(sOuterWindowsById->Get(mWindowID), "This window should be in the hash table"); sOuterWindowsById->Remove(mWindowID); } - --gRefCnt; + nsContentUtils::InnerOrOuterWindowDestroyed(); #ifdef DEBUG if (!PR_GetEnv("MOZ_QUIET")) { @@ -794,18 +953,17 @@ nsGlobalWindowOuter::~nsGlobalWindowOuter() } } - nsGlobalWindowOuter* outer = nsGlobalWindowOuter::Cast(mOuterWindow); printf_stderr("--DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p] [url = %s]\n", - gRefCnt, + nsContentUtils::GetCurrentInnerOrOuterWindowCount(), static_cast(ToCanonicalSupports(this)), getpid(), mSerial, - static_cast(ToCanonicalSupports(outer)), + nullptr, url.get()); } #endif - MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug, ("DOMWINDOW %p destroyed", this)); + MOZ_LOG(gDOMLeakPRLogOuter, LogLevel::Debug, ("DOMWINDOW %p destroyed", this)); JSObject *proxy = GetWrapperMaybeDead(); if (proxy) { @@ -849,25 +1007,10 @@ nsGlobalWindowOuter::ShutDown() { AssertIsOnMainThread(); - if (gDumpFile && gDumpFile != stdout) { - fclose(gDumpFile); - } - gDumpFile = nullptr; - delete sOuterWindowsById; sOuterWindowsById = nullptr; } -// static -void -nsGlobalWindowOuter::CleanupCachedXBLHandlers() -{ - if (mCachedXBLPrototypeHandlers && - mCachedXBLPrototypeHandlers->Count() > 0) { - mCachedXBLPrototypeHandlers->Clear(); - } -} - void nsGlobalWindowOuter::MaybeForgiveSpamCount() { @@ -879,8 +1022,6 @@ nsGlobalWindowOuter::MaybeForgiveSpamCount() void nsGlobalWindowOuter::SetIsPopupSpamWindow(bool aIsPopupSpam) { - MOZ_ASSERT(IsOuterWindow()); - mIsPopupSpam = aIsPopupSpam; if (aIsPopupSpam) { ++gOpenPopupSpamCount; @@ -894,7 +1035,6 @@ nsGlobalWindowOuter::SetIsPopupSpamWindow(bool aIsPopupSpam) void nsGlobalWindowOuter::DropOuterWindowDocs() { - MOZ_ASSERT(IsOuterWindow()); MOZ_ASSERT_IF(mDoc, !mDoc->EventHandlingSuppressed()); mDoc = nullptr; mSuspendedDoc = nullptr; @@ -910,45 +1050,8 @@ nsGlobalWindowOuter::CleanUp() StartDying(); - MOZ_RELEASE_ASSERT(!mObserver, "mObserver should only be set on the inner window"); - - if (mNavigator) { - mNavigator->Invalidate(); - mNavigator = nullptr; - } - - mScreen = nullptr; - mMenubar = nullptr; - mToolbar = nullptr; - mLocationbar = nullptr; - mPersonalbar = nullptr; - mStatusbar = nullptr; - mScrollbars = nullptr; - mHistory = nullptr; - mCustomElements = nullptr; mFrames = nullptr; mWindowUtils = nullptr; - mApplicationCache = nullptr; - mIndexedDB = nullptr; - - mConsole = nullptr; - - mAudioWorklet = nullptr; - mPaintWorklet = nullptr; - - mExternal = nullptr; - - mMozSelfSupport = nullptr; - - mPerformance = nullptr; - -#ifdef MOZ_WEBSPEECH - mSpeechSynthesis = nullptr; -#endif - -#if defined(MOZ_WIDGET_ANDROID) - mOrientationChangeObserver = nullptr; -#endif ClearControllers(); @@ -964,35 +1067,12 @@ nsGlobalWindowOuter::CleanUp() inner->CleanUp(); } - MOZ_ASSERT(!mHasGamepad); - MOZ_ASSERT(!mHasVREvents); - MOZ_ASSERT(!mHasVRDisplayActivateEvents); - - if (mCleanMessageManager) { - MOZ_ASSERT(mIsChrome, "only chrome should have msg manager cleaned"); - if (mChromeFields.mMessageManager) { - static_cast( - mChromeFields.mMessageManager.get())->Disconnect(); - } - } - mArguments = nullptr; - CleanupCachedXBLHandlers(); - - for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) { - mAudioContexts[i]->Shutdown(); - } - mAudioContexts.Clear(); - if (mIdleTimer) { mIdleTimer->Cancel(); mIdleTimer = nullptr; } - - mServiceWorkerRegistrationTable.Clear(); - - mIntlUtils = nullptr; } void @@ -1033,7 +1113,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindowOuter) if (aIID.Equals(NS_GET_IID(nsPIDOMWindowOuter))) { foundInterface = static_cast(this); } else - if (aIID.Equals(NS_GET_IID(mozIDOMWindowProxy)) && IsOuterWindow()) { + if (aIID.Equals(NS_GET_IID(mozIDOMWindowProxy))) { foundInterface = static_cast(this); } else if (aIID.Equals(NS_GET_IID(nsIDOMChromeWindow)) && IsChromeWindow()) { @@ -1053,19 +1133,9 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGlobalWindowOuter) return true; } tmp->mCanSkipCCGeneration = nsCCUncollectableMarker::sGeneration; - if (tmp->mCachedXBLPrototypeHandlers) { - for (auto iter = tmp->mCachedXBLPrototypeHandlers->Iter(); - !iter.Done(); - iter.Next()) { - iter.Data().exposeToActiveJS(); - } - } if (EventListenerManager* elm = tmp->GetExistingListenerManager()) { elm->MarkForCC(); } - if (tmp->mTimeoutManager) { - tmp->mTimeoutManager->UnmarkGrayTimers(); - } return true; } NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END @@ -1087,8 +1157,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter) if (tmp->mDoc && tmp->mDoc->GetDocumentURI()) { uri = tmp->mDoc->GetDocumentURI()->GetSpecOrDefault(); } - SprintfLiteral(name, "nsGlobalWindowOuter # %" PRIu64 " %s %s", tmp->mWindowID, - tmp->IsInnerWindow() ? "inner" : "outer", uri.get()); + SprintfLiteral(name, "nsGlobalWindowOuter # %" PRIu64 " outer %s", tmp->mWindowID, + uri.get()); cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name); } else { NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsGlobalWindowOuter, tmp->mRefCnt.get()) @@ -1098,191 +1168,61 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControllers) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mArguments) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReturnValue) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPerformance) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerRegistrationTable) - -#ifdef MOZ_WEBSPEECH - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSpeechSynthesis) -#endif - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOuterWindow) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTopInnerWindow) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListenerManager) - - if (tmp->mTimeoutManager) { - tmp->mTimeoutManager->ForEachUnorderedTimeout([&cb](Timeout* timeout) { - cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(Timeout)); - }); - } - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHistory) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCustomElements) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocalStorage) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSessionStorage) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mApplicationCache) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDoc) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTabChild) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleService) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleRequestExecutor) - for (IdleRequest* request : tmp->mIdleRequestCallbacks) { - cb.NoteNativeChild(request, NS_CYCLE_COLLECTION_PARTICIPANT(IdleRequest)); - } - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleObservers) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDisplays) - // Traverse stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameElement) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode) - - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMenubar) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mToolbar) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocationbar) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPersonalbar) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mU2F) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioWorklet) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPaintWorklet) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExternal) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMozSelfSupport) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIntlUtils) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOpenerForInitialContentBrowser) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocShell) tmp->TraverseHostObjectURIs(cb); NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mBrowserDOMWindow) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mMessageManager) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mGroupMessageManagers) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mOpenerForInitialContentBrowser) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowOuter) - tmp->CleanupCachedXBLHandlers(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mContext) NS_IMPL_CYCLE_COLLECTION_UNLINK(mControllers) NS_IMPL_CYCLE_COLLECTION_UNLINK(mArguments) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mReturnValue) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mPerformance) - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mServiceWorkerRegistrationTable) - -#ifdef MOZ_WEBSPEECH - NS_IMPL_CYCLE_COLLECTION_UNLINK(mSpeechSynthesis) -#endif - - if (tmp->mListenerManager) { - tmp->mListenerManager->Disconnect(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mListenerManager) - } - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mTopInnerWindow) - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mHistory) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mCustomElements) NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocalStorage) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mSessionStorage) - if (tmp->mApplicationCache) { - static_cast(tmp->mApplicationCache.get())->Disconnect(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplicationCache) - } NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDoc) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTabChild) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleService) NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleObservers) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads) - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDisplays) - // Unlink stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameElement) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode) - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mMenubar) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mToolbar) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocationbar) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mPersonalbar) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mU2F) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioWorklet) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mPaintWorklet) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mExternal) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mMozSelfSupport) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mIntlUtils) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mOpenerForInitialContentBrowser) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell) tmp->UnlinkHostObjectURIs(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleRequestExecutor) - if (tmp->IsChromeWindow()) { NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mBrowserDOMWindow) - if (tmp->mChromeFields.mMessageManager) { - static_cast( - tmp->mChromeFields.mMessageManager.get())->Disconnect(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mMessageManager) - } - tmp->DisconnectAndClearGroupMessageManagers(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mGroupMessageManagers) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mOpenerForInitialContentBrowser) } NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END -#ifdef DEBUG -void -nsGlobalWindowOuter::RiskyUnlink() -{ - NS_CYCLE_COLLECTION_INNERNAME.Unlink(this); -} -#endif - NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGlobalWindowOuter) - if (tmp->mCachedXBLPrototypeHandlers) { - for (auto iter = tmp->mCachedXBLPrototypeHandlers->Iter(); - !iter.Done(); - iter.Next()) { - aCallbacks.Trace(&iter.Data(), "Cached XBL prototype handler", aClosure); - } - } NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_TRACE_END @@ -1351,8 +1291,6 @@ nsGlobalWindowOuter::TraceGlobalJSObject(JSTracer* aTrc) bool nsGlobalWindowOuter::WouldReuseInnerWindow(nsIDocument* aNewDocument) { - MOZ_ASSERT(IsOuterWindow()); - // We reuse the inner window when: // a. We are currently at our original document. // b. At least one of the following conditions are true: @@ -1397,8 +1335,6 @@ nsGlobalWindowOuter::WouldReuseInnerWindow(nsIDocument* aNewDocument) void nsGlobalWindowOuter::SetInitialPrincipalToSubject() { - MOZ_ASSERT(IsOuterWindow()); - // First, grab the subject principal. nsCOMPtr newWindowPrincipal = nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller(); @@ -1451,20 +1387,19 @@ PopupControlState nsGlobalWindowOuter::PushPopupControlState(PopupControlState aState, bool aForce) const { - return ::PushPopupControlState(aState, aForce); + return nsContentUtils::PushPopupControlState(aState, aForce); } void nsGlobalWindowOuter::PopPopupControlState(PopupControlState aState) const { - ::PopPopupControlState(aState); + nsContentUtils::PopPopupControlState(aState); } PopupControlState nsGlobalWindowOuter::GetPopupControlState() const { - MOZ_ASSERT(NS_IsMainThread()); - return gPopupControlState; + return nsContentUtils::GetPopupControlState(); } #define WINDOWSTATEHOLDER_IID \ @@ -1502,7 +1437,6 @@ WindowStateHolder::WindowStateHolder(nsGlobalWindowInner* aWindow) mInnerWindowReflector(RootingCx(), aWindow->GetWrapper()) { NS_PRECONDITION(aWindow, "null window"); - NS_PRECONDITION(aWindow->IsInnerWindow(), "Saving an outer window"); aWindow->Suspend(); @@ -1527,8 +1461,6 @@ NS_IMPL_ISUPPORTS(WindowStateHolder, WindowStateHolder) bool nsGlobalWindowOuter::ComputeIsSecureContext(nsIDocument* aDocument, SecureContextFlags aFlags) { - MOZ_ASSERT(IsOuterWindow()); - nsCOMPtr principal = aDocument->NodePrincipal(); if (nsContentUtils::IsSystemPrincipal(principal)) { return true; @@ -1608,6 +1540,154 @@ nsGlobalWindowOuter::ComputeIsSecureContext(nsIDocument* aDocument, SecureContex return false; } +// We need certain special behavior for remote XUL whitelisted domains, but we +// don't want that behavior to take effect in automation, because we whitelist +// all the mochitest domains. So we need to check a pref here. +static bool +TreatAsRemoteXUL(nsIPrincipal* aPrincipal) +{ + MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(aPrincipal)); + return nsContentUtils::AllowXULXBLForPrincipal(aPrincipal) && + !Preferences::GetBool("dom.use_xbl_scopes_for_remote_xul", false); +} + +static bool +EnablePrivilege(JSContext* cx, unsigned argc, JS::Value* vp) +{ + Telemetry::Accumulate(Telemetry::ENABLE_PRIVILEGE_EVER_CALLED, true); + return xpc::EnableUniversalXPConnect(cx); +} + +static const JSFunctionSpec EnablePrivilegeSpec[] = { + JS_FN("enablePrivilege", EnablePrivilege, 1, 0), + JS_FS_END +}; + +static bool +InitializeLegacyNetscapeObject(JSContext* aCx, JS::Handle aGlobal) +{ + JSAutoCompartment ac(aCx, aGlobal); + + // Note: MathJax depends on window.netscape being exposed. See bug 791526. + JS::Rooted obj(aCx); + obj = JS_DefineObject(aCx, aGlobal, "netscape", nullptr); + NS_ENSURE_TRUE(obj, false); + + obj = JS_DefineObject(aCx, obj, "security", nullptr); + NS_ENSURE_TRUE(obj, false); + + // We hide enablePrivilege behind a pref because it has been altered in a + // way that makes it fundamentally insecure to use in production. Mozilla + // uses this pref during automated testing to support legacy test code that + // uses enablePrivilege. If you're not doing test automation, you _must_ not + // flip this pref, or you will be exposing all your users to security + // vulnerabilities. + if (!xpc::IsInAutomation()) { + return true; + } + + /* Define PrivilegeManager object with the necessary "static" methods. */ + obj = JS_DefineObject(aCx, obj, "PrivilegeManager", nullptr); + NS_ENSURE_TRUE(obj, false); + + return JS_DefineFunctions(aCx, obj, EnablePrivilegeSpec); +} + +static JS::CompartmentCreationOptions& +SelectZoneGroup(nsGlobalWindowInner* aNewInner, + JS::CompartmentCreationOptions& aOptions) +{ + JS::CompartmentCreationOptions options; + + if (aNewInner->GetOuterWindow()) { + nsGlobalWindowOuter *top = aNewInner->GetTopInternal(); + + // If we have a top-level window, use its zone (and zone group). + if (top && top->GetGlobalJSObject()) { + return aOptions.setExistingZone(top->GetGlobalJSObject()); + } + } + + // If we're in the parent process, don't bother with zone groups. + if (XRE_IsParentProcess()) { + return aOptions.setNewZoneInSystemZoneGroup(); + } + + // Otherwise, find a zone group from the TabGroup. Typically we only have to + // go through one iteration of this loop. + RefPtr tabGroup = aNewInner->TabGroup(); + for (nsPIDOMWindowOuter* outer : tabGroup->GetWindows()) { + nsGlobalWindowOuter* window = nsGlobalWindowOuter::Cast(outer); + if (JSObject* global = window->GetGlobalJSObject()) { + return aOptions.setNewZoneInExistingZoneGroup(global); + } + } + + return aOptions.setNewZoneInNewZoneGroup(); +} + +/** + * Create a new global object that will be used for an inner window. + * Return the native global and an nsISupports 'holder' that can be used + * to manage the lifetime of it. + */ +static nsresult +CreateNativeGlobalForInner(JSContext* aCx, + nsGlobalWindowInner* aNewInner, + nsIURI* aURI, + nsIPrincipal* aPrincipal, + JS::MutableHandle aGlobal, + bool aIsSecureContext) +{ + MOZ_ASSERT(aCx); + MOZ_ASSERT(aNewInner); + MOZ_ASSERT(aPrincipal); + + // DOMWindow with nsEP is not supported, we have to make sure + // no one creates one accidentally. + nsCOMPtr nsEP = do_QueryInterface(aPrincipal); + MOZ_RELEASE_ASSERT(!nsEP, "DOMWindow with nsEP is not supported"); + + JS::CompartmentOptions options; + + SelectZoneGroup(aNewInner, options.creationOptions()); + + // Sometimes add-ons load their own XUL windows, either as separate top-level + // windows or inside a browser element. In such cases we want to tag the + // window's compartment with the add-on ID. See bug 1092156. + if (nsContentUtils::IsSystemPrincipal(aPrincipal)) { + options.creationOptions().setAddonId(MapURIToAddonID(aURI)); + } + + options.creationOptions().setSecureContext(aIsSecureContext); + + xpc::InitGlobalObjectOptions(options, aPrincipal); + + // Determine if we need the Components object. + bool needComponents = nsContentUtils::IsSystemPrincipal(aPrincipal) || + TreatAsRemoteXUL(aPrincipal); + uint32_t flags = needComponents ? 0 : xpc::OMIT_COMPONENTS_OBJECT; + flags |= xpc::DONT_FIRE_ONNEWGLOBALHOOK; + + if (!WindowBinding::Wrap(aCx, aNewInner, aNewInner, options, + nsJSPrincipals::get(aPrincipal), false, aGlobal) || + !xpc::InitGlobalObject(aCx, aGlobal, flags)) { + return NS_ERROR_FAILURE; + } + + MOZ_ASSERT(aNewInner->GetWrapperPreserveColor() == aGlobal); + + // Set the location information for the new global, so that tools like + // about:memory may use that information + xpc::SetLocationForGlobal(aGlobal, aURI); + + if (!InitializeLegacyNetscapeObject(aCx, aGlobal)) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + nsresult nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument, nsISupports* aState, @@ -1617,8 +1697,6 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument, "mDocumentPrincipal prematurely set!"); MOZ_ASSERT(aDocument); - NS_PRECONDITION(IsOuterWindow(), "Must only be called on outer windows"); - // Bail out early if we're in process of closing down the window. NS_ENSURE_STATE(!mCleanedUp); @@ -2016,9 +2094,7 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument, void nsGlobalWindowOuter::PreloadLocalStorage() { - MOZ_ASSERT(IsOuterWindow()); - - if (!Preferences::GetBool(kStorageEnabled)) { + if (!Storage::StoragePrefIsEnabled()) { return; } @@ -2053,8 +2129,6 @@ nsGlobalWindowOuter::PreloadLocalStorage() void nsGlobalWindowOuter::DispatchDOMWindowCreated() { - MOZ_ASSERT(IsOuterWindow()); - if (!mDoc) { return; } @@ -2092,7 +2166,6 @@ nsGlobalWindowOuter::ClearStatus() void nsGlobalWindowOuter::SetDocShell(nsIDocShell* aDocShell) { - NS_ASSERTION(IsOuterWindow(), "Uh, SetDocShell() called on inner window!"); MOZ_ASSERT(aDocShell); if (aDocShell == mDocShell) { @@ -2108,8 +2181,6 @@ nsGlobalWindowOuter::SetDocShell(nsIDocShell* aDocShell) mTopLevelOuterContentWindow = !mIsChrome && GetScriptableTopInternal() == this; - NS_ASSERTION(!mNavigator, "Non-null mNavigator in outer window!"); - if (mFrames) { mFrames->SetDocShell(aDocShell); } @@ -2144,8 +2215,6 @@ nsGlobalWindowOuter::SetDocShell(nsIDocShell* aDocShell) void nsGlobalWindowOuter::DetachFromDocShell() { - NS_ASSERTION(IsOuterWindow(), "Uh, DetachFromDocShell() called on inner window!"); - // DetachFromDocShell means the window is being torn down. Drop our // reference to the script context, allowing it to be deleted // later. Meanwhile, keep our weak reference to the script object @@ -2160,7 +2229,6 @@ nsGlobalWindowOuter::DetachFromDocShell() node = PR_NEXT_LINK(inner)) { // This cast is safe because `node != this`. Non-this nodes are inner windows. inner = static_cast(node); - MOZ_ASSERT(inner->IsInnerWindow()); MOZ_ASSERT(!inner->mOuterWindow || inner->mOuterWindow == this); inner->FreeInnerObjects(); } @@ -2182,7 +2250,6 @@ nsGlobalWindowOuter::DetachFromDocShell() // Release our document reference DropOuterWindowDocs(); - mFocusedNode = nullptr; } ClearControllers(); @@ -2201,8 +2268,6 @@ nsGlobalWindowOuter::DetachFromDocShell() mDocShell = nullptr; // Weak Reference - NS_ASSERTION(!mNavigator, "Non-null mNavigator in outer window!"); - if (mFrames) { mFrames->SetDocShell(nullptr); } @@ -2266,18 +2331,20 @@ nsGlobalWindowOuter::UpdateParentTarget() nsCOMPtr frameElement = GetOuterWindow()->GetFrameElementInternal(); nsCOMPtr eventTarget = - TryGetTabChildGlobalAsEventTarget(frameElement); + nsContentUtils::TryGetTabChildGlobalAsEventTarget(frameElement); if (!eventTarget) { nsGlobalWindowOuter* topWin = GetScriptableTopInternal(); if (topWin) { frameElement = topWin->GetFrameElementInternal(); - eventTarget = TryGetTabChildGlobalAsEventTarget(frameElement); + eventTarget = + nsContentUtils::TryGetTabChildGlobalAsEventTarget(frameElement); } } if (!eventTarget) { - eventTarget = TryGetTabChildGlobalAsEventTarget(mChromeEventHandler); + eventTarget = + nsContentUtils::TryGetTabChildGlobalAsEventTarget(mChromeEventHandler); } if (!eventTarget) { @@ -2308,14 +2375,12 @@ nsGlobalWindowOuter::WillHandleEvent(EventChainPostVisitor& aVisitor) nsresult nsGlobalWindowOuter::GetEventTargetParent(EventChainPreVisitor& aVisitor) { - MOZ_CRASH("Virtual inner window only function"); + MOZ_CRASH("The outer window should not be part of an event path"); } bool nsGlobalWindowOuter::ShouldPromptToBlockDialogs() { - MOZ_ASSERT(IsOuterWindow()); - nsGlobalWindowOuter *topWindowOuter = GetScriptableTopInternal(); if (!topWindowOuter) { NS_ASSERTION(!mDocShell, "ShouldPromptToBlockDialogs() called without a top window?"); @@ -2333,8 +2398,6 @@ nsGlobalWindowOuter::ShouldPromptToBlockDialogs() bool nsGlobalWindowOuter::AreDialogsEnabled() { - MOZ_ASSERT(IsOuterWindow()); - nsGlobalWindowOuter *topWindowOuter = GetScriptableTopInternal(); if (!topWindowOuter) { NS_ERROR("AreDialogsEnabled() called without a top window?"); @@ -2375,8 +2438,6 @@ nsGlobalWindowOuter::AreDialogsEnabled() bool nsGlobalWindowOuter::ConfirmDialogIfNeeded() { - MOZ_ASSERT(IsOuterWindow()); - NS_ENSURE_TRUE(mDocShell, false); nsCOMPtr promptSvc = do_GetService("@mozilla.org/embedcomp/prompt-service;1"); @@ -2440,13 +2501,12 @@ nsGlobalWindowOuter::EnableDialogs() nsresult nsGlobalWindowOuter::PostHandleEvent(EventChainPostVisitor& aVisitor) { - MOZ_CRASH("Virtual inner window only function"); + MOZ_CRASH("The outer window should not be part of an event path"); } void nsGlobalWindowOuter::PoisonOuterWindowProxy(JSObject *aObject) { - MOZ_ASSERT(IsOuterWindow()); if (aObject == GetWrapperMaybeDead()) { PoisonWrapper(); } @@ -2455,7 +2515,6 @@ nsGlobalWindowOuter::PoisonOuterWindowProxy(JSObject *aObject) nsresult nsGlobalWindowOuter::SetArguments(nsIArray *aArguments) { - MOZ_ASSERT(IsOuterWindow()); nsresult rv; // Historically, we've used the same machinery to handle openDialog arguments @@ -2519,7 +2578,6 @@ void nsPIDOMWindowOuter::SetInitialKeyboardIndicators( UIStateChangeType aShowAccelerators, UIStateChangeType aShowFocusRings) { - MOZ_ASSERT(IsOuterWindow()); MOZ_ASSERT(!GetCurrentInnerWindow()); nsPIDOMWindowOuter* piWin = GetPrivateRoot(); @@ -2550,14 +2608,12 @@ nsPIDOMWindowOuter::SetInitialKeyboardIndicators( Element* nsPIDOMWindowOuter::GetFrameElementInternal() const { - MOZ_ASSERT(IsOuterWindow()); return mFrameElement; } void nsPIDOMWindowOuter::SetFrameElementInternal(Element* aFrameElement) { - MOZ_ASSERT(IsOuterWindow()); mFrameElement = aFrameElement; } @@ -2573,12 +2629,6 @@ nsGlobalWindowOuter::GetScreen() FORWARD_TO_INNER(GetScreen, (), nullptr); } -CustomElementRegistry* -nsGlobalWindowOuter::CustomElements() -{ - MOZ_CRASH("Virtual inner window only function"); -} - void nsPIDOMWindowOuter::MaybeActiveMediaComponents() { @@ -2714,8 +2764,6 @@ nsPIDOMWindowOuter::GetServiceWorkersTestingEnabled() already_AddRefed nsGlobalWindowOuter::GetParentOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { return nullptr; } @@ -2762,8 +2810,6 @@ nsGlobalWindowOuter::GetScriptableParentOrNull() already_AddRefed nsGlobalWindowOuter::GetParent() { - MOZ_ASSERT(IsOuterWindow()); - if (!mDocShell) { return nullptr; } @@ -2833,7 +2879,6 @@ nsGlobalWindowOuter::GetScriptableTop() already_AddRefed nsGlobalWindowOuter::GetTop() { - MOZ_ASSERT(IsOuterWindow()); nsCOMPtr window; GetTopImpl(this, getter_AddRefs(window), /* aScriptable = */ false); return window.forget(); @@ -2845,8 +2890,6 @@ nsGlobalWindowOuter::GetContentOuter(JSContext* aCx, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr content = GetContentInternal(aError, aCallerType); if (aError.Failed()) { @@ -2870,8 +2913,6 @@ nsGlobalWindowOuter::GetContentOuter(JSContext* aCx, already_AddRefed nsGlobalWindowOuter::GetContentInternal(ErrorResult& aError, CallerType aCallerType) { - MOZ_ASSERT(IsOuterWindow()); - // First check for a named frame named "content" nsCOMPtr domWindow = GetChildWindow(NS_LITERAL_STRING("content")); @@ -2940,8 +2981,6 @@ nsGlobalWindowOuter::GetPrompter(nsIPrompt** aPrompt) bool nsGlobalWindowOuter::GetClosedOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - // If someone called close(), or if we don't have a docshell, we're closed. return mIsClosed || !mDocShell; } @@ -2949,16 +2988,12 @@ nsGlobalWindowOuter::GetClosedOuter() bool nsGlobalWindowOuter::Closed() { - MOZ_ASSERT(IsOuterWindow()); - return GetClosedOuter(); } nsDOMWindowList* nsGlobalWindowOuter::GetWindowList() { - MOZ_ASSERT(IsOuterWindow()); - if (!mFrames && mDocShell) { mFrames = new nsDOMWindowList(mDocShell); } @@ -2976,25 +3011,15 @@ nsGlobalWindowOuter::GetFrames() already_AddRefed nsGlobalWindowOuter::IndexedGetterOuter(uint32_t aIndex) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsDOMWindowList* windows = GetWindowList(); NS_ENSURE_TRUE(windows, nullptr); return windows->IndexedGetter(aIndex); } -already_AddRefed -nsGlobalWindowOuter::GetApplicationCache() -{ - FORWARD_TO_INNER(GetApplicationCache, (), nullptr); -} - nsIControllers* nsGlobalWindowOuter::GetControllersOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mControllers) { nsresult rv; mControllers = do_CreateInstance(kXULControllersCID, &rv); @@ -3068,8 +3093,6 @@ nsGlobalWindowOuter::GetSanitizedOpener(nsPIDOMWindowOuter* aOpener) nsPIDOMWindowOuter* nsGlobalWindowOuter::GetOpenerWindowOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr opener = do_QueryReferent(mOpener); if (!opener) { @@ -3099,16 +3122,12 @@ nsGlobalWindowOuter::GetOpener() void nsGlobalWindowOuter::GetStatusOuter(nsAString& aStatus) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - aStatus = mStatus; } void nsGlobalWindowOuter::SetStatusOuter(const nsAString& aStatus) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - mStatus = aStatus; /* @@ -3130,8 +3149,6 @@ nsGlobalWindowOuter::SetStatusOuter(const nsAString& aStatus) void nsGlobalWindowOuter::GetNameOuter(nsAString& aName) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (mDocShell) { mDocShell->GetName(aName); } @@ -3140,8 +3157,6 @@ nsGlobalWindowOuter::GetNameOuter(nsAString& aName) void nsGlobalWindowOuter::SetNameOuter(const nsAString& aName, mozilla::ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (mDocShell) { aError = mDocShell->SetName(aName); } @@ -3211,8 +3226,6 @@ nsGlobalWindowOuter::CSSToDevIntPixels(nsIntSize px) nsresult nsGlobalWindowOuter::GetInnerSize(CSSIntSize& aSize) { - MOZ_ASSERT(IsOuterWindow()); - EnsureSizeAndPositionUpToDate(); NS_ENSURE_STATE(mDocShell); @@ -3250,8 +3263,6 @@ nsGlobalWindowOuter::GetInnerSize(CSSIntSize& aSize) int32_t nsGlobalWindowOuter::GetInnerWidthOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - CSSIntSize size; aError = GetInnerSize(size); return size.width; @@ -3268,8 +3279,6 @@ nsGlobalWindowOuter::SetInnerWidthOuter(int32_t aInnerWidth, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { aError.Throw(NS_ERROR_UNEXPECTED); return; @@ -3304,8 +3313,6 @@ nsGlobalWindowOuter::SetInnerWidthOuter(int32_t aInnerWidth, int32_t nsGlobalWindowOuter::GetInnerHeightOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - CSSIntSize size; aError = GetInnerSize(size); return size.height; @@ -3322,8 +3329,6 @@ nsGlobalWindowOuter::SetInnerHeightOuter(int32_t aInnerHeight, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { aError.Throw(NS_ERROR_UNEXPECTED); return; @@ -3357,8 +3362,6 @@ nsGlobalWindowOuter::SetInnerHeightOuter(int32_t aInnerHeight, nsIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType, ErrorResult& aError) { - MOZ_ASSERT(IsOuterWindow()); - if (nsContentUtils::ResistFingerprinting(aCallerType)) { CSSIntSize size; aError = GetInnerSize(size); @@ -3383,14 +3386,12 @@ nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType, ErrorResult& aError) int32_t nsGlobalWindowOuter::GetOuterWidthOuter(CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); return GetOuterSize(aCallerType, aError).width; } int32_t nsGlobalWindowOuter::GetOuterHeightOuter(CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); return GetOuterSize(aCallerType, aError).height; } @@ -3398,8 +3399,6 @@ void nsGlobalWindowOuter::SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth, CallerType aCallerType, ErrorResult& aError) { - MOZ_ASSERT(IsOuterWindow()); - nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { aError.Throw(NS_ERROR_FAILURE); @@ -3432,8 +3431,6 @@ nsGlobalWindowOuter::SetOuterWidthOuter(int32_t aOuterWidth, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - SetOuterSize(aOuterWidth, true, aCallerType, aError); } @@ -3442,16 +3439,12 @@ nsGlobalWindowOuter::SetOuterHeightOuter(int32_t aOuterHeight, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - SetOuterSize(aOuterHeight, false, aCallerType, aError); } CSSIntPoint nsGlobalWindowOuter::GetScreenXY(CallerType aCallerType, ErrorResult& aError) { - MOZ_ASSERT(IsOuterWindow()); - // When resisting fingerprinting, always return (0,0) if (nsContentUtils::ResistFingerprinting(aCallerType)) { return CSSIntPoint(0, 0); @@ -3498,16 +3491,12 @@ nsGlobalWindowOuter::GetScreenXY(CallerType aCallerType, ErrorResult& aError) int32_t nsGlobalWindowOuter::GetScreenXOuter(CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - return GetScreenXY(aCallerType, aError).x; } nsRect nsGlobalWindowOuter::GetInnerScreenRect() { - MOZ_ASSERT(IsOuterWindow()); - if (!mDocShell) { return nsRect(); } @@ -3533,8 +3522,6 @@ nsGlobalWindowOuter::GetInnerScreenRect() float nsGlobalWindowOuter::GetMozInnerScreenXOuter(CallerType aCallerType) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - // When resisting fingerprinting, always return 0. if (nsContentUtils::ResistFingerprinting(aCallerType)) { return 0.0; @@ -3547,8 +3534,6 @@ nsGlobalWindowOuter::GetMozInnerScreenXOuter(CallerType aCallerType) float nsGlobalWindowOuter::GetMozInnerScreenYOuter(CallerType aCallerType) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - // Return 0 to prevent fingerprinting. if (nsContentUtils::ResistFingerprinting(aCallerType)) { return 0.0; @@ -3561,8 +3546,6 @@ nsGlobalWindowOuter::GetMozInnerScreenYOuter(CallerType aCallerType) double nsGlobalWindowOuter::GetDevicePixelRatioOuter(CallerType aCallerType) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { return 1.0; } @@ -3596,8 +3579,6 @@ nsPIDOMWindowOuter::GetDevicePixelRatio(CallerType aCallerType) uint64_t nsGlobalWindowOuter::GetMozPaintCountOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { return 0; } @@ -3610,8 +3591,6 @@ already_AddRefed nsGlobalWindowOuter::MatchMediaOuter(const nsAString& aMediaQueryList, CallerType aCallerType) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDoc) { return nullptr; } @@ -3624,8 +3603,6 @@ nsGlobalWindowOuter::SetScreenXOuter(int32_t aScreenX, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { aError.Throw(NS_ERROR_FAILURE); @@ -3649,8 +3626,6 @@ nsGlobalWindowOuter::SetScreenXOuter(int32_t aScreenX, int32_t nsGlobalWindowOuter::GetScreenYOuter(CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - return GetScreenXY(aCallerType, aError).y; } @@ -3660,8 +3635,6 @@ nsGlobalWindowOuter::SetScreenYOuter(int32_t aScreenY, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { aError.Throw(NS_ERROR_FAILURE); @@ -3688,8 +3661,6 @@ void nsGlobalWindowOuter::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight, CallerType aCallerType) { - MOZ_ASSERT(IsOuterWindow()); - #ifdef MOZ_XUL if (aCallerType != CallerType::System) { // if attempting to resize the window, hide any open popups @@ -3717,8 +3688,6 @@ nsGlobalWindowOuter::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeig nsresult nsGlobalWindowOuter::SetDocShellWidthAndHeight(int32_t aInnerWidth, int32_t aInnerHeight) { - MOZ_ASSERT(IsOuterWindow()); - NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); nsCOMPtr treeOwner; @@ -3735,8 +3704,6 @@ nsGlobalWindowOuter::SetDocShellWidthAndHeight(int32_t aInnerWidth, int32_t aInn void nsGlobalWindowOuter::SetCSSViewportWidthAndHeight(nscoord aInnerWidth, nscoord aInnerHeight) { - MOZ_ASSERT(IsOuterWindow()); - RefPtr presContext; mDocShell->GetPresContext(getter_AddRefs(presContext)); @@ -3753,8 +3720,6 @@ void nsGlobalWindowOuter::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop, CallerType aCallerType) { - 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 @@ -3829,8 +3794,6 @@ nsGlobalWindowOuter::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop, int32_t nsGlobalWindowOuter::GetScrollBoundaryOuter(Side aSide) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - FlushPendingNotifications(FlushType::Layout); if (nsIScrollableFrame *sf = GetScrollFrame()) { return nsPresContext:: @@ -3842,8 +3805,6 @@ nsGlobalWindowOuter::GetScrollBoundaryOuter(Side aSide) CSSPoint nsGlobalWindowOuter::GetScrollXY(bool aDoFlush) { - MOZ_ASSERT(IsOuterWindow()); - if (aDoFlush) { FlushPendingNotifications(FlushType::Layout); } else { @@ -3869,14 +3830,12 @@ nsGlobalWindowOuter::GetScrollXY(bool aDoFlush) double nsGlobalWindowOuter::GetScrollXOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); return GetScrollXY(false).x; } double nsGlobalWindowOuter::GetScrollYOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); return GetScrollXY(false).y; } @@ -3891,8 +3850,6 @@ nsGlobalWindowOuter::Length() already_AddRefed nsGlobalWindowOuter::GetTopOuter() { - MOZ_ASSERT(IsOuterWindow()); - nsCOMPtr top = GetScriptableTop(); return top.forget(); } @@ -3913,8 +3870,6 @@ nsGlobalWindowOuter::GetChildWindow(const nsAString& aName) bool nsGlobalWindowOuter::DispatchCustomEvent(const nsAString& aEventName) { - MOZ_ASSERT(IsOuterWindow()); - bool defaultActionEnabled = true; nsContentUtils::DispatchTrustedEvent(mDoc, ToSupports(this), aEventName, true, true, &defaultActionEnabled); @@ -3925,8 +3880,6 @@ nsGlobalWindowOuter::DispatchCustomEvent(const nsAString& aEventName) bool nsGlobalWindowOuter::DispatchResizeEvent(const CSSIntSize& aSize) { - MOZ_ASSERT(IsOuterWindow()); - ErrorResult res; RefPtr domEvent = mDoc->CreateEvent(NS_LITERAL_STRING("CustomEvent"), CallerType::System, @@ -3987,7 +3940,6 @@ nsGlobalWindowOuter::WindowExists(const nsAString& aName, bool aForceNoOpener, bool aLookForCallerOnJSStack) { - NS_PRECONDITION(IsOuterWindow(), "Must be outer window"); NS_PRECONDITION(mDocShell, "Must have docshell"); if (aForceNoOpener) { @@ -4041,8 +3993,6 @@ nsGlobalWindowOuter::GetNearestWidget() const void nsGlobalWindowOuter::SetFullScreenOuter(bool aFullScreen, mozilla::ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - aError = SetFullscreenInternal(FullscreenReason::ForFullscreenMode, aFullScreen); } @@ -4332,7 +4282,6 @@ nsresult nsGlobalWindowOuter::SetFullscreenInternal(FullscreenReason aReason, bool aFullScreen) { - MOZ_ASSERT(IsOuterWindow()); MOZ_ASSERT(nsContentUtils::IsSafeToRunScript(), "Requires safe to run script as it " "may call FinishDOMFullscreenChange"); @@ -4426,7 +4375,6 @@ bool nsGlobalWindowOuter::SetWidgetFullscreen(FullscreenReason aReason, bool aIsFullscreen, nsIWidget* aWidget, nsIScreen* aScreen) { - MOZ_ASSERT(IsOuterWindow()); MOZ_ASSERT(this == GetTopInternal(), "Only topmost window should call this"); MOZ_ASSERT(!GetFrameElementInternal(), "Content window should not call this"); MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); @@ -4464,8 +4412,6 @@ nsGlobalWindowOuter::FullscreenWillChange(bool aIsFullscreen) /* virtual */ void nsGlobalWindowOuter::FinishFullscreenChange(bool aIsFullscreen) { - MOZ_ASSERT(IsOuterWindow()); - if (aIsFullscreen != mFullScreen) { NS_WARNING("Failed to toggle fullscreen state of the widget"); // We failed to make the widget enter fullscreen. @@ -4527,8 +4473,6 @@ nsGlobalWindowOuter::FinishFullscreenChange(bool aIsFullscreen) bool nsGlobalWindowOuter::FullScreen() const { - MOZ_ASSERT(IsOuterWindow()); - NS_ENSURE_TRUE(mDocShell, mFullScreen); // Get the fullscreen value of the root window, to always have the value @@ -4557,7 +4501,6 @@ nsGlobalWindowOuter::FullScreen() const bool nsGlobalWindowOuter::GetFullScreenOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); return FullScreen(); } @@ -4570,7 +4513,6 @@ nsGlobalWindowOuter::GetFullScreen() void nsGlobalWindowOuter::EnsureReflowFlushAndPaint() { - MOZ_ASSERT(IsOuterWindow()); NS_ASSERTION(mDocShell, "EnsureReflowFlushAndPaint() called with no " "docshell!"); @@ -4655,8 +4597,6 @@ nsGlobalWindowOuter::MakeScriptDialogTitle(nsAString& aOutTitle, bool nsGlobalWindowOuter::CanMoveResizeWindows(CallerType aCallerType) { - MOZ_ASSERT(IsOuterWindow()); - // When called from chrome, we can avoid the following checks. if (aCallerType != CallerType::System) { // Don't allow scripts to move or resize windows that were not opened by a @@ -4697,11 +4637,11 @@ nsGlobalWindowOuter::CanMoveResizeWindows(CallerType aCallerType) return false; } - if (gMouseDown && !gDragServiceDisabled) { + if (nsGlobalWindowInner::sMouseDown && !nsGlobalWindowInner::sDragServiceDisabled) { nsCOMPtr ds = do_GetService("@mozilla.org/widget/dragservice;1"); if (ds) { - gDragServiceDisabled = true; + nsGlobalWindowInner::sDragServiceDisabled = true; ds->Suppress(); } } @@ -4716,8 +4656,6 @@ nsGlobalWindowOuter::AlertOrConfirm(bool aAlert, { // XXX This method is very similar to nsGlobalWindowOuter::Prompt, make // sure any modifications here don't need to happen over there! - MOZ_ASSERT(IsOuterWindow()); - if (!AreDialogsEnabled()) { // Just silently return. In the case of alert(), the return value is // ignored. In the case of confirm(), returning false is the same thing as @@ -4792,7 +4730,6 @@ nsGlobalWindowOuter::AlertOuter(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); AlertOrConfirm(/* aAlert = */ true, aMessage, aSubjectPrincipal, aError); } @@ -4801,8 +4738,6 @@ nsGlobalWindowOuter::ConfirmOuter(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - return AlertOrConfirm(/* aAlert = */ false, aMessage, aSubjectPrincipal, aError); } @@ -4816,8 +4751,6 @@ nsGlobalWindowOuter::PromptOuter(const nsAString& aMessage, { // XXX This method is very similar to nsGlobalWindowOuter::AlertOrConfirm, make // sure any modifications here don't need to happen over there! - MOZ_RELEASE_ASSERT(IsOuterWindow()); - SetDOMStringToNull(aReturn); if (!AreDialogsEnabled()) { @@ -4899,8 +4832,6 @@ nsGlobalWindowOuter::PromptOuter(const nsAString& aMessage, void nsGlobalWindowOuter::FocusOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsIFocusManager* fm = nsFocusManager::GetFocusManager(); if (!fm) { return; @@ -4927,7 +4858,7 @@ nsGlobalWindowOuter::FocusOuter(ErrorResult& aError) // (bugs 355482 and 369306). bool canFocus = CanSetProperty("dom.disable_window_flip") || (opener == callerOuter && - RevisePopupAbuseLevel(gPopupControlState) < openBlocked); + RevisePopupAbuseLevel(GetPopupControlState()) < openBlocked); nsCOMPtr activeDOMWindow; fm->GetActiveWindow(getter_AddRefs(activeDOMWindow)); @@ -5013,8 +4944,6 @@ nsGlobalWindowOuter::Focus() void nsGlobalWindowOuter::BlurOuter() { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - // If dom.disable_window_flip == true, then content should not be allowed // to call this function (this would allow popunders, bug 369306) if (!CanSetProperty("dom.disable_window_flip")) { @@ -5046,8 +4975,6 @@ nsGlobalWindowOuter::BlurOuter() void nsGlobalWindowOuter::BackOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr webNav(do_QueryInterface(mDocShell)); if (!webNav) { aError.Throw(NS_ERROR_FAILURE); @@ -5060,8 +4987,6 @@ nsGlobalWindowOuter::BackOuter(ErrorResult& aError) void nsGlobalWindowOuter::ForwardOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr webNav(do_QueryInterface(mDocShell)); if (!webNav) { aError.Throw(NS_ERROR_FAILURE); @@ -5074,8 +4999,6 @@ nsGlobalWindowOuter::ForwardOuter(ErrorResult& aError) void nsGlobalWindowOuter::HomeOuter(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { return; } @@ -5127,8 +5050,6 @@ nsGlobalWindowOuter::HomeOuter(nsIPrincipal& aSubjectPrincipal, ErrorResult& aEr void nsGlobalWindowOuter::StopOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr webNav(do_QueryInterface(mDocShell)); if (webNav) { aError = webNav->Stop(nsIWebNavigation::STOP_ALL); @@ -5138,8 +5059,6 @@ nsGlobalWindowOuter::StopOuter(ErrorResult& aError) void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - #ifdef NS_PRINTING if (!AreDialogsEnabled()) { // We probably want to keep throwing here; silently doing nothing is a bit @@ -5226,7 +5145,6 @@ void nsGlobalWindowOuter::MoveToOuter(int32_t aXPos, int32_t aYPos, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); /* * If caller is not chrome and the user has not explicitly exempted the site, * prevent window.moveTo() by exiting early @@ -5285,8 +5203,6 @@ void nsGlobalWindowOuter::MoveByOuter(int32_t aXDif, int32_t aYDif, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - /* * If caller is not chrome and the user has not explicitly exempted the site, * prevent window.moveBy() by exiting early @@ -5341,8 +5257,6 @@ nsGlobalWindowOuter::ResizeToOuter(int32_t aWidth, int32_t aHeight, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - /* * If caller is a browser-element then dispatch a resize event to * the embedder. @@ -5385,8 +5299,6 @@ void nsGlobalWindowOuter::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - /* * If caller is a browser-element then dispatch a resize event to * parent. @@ -5449,8 +5361,6 @@ nsGlobalWindowOuter::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, void nsGlobalWindowOuter::SizeToContentOuter(CallerType aCallerType, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell) { return; } @@ -5533,7 +5443,6 @@ nsGlobalWindowOuter::FirePopupBlockedEvent(nsIDocument* aDoc, const nsAString& aPopupWindowName, const nsAString& aPopupWindowFeatures) { - MOZ_ASSERT(IsOuterWindow(), "All callers seem to assume we're an outer window?"); MOZ_ASSERT(aDoc); // Fire a "DOMPopupBlocked" event so that the UI can hear about @@ -5597,8 +5506,6 @@ nsGlobalWindowOuter::PopupWhitelisted() PopupControlState nsGlobalWindowOuter::RevisePopupAbuseLevel(PopupControlState aControl) { - MOZ_ASSERT(IsOuterWindow()); - NS_ASSERTION(mDocShell, "Must have docshell"); if (mDocShell->ItemType() != nsIDocShellTreeItem::typeContent) { @@ -5641,7 +5548,6 @@ nsGlobalWindowOuter::FireAbuseEvents(const nsAString &aPopupURL, const nsAString &aPopupWindowName, const nsAString &aPopupWindowFeatures) { - MOZ_ASSERT(IsOuterWindow()); // fetch the URI of the window requesting the opened window nsCOMPtr window = GetTop(); @@ -5678,7 +5584,6 @@ already_AddRefed nsGlobalWindowOuter::OpenOuter(const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); nsCOMPtr window; aError = OpenJS(aUrl, aName, aOptions, getter_AddRefs(window)); return window.forget(); @@ -5705,7 +5610,6 @@ nsresult nsGlobalWindowOuter::OpenJS(const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions, nsPIDOMWindowOuter **_retval) { - MOZ_ASSERT(IsOuterWindow()); return OpenInternal(aUrl, aName, aOptions, false, // aDialog false, // aContentModal @@ -5726,7 +5630,6 @@ nsGlobalWindowOuter::OpenDialog(const nsAString& aUrl, const nsAString& aName, nsISupports* aExtraArgument, nsPIDOMWindowOuter** _retval) { - MOZ_ASSERT(IsOuterWindow()); return OpenInternal(aUrl, aName, aOptions, true, // aDialog false, // aContentModal @@ -5746,7 +5649,6 @@ nsGlobalWindowOuter::OpenNoNavigate(const nsAString& aUrl, const nsAString& aOptions, nsPIDOMWindowOuter **_retval) { - MOZ_ASSERT(IsOuterWindow()); return OpenInternal(aUrl, aName, aOptions, false, // aDialog false, // aContentModal @@ -5766,8 +5668,6 @@ nsGlobalWindowOuter::OpenDialogOuter(JSContext* aCx, const nsAString& aUrl, const Sequence& aExtraArgument, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - nsCOMPtr argvArray; aError = NS_CreateJSArgv(aCx, aExtraArgument.Length(), aExtraArgument.Elements(), @@ -5840,8 +5740,6 @@ nsGlobalWindowOuter::PostMessageMozOuter(JSContext* aCx, JS::Handle a nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - // // Window.postMessage is an intentional subversion of the same-origin policy. // As such, this code must be particularly careful in the information it @@ -5854,9 +5752,6 @@ nsGlobalWindowOuter::PostMessageMozOuter(JSContext* aCx, JS::Handle a RefPtr callerInnerWin = CallerInnerWindow(); nsIPrincipal* callerPrin; if (callerInnerWin) { - MOZ_ASSERT(callerInnerWin->IsInnerWindow(), - "should have gotten an inner window here"); - // Compute the caller's origin either from its principal or, in the case the // principal doesn't carry a URI (e.g. the system principal), the caller's // document. We must get this now instead of when the event is created and @@ -6023,8 +5918,6 @@ public: bool nsGlobalWindowOuter::CanClose() { - MOZ_ASSERT(IsOuterWindow()); - if (mIsChrome) { nsCOMPtr bwin; GetBrowserDOMWindow(getter_AddRefs(bwin)); @@ -6063,8 +5956,6 @@ nsGlobalWindowOuter::CanClose() void nsGlobalWindowOuter::CloseOuter(bool aTrustedCaller) { - MOZ_RELEASE_ASSERT(IsOuterWindow()); - if (!mDocShell || IsInModalState() || (IsFrame() && !mDocShell->GetIsMozBrowser())) { // window.close() is called on a frame in a frameset, on a window @@ -6145,7 +6036,6 @@ nsGlobalWindowOuter::Close() void nsGlobalWindowOuter::ForceClose() { - MOZ_ASSERT(IsOuterWindow()); MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); if (IsFrame() || !mDocShell) { @@ -6170,8 +6060,6 @@ nsGlobalWindowOuter::ForceClose() void nsGlobalWindowOuter::FinalClose() { - MOZ_ASSERT(IsOuterWindow()); - // Flag that we were closed. mIsClosed = true; @@ -6259,8 +6147,6 @@ nsGlobalWindowOuter::ReallyCloseWindow() void nsGlobalWindowOuter::EnterModalState() { - MOZ_ASSERT(IsOuterWindow(), "Modal state is maintained on outer windows"); - // GetScriptableTop, not GetTop, so that EnterModalState works properly with //