PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/services/sync/Weave.js

http://github.com/zpao/v8monkey
JavaScript | 106 lines | 55 code | 12 blank | 39 comment | 3 complexity | 7e29ee7fa4ee92acee6982178019eda6 MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is Weave.
 15 *
 16 * The Initial Developer of the Original Code is Mozilla.
 17 * Portions created by the Initial Developer are Copyright (C) 2008
 18 * the Initial Developer. All Rights Reserved.
 19 *
 20 * Contributor(s):
 21 *  Dan Mills <thunder@mozilla.com>
 22 *  Philipp von Weitershausen <philipp@weitershausen.de>
 23 *
 24 * Alternatively, the contents of this file may be used under the terms of
 25 * either the GNU General Public License Version 2 or later (the "GPL"), or
 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 27 * in which case the provisions of the GPL or the LGPL are applicable instead
 28 * of those above. If you wish to allow use of your version of this file only
 29 * under the terms of either the GPL or the LGPL, and not to allow others to
 30 * use your version of this file under the terms of the MPL, indicate your
 31 * decision by deleting the provisions above and replace them with the notice
 32 * and other provisions required by the GPL or the LGPL. If you do not delete
 33 * the provisions above, a recipient may use your version of this file under
 34 * the terms of any one of the MPL, the GPL or the LGPL.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37
 38const Cc = Components.classes;
 39const Ci = Components.interfaces;
 40const Cu = Components.utils;
 41
 42Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 43Cu.import("resource://gre/modules/Services.jsm");
 44Cu.import("resource://gre/modules/FileUtils.jsm");
 45
 46function WeaveService() {
 47  this.wrappedJSObject = this;
 48}
 49WeaveService.prototype = {
 50  classID: Components.ID("{74b89fb0-f200-4ae8-a3ec-dd164117f6de}"),
 51
 52  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
 53                                         Ci.nsISupportsWeakReference]),
 54
 55  observe: function BSS__observe(subject, topic, data) {
 56    switch (topic) {
 57    case "app-startup":
 58      let os = Cc["@mozilla.org/observer-service;1"].
 59               getService(Ci.nsIObserverService);
 60      os.addObserver(this, "final-ui-startup", true);
 61      break;
 62
 63    case "final-ui-startup":
 64      // Force Weave service to load if it hasn't triggered from overlays
 65      this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 66      this.timer.initWithCallback({
 67        notify: function() {
 68          Cu.import("resource://services-sync/main.js");
 69          if (Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED)
 70            Weave.Service;
 71        }
 72      }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
 73      break;
 74    }
 75  }
 76};
 77
 78function AboutWeaveLog() {}
 79AboutWeaveLog.prototype = {
 80  classID: Components.ID("{d28f8a0b-95da-48f4-b712-caf37097be41}"),
 81
 82  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
 83                                         Ci.nsISupportsWeakReference]),
 84
 85  getURIFlags: function(aURI) {
 86    return 0;
 87  },
 88
 89  newChannel: function(aURI) {
 90    let dir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
 91    let uri = Services.io.newFileURI(dir);
 92    let channel = Services.io.newChannelFromURI(uri);
 93    channel.originalURI = aURI;
 94
 95    // Ensure that the about page has the same privileges as a regular directory
 96    // view. That way links to files can be opened.
 97    let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
 98                .getService(Ci.nsIScriptSecurityManager);
 99    let principal = ssm.getCodebasePrincipal(uri);
100    channel.owner = principal;
101    return channel;
102  }
103};
104
105const components = [WeaveService, AboutWeaveLog];
106const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);