Bug 771892 - [New Tab Page] check for private browsing mode *every* time a user drags a link onto the grid; r=ehsan
authorTim Taubert <tim.taubert@gmx.de>
Tue, 10 Jul 2012 00:35:30 +0200
changeset 98750 90c8e72e00b6f1e85f3688882ac8f7067f35b978
parent 98749 d6c83328d74190ed1076fb8d1f0f0fbcb26ca7c5
child 98751 8bba6a37776e41e0f8aa0785bcd0cc8dab7d00ae
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs771892
milestone16.0a1
Bug 771892 - [New Tab Page] check for private browsing mode *every* time a user drags a link onto the grid; r=ehsan
browser/base/content/newtab/cells.js
browser/base/content/newtab/newTab.js
--- a/browser/base/content/newtab/cells.js
+++ b/browser/base/content/newtab/cells.js
@@ -93,21 +93,21 @@ Cell.prototype = {
   isEmpty: function Cell_isEmpty() {
     return !this.site;
   },
 
   /**
    * Handles all cell events.
    */
   handleEvent: function Cell_handleEvent(aEvent) {
-    // We're not responding to external drag/drop events 
+    // We're not responding to external drag/drop events
     // when our parent window is in private browsing mode.
-    if (inPrivateBrowsingMode && !gDrag.draggedSite)
+    if (inPrivateBrowsingMode() && !gDrag.draggedSite)
       return;
-    
+
     if (aEvent.type != "dragexit" && !gDrag.isValid(aEvent))
       return;
 
     switch (aEvent.type) {
       case "dragenter":
         aEvent.preventDefault();
         gDrop.enter(this, aEvent);
         break;
--- a/browser/base/content/newtab/newTab.js
+++ b/browser/base/content/newtab/newTab.js
@@ -17,36 +17,38 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 
 let {
   links: gLinks,
   allPages: gAllPages,
   pinnedLinks: gPinnedLinks,
   blockedLinks: gBlockedLinks
 } = NewTabUtils;
 
-let chromeWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.nsIWebNavigation)
-                      .QueryInterface(Ci.nsIDocShellTreeItem)
-                      .rootTreeItem
-                      .QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.nsIDOMWindow)
-                      .wrappedJSObject;
-
-let inPrivateBrowsingMode = false;
-
-if ("gPrivateBrowsingUI" in chromeWin)
-  inPrivateBrowsingMode = chromeWin.gPrivateBrowsingUI.privateWindow;
-
 XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {
   return Services.strings.
     createBundle("chrome://browser/locale/newTab.properties");
 });
 
 function newTabString(name) gStringBundle.GetStringFromName('newtab.' + name);
 
+function inPrivateBrowsingMode() {
+  let chromeWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIWebNavigation)
+                        .QueryInterface(Ci.nsIDocShellTreeItem)
+                        .rootTreeItem
+                        .QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIDOMWindow)
+                        .wrappedJSObject;
+
+  if ("gPrivateBrowsingUI" in chromeWin)
+    return chromeWin.gPrivateBrowsingUI.privateWindow;
+
+  return false;
+}
+
 const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
 
 #include batch.js
 #include transformations.js
 #include page.js
 #include grid.js
 #include cells.js
 #include sites.js