Bug 1069059 - [e10s] Convert isWindowPrivate calls to isBrowserPrivate/isContentWindowPrivate as appropriate (r=mconley,margaret)
authorBill McCloskey <wmccloskey@mozilla.com>
Tue, 23 Sep 2014 15:48:52 -0700
changeset 222398 324798b60ba39e6812e9c6fec7026fcdbc188baf
parent 222397 752ce35b166b97c3cf1eb92baa9f16a91f32ab1f
child 222399 e3d791f5094f3d16ee2cac1da1e78ed39872f797
push id7107
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 17:43:31 +0000
treeherdermozilla-aurora@b4b34e0acc75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, margaret
bugs1069059
milestone35.0a1
Bug 1069059 - [e10s] Convert isWindowPrivate calls to isBrowserPrivate/isContentWindowPrivate as appropriate (r=mconley,margaret)
browser/base/content/browser-places.js
browser/base/content/content.js
browser/devtools/webconsole/test/browser_console_private_browsing.js
browser/modules/ContentSearch.jsm
embedding/test/test_private_window_from_content.html
mobile/android/chrome/content/MemoryObserver.js
mobile/android/chrome/content/SelectionHandler.js
mobile/android/chrome/content/browser.js
mobile/android/components/SessionStore.js
services/sync/modules/engines/tabs.js
testing/specialpowers/content/specialpowersAPI.js
toolkit/components/passwordmgr/LoginManagerContent.jsm
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
toolkit/components/satchel/formSubmitListener.js
toolkit/modules/PrivateBrowsingUtils.jsm
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -307,17 +307,17 @@ var PlacesCommandHook = {
                    aParent : PlacesUtils.unfiledBookmarksFolderId;
       var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description };
       var txn = new PlacesCreateBookmarkTransaction(uri, parent, 
                                                     PlacesUtils.bookmarks.DEFAULT_INDEX,
                                                     title, null, [descAnno]);
       PlacesUtils.transactionManager.doTransaction(txn);
       itemId = txn.item.id;
       // Set the character-set
-      if (charset && !PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow))
+      if (charset && !PrivateBrowsingUtils.isBrowserPrivate(aBrowser))
         PlacesUtils.setCharsetForURI(uri, charset);
     }
 
     // Revert the contents of the location bar
     if (gURLBar)
       gURLBar.handleRevert();
 
     // If it was not requested to open directly in "edit" mode, we are done.
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -152,17 +152,17 @@ let AboutHomeListener = {
       case "AboutHome:FocusInput":
         this.onFocusInput();
         break;
     }
   },
 
   onUpdate: function(aData) {
     let doc = content.document;
-    if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isWindowPrivate(content))
+    if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isContentWindowPrivate(content))
       doc.getElementById("launcher").setAttribute("session", "true");
 
     // Inject search engine and snippets URL.
     let docElt = doc.documentElement;
     // set the following attributes BEFORE searchEngineName, which triggers to
     // show the snippets when it's set.
     docElt.setAttribute("snippetsURL", aData.snippetsURL);
     if (aData.showKnowYourRights)
--- a/browser/devtools/webconsole/test/browser_console_private_browsing.js
+++ b/browser/devtools/webconsole/test/browser_console_private_browsing.js
@@ -60,17 +60,17 @@ function test()
     info("private browser window opened");
     privateBrowser = privateWindow.gBrowser;
 
     privateTab = privateBrowser.selectedTab = privateBrowser.addTab(TEST_URI);
     privateBrowser.selectedBrowser.addEventListener("load", function onLoad() {
       info("private tab opened");
       privateBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
       privateContent = privateBrowser.selectedBrowser.contentWindow;
-      ok(PrivateBrowsingUtils.isWindowPrivate(privateContent), "tab window is private");
+      ok(PrivateBrowsingUtils.isBrowserPrivate(privateBrowser.selectedBrowser), "tab window is private");
       openConsole(privateTab, consoleOpened);
     }, true);
   }
 
   function addMessages()
   {
     let button = privateContent.document.querySelector("button");
     ok(button, "button in page");
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -273,17 +273,17 @@ this.ContentSearch = {
   }),
 
   _onMessageAddFormHistoryEntry: function (msg, entry) {
     // There are some tests that use about:home and newtab that trigger a search
     // and then immediately close the tab.  In those cases, the browser may have
     // been destroyed by the time we receive this message, and as a result
     // contentWindow is undefined.
     if (!msg.target.contentWindow ||
-        PrivateBrowsingUtils.isWindowPrivate(msg.target.contentWindow)) {
+        PrivateBrowsingUtils.isBrowserPrivate(msg.target)) {
       return Promise.resolve();
     }
     let browserData = this._suggestionDataForBrowser(msg.target, true);
     FormHistory.update({
       op: "bump",
       fieldname: browserData.controller.formHistoryParam,
       value: entry,
     }, {
--- a/embedding/test/test_private_window_from_content.html
+++ b/embedding/test/test_private_window_from_content.html
@@ -1,12 +1,12 @@
 <!DOCTYPE html>
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script>
   // Make sure that we cannot open private browsing windows from unprivileged content
   var win = window.open("about:blank", "_blank", "private");
-  ok(!SpecialPowers.isWindowPrivate(win));
+  ok(!SpecialPowers.isContentWindowPrivate(win));
   win.close();
   // Also, make sure that passing non-private doesn't make any difference either
   win = window.open("about:blank", "_blank", "non-private");
-  ok(!SpecialPowers.isWindowPrivate(win));
+  ok(!SpecialPowers.isContentWindowPrivate(win));
   win.close();
 </script>
--- a/mobile/android/chrome/content/MemoryObserver.js
+++ b/mobile/android/chrome/content/MemoryObserver.js
@@ -39,17 +39,17 @@ var MemoryObserver = {
     let browser = tab.browser;
     let data = browser.__SS_data;
     let extra = browser.__SS_extdata;
 
     // We need this data to correctly create and position the new browser
     // If this browser is already a zombie, fallback to the session data
     let currentURL = browser.__SS_restore ? data.entries[0].url : browser.currentURI.spec;
     let sibling = browser.nextSibling;
-    let isPrivate = PrivateBrowsingUtils.isWindowPrivate(browser.contentWindow);
+    let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(browser);
 
     tab.destroy();
     tab.create(currentURL, { sibling: sibling, zombifying: true, delayLoad: true, isPrivate: isPrivate });
 
     // Reattach session store data and flag this browser so it is restored on select
     browser = tab.browser;
     browser.__SS_data = data;
     browser.__SS_extdata = extra;
--- a/mobile/android/chrome/content/SelectionHandler.js
+++ b/mobile/android/chrome/content/SelectionHandler.js
@@ -943,17 +943,17 @@ var SelectionHandler = {
     this._closeSelection();
   },
 
   searchSelection: function sh_searchSelection() {
     let selectedText = this._getSelectedText();
     if (selectedText.length) {
       let req = Services.search.defaultEngine.getSubmission(selectedText);
       let parent = BrowserApp.selectedTab;
-      let isPrivate = PrivateBrowsingUtils.isWindowPrivate(parent.browser.contentWindow);
+      let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(parent.browser);
       // Set current tab as parent of new tab, and set new tab as private if the parent is.
       BrowserApp.addTab(req.uri.spec, {parentId: parent.id,
                                        selected: true,
                                        isPrivate: isPrivate});
     }
     this._closeSelection();
   },
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1204,17 +1204,17 @@ var BrowserApp = {
     let webBrowserPrint = aBrowser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                                                 .getInterface(Ci.nsIWebBrowserPrint);
 
     let cancelable = {
       cancel: function (aReason) {
         webBrowserPrint.cancel();
       }
     }
-    let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow);
+    let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aBrowser);
     let download = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
                                   aBrowser.currentURI,
                                   Services.io.newFileURI(file), "", mimeInfo,
                                   Date.now() * 1000, null, cancelable, isPrivate);
 
     webBrowserPrint.print(printSettings, download);
   },
 
@@ -1624,17 +1624,17 @@ var BrowserApp = {
 
       case "keyword-search":
         // This event refers to a search via the URL bar, not a bookmarks
         // keyword search. Note that this code assumes that the user can only
         // perform a keyword search on the selected tab.
         this.isSearch = true;
 
         // Don't store queries in private browsing mode.
-        let isPrivate = PrivateBrowsingUtils.isWindowPrivate(this.selectedTab.browser.contentWindow);
+        let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(this.selectedTab.browser);
         let query = isPrivate ? "" : aData;
 
         let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
         Messaging.sendRequest({
           type: "Search:Keyword",
           identifier: engine.identifier,
           name: engine.name,
           query: query
@@ -2103,17 +2103,17 @@ var NativeWindow = {
           return false;
         }
       };
     },
 
     linkOpenableNonPrivateContext: {
       matches: function linkOpenableNonPrivateContextMatches(aElement) {
         let doc = aElement.ownerDocument;
-        if (!doc || PrivateBrowsingUtils.isWindowPrivate(doc.defaultView)) {
+        if (!doc || PrivateBrowsingUtils.isContentWindowPrivate(doc.defaultView)) {
           return false;
         }
 
         return NativeWindow.contextmenus.linkOpenableContext.matches(aElement);
       }
     },
 
     linkOpenableContext: {
@@ -2974,17 +2974,17 @@ nsBrowserAccess.prototype = {
     let isPrivate = false;
 
     if (newTab) {
       let parentId = -1;
       if (!isExternal && aOpener) {
         let parent = BrowserApp.getTabForWindow(aOpener.top);
         if (parent) {
           parentId = parent.id;
-          isPrivate = PrivateBrowsingUtils.isWindowPrivate(parent.browser.contentWindow);
+          isPrivate = PrivateBrowsingUtils.isBrowserPrivate(parent.browser);
         }
       }
 
       // BrowserApp.addTab calls loadURIWithFlags with the appropriate params
       let tab = BrowserApp.addTab(aURI ? aURI.spec : "about:blank", { flags: loadflags,
                                                                       referrerURI: referrer,
                                                                       external: isExternal,
                                                                       parentId: parentId,
@@ -6342,17 +6342,17 @@ var PopupBlockerObserver = {
         // useful to the user, so we won't create a menu item for it.
         if (popupURIspec == "" || popupURIspec == "about:blank" || popupURIspec == uri.spec)
           continue;
 
         let popupFeatures = pageReport[i].popupWindowFeatures;
         let popupName = pageReport[i].popupWindowName;
 
         let parent = BrowserApp.selectedTab;
-        let isPrivate = PrivateBrowsingUtils.isWindowPrivate(parent.browser.contentWindow);
+        let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(parent.browser);
         BrowserApp.addTab(popupURIspec, { parentId: parent.id, isPrivate: isPrivate });
       }
     }
   }
 };
 
 
 var IndexedDB = {
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -925,17 +925,17 @@ SessionStore.prototype = {
     }
   },
 
   _sendClosedTabsToJava: function ss_sendClosedTabsToJava(aWindow) {
     if (!aWindow.__SSID)
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
-    let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aWindow.BrowserApp.selectedBrowser.contentWindow);
+    let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aWindow.BrowserApp.selectedBrowser);
 
     let tabs = closedTabs
       .filter(tab => tab.isPrivate == isPrivate)
       .map(function (tab) {
         // Get the url and title for the last entry in the session history.
         let lastEntry = tab.entries[tab.entries.length - 1];
         return {
           url: lastEntry.url,
--- a/services/sync/modules/engines/tabs.js
+++ b/services/sync/modules/engines/tabs.js
@@ -313,18 +313,18 @@ TabTracker.prototype = {
         // Add tab listeners now that a window has opened.
         subject.addEventListener("load", onLoad, false);
         break;
     }
   },
 
   onTab: function onTab(event) {
     if (event.originalTarget.linkedBrowser) {
-      let win = event.originalTarget.linkedBrowser.contentWindow;
-      if (PrivateBrowsingUtils.isWindowPrivate(win) &&
+      let browser = event.originalTarget.linkedBrowser;
+      if (PrivateBrowsingUtils.isBrowserPrivate(browser) &&
           !PrivateBrowsingUtils.permanentPrivateBrowsing) {
         this._log.trace("Ignoring tab event from private browsing.");
         return;
       }
     }
 
     this._log.trace("onTab event: " + event.type);
     this.modified = true;
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -1798,18 +1798,18 @@ SpecialPowersAPI.prototype = {
     };
     return this._sendSyncMessage('SPPermissionManager', msg)[0];
   },
 
   getMozFullPath: function(file) {
     return file.mozFullPath;
   },
 
-  isWindowPrivate: function(win) {
-    return PrivateBrowsingUtils.isWindowPrivate(win);
+  isContentWindowPrivate: function(win) {
+    return PrivateBrowsingUtils.isContentWindowPrivate(win);
   },
 
   notifyObserversInParentProcess: function(subject, topic, data) {
     if (subject) {
       throw new Error("Can't send subject to another process!");
     }
     if (this.isMainProcess()) {
       this.notifyObservers(subject, topic, data);
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -243,17 +243,17 @@ var LoginManagerContent = {
       log("onFormPassword for", form.ownerDocument.documentURI);
       this._asyncFindLogins(form, { showMasterPassword: true })
           .then(this.loginsFound.bind(this))
           .then(null, Cu.reportError);
     },
 
     loginsFound: function({ form, loginsFound }) {
         let doc = form.ownerDocument;
-        let autofillForm = gAutofillForms && !PrivateBrowsingUtils.isWindowPrivate(doc.defaultView);
+        let autofillForm = gAutofillForms && !PrivateBrowsingUtils.isContentWindowPrivate(doc.defaultView);
 
         this._fillForm(form, autofillForm, false, false, false, loginsFound);
     },
 
     /*
      * onUsernameInput
      *
      * Listens for DOMAutoComplete and blur events on an input field.
@@ -476,17 +476,17 @@ var LoginManagerContent = {
      * [Note that this happens before any DOM onsubmit handlers are invoked.]
      * Looks for a password change in the submitted form, so we can update
      * our stored password.
      */
     _onFormSubmit : function (form) {
         var doc = form.ownerDocument;
         var win = doc.defaultView;
 
-        if (PrivateBrowsingUtils.isWindowPrivate(win)) {
+        if (PrivateBrowsingUtils.isContentWindowPrivate(win)) {
             // We won't do anything in private browsing mode anyway,
             // so there's no need to perform further checks.
             log("(form submission ignored in private browsing mode)");
             return;
         }
 
         // If password saving is disabled (globally or for host), bail out now.
         if (!gEnabled)
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -248,17 +248,17 @@ LoginManagerPrompter.prototype = {
         }
         return this.__ellipsis;
     },
 
 
     // Whether we are in private browsing mode
     get _inPrivateBrowsing() {
       if (this._window) {
-        return PrivateBrowsingUtils.isWindowPrivate(this._window);
+        return PrivateBrowsingUtils.isContentWindowPrivate(this._window);
       } else {
         // If we don't that we're in private browsing mode if the caller did
         // not provide a window.  The callers which really care about this
         // will indeed pass down a window to us, and for those who don't,
         // we can just assume that we don't want to save the entered login
         // information.
         return true;
       }
--- a/toolkit/components/satchel/formSubmitListener.js
+++ b/toolkit/components/satchel/formSubmitListener.js
@@ -99,17 +99,17 @@ var satchelFormListener = {
             // Even though the global context is for a specific browser, we
             // can receive observer events from other tabs! Ensure this event
             // is about our content.
             if (domWin.top != content)
                 return;
             if (!this.enabled)
                 return;
 
-            if (PrivateBrowsingUtils.isWindowPrivate(domWin))
+            if (PrivateBrowsingUtils.isContentWindowPrivate(domWin))
                 return;
 
             this.log("Form submit observer notified.");
 
             if (!this.saveHttpsForms) {
                 if (actionURI.schemeIs("https"))
                     return;
                 if (form.ownerDocument.documentURIObject.schemeIs("https"))
--- a/toolkit/modules/PrivateBrowsingUtils.jsm
+++ b/toolkit/modules/PrivateBrowsingUtils.jsm
@@ -14,16 +14,27 @@ let gTemporaryAutoStartMode = false;
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 this.PrivateBrowsingUtils = {
   // Rather than passing content windows to this function, please use
   // isBrowserPrivate since it works with e10s.
   isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
+    if (!(aWindow instanceof Components.interfaces.nsIDOMChromeWindow)) {
+      dump("WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " +
+           "Use isContentWindowPrivate instead (but only for frame scripts).\n"
+           + new Error().stack);
+    }
+
+    return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
+  },
+
+  // This should be used only in frame scripts.
+  isContentWindowPrivate: function pbu_isWindowPrivate(aWindow) {
     return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
   },
 
   isBrowserPrivate: function(aBrowser) {
     return this.isWindowPrivate(aBrowser.ownerDocument.defaultView);
   },
 
   privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {