Bug 1160407 - Redirect links within the Pocket panel to open in non-private windows when temporary Private Browsing is used. r=dolske, a=sledru
authorJared Wein <jwein@mozilla.com>
Fri, 15 May 2015 18:56:14 -0400
changeset 260524 f5828f333524
parent 260523 e6f89a184268
child 260525 f44dff585598
push id807
push userryanvm@gmail.com
push date2015-05-18 18:43 +0000
treeherdermozilla-release@f5828f333524 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske, sledru
bugs1160407
milestone38.0.5
Bug 1160407 - Redirect links within the Pocket panel to open in non-private windows when temporary Private Browsing is used. r=dolske, a=sledru
browser/base/content/browser-menubar.inc
browser/components/pocket/main.js
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -406,17 +406,17 @@
                 label="&showAllBookmarks2.label;"
                 command="Browser:ShowAllBookmarks"
                 key="manBookmarkKb"/>
       <menuseparator id="organizeBookmarksSeparator"/>
       <menuitem id="menu_pocket" label="&pocketMenuitem.label;"
 #ifndef XP_MACOSX
                 class="menuitem-iconic"
 #endif
-                oncommand="openUILink(Pocket.listURL, event);"/>
+                oncommand="window.pktUI.openTabWithUrl(Pocket.listURL);"/>
       <menuseparator id="menu_pocketSeparator"/>
       <menuitem id="menu_bookmarkThisPage"
                 command="Browser:AddBookmarkAs"
                 observes="bookmarkThisPageBroadcaster"
                 key="addBookmarkAsKb"/>
       <menuitem id="subscribeToPageMenuitem"
 #ifndef XP_MACOSX
                 class="menuitem-iconic"
--- a/browser/components/pocket/main.js
+++ b/browser/components/pocket/main.js
@@ -37,17 +37,22 @@
 
 // TODO : Get the toolbar icons from Firefox's build (Nikki needs to give us a red saved icon)
 // TODO : [needs clarificaiton from Fx] Firefox's plan was to hide Pocket from context menus until the user logs in. Now that it's an extension I'm wondering if we still need to do this.
 // TODO : [needs clarificaiton from Fx] Reader mode (might be a something they need to do since it's in html, need to investigate their code)
 // TODO : [needs clarificaiton from Fx] Move prefs within pktApi.s to sqlite or a local file so it's not editable (and is safer)
 // TODO : [nice to have] - Immediately save, buffer the actions in a local queue and send (so it works offline, works like our native extensions)
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/ReaderMode.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+  "resource://gre/modules/AppConstants.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
+  "resource://gre/modules/PrivateBrowsingUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode",
+  "resource://gre/modules/ReaderMode.jsm");
 
 var pktUI = (function() {
 
 	// -- Initialization (on startup and new windows) -- //
 	var inited = false;
 	var _currentPanelDidShow;
     var _currentPanelDidHide;
 	var _isHidden = false;
@@ -611,21 +616,48 @@ var pktUI = (function() {
 	}
 
 	// -- Browser Navigation -- //
 
 	/**
      * Open a new tab with a given url and notify the iframe panel that it was opened
      */
 
-	function openTabWithUrl(url, activate) {
-        var tab = gBrowser.addTab(url);
-        if (activate) {
-            gBrowser.selectedTab = tab;
+	function openTabWithUrl(url) {
+        let recentWindow = Services.wm.getMostRecentWindow("navigator:browser");
+        if (!recentWindow) {
+          if (this.AppConstants.platform == "macosx") {
+            let hiddenWindow = Services.appShell.hiddenDOMWindow;
+            // If there are no open browser windows, open a new one.
+            hiddenWindow.openDialog("chrome://browser/content/", "_blank",
+                                    "chrome,all,dialog=no", url);
+          }
+          return;
         }
+
+        // If the user is in permanent private browsing than this is not an issue,
+        // since the current window will always share the same cookie jar as the other
+        // windows.
+        if (!PrivateBrowsingUtils.isWindowPrivate(recentWindow) ||
+            PrivateBrowsingUtils.permanentPrivateBrowsing) {
+          recentWindow.openUILinkIn(url, "tab");
+          return;
+        }
+
+        let windows = Services.wm.getEnumerator("navigator:browser");
+        while (windows.hasMoreElements()) {
+          let win = windows.getNext();
+          if (!PrivateBrowsingUtils.isWindowPrivate(win)) {
+            win.openUILinkIn(url, "tab");
+            return;
+          }
+        }
+
+        // If there were no non-private windows opened already.
+        recentWindow.openUILinkIn(url, "window");
 	}
 
 
     // -- Helper Functions -- //
 
     function getCurrentUrl() {
     	return getBrowser().currentURI.spec;
     }
@@ -784,16 +816,18 @@ var pktUI = (function() {
     
 	/**
      * Public functions
      */
     return {
     	onLoad: onLoad,
     	getPanelFrame: getPanelFrame,
 
+        openTabWithUrl: openTabWithUrl,
+
     	pocketButtonOnCommand: pocketButtonOnCommand,
     	pocketPanelDidShow: pocketPanelDidShow,
     	pocketPanelDidHide: pocketPanelDidHide,
 
         pocketContextSaveLinkOnCommand,
         pocketContextSavePageOnCommand,
 
         pocketBookmarkBarOpenPocketCommand,