Bug 1404088 - Standardize RDM's exposed browser properties. r=ochameau
MozReview-Commit-ID: KIykapQm5mP
--- a/devtools/client/responsive.html/browser/tunnel.js
+++ b/devtools/client/responsive.html/browser/tunnel.js
@@ -35,16 +35,33 @@ const SWAPPED_BROWSER_STATE = [
"_fullZoom",
"_textZoom",
"_isSyntheticDocument",
"_innerWindowID",
"_manifestURI",
];
/**
+ * Various parts of the Firefox code base expect to access properties on the browser
+ * window in response to events (by reaching for the window via the event's target).
+ *
+ * When RDM is enabled, these bits of code instead reach the RDM tool's window instead of
+ * the browser window, which won't have the properties they are looking for. At the
+ * moment, we address this by exposing them from the browser window on RDM's window as
+ * needed.
+ */
+const PROPERTIES_FROM_BROWSER_WINDOW = [
+ // This is used by PermissionUI.jsm for permission doorhangers.
+ "PopupNotifications",
+ // This is used by ContentClick.jsm when opening links in ways other than just
+ // navigating the viewport.
+ "whereToOpenLink",
+];
+
+/**
* This module takes an "outer" <xul:browser> from a browser tab as described by
* Firefox's tabbrowser.xml and wires it up to an "inner" <iframe mozbrowser>
* browser element containing arbitrary page content of interest.
*
* The inner <iframe mozbrowser> element is _just_ the page content. It is not
* enough to to replace <xul:browser> on its own. <xul:browser> comes along
* with lots of associated functionality via XBL bindings defined for such
* elements in browser.xml and remote-browser.xml, and the Firefox UI depends on
@@ -194,38 +211,28 @@ function tunnelToInnerBrowser(outer, inn
gBrowser._tabForBrowser.set(inner, tab);
// All of the browser state from content was swapped onto the inner browser. Pull
// this state up to the outer browser.
for (let property of SWAPPED_BROWSER_STATE) {
outer[property] = inner[property];
}
- // Expose `PopupNotifications` on the content's owner global.
- // This is used by PermissionUI.jsm for permission doorhangers.
- // Note: This pollutes the responsive.html tool UI's global.
- Object.defineProperty(inner.ownerGlobal, "PopupNotifications", {
- get() {
- return outer.ownerGlobal.PopupNotifications;
- },
- configurable: true,
- enumerable: true,
- });
-
- // Expose `whereToOpenLink` on the content's owner global.
- // This is used by ContentClick.jsm when opening links in ways other than just
- // navigating the viewport.
- // Note: This pollutes the responsive.html tool UI's global.
- Object.defineProperty(inner.ownerGlobal, "whereToOpenLink", {
- get() {
- return outer.ownerGlobal.whereToOpenLink;
- },
- configurable: true,
- enumerable: true,
- });
+ // Expose various properties from the browser window on the RDM tool's global. This
+ // aids various bits of code that expect to find a browser window, such as event
+ // handlers that reach for the window via the event's target.
+ for (let property of PROPERTIES_FROM_BROWSER_WINDOW) {
+ Object.defineProperty(inner.ownerGlobal, property, {
+ get() {
+ return outer.ownerGlobal[property];
+ },
+ configurable: true,
+ enumerable: true,
+ });
+ }
// Add mozbrowser event handlers
inner.addEventListener("mozbrowseropenwindow", this);
}),
handleEvent(event) {
if (event.type != "mozbrowseropenwindow") {
return;
@@ -272,18 +279,19 @@ function tunnelToInnerBrowser(outer, inn
outer.destroy();
outer.style.MozBinding = "";
// Reset @remote since this is now back to a regular, non-remote browser
outer.setAttribute("remote", "false");
outer.removeAttribute("remoteType");
// Delete browser window properties exposed on content's owner global
- delete inner.ownerGlobal.PopupNotifications;
- delete inner.ownerGlobal.whereToOpenLink;
+ for (let property of PROPERTIES_FROM_BROWSER_WINDOW) {
+ delete inner.ownerGlobal[property];
+ }
// Remove mozbrowser event handlers
inner.removeEventListener("mozbrowseropenwindow", this);
mmTunnel.destroy();
mmTunnel = null;
// Reset overridden XBL properties and methods. Deleting the override