Bug 906088 - part 4 - refactor browser.js's getPreferences function into a JSON frontend and a "raw" backend; r=mfinkle
authorNathan Froyd <froydnj@mozilla.com>
Wed, 04 Sep 2013 09:58:15 -0400
changeset 147041 d8ccee9586b65fa20c2bf6f0e6791d8817e65b52
parent 147040 460a4dccb18bd87287f80c949fe50864e632914b
child 147042 b90df20f637ff2c8ff264d629cfc6d048993892a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmfinkle
bugs906088
milestone26.0a1
Bug 906088 - part 4 - refactor browser.js's getPreferences function into a JSON frontend and a "raw" backend; r=mfinkle This is a small patch, but I think it makes part 5 a little easier to understand. In part five, we're going to be introducing XPCOM methods that browser.js needs to implement. That patch is going to require something very much like handlePreferencesRequest, so just make it visible here and then part 5 should be much easier to understand.
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -995,30 +995,39 @@ var BrowserApp = {
     this._prefObservers[aPref].forEach(function(aRequestId) {
       let request = { requestId : aRequestId,
                       preferences : [aPref] };
       this.getPreferences(request);
     }, this);
   },
 
   getPreferences: function getPreferences(aPrefsRequest, aListen) {
+    this.handlePreferencesRequest(aPrefsRequest.requestId,
+                                  aPrefsRequest.preferences,
+                                  aListen);
+  },
+
+  handlePreferencesRequest: function handlePreferencesRequest(aRequestId,
+                                                              aPrefNames,
+                                                              aListen) {
+
     let prefs = [];
 
-    for (let prefName of aPrefsRequest.preferences) {
+    for (let prefName of aPrefNames) {
       let pref = {
         name: prefName,
         type: "",
         value: null
       };
 
       if (aListen) {
         if (this._prefObservers[prefName])
-          this._prefObservers[prefName].push(aPrefsRequest.requestId);
+          this._prefObservers[prefName].push(aRequestId);
         else
-          this._prefObservers[prefName] = [ aPrefsRequest.requestId ];
+          this._prefObservers[prefName] = [ aRequestId ];
         Services.prefs.addObserver(prefName, this, false);
       }
 
       // These pref names are not "real" pref names.
       // They are used in the setting menu,
       // and these are passed when initializing the setting menu.
       switch (prefName) {
         // The plugin pref is actually two separate prefs, so
@@ -1115,17 +1124,17 @@ var BrowserApp = {
           break;
       }
 
       prefs.push(pref);
     }
 
     sendMessageToJava({
       type: "Preferences:Data",
-      requestId: aPrefsRequest.requestId,    // opaque request identifier, can be any string/int/whatever
+      requestId: aRequestId,    // opaque request identifier, can be any string/int/whatever
       preferences: prefs
     });
   },
 
   removePreferenceObservers: function removePreferenceObservers(aRequestId) {
     let newPrefObservers = [];
     for (let prefName in this._prefObservers) {
       let requestIds = this._prefObservers[prefName];