|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 this.EXPORTED_SYMBOLS = ["Services"]; |
|
6 |
|
7 const Ci = Components.interfaces; |
|
8 const Cc = Components.classes; |
|
9 const Cr = Components.results; |
|
10 |
|
11 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
12 |
|
13 this.Services = {}; |
|
14 |
|
15 XPCOMUtils.defineLazyGetter(Services, "prefs", function () { |
|
16 return Cc["@mozilla.org/preferences-service;1"] |
|
17 .getService(Ci.nsIPrefService) |
|
18 .QueryInterface(Ci.nsIPrefBranch); |
|
19 }); |
|
20 |
|
21 XPCOMUtils.defineLazyGetter(Services, "appinfo", function () { |
|
22 let appinfo = Cc["@mozilla.org/xre/app-info;1"] |
|
23 .getService(Ci.nsIXULRuntime); |
|
24 try { |
|
25 appinfo.QueryInterface(Ci.nsIXULAppInfo); |
|
26 } catch (ex if ex instanceof Components.Exception && |
|
27 ex.result == Cr.NS_NOINTERFACE) { |
|
28 // Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't). |
|
29 } |
|
30 return appinfo; |
|
31 }); |
|
32 |
|
33 XPCOMUtils.defineLazyGetter(Services, "dirsvc", function () { |
|
34 return Cc["@mozilla.org/file/directory_service;1"] |
|
35 .getService(Ci.nsIDirectoryService) |
|
36 .QueryInterface(Ci.nsIProperties); |
|
37 }); |
|
38 |
|
39 #ifdef MOZ_CRASHREPORTER |
|
40 XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => { |
|
41 let ns = {}; |
|
42 Components.utils.import("resource://gre/modules/CrashManager.jsm", ns); |
|
43 |
|
44 return ns.CrashManager.Singleton; |
|
45 }); |
|
46 #endif |
|
47 |
|
48 let initTable = [ |
|
49 #ifdef MOZ_WIDGET_ANDROID |
|
50 ["androidBridge", "@mozilla.org/android/bridge;1", "nsIAndroidBridge"], |
|
51 #endif |
|
52 ["appShell", "@mozilla.org/appshell/appShellService;1", "nsIAppShellService"], |
|
53 ["cache", "@mozilla.org/network/cache-service;1", "nsICacheService"], |
|
54 ["cache2", "@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"], |
|
55 ["console", "@mozilla.org/consoleservice;1", "nsIConsoleService"], |
|
56 ["contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService"], |
|
57 ["cookies", "@mozilla.org/cookiemanager;1", "nsICookieManager2"], |
|
58 ["downloads", "@mozilla.org/download-manager;1", "nsIDownloadManager"], |
|
59 ["droppedLinkHandler", "@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"], |
|
60 ["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"], |
|
61 ["io", "@mozilla.org/network/io-service;1", "nsIIOService2"], |
|
62 ["locale", "@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"], |
|
63 ["logins", "@mozilla.org/login-manager;1", "nsILoginManager"], |
|
64 ["obs", "@mozilla.org/observer-service;1", "nsIObserverService"], |
|
65 ["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"], |
|
66 ["prompt", "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"], |
|
67 ["scriptloader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"], |
|
68 ["scriptSecurityManager", "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager"], |
|
69 #ifdef MOZ_TOOLKIT_SEARCH |
|
70 ["search", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"], |
|
71 #endif |
|
72 ["storage", "@mozilla.org/storage/service;1", "mozIStorageService"], |
|
73 ["domStorageManager", "@mozilla.org/dom/localStorage-manager;1", "nsIDOMStorageManager"], |
|
74 ["strings", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"], |
|
75 ["telemetry", "@mozilla.org/base/telemetry;1", "nsITelemetry"], |
|
76 ["tm", "@mozilla.org/thread-manager;1", "nsIThreadManager"], |
|
77 ["urlFormatter", "@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"], |
|
78 ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"], |
|
79 ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"], |
|
80 ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"], |
|
81 ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"], |
|
82 ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"], |
|
83 ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"], |
|
84 ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"], |
|
85 ["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"], |
|
86 ["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"], |
|
87 ["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"], |
|
88 #ifdef XP_WIN |
|
89 #ifdef MOZ_METRO |
|
90 ["metro", "@mozilla.org/windows-metroutils;1", "nsIWinMetroUtils"], |
|
91 #endif |
|
92 #endif |
|
93 ]; |
|
94 |
|
95 initTable.forEach(function ([name, contract, intf]) |
|
96 XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf)); |
|
97 |
|
98 initTable = undefined; |