Bug 610832 - Make about:sync-log a directory listing. r=rnewman,mconnor
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Mon, 13 Jun 2011 20:40:08 +0200
changeset 70956 ef04efcc4fb3d8130051ab100955039c5ce8d0eb
parent 70955 cc5b247929105668b5f7a544118044d57e7db5dc
child 70957 0122402eba0536e1bc0b4ec8feae8dc084bf157c
push id115
push userpweitershausen@mozilla.com
push dateMon, 13 Jun 2011 18:42:54 +0000
treeherderservices-central@0122402eba05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, mconnor
bugs610832
milestone7.0a1
Bug 610832 - Make about:sync-log a directory listing. r=rnewman,mconnor
services/sync/SyncComponents.manifest
services/sync/Weave.js
--- a/services/sync/SyncComponents.manifest
+++ b/services/sync/SyncComponents.manifest
@@ -1,11 +1,9 @@
 # Weave.js
 component {74b89fb0-f200-4ae8-a3ec-dd164117f6de} Weave.js
 contract @mozilla.org/weave/service;1 {74b89fb0-f200-4ae8-a3ec-dd164117f6de}
 category app-startup WeaveService service,@mozilla.org/weave/service;1
 component {d28f8a0b-95da-48f4-b712-caf37097be41} Weave.js
 contract @mozilla.org/network/protocol/about;1?what=sync-log {d28f8a0b-95da-48f4-b712-caf37097be41}
-component {a08ee179-df50-48e0-9c87-79e4dd5caeb1} Weave.js
-contract @mozilla.org/network/protocol/about;1?what=sync-log.1 {a08ee179-df50-48e0-9c87-79e4dd5caeb1}
 # Register resource aliases
 resource services-sync resource:///modules/services-sync/
 resource services-crypto resource:///modules/services-crypto/
--- a/services/sync/Weave.js
+++ b/services/sync/Weave.js
@@ -14,16 +14,17 @@
  * The Original Code is Weave.
  *
  * The Initial Developer of the Original Code is Mozilla.
  * Portions created by the Initial Developer are Copyright (C) 2008
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *  Dan Mills <thunder@mozilla.com>
+ *  Philipp von Weitershausen <philipp@weitershausen.de>
  *
  * 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
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -34,16 +35,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/FileUtils.jsm");
 
 function WeaveService() {
   this.wrappedJSObject = this;
 }
 WeaveService.prototype = {
   classID: Components.ID("{74b89fb0-f200-4ae8-a3ec-dd164117f6de}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
@@ -79,58 +82,25 @@ AboutWeaveLog.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
                                          Ci.nsISupportsWeakReference]),
 
   getURIFlags: function(aURI) {
     return 0;
   },
 
   newChannel: function(aURI) {
-    let dir = Cc["@mozilla.org/file/directory_service;1"].
-      getService(Ci.nsIProperties);
-    let file = dir.get("ProfD", Ci.nsILocalFile);
-    file.append("weave");
-    file.append("logs");
-    file.append("verbose-log.txt");
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-      getService(Ci.nsIIOService);
-    let ch = ios.newChannel(ios.newFileURI(file).spec, null, null);
-    ch.originalURI = aURI;
-    return ch;
+    let dir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
+    let uri = Services.io.newFileURI(dir);
+    let channel = Services.io.newChannelFromURI(uri);
+    channel.originalURI = aURI;
+
+    // Ensure that the about page has the same privileges as a regular directory
+    // view. That way links to files can be opened.
+    let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
+                .getService(Ci.nsIScriptSecurityManager);
+    let principal = ssm.getCodebasePrincipal(uri);
+    channel.owner = principal;
+    return channel;
   }
 };
 
-function AboutWeaveLog1() {}
-AboutWeaveLog1.prototype = {
-  classID: Components.ID("{a08ee179-df50-48e0-9c87-79e4dd5caeb1}"),
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
-                                         Ci.nsISupportsWeakReference]),
-
-  getURIFlags: function(aURI) {
-    return 0;
-  },
-
-  newChannel: function(aURI) {
-    let dir = Cc["@mozilla.org/file/directory_service;1"].
-      getService(Ci.nsIProperties);
-    let file = dir.get("ProfD", Ci.nsILocalFile);
-    file.append("weave");
-    file.append("logs");
-    file.append("verbose-log.txt.1");
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-      getService(Ci.nsIIOService);
-    let ch = ios.newChannel(ios.newFileURI(file).spec, null, null);
-    ch.originalURI = aURI;
-    return ch;
-  }
-};
-
-let components = [WeaveService, AboutWeaveLog, AboutWeaveLog1];
-
-// Gecko <2.0
-function NSGetModule(compMgr, fileSpec) {
-  return XPCOMUtils.generateModule(components);
-}
-
-// Gecko >=2.0
-if (typeof XPCOMUtils.generateNSGetFactory == "function")
-    const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
+const components = [WeaveService, AboutWeaveLog];
+const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);