Bug 1247435 - Fix context.incognito (this completes part of bug 1309610) r=kmag
authorMatthew Wein <mwein@mozilla.com>
Fri, 04 Nov 2016 14:37:09 +0000
changeset 321408 7ac1ed5691cff25456127589fa3d40a52048d50e
parent 321407 c3a6dadbb885b0c0d42d28e07d026e31be8b6665
child 321409 c5d86a74509d4c3ec16203a210d43f62e70549a9
push id30927
push userphilringnalda@gmail.com
push dateTue, 08 Nov 2016 04:37:38 +0000
treeherdermozilla-central@f88d94ae4967 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1247435, 1309610
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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 => {