[Pkg-mozext-commits] [personasplus] 24/42: Warn users about lack of cookies and private browsing windows.

David Prévot taffit at moszumanska.debian.org
Wed Feb 3 16:15:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository personasplus.

commit 10613b78b022e282eb9f546a75591f429dbf0255
Author: Kris Maglione <maglione.k at gmail.com>
Date:   Wed Apr 17 12:22:50 2013 -0700

    Warn users about lack of cookies and private browsing windows.
---
 extension/content/personas.js              | 133 ++++++++---------------------
 extension/install.rdf                      |   2 +-
 extension/locale/en-US/personas.properties |  24 ++++++
 extension/modules/service.js               |  44 ++++++++++
 4 files changed, 104 insertions(+), 99 deletions(-)

diff --git a/extension/content/personas.js b/extension/content/personas.js
index 396772f..119c304 100644
--- a/extension/content/personas.js
+++ b/extension/content/personas.js
@@ -273,13 +273,12 @@ let PersonaController = {
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "SelectPersona":
-        this.onSelectPersonaFromContent(aEvent);
-        break;
       case "PreviewPersona":
-        this.onPreviewPersonaFromContent(aEvent);
-        break;
       case "ResetPersona":
-        this.onResetPersonaFromContent(aEvent);
+        let doc = aEvent.originalTarget.ownerDocument;
+        if (Services.perms.testPermission(doc.documentURIObject, "install") 
+              == Services.perms.ALLOW_ACTION)
+          this.checkPrivateBrowsing();
         break;
       case "CheckPersonas":
         this.onCheckPersonasFromContent(aEvent);
@@ -290,17 +289,12 @@ let PersonaController = {
       case "RemoveFavoritePersona":
         this.onRemoveFavoritePersonaFromContent(aEvent);
         break;
-      case "pagehide":
-      case "TabSelect":
-        this.onResetPersona();
-        break;
     }
   },
 
   // Tab Monitor methods (Thunderbird)
   onTabTitleChanged : function(aTab) { /* ignored */ },
   onTabSwitched : function(aTab, aOldTab) {
-    this.onResetPersona();
   },
 
   //**************************************************************************//
@@ -314,27 +308,9 @@ let PersonaController = {
       this._strings.get("dataUnavailable",
                         [this._brandStrings.get("brandShortName")]);
 
-    if (!this.LightweightThemeManager) {
-      // Observe various changes that we should apply to the browser window.
-      this.Observers.add("personas:persona:changed", this);
-      this.Observers.add("domwindowopened", this);
-
-      // Listen for various persona-related events that can bubble up from content.
-      document.addEventListener("SelectPersona", this, false, true);
-      document.addEventListener("PreviewPersona", this, false, true);
-      document.addEventListener("ResetPersona", this, false, true);
-      window.addEventListener("pagehide", this, false, true);
-      // Detect when the selected tab is changed to remove the persona being
-      // previewed.
-      switch (PersonaService.appInfo.ID) {
-        case PersonaService.FIREFOX_ID:
-          gBrowser.tabContainer.addEventListener("TabSelect", this, false);
-          break;
-        case PersonaService.THUNDERBIRD_ID:
-          document.getElementById("tabmail").registerTabMonitor(this);
-          break;
-      }
-    }
+    document.addEventListener("SelectPersona", this, false, true);
+    document.addEventListener("PreviewPersona", this, false, true);
+    document.addEventListener("ResetPersona", this, false, true);
     // Listen for various persona-related events that can bubble up from content,
     // not handled by the LightweightThemeManager.
     document.addEventListener("CheckPersonas", this, false, true);
@@ -348,21 +324,6 @@ let PersonaController = {
         this._prefs.set("lastversion", aAddon.version);
       }.bind(this));
 
-    // Apply the current persona to the window if the LightweightThemeManager
-    // is not available.
-    // Also, we don't apply the default persona because Firefox starts with that.
-    // Check for per-window personas and restore the persona from session store.
-    if (!this.LightweightThemeManager) {
-      if (this._prefs.get("perwindow") &&
-          this._sessionStore.getWindowValue(window, "persona")) {
-        this._applyPersona(JSON.parse(
-          this._sessionStore.getWindowValue(window, "persona")
-        ));
-      } else if (PersonaService.selected != "default") {
-        this._applyPersona(PersonaService.currentPersona);
-      }
-    }
-
     // Perform special operations for Firefox 4 compatibility:
     // * Hide the status bar button
     // * Install the toolbar button in the Add-on bar (first time only).
@@ -380,22 +341,9 @@ let PersonaController = {
   },
 
   shutDown: function() {
-    if (!this.LightweightThemeManager) {
-      this.Observers.remove("personas:persona:changed", this);
-      this.Observers.remove("domwindowopened", this);
-      document.removeEventListener("SelectPersona", this, false);
-      document.removeEventListener("PreviewPersona", this, false);
-      document.removeEventListener("ResetPersona", this, false);
-      window.removeEventListener("pagehide", this, false);
-      switch (PersonaService.appInfo.ID) {
-        case PersonaService.FIREFOX_ID:
-          gBrowser.tabContainer.removeEventListener("TabSelect", this, false);
-          break;
-        case PersonaService.THUNDERBIRD_ID:
-          document.getElementById("tabmail").unregisterTabMonitor(this);
-          break;
-      }
-    }
+    document.removeEventListener("SelectPersona", this, false);
+    document.removeEventListener("PreviewPersona", this, false);
+    document.removeEventListener("ResetPersona", this, false);
     document.removeEventListener("CheckPersonas", this, false);
     document.removeEventListener("AddFavoritePersona", this, false);
     document.removeEventListener("RemoveFavoritePersona", this, false);
@@ -669,23 +617,36 @@ let PersonaController = {
     }
   },
 
+  /**
+   * Checks if the current window is in private browsing mode, and shows
+   * an alert warning that personas will not work, if so.
+   */
+  checkPrivateBrowsing: function() {
+    if (typeof PrivateBrowsingUtils !== "undefined" &&
+          PrivateBrowsingUtils.isWindowPrivate(window)) {
+
+      const ID = "personas-plus-private-browsing-warning";
+
+      var notifications = gBrowser.getNotificationBox();
+      if(!notifications.getNotificationWithValue(ID)) {
+        let _ = this._strings.get.bind(this._strings);
+
+        notifications.appendNotification(
+            _("pbm.message"), ID,
+            "chrome://personas/content/personas_16x16.png",
+            notifications.PRIORITY_WARNING_HIGH,
+            [{ label: _("pbm.button.label"),
+                accessKey: _("pbm.button.accesskey"),
+                callback: function (n) { n.close() } }]);
+      }
+    }
+  },
+
 
   //**************************************************************************//
   // Persona Selection, Preview, and Reset
 
   /**
-   * Select the persona specified by a web page via a SelectPersona event.
-   * Checks to ensure the page is hosted on a server authorized to select personas.
-   *
-   * @param event   {Event}
-   *        the SelectPersona DOM event
-   */
-  onSelectPersonaFromContent: PersonaService.wrap(function(event) {
-    this._authorizeHost(event);
-    this.onSelectPersona(event);
-  }),
-
-  /**
    * Select the persona specified by the DOM node target of the given event.
    *
    * @param event   {Event}
@@ -739,18 +700,6 @@ let PersonaController = {
     }
   }),
 
-  /**
-   * Preview the persona specified by a web page via a PreviewPersona event.
-   * Checks to ensure the page is hosted on a server authorized to set personas.
-   *
-   * @param   event   {Event}
-   *          the PreviewPersona DOM event
-   */
-  onPreviewPersonaFromContent: PersonaService.wrap(function(event) {
-    this._authorizeHost(event);
-    this.onPreviewPersona(event);
-  }),
-
   onPreviewPersona: PersonaService.wrap(function(event) {
     if (!this._prefs.get("previewEnabled"))
       return;
@@ -791,18 +740,6 @@ let PersonaController = {
     PersonaService.previewPersona(persona);
   },
 
-  /**
-   * Reset the persona as specified by a web page via a ResetPersona event.
-   * Checks to ensure the page is hosted on a server authorized to reset personas.
-   *
-   * @param event   {Event}
-   *        the ResetPersona DOM event
-   */
-  onResetPersonaFromContent: PersonaService.wrap(function(event) {
-    this._authorizeHost(event);
-    this.onResetPersona();
-  }),
-
   onResetPersona: PersonaService.wrap(function(event) {
     if (!this._prefs.get("previewEnabled"))
       return;
diff --git a/extension/install.rdf b/extension/install.rdf
index 3475123..73198f0 100644
--- a/extension/install.rdf
+++ b/extension/install.rdf
@@ -5,7 +5,7 @@
 
     <em:id>personas at christopher.beard</em:id>
     <em:name>Personas Plus</em:name>
-    <em:version>1.7.1</em:version>
+    <em:version>1.7.2</em:version>
     <em:description>Your Firefox, your style. Easy-to-change themes.</em:description>
 
     <em:creator>Chris Beard</em:creator>
diff --git a/extension/locale/en-US/personas.properties b/extension/locale/en-US/personas.properties
index 50c7bcf..3bafce2 100644
--- a/extension/locale/en-US/personas.properties
+++ b/extension/locale/en-US/personas.properties
@@ -72,3 +72,27 @@ dataUnavailable   = Personas data is not available yet.  Please check your netwo
 # be in an editor-specific properties file, but since translators have already
 # translated it in this one, we'll leave it here for now.
 backgroundPickerDialogTitle = Select a File
+
+
+
+# The title of the confirmation dialog requesting that AMO cookies
+# be enabled
+cookies.confirm.title = Personas Plus
+
+# The message prompting to enable cookies for AMO
+#   %1$S = the hostname of the currently selected add-on site
+cookies.confirm.message = In order for background themes to function correctly, cookies must be enabled for '%1$S'. Enable them now?
+
+# The checkbox label opting out of further notifications
+cookies.confirm.checkbox = Do not ask me about this again
+
+
+# The message shown when a user is attempting to use personas in
+# a private browsing window
+pbm.message = Background themes are not currently supported in private browsing windows
+
+# The accept button for the private browsing notification
+pbm.button.label = OK
+
+# The accept button's access key for the private browsing notification
+pbm.button.accesskey = OK
diff --git a/extension/modules/service.js b/extension/modules/service.js
index eeef53f..d2f62e9 100644
--- a/extension/modules/service.js
+++ b/extension/modules/service.js
@@ -1067,10 +1067,54 @@ let PersonaService = {
   },
 
   /**
+   * Ensures that cookies are enabled for our current add-ons host, and
+   * prompts the user to enable them if not.
+   */
+  checkCookiesEnabled: function() {
+    const PERM = "cookie";
+    const ALLOW = 1, SESSION_ONLY = 8;
+
+    try {
+      let prefs = new Preferences("network.cookie.");
+      let cookiesEnabled = (prefs.get("alwaysAcceptSessionCookies") ||
+                            prefs.get("cookieBehavior") != 2);
+      let uri = Services.io.newURI(this.getURL("favorites-feed"), null, null);
+
+      let _ = this._strings.get.bind(this._strings);
+      if (cookiesEnabled
+            || ~[ALLOW, SESSION_ONLY].indexOf(Services.perms.testPermission(uri, PERM))) {
+        this._prefs.reset("naggedAboutCookies");
+      } else {
+        if (this._prefs.get("naggedAboutCookies") == this.addonsHost)
+          return;
+
+        let stopNagging = { value: true };
+        let enableCookies = Services.prompt.confirmCheck(
+            null, _("cookies.confirm.title"),
+            _("cookies.confirm.message", [this.addonsHost]),
+            _("cookies.confirm.checkbox"),
+            stopNagging);
+
+        if (enableCookies) {
+          Services.perms.remove(uri.host, PERM);
+          Services.perms.add(uri, PERM, ALLOW);
+        }
+        else if (stopNagging.value) {
+          this._prefs.set("naggedAboutCookies", this.addonsHost);
+        }
+      }
+    }
+    catch (e) {
+        Cu.reportError(e);
+    }
+  },
+
+  /**
    * Handles the addons-host preference being changed.
    */
   onAddonsHostChanged: function() {
     this.addonsHost = this._prefs.get("addons-host");
+    this.checkCookiesEnabled()
     this.refreshFavorites();
   },
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/personasplus.git



More information about the Pkg-mozext-commits mailing list