/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. const Cc = Components.classes;
  38. const Ci = Components.interfaces;
  39. const Cu = Components.utils;
  40. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
  41. Cu.import("resource://gre/modules/Services.jsm");
  42. Cu.import("resource://gre/modules/FileUtils.jsm");
  43. function WeaveService() {
  44. this.wrappedJSObject = this;
  45. }
  46. WeaveService.prototype = {
  47. classID: Components.ID("{74b89fb0-f200-4ae8-a3ec-dd164117f6de}"),
  48. QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
  49. Ci.nsISupportsWeakReference]),
  50. observe: function BSS__observe(subject, topic, data) {
  51. switch (topic) {
  52. case "app-startup":
  53. let os = Cc["@mozilla.org/observer-service;1"].
  54. getService(Ci.nsIObserverService);
  55. os.addObserver(this, "final-ui-startup", true);
  56. break;
  57. case "final-ui-startup":
  58. // Force Weave service to load if it hasn't triggered from overlays
  59. this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  60. this.timer.initWithCallback({
  61. notify: function() {
  62. Cu.import("resource://services-sync/main.js");
  63. if (Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED)
  64. Weave.Service;
  65. }
  66. }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
  67. break;
  68. }
  69. }
  70. };
  71. function AboutWeaveLog() {}
  72. AboutWeaveLog.prototype = {
  73. classID: Components.ID("{d28f8a0b-95da-48f4-b712-caf37097be41}"),
  74. QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
  75. Ci.nsISupportsWeakReference]),
  76. getURIFlags: function(aURI) {
  77. return 0;
  78. },
  79. newChannel: function(aURI) {
  80. let dir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
  81. let uri = Services.io.newFileURI(dir);
  82. let channel = Services.io.newChannelFromURI(uri);
  83. channel.originalURI = aURI;
  84. // Ensure that the about page has the same privileges as a regular directory
  85. // view. That way links to files can be opened.
  86. let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
  87. .getService(Ci.nsIScriptSecurityManager);
  88. let principal = ssm.getCodebasePrincipal(uri);
  89. channel.owner = principal;
  90. return channel;
  91. }
  92. };
  93. const components = [WeaveService, AboutWeaveLog];
  94. const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);