1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/Services.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +this.EXPORTED_SYMBOLS = ["Services"]; 1.9 + 1.10 +const Ci = Components.interfaces; 1.11 +const Cc = Components.classes; 1.12 +const Cr = Components.results; 1.13 + 1.14 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.15 + 1.16 +this.Services = {}; 1.17 + 1.18 +XPCOMUtils.defineLazyGetter(Services, "prefs", function () { 1.19 + return Cc["@mozilla.org/preferences-service;1"] 1.20 + .getService(Ci.nsIPrefService) 1.21 + .QueryInterface(Ci.nsIPrefBranch); 1.22 +}); 1.23 + 1.24 +XPCOMUtils.defineLazyGetter(Services, "appinfo", function () { 1.25 + let appinfo = Cc["@mozilla.org/xre/app-info;1"] 1.26 + .getService(Ci.nsIXULRuntime); 1.27 + try { 1.28 + appinfo.QueryInterface(Ci.nsIXULAppInfo); 1.29 + } catch (ex if ex instanceof Components.Exception && 1.30 + ex.result == Cr.NS_NOINTERFACE) { 1.31 + // Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't). 1.32 + } 1.33 + return appinfo; 1.34 +}); 1.35 + 1.36 +XPCOMUtils.defineLazyGetter(Services, "dirsvc", function () { 1.37 + return Cc["@mozilla.org/file/directory_service;1"] 1.38 + .getService(Ci.nsIDirectoryService) 1.39 + .QueryInterface(Ci.nsIProperties); 1.40 +}); 1.41 + 1.42 +#ifdef MOZ_CRASHREPORTER 1.43 +XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => { 1.44 + let ns = {}; 1.45 + Components.utils.import("resource://gre/modules/CrashManager.jsm", ns); 1.46 + 1.47 + return ns.CrashManager.Singleton; 1.48 +}); 1.49 +#endif 1.50 + 1.51 +let initTable = [ 1.52 +#ifdef MOZ_WIDGET_ANDROID 1.53 + ["androidBridge", "@mozilla.org/android/bridge;1", "nsIAndroidBridge"], 1.54 +#endif 1.55 + ["appShell", "@mozilla.org/appshell/appShellService;1", "nsIAppShellService"], 1.56 + ["cache", "@mozilla.org/network/cache-service;1", "nsICacheService"], 1.57 + ["cache2", "@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"], 1.58 + ["console", "@mozilla.org/consoleservice;1", "nsIConsoleService"], 1.59 + ["contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService"], 1.60 + ["cookies", "@mozilla.org/cookiemanager;1", "nsICookieManager2"], 1.61 + ["downloads", "@mozilla.org/download-manager;1", "nsIDownloadManager"], 1.62 + ["droppedLinkHandler", "@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"], 1.63 + ["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"], 1.64 + ["io", "@mozilla.org/network/io-service;1", "nsIIOService2"], 1.65 + ["locale", "@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"], 1.66 + ["logins", "@mozilla.org/login-manager;1", "nsILoginManager"], 1.67 + ["obs", "@mozilla.org/observer-service;1", "nsIObserverService"], 1.68 + ["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"], 1.69 + ["prompt", "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"], 1.70 + ["scriptloader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"], 1.71 + ["scriptSecurityManager", "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager"], 1.72 +#ifdef MOZ_TOOLKIT_SEARCH 1.73 + ["search", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"], 1.74 +#endif 1.75 + ["storage", "@mozilla.org/storage/service;1", "mozIStorageService"], 1.76 + ["domStorageManager", "@mozilla.org/dom/localStorage-manager;1", "nsIDOMStorageManager"], 1.77 + ["strings", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"], 1.78 + ["telemetry", "@mozilla.org/base/telemetry;1", "nsITelemetry"], 1.79 + ["tm", "@mozilla.org/thread-manager;1", "nsIThreadManager"], 1.80 + ["urlFormatter", "@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"], 1.81 + ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"], 1.82 + ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"], 1.83 + ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"], 1.84 + ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"], 1.85 + ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"], 1.86 + ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"], 1.87 + ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"], 1.88 + ["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"], 1.89 + ["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"], 1.90 + ["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"], 1.91 +#ifdef XP_WIN 1.92 +#ifdef MOZ_METRO 1.93 + ["metro", "@mozilla.org/windows-metroutils;1", "nsIWinMetroUtils"], 1.94 +#endif 1.95 +#endif 1.96 +]; 1.97 + 1.98 +initTable.forEach(function ([name, contract, intf]) 1.99 + XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf)); 1.100 + 1.101 +initTable = undefined;