1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
2 /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
10 * This code exists to be a "grab bag" of global code that needs to be
11 * loaded per B2G process, but doesn't need to directly interact with
14 * (It's written as an XPCOM service because it needs to watch
18 const Cc = Components.classes;
19 const Ci = Components.interfaces;
20 const Cu = Components.utils;
22 Cu.import('resource://gre/modules/Services.jsm');
23 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
25 // Preloading the CSP jsm in this process early on.
26 Cu.import("resource://gre/modules/CSPUtils.jsm");
32 // This file implements console.log(), so use dump().
33 //dump('ProcessGlobal: ' + msg + '\n');
36 function ProcessGlobal() {}
37 ProcessGlobal.prototype = {
38 classID: Components.ID('{1a94c87a-5ece-4d11-91e1-d29c29f21b28}'),
39 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
40 Ci.nsISupportsWeakReference]),
42 observe: function pg_observe(subject, topic, data) {
45 Services.obs.addObserver(this, 'console-api-log-event', false);
48 case 'console-api-log-event': {
49 // Pipe `console` log messages to the nsIConsoleService which
50 // writes them to logcat on Gonk.
51 let message = subject.wrappedJSObject;
52 let prefix = ('Content JS ' + message.level.toUpperCase() +
53 ' at ' + message.filename + ':' + message.lineNumber +
54 ' in ' + (message.functionName || 'anonymous') + ': ');
55 Services.console.logStringMessage(prefix + Array.join(message.arguments,
63 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ProcessGlobal]);