Services.jsm

  • Revision slug: JavaScript_code_modules/Services.jsm
  • Revision title: Services.jsm
  • Revision id: 37225
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 146 words added, 3 words removed

Revision Content

{{ gecko_minversion_header("1.9.3") }}

The Services.jsm JavaScript code module offers a wide assortment of lazy getters that simplify the process of obtaining references to commonly used services.

To use it, you first need to import the code module into your JavaScript scope:

Components.utils.import(resource://gre/modules/Services.jsm);

Then you can obtain references to services by simply accessing them from the Services object exported by the code module. For example, to obtain a reference to the preferences service:

var prefsService = Services.prefs;

Provided service getters

Service Accessor Service Interface Service Name
appinfo {{ interface("nsIXULAppInfo") }} Application information service
dirsvc {{ interface("nsIDirectoryService") }} Directory service
io
{{ interface("nsIIOService2") }} I/O Service
locale
{{ interface("nsILocaleService") }} Locale service
obs
{{ interface("nsIObserverService") }} Observer service
perms
{{ interface("nsIPermissionManager") }} Permission Manager service
prefs {{ interface("nsIPrefService") }} Preferences service
prompt
{{ interface("nsIPromptService") }} Prompt service
scriptloader
{{ interface("mozIJSSubScriptLoader") }} JavaScript subscript loader service
search
{{ interface("nsIBrowserSearchService") }} Browser search service
storage
{{ interface("mozIStorageService") }} Storage API service
tm
{{ interface("nsIThreadManager") }} Thread Manager service.
vc
{{ interface("nsIVersionComparator") }} Version comparator service
wm
{{ interface("nsIWindowMediator") }} Window mediator service
ww
{{ interface("nsIWindowWatcher") }} Window watcher service

See also

Revision Source

<p>{{ gecko_minversion_header("1.9.3") }}</p>
<p>The <code>Services.jsm</code> JavaScript code module offers a wide assortment of lazy getters that simplify the process of obtaining references to commonly used services.</p>
<p>To use it, you first need to import the code module into your JavaScript scope:</p>
<pre class="eval"><span class="nowiki">Components.utils.import(resource://gre/modules/Services.jsm);</span></pre>
<p>Then you can obtain references to services by simply accessing them from the <code>Services</code> object exported by the code module. For example, to obtain a reference to the preferences service:</p>
<pre class="brush: js">var prefsService = Services.prefs;
</pre>
<h2>Provided service getters</h2>
<table class="standard-table" style="width: auto;"> <tbody> <tr> <td class="header">Service Accessor</td> <td class="header">Service Interface</td> <td class="header">Service Name</td> </tr> <tr> <td><code>appinfo</code></td> <td>{{ interface("nsIXULAppInfo") }}</td> <td>Application information service</td> </tr> <tr> <td><code>dirsvc</code></td> <td>{{ interface("nsIDirectoryService") }}</td> <td>Directory service</td> </tr> <tr> <td><code>io<br> </code></td> <td>{{ interface("nsIIOService2") }}</td> <td>I/O Service</td> </tr> <tr> <td><code>locale<br> </code></td> <td>{{ interface("nsILocaleService") }}</td> <td>Locale service</td> </tr> <tr> <td><code>obs<br> </code></td> <td>{{ interface("nsIObserverService") }}</td> <td>Observer service</td> </tr> <tr> <td><code>perms<br> </code></td> <td>{{ interface("nsIPermissionManager") }}</td> <td>Permission Manager service</td> </tr> <tr> <td><code>prefs</code></td> <td>{{ interface("nsIPrefService") }}</td> <td>Preferences service</td> </tr> <tr> <td><code>prompt<br> </code></td> <td>{{ interface("nsIPromptService") }}</td> <td>Prompt service</td> </tr> <tr> <td><code>scriptloader<br> </code></td> <td>{{ interface("mozIJSSubScriptLoader") }}</td> <td>JavaScript subscript loader service</td> </tr> <tr> <td><code>search<br> </code></td> <td>{{ interface("nsIBrowserSearchService") }}</td> <td>Browser search service</td> </tr> <tr> <td><code>storage<br> </code></td> <td>{{ interface("mozIStorageService") }}</td> <td><a href="/en/Storage" title="en/Storage">Storage API</a> service</td> </tr> <tr> <td><code>tm<br> </code></td> <td>{{ interface("nsIThreadManager") }}</td> <td><a href="/en/The_Thread_Manager" title="en/The Thread Manager">Thread Manager</a> service.</td> </tr> <tr> <td><code>vc<br> </code></td> <td>{{ interface("nsIVersionComparator") }}</td> <td>Version comparator service</td> </tr> <tr> <td><code>wm<br> </code></td> <td>{{ interface("nsIWindowMediator") }}</td> <td>Window mediator service</td> </tr> <tr> <td><code>ww<br> </code></td> <td>{{ interface("nsIWindowWatcher") }}</td> <td>Window watcher service</td> </tr> </tbody>
</table>
<h2>See also</h2>
<ul> <li><a class="internal" href="/en/JavaScript_code_modules/Using_JavaScript_code_modules" title="en/JavaScript code modules/Using
    JavaScript code
    modules">Using JavaScript code modules</a></li> <li><a class="internal" href="/en/JavaScript_code_modules" title="en/JavaScript code
    modules">JavaScript code modules</a></li>
</ul>
Revert to this revision