Bug 1317185 - Propagate contextual-identity-updated notification when an ContextualIdentity is modified, r=gijs
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 07 Dec 2016 10:24:08 -1000
changeset 325389 2ff0d7460eb608032bce7a991b0d95ca78794dda
parent 325388 653e7327b3f835cdc42de5632f8831f1616fcddc
child 325390 2a0223e35b0e3102fcf31edaff48a7319eeed142
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersgijs
bugs1317185
milestone53.0a1
Bug 1317185 - Propagate contextual-identity-updated notification when an ContextualIdentity is modified, r=gijs
browser/base/content/tabbrowser.xml
toolkit/components/contextualidentity/ContextualIdentityService.jsm
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -4805,32 +4805,41 @@
                 let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
                 if (fl && fl.tabParent) {
                   fl.tabParent.suppressDisplayport(false);
                   this.mActiveResizeDisplayportSuppression = null;
                 }
               }
               break;
             }
+            case "contextual-identity-updated": {
+              for (let tab of this.tabs) {
+                if (tab.getAttribute("usercontextid") == aData) {
+                  ContextualIdentityService.setTabStyle(tab);
+                }
+              }
+              break;
+            }
             case "nsPref:changed": {
               // This is the only pref observed.
               this._findAsYouType = Services.prefs.getBoolPref("accessibility.typeaheadfind");
               break;
             }
           }
         ]]></body>
       </method>
 
       <constructor>
         <![CDATA[
           this.mCurrentBrowser = document.getAnonymousElementByAttribute(this, "anonid", "initialBrowser");
           this.mCurrentBrowser.permanentKey = {};
 
           Services.obs.addObserver(this, "live-resize-start", false);
           Services.obs.addObserver(this, "live-resize-end", false);
+          Services.obs.addObserver(this, "contextual-identity-updated", false);
 
           this.mCurrentTab = this.tabContainer.firstChild;
           const nsIEventListenerService =
             Components.interfaces.nsIEventListenerService;
           let els = Components.classes["@mozilla.org/eventlistenerservice;1"]
                               .getService(nsIEventListenerService);
           els.addSystemEventListener(document, "keydown", this, false);
           if (this.AppConstants.platform == "macosx") {
@@ -4920,16 +4929,17 @@
           return "panel-" + outerID + "-" + (++this._uniquePanelIDCounter);
         ]]></body>
       </method>
 
       <destructor>
         <![CDATA[
           Services.obs.removeObserver(this, "live-resize-start", false);
           Services.obs.removeObserver(this, "live-resize-end", false);
+          Services.obs.removeObserver(this, "contextual-identity-updated", false);
 
           for (let tab of this.tabs) {
             let browser = tab.linkedBrowser;
             if (browser.registeredOpenURI) {
               this._unifiedComplete.unregisterOpenPage(browser.registeredOpenURI,
                                                        browser.getAttribute("usercontextid") || 0);
               delete browser.registeredOpenURI;
             }
--- a/toolkit/components/contextualidentity/ContextualIdentityService.jsm
+++ b/toolkit/components/contextualidentity/ContextualIdentityService.jsm
@@ -188,16 +188,18 @@ function _ContextualIdentityService(path
     let identity = this._identities.find(identity => identity.userContextId == userContextId &&
                                          identity.public);
     if (identity && name) {
       identity.name = name;
       identity.color = color;
       identity.icon = icon;
       delete identity.l10nID;
       delete identity.accessKey;
+
+      Services.obs.notifyObservers(null, "contextual-identity-updated", userContextId);
       this.saveSoon();
     }
 
     return !!identity;
   },
 
   remove(userContextId) {
     let index = this._identities.findIndex(i => i.userContextId == userContextId && i.public);