michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: this.EXPORTED_SYMBOLS = ["Services"]; michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: this.Services = {}; michael@0: michael@0: XPCOMUtils.defineLazyGetter(Services, "prefs", function () { michael@0: return Cc["@mozilla.org/preferences-service;1"] michael@0: .getService(Ci.nsIPrefService) michael@0: .QueryInterface(Ci.nsIPrefBranch); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(Services, "appinfo", function () { michael@0: let appinfo = Cc["@mozilla.org/xre/app-info;1"] michael@0: .getService(Ci.nsIXULRuntime); michael@0: try { michael@0: appinfo.QueryInterface(Ci.nsIXULAppInfo); michael@0: } catch (ex if ex instanceof Components.Exception && michael@0: ex.result == Cr.NS_NOINTERFACE) { michael@0: // Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't). michael@0: } michael@0: return appinfo; michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(Services, "dirsvc", function () { michael@0: return Cc["@mozilla.org/file/directory_service;1"] michael@0: .getService(Ci.nsIDirectoryService) michael@0: .QueryInterface(Ci.nsIProperties); michael@0: }); michael@0: michael@0: #ifdef MOZ_CRASHREPORTER michael@0: XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => { michael@0: let ns = {}; michael@0: Components.utils.import("resource://gre/modules/CrashManager.jsm", ns); michael@0: michael@0: return ns.CrashManager.Singleton; michael@0: }); michael@0: #endif michael@0: michael@0: let initTable = [ michael@0: #ifdef MOZ_WIDGET_ANDROID michael@0: ["androidBridge", "@mozilla.org/android/bridge;1", "nsIAndroidBridge"], michael@0: #endif michael@0: ["appShell", "@mozilla.org/appshell/appShellService;1", "nsIAppShellService"], michael@0: ["cache", "@mozilla.org/network/cache-service;1", "nsICacheService"], michael@0: ["cache2", "@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"], michael@0: ["console", "@mozilla.org/consoleservice;1", "nsIConsoleService"], michael@0: ["contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService"], michael@0: ["cookies", "@mozilla.org/cookiemanager;1", "nsICookieManager2"], michael@0: ["downloads", "@mozilla.org/download-manager;1", "nsIDownloadManager"], michael@0: ["droppedLinkHandler", "@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"], michael@0: ["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"], michael@0: ["io", "@mozilla.org/network/io-service;1", "nsIIOService2"], michael@0: ["locale", "@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"], michael@0: ["logins", "@mozilla.org/login-manager;1", "nsILoginManager"], michael@0: ["obs", "@mozilla.org/observer-service;1", "nsIObserverService"], michael@0: ["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"], michael@0: ["prompt", "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"], michael@0: ["scriptloader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"], michael@0: ["scriptSecurityManager", "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager"], michael@0: #ifdef MOZ_TOOLKIT_SEARCH michael@0: ["search", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"], michael@0: #endif michael@0: ["storage", "@mozilla.org/storage/service;1", "mozIStorageService"], michael@0: ["domStorageManager", "@mozilla.org/dom/localStorage-manager;1", "nsIDOMStorageManager"], michael@0: ["strings", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"], michael@0: ["telemetry", "@mozilla.org/base/telemetry;1", "nsITelemetry"], michael@0: ["tm", "@mozilla.org/thread-manager;1", "nsIThreadManager"], michael@0: ["urlFormatter", "@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"], michael@0: ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"], michael@0: ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"], michael@0: ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"], michael@0: ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"], michael@0: ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"], michael@0: ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"], michael@0: ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"], michael@0: ["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"], michael@0: ["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"], michael@0: ["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"], michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: ["metro", "@mozilla.org/windows-metroutils;1", "nsIWinMetroUtils"], michael@0: #endif michael@0: #endif michael@0: ]; michael@0: michael@0: initTable.forEach(function ([name, contract, intf]) michael@0: XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf)); michael@0: michael@0: initTable = undefined;