Bug 1300587 - Workaround issues with dock/undock devtools toolbox with a devtools_panel. draft
authorLuca Greco <lgreco@mozilla.com>
Fri, 07 Oct 2016 12:37:53 +0200
changeset 485261 34b50fe5f69b0d55bac53498d4745511eb72b905
parent 485260 f9ee8c4dc011772b4f5a3cc4eb57bf2d00ee5624
child 545972 5d8b116a8b1c01c5654d9d77ac5ac4f5e6de6930
push id45684
push userluca.greco@alcacoop.it
push dateThu, 16 Feb 2017 12:27:56 +0000
bugs1300587, 1075490
milestone54.0a1
Bug 1300587 - Workaround issues with dock/undock devtools toolbox with a devtools_panel. - this workaround is related to the same issue described in Bug 1075490 for the SDK "dev/panel" module. MozReview-Commit-ID: 5UYn1F88u1
browser/components/extensions/ext-devtools-panels.js
toolkit/components/extensions/ExtensionManagement.jsm
--- a/browser/components/extensions/ext-devtools-panels.js
+++ b/browser/components/extensions/ext-devtools-panels.js
@@ -1,12 +1,13 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
+Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/ExtensionParent.jsm");
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
                                   "resource:///modules/E10SUtils.jsm");
 
 const {
@@ -116,16 +117,22 @@ class ParentDevToolsPanel {
 
     const {extension} = this.context;
 
     let awaitFrameLoader = Promise.resolve();
     if (extension.remote) {
       browser.setAttribute("remote", "true");
       browser.setAttribute("remoteType", E10SUtils.EXTENSION_REMOTE_TYPE);
       awaitFrameLoader = promiseEvent(browser, "XULFrameLoaderCreated");
+    } else if (!AppConstants.RELEASE_OR_BETA) {
+      // NOTE: Using a content iframe here breaks the devtools panel
+      // switching between docked and undocked mode,
+      // because of a swapFrameLoader exception (see bug 1075490).
+      browser.setAttribute("type", "chrome");
+      browser.setAttribute("forcemessagemanager", true);
     }
 
     let hasTopLevelContext = false;
 
     // Listening to new proxy contexts.
     const unwatchExtensionProxyContextLoad = watchExtensionProxyContextLoad(this, context => {
       // Keep track of the toolbox and target associated to the context, which is
       // needed by the API methods implementation.
--- a/toolkit/components/extensions/ExtensionManagement.jsm
+++ b/toolkit/components/extensions/ExtensionManagement.jsm
@@ -278,20 +278,31 @@ function getAPILevelForWindow(window, ad
     let parentWindow = docShell.sameTypeParent.QueryInterface(Ci.nsIInterfaceRequestor)
                                .getInterface(Ci.nsIDOMWindow);
 
     // The option page iframe embedded in the about:addons tab should have
     // full API level privileges. (see Bug 1256282 for rationale)
     let parentDocument = parentWindow.document;
     let parentIsSystemPrincipal = Services.scriptSecurityManager
                                           .isSystemPrincipal(parentDocument.nodePrincipal);
+
     if (parentDocument.location.href == "about:addons" && parentIsSystemPrincipal) {
       return FULL_PRIVILEGES;
     }
 
+    // NOTE: Special handling for devtools panels using a chrome iframe here
+    // for the devtools panel, it is needed because a content iframe breaks
+    // switching between docked and undocked mode (see bug 1075490).
+    let devtoolsBrowser = parentDocument.querySelector(
+      "browser[webextension-view-type='devtools_panel']");
+    if (devtoolsBrowser && devtoolsBrowser.contentWindow === window &&
+        parentIsSystemPrincipal) {
+      return FULL_PRIVILEGES;
+    }
+
     // The addon iframes embedded in a addon page from with the same addonId
     // should have the same privileges of the sameTypeParent.
     // (see Bug 1258347 for rationale)
     let parentSameAddonPrivileges = getAPILevelForWindow(parentWindow, addonId);
     if (parentSameAddonPrivileges > NO_PRIVILEGES) {
       return parentSameAddonPrivileges;
     }