Bug 1208563 - Implement chrome.extension.inIncognitoContext property for chrome/popups. r=billm
authorTom Schuster <evilpies@gmail.com>
Fri, 16 Oct 2015 20:54:16 +0200
changeset 268057 7b8dd562685d5244459d85f4e93308d0bfcfce01
parent 268056 f41fd6c7d52289a64fdbb8710b08af24cdcf0c61
child 268058 03359b8a14ee6ad9f67acfbacf8a15edb306e363
push id66696
push userevilpies@gmail.com
push dateFri, 16 Oct 2015 18:54:44 +0000
treeherdermozilla-inbound@7b8dd562685d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1208563
milestone44.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 1208563 - Implement chrome.extension.inIncognitoContext property for chrome/popups. r=billm
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/ext-extension.js
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -26,16 +26,18 @@ Cu.import("resource://gre/modules/devtoo
 XPCOMUtils.defineLazyModuleGetter(this, "Locale",
                                   "resource://gre/modules/Locale.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "MatchPattern",
                                   "resource://gre/modules/MatchPattern.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
                                   "resource://gre/modules/FileUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
+                                  "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 Cu.import("resource://gre/modules/ExtensionManagement.jsm");
 
 // Register built-in parts of the API. Other parts may be registered
 // in browser/, mobile/, or b2g/.
 ExtensionManagement.registerScript("chrome://extensions/content/ext-alarms.js");
 ExtensionManagement.registerScript("chrome://extensions/content/ext-backgroundPage.js");
 ExtensionManagement.registerScript("chrome://extensions/content/ext-cookies.js");
@@ -162,23 +164,25 @@ var globalBroker = new MessageBroker([Se
 // (type="background"), popups (type="popup"), and any extension
 // content loaded into browser tabs (type="tab").
 //
 // |params| is an object with the following properties:
 // |type| is one of "background", "popup", or "tab".
 // |contentWindow| is the DOM window the content runs in.
 // |uri| is the URI of the content (optional).
 // |docShell| is the docshell the content runs in (optional).
+// |incognito| is the content running in a private context (default: false).
 function ExtensionPage(extension, params)
 {
   let {type, contentWindow, uri, docShell} = params;
   this.extension = extension;
   this.type = type;
   this.contentWindow = contentWindow || null;
   this.uri = uri || extension.baseURI;
+  this.incognito = params.incognito || false;
   this.onClose = new Set();
 
   // This is the sender property passed to the Messenger for this
   // page. It can be augmented by the "page-open" hook.
   let sender = {id: extension.id};
   if (uri) {
     sender.url = uri.spec;
   }
@@ -296,17 +300,18 @@ var GlobalManager = {
     // API into webAccessibleResources.
     let principal = contentWindow.document.nodePrincipal;
     let id = principal.originAttributes.addonId;
     if (!this.extensionMap.has(id)) {
       return;
     }
     let extension = this.extensionMap.get(id);
     let uri = contentWindow.document.documentURIObject;
-    let context = new ExtensionPage(extension, {type: "tab", contentWindow, uri, docShell});
+    let incognito = PrivateBrowsingUtils.isContentWindowPrivate(contentWindow);
+    let context = new ExtensionPage(extension, {type: "tab", contentWindow, uri, docShell, incognito});
     inject(extension, context);
 
     let eventHandler = docShell.chromeEventHandler;
     let listener = event => {
       eventHandler.removeEventListener("unload", listener);
       context.unload();
     };
     eventHandler.addEventListener("unload", listener, true);
--- a/toolkit/components/extensions/ext-extension.js
+++ b/toolkit/components/extensions/ext-extension.js
@@ -21,12 +21,16 @@ extensions.registerAPI((extension, conte
             }
           }
 
           result.push(view.contentWindow);
         }
 
         return result;
       },
+
+      get inIncognitoContext() {
+        return context.incognito;
+      }
     },
   };
 });