Bug 1247435 - Fix context.incognito (this completes part of bug 1309610) r?kmag draft
authorMatthew Wein <mwein@mozilla.com>
Fri, 04 Nov 2016 14:37:09 +0000
changeset 434846 6c6ed5d7155ceed03e249f92612aa91b90d4211e
parent 434838 060f80b690b8aaa5d927e03578673a3eff3b4c64
child 434847 17124ec52046d5909064561f3955b7d6ce59d4d2
push id34848
push usermwein@mozilla.com
push dateMon, 07 Nov 2016 16:45:29 +0000
reviewerskmag
bugs1247435, 1309610
milestone52.0a1
Bug 1247435 - Fix context.incognito (this completes part of bug 1309610) r?kmag MozReview-Commit-ID: IFW8SfNymbE
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/ExtensionChild.jsm
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/ext-c-extension.js
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -278,16 +278,18 @@ class BrowserDocshellFollower {
 }
 
 class ProxyContext extends BaseContext {
   constructor(envType, extension, params, xulBrowser, principal) {
     super(envType, extension);
 
     this.uri = NetUtil.newURI(params.url);
 
+    this.incognito = params.incognito;
+
     // This message manager is used by ParentAPIManager to send messages and to
     // close the ProxyContext if the underlying message manager closes. This
     // message manager object may change when `xulBrowser` swaps docshells, e.g.
     // when a tab is moved to a different window.
     this.currentMessageManager = xulBrowser.messageManager;
     this._docShellTracker = new BrowserDocshellFollower(xulBrowser,
         this.onBrowserChange.bind(this));
 
--- a/toolkit/components/extensions/ExtensionChild.jsm
+++ b/toolkit/components/extensions/ExtensionChild.jsm
@@ -247,16 +247,17 @@ defineLazyGetter(ExtensionContext.protot
   if (this.viewType == "background") {
     apiManager.global.initializeBackgroundPage(this.contentWindow);
   }
 
   let childManager = new WannabeChildAPIManager(this, this.messageManager, localApis, {
     envType: "addon_parent",
     viewType: this.viewType,
     url: this.uri.spec,
+    incognito: this.incognito,
   });
 
   this.callOnClose(childManager);
 
   return childManager;
 });
 
 // All subframes in a tab, background page, popup, etc. have the same view type.
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -27,16 +27,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "Locale",
                                   "resource://gre/modules/Locale.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "MessageChannel",
                                   "resource://gre/modules/MessageChannel.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
                                   "resource://gre/modules/Preferences.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
+                                  "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
                                   "resource://gre/modules/PromiseUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Schemas",
                                   "resource://gre/modules/Schemas.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "styleSheetService",
                                    "@mozilla.org/content/style-sheet-service;1",
                                    "nsIStyleSheetService");
@@ -183,32 +185,36 @@ class BaseContext {
     this.onClose = new Set();
     this.checkedLastError = false;
     this._lastError = null;
     this.contextId = `${++gContextId}-${Services.appinfo.uniqueProcessID}`;
     this.unloaded = false;
     this.extension = extension;
     this.jsonSandbox = null;
     this.active = true;
-
+    this.incognito = null;
     this.messageManager = null;
     this.docShell = null;
     this.contentWindow = null;
     this.innerWindowID = 0;
   }
 
   setContentWindow(contentWindow) {
     let {document} = contentWindow;
     let docShell = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                                 .getInterface(Ci.nsIDocShell);
 
     this.innerWindowID = getInnerWindowID(contentWindow);
     this.messageManager = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                                   .getInterface(Ci.nsIContentFrameMessageManager);
 
+    if (this.incognito == null) {
+      this.incognito = PrivateBrowsingUtils.isContentWindowPrivate(contentWindow);
+    }
+
     MessageChannel.setupMessageManagers([this.messageManager]);
 
     let onPageShow = event => {
       if (!event || event.target === document) {
         this.docShell = docShell;
         this.contentWindow = contentWindow;
         this.active = true;
       }
--- a/toolkit/components/extensions/ext-c-extension.js
+++ b/toolkit/components/extensions/ext-c-extension.js
@@ -10,17 +10,17 @@ function extensionApiFactory(context) {
         return context.extension.baseURI.resolve(url);
       },
 
       get lastError() {
         return context.lastError;
       },
 
       get inIncognitoContext() {
-        return PrivateBrowsingUtils.isContentWindowPrivate(context.contentWindow);
+        return context.incognito;
       },
     },
   };
 }
 
 extensions.registerSchemaAPI("extension", "addon_child", extensionApiFactory);
 extensions.registerSchemaAPI("extension", "content_child", extensionApiFactory);
 extensions.registerSchemaAPI("extension", "addon_child", context => {