Bug 1255461 - Notify pref handlers when pseudo-prefs change; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 18 Mar 2016 15:18:51 -0400
changeset 289395 aa409880028ad90ee004dd062a2a865b1fb50c3b
parent 289394 071a81d2a723bf55d20ceefa853e816eb31bd088
child 289396 b74f559972724f3c81b9bfc46caaf4e5362dd44a
push id30102
push userryanvm@gmail.com
push dateSat, 19 Mar 2016 15:23:17 +0000
treeherdermozilla-central@720fb3d55e28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1255461
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1255461 - Notify pref handlers when pseudo-prefs change; r=snorp When "pseudo-prefs" change, the Java side expects the same change notification as regular prefs.
mobile/android/chrome/content/MasterPassword.js
widget/android/PrefsHelper.h
--- a/mobile/android/chrome/content/MasterPassword.js
+++ b/mobile/android/chrome/content/MasterPassword.js
@@ -39,30 +39,28 @@ var MasterPassword = {
 
       let token = this._pk11DB.findTokenByName(this._tokenName);
 
       if (status == Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED)
         token.initPassword(aPassword);
       else if (status == Ci.nsIPKCS11Slot.SLOT_READY)
         token.changePassword("", aPassword);
 
-      BrowserApp.notifyPrefObservers(this.pref);
       return true;
     } catch(e) {
       dump("MasterPassword.setPassword: " + e);
     }
     return false;
   },
 
   removePassword: function removePassword(aOldPassword) {
     try {
       let token = this._pk11DB.getInternalKeyToken();
       if (token.checkPassword(aOldPassword)) {
         token.changePassword(aOldPassword, "");
-        BrowserApp.notifyPrefObservers(this.pref);
         return true;
       }
     } catch(e) {
       dump("MasterPassword.removePassword: " + e + "\n");
     }
     Snackbars.show(Strings.browser.GetStringFromName("masterPassword.incorrect"), Snackbars.LENGTH_LONG);
     return false;
   }
--- a/widget/android/PrefsHelper.h
+++ b/widget/android/PrefsHelper.h
@@ -22,17 +22,17 @@ class PrefsHelper
     : public widget::PrefsHelper::Natives<PrefsHelper>
     , public UsesGeckoThreadProxy
 {
     PrefsHelper() = delete;
 
     static bool GetVariantPref(nsIObserverService* aObsServ,
                                nsIWritableVariant* aVariant,
                                jni::Object::Param aPrefHandler,
-                               jni::String::LocalRef& aPrefName)
+                               const jni::String::LocalRef& aPrefName)
     {
         if (NS_FAILED(aObsServ->NotifyObservers(aVariant, "android-get-pref",
                                                 aPrefName->ToString().get()))) {
             return false;
         }
 
         uint16_t varType = nsIDataType::VTYPE_EMPTY;
         if (NS_FAILED(aVariant->GetDataType(&varType))) {
@@ -66,18 +66,23 @@ class PrefsHelper
             default:
                 return false;
         }
 
         const auto& jstrVal = type == widget::PrefsHelper::PREF_STRING ?
                 jni::StringParam(strVal, aPrefName.Env()) :
                 jni::StringParam(nullptr);
 
-        widget::PrefsHelper::CallPrefHandler(
-                aPrefHandler, type, aPrefName, boolVal, intVal, jstrVal);
+        if (aPrefHandler) {
+            widget::PrefsHelper::CallPrefHandler(
+                    aPrefHandler, type, aPrefName, boolVal, intVal, jstrVal);
+        } else {
+            widget::PrefsHelper::OnPrefChange(
+                    aPrefName, type, boolVal, intVal, jstrVal);
+        }
         return true;
     }
 
     static bool SetVariantPref(nsIObserverService* aObsServ,
                                nsIWritableVariant* aVariant,
                                jni::String::Param aPrefName,
                                bool aFlush,
                                int32_t aType,
@@ -208,16 +213,19 @@ public:
 
         if (Preferences::GetType(name.get()) == nsIPrefBranch::PREF_INVALID) {
             // No pref; try asking first.
             nsCOMPtr<nsIObserverService> obsServ =
                     services::GetObserverService();
             nsCOMPtr<nsIWritableVariant> value = new nsVariant();
             if (obsServ && SetVariantPref(obsServ, value, aPrefName, aFlush,
                                           aType, aBoolVal, aIntVal, aStrVal)) {
+                // The "pref" has changed; send a notification.
+                GetVariantPref(obsServ, value, nullptr,
+                               jni::String::LocalRef(aPrefName));
                 return;
             }
         }
 
         switch (aType) {
             case widget::PrefsHelper::PREF_BOOL:
                 Preferences::SetBool(name.get(), aBoolVal);
                 break;