Browse Source

b=423008, r=mfinkle, Prism web apps should inherit preferences from Firefox

matthew@allpeers.com 15 years ago
parent
commit
89a32ac614

+ 29 - 4
extension/chrome/content/refractor-overlay.js

@@ -19,7 +19,7 @@
  *
  * Contributor(s):
  *   Cesar Oliveira <a.sacred.line@gmail.com>
- *   Matthew Gertner <matthew@allpeers.com>
+ *   Matthew Gertner <matthew.gertner@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -54,9 +54,33 @@ var Prism = {
       WebAppProperties.appBundle = null;
     }
 
-    var allowLaunch = {value: false};
-    window.openDialog("chrome://refractor/content/install-shortcut.xul", "install", "centerscreen,modal", WebAppProperties, allowLaunch);
+    window.openDialog("chrome://refractor/content/install-shortcut.xul", "install", "centerscreen,modal", WebAppProperties, this.exportPrefs);
   },
+
+  exportPrefs : function()
+  {
+    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
+    prefs = prefs.getBranch("network.proxy.");
+    prefList = prefs.getChildList("", {});
+    var prefValues = new Array;
+    for (prefNum in prefList) {
+      var pref = prefList[prefNum];
+      var prefType = prefs.getPrefType(pref);
+      var prefValue = null;
+      switch (prefType) {
+        case prefs.PREF_STRING: prefValue = prefs.getCharPref(pref); break;
+        case prefs.PREF_INT: prefValue = prefs.getIntPref(pref); break;
+        case prefs.PREF_BOOL: prefValue = prefs.getBoolPref(pref); break;
+      }
+      prefValues[prefNum] = { name: pref, type: prefType, value: prefValue };
+    }
+    var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
+    var json = nativeJSON.encode(prefValues);
+    var file = WebAppProperties.getAppRoot();
+    file.append("prefs.json");
+    FileIO.stringToFile(json, file);
+  },
+
   onLoad : function() {
     var uriloader = Cc["@mozilla.org/uriloader;1"].getService(Ci.nsIURILoader);
     uriloader.registerContentListener(PrismContentListener);
@@ -103,8 +127,9 @@ var PrismWebAppDownload = {
     var packageDir = WebAppInstall.install(file);
     WebAppProperties.init(packageDir);
     Prism.convertToApplication(false);
+    Prism.exportPrefs();
   },
-
+  
   getTemporaryFileForUri : function(uri)
   {
     var tempDir =

+ 4 - 5
newapp/chrome/content/install-shortcut.js

@@ -39,7 +39,7 @@ var InstallShortcut = {
   _userIcon : null,
   _iframe : null,
   _mode : "edit",
-  _launch : false,
+  _oncomplete : false,
   _faviconDownloader : new FaviconDownloader,
 
   init : function() {
@@ -47,7 +47,7 @@ var InstallShortcut = {
 
     // Check the dialog mode
     this._mode = (window.arguments && window.arguments.length == 2) ? "install" : "edit";
-    this._launch = (window.arguments && window.arguments.length == 2) ? window.arguments[1].value : false;
+    this._oncomplete = (window.arguments && window.arguments.length == 2) ? window.arguments[1] : null;
 
     // Default the UI from the given config
     if (WebAppProperties.uri) {
@@ -221,9 +221,8 @@ var InstallShortcut = {
     // Make any desired shortcuts
     var shortcut = WebAppInstall.createShortcut(name, WebAppProperties.id, shortcuts.split(","));
 
-    if (this._launch) {
-      // We should launch the webapp
-      WebAppInstall.restart(WebAppProperties.id, shortcut);
+    if (this._oncomplete) {
+      this._oncomplete(WebAppInstall, WebAppProperties.id, shortcut);
     }
 
     return true;

+ 2 - 2
runtime/chrome/content/webrunner.js

@@ -677,8 +677,8 @@ var WebRunner = {
     // Do we need to handle making a web application?
     if (install) {
       // If the install is successful, launch the webapp
-      var allowLaunch = {value: true};
-      window.openDialog("chrome://newapp/content/install-shortcut.xul", "install", "dialog=no,centerscreen", WebAppProperties, allowLaunch);
+      window.openDialog("chrome://newapp/content/install-shortcut.xul", "install", "dialog=no,centerscreen", WebAppProperties,
+        function(install, id, shortcut) { install.restart(id, shortcut); } );
 
       // Hide the main window so it doesn't flash on the screen before closing
       this._xulWindow.QueryInterface(Ci.nsIBaseWindow).visibility = false;

+ 32 - 0
runtime/components/src/nsCommandLineHandler.js

@@ -87,6 +87,11 @@ WebRunnerCommandLineHandler.prototype = {
       }
     }
 
+    // Load any prefs from the bundle (e.g. inherited from Firefox)
+    if (file) {
+      this.loadPrefs(file);
+    }
+
     var protocolURI = null;
     var callback = {};
 
@@ -163,6 +168,33 @@ WebRunnerCommandLineHandler.prototype = {
     return win;
   },
 
+  loadPrefs : function(root) {
+    try {
+      var prefFile = root.clone();
+      prefFile.append("prefs.json");
+      if (prefFile.exists()) {
+        var json = FileIO.fileToString(prefFile);
+        var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
+        var prefValues = nativeJSON.decode(json);
+        var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
+        prefs = prefs.getBranch("network.proxy.");
+        for (prefNum in prefValues) {
+          var pref = prefValues[prefNum];
+          switch (pref.type) {
+            case prefs.PREF_STRING: prefs.setCharPref(pref.name, pref.value); break;
+            case prefs.PREF_INT: prefs.setIntPref(pref.name, pref.value); break;
+            case prefs.PREF_BOOL: prefs.setBoolPref(pref.name, pref.value); break;
+          }
+        }
+        prefFile.remove(false);
+      }
+    }
+    catch(e) {
+      // Something went wrong, let's catch it here so we can at least run the app properly
+      Components.utils.reportError(e);
+    }
+  },
+  
   helpInfo : "",
 };