Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / |
michael@0 | 2 | /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | 'use strict'; |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * This code exists to be a "grab bag" of global code that needs to be |
michael@0 | 11 | * loaded per B2G process, but doesn't need to directly interact with |
michael@0 | 12 | * web content. |
michael@0 | 13 | * |
michael@0 | 14 | * (It's written as an XPCOM service because it needs to watch |
michael@0 | 15 | * app-startup.) |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | const Cc = Components.classes; |
michael@0 | 19 | const Ci = Components.interfaces; |
michael@0 | 20 | const Cu = Components.utils; |
michael@0 | 21 | |
michael@0 | 22 | Cu.import('resource://gre/modules/Services.jsm'); |
michael@0 | 23 | Cu.import('resource://gre/modules/XPCOMUtils.jsm'); |
michael@0 | 24 | |
michael@0 | 25 | // Preloading the CSP jsm in this process early on. |
michael@0 | 26 | Cu.import("resource://gre/modules/CSPUtils.jsm"); |
michael@0 | 27 | |
michael@0 | 28 | function debug(msg) { |
michael@0 | 29 | log(msg); |
michael@0 | 30 | } |
michael@0 | 31 | function log(msg) { |
michael@0 | 32 | // This file implements console.log(), so use dump(). |
michael@0 | 33 | //dump('ProcessGlobal: ' + msg + '\n'); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function ProcessGlobal() {} |
michael@0 | 37 | ProcessGlobal.prototype = { |
michael@0 | 38 | classID: Components.ID('{1a94c87a-5ece-4d11-91e1-d29c29f21b28}'), |
michael@0 | 39 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, |
michael@0 | 40 | Ci.nsISupportsWeakReference]), |
michael@0 | 41 | |
michael@0 | 42 | observe: function pg_observe(subject, topic, data) { |
michael@0 | 43 | switch (topic) { |
michael@0 | 44 | case 'app-startup': { |
michael@0 | 45 | Services.obs.addObserver(this, 'console-api-log-event', false); |
michael@0 | 46 | break; |
michael@0 | 47 | } |
michael@0 | 48 | case 'console-api-log-event': { |
michael@0 | 49 | // Pipe `console` log messages to the nsIConsoleService which |
michael@0 | 50 | // writes them to logcat on Gonk. |
michael@0 | 51 | let message = subject.wrappedJSObject; |
michael@0 | 52 | let prefix = ('Content JS ' + message.level.toUpperCase() + |
michael@0 | 53 | ' at ' + message.filename + ':' + message.lineNumber + |
michael@0 | 54 | ' in ' + (message.functionName || 'anonymous') + ': '); |
michael@0 | 55 | Services.console.logStringMessage(prefix + Array.join(message.arguments, |
michael@0 | 56 | ' ')); |
michael@0 | 57 | break; |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | }, |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ProcessGlobal]); |