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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function ChromePowers(window) { |
michael@0 | 6 | this.window = Components.utils.getWeakReference(window); |
michael@0 | 7 | |
michael@0 | 8 | // In the case of browser-chrome tests, we are running as a [ChromeWindow] |
michael@0 | 9 | // and we have no window.QueryInterface available, content.window is what we need |
michael@0 | 10 | if (typeof(window) == "ChromeWindow" && typeof(content.window) == "Window") { |
michael@0 | 11 | this.DOMWindowUtils = bindDOMWindowUtils(content.window); |
michael@0 | 12 | this.window = Components.utils.getWeakReference(content.window); |
michael@0 | 13 | } else { |
michael@0 | 14 | this.DOMWindowUtils = bindDOMWindowUtils(window); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | this.spObserver = new SpecialPowersObserverAPI(); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | ChromePowers.prototype = new SpecialPowersAPI(); |
michael@0 | 21 | |
michael@0 | 22 | ChromePowers.prototype.toString = function() { return "[ChromePowers]"; }; |
michael@0 | 23 | ChromePowers.prototype.sanityCheck = function() { return "foo"; }; |
michael@0 | 24 | |
michael@0 | 25 | // This gets filled in in the constructor. |
michael@0 | 26 | ChromePowers.prototype.DOMWindowUtils = undefined; |
michael@0 | 27 | |
michael@0 | 28 | ChromePowers.prototype._sendSyncMessage = function(type, msg) { |
michael@0 | 29 | var aMessage = {'name':type, 'json': msg}; |
michael@0 | 30 | return [this._receiveMessage(aMessage)]; |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | ChromePowers.prototype._sendAsyncMessage = function(type, msg) { |
michael@0 | 34 | var aMessage = {'name':type, 'json': msg}; |
michael@0 | 35 | this._receiveMessage(aMessage); |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | ChromePowers.prototype.registerProcessCrashObservers = function() { |
michael@0 | 39 | this._sendSyncMessage("SPProcessCrashService", { op: "register-observer" }); |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | ChromePowers.prototype.unregisterProcessCrashObservers = function() { |
michael@0 | 43 | this._sendSyncMessage("SPProcessCrashService", { op: "unregister-observer" }); |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | ChromePowers.prototype._receiveMessage = function(aMessage) { |
michael@0 | 47 | switch (aMessage.name) { |
michael@0 | 48 | case "SpecialPowers.Quit": |
michael@0 | 49 | let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); |
michael@0 | 50 | appStartup.quit(Ci.nsIAppStartup.eForceQuit); |
michael@0 | 51 | break; |
michael@0 | 52 | case "SPProcessCrashService": |
michael@0 | 53 | if (aMessage.json.op == "register-observer" || aMessage.json.op == "unregister-observer") { |
michael@0 | 54 | // Hack out register/unregister specifically for browser-chrome leaks |
michael@0 | 55 | break; |
michael@0 | 56 | } else if (aMessage.type == "crash-observed") { |
michael@0 | 57 | for (let e of msg.dumpIDs) { |
michael@0 | 58 | this._encounteredCrashDumpFiles.push(e.id + "." + e.extension); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | default: |
michael@0 | 62 | // All calls go here, because we need to handle SPProcessCrashService calls as well |
michael@0 | 63 | return this.spObserver._receiveMessageAPI(aMessage); |
michael@0 | 64 | } |
michael@0 | 65 | return undefined; // Avoid warning. |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | ChromePowers.prototype.quit = function() { |
michael@0 | 69 | // We come in here as SpecialPowers.quit, but SpecialPowers is really ChromePowers. |
michael@0 | 70 | // For some reason this.<func> resolves to TestRunner, so using SpecialPowers |
michael@0 | 71 | // allows us to use the ChromePowers object which we defined below. |
michael@0 | 72 | SpecialPowers._sendSyncMessage("SpecialPowers.Quit", {}); |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | ChromePowers.prototype.focus = function(aWindow) { |
michael@0 | 76 | // We come in here as SpecialPowers.focus, but SpecialPowers is really ChromePowers. |
michael@0 | 77 | // For some reason this.<func> resolves to TestRunner, so using SpecialPowers |
michael@0 | 78 | // allows us to use the ChromePowers object which we defined below. |
michael@0 | 79 | if (aWindow) |
michael@0 | 80 | aWindow.focus(); |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | ChromePowers.prototype.executeAfterFlushingMessageQueue = function(aCallback) { |
michael@0 | 84 | aCallback(); |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | // Expose everything but internal APIs (starting with underscores) to |
michael@0 | 88 | // web content. We cannot use Object.keys to view SpecialPowers.prototype since |
michael@0 | 89 | // we are using the functions from SpecialPowersAPI.prototype |
michael@0 | 90 | ChromePowers.prototype.__exposedProps__ = {}; |
michael@0 | 91 | for (var i in ChromePowers.prototype) { |
michael@0 | 92 | if (i.charAt(0) != "_") |
michael@0 | 93 | ChromePowers.prototype.__exposedProps__[i] = "r"; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | if ((window.parent !== null) && |
michael@0 | 97 | (window.parent !== undefined) && |
michael@0 | 98 | (window.parent.wrappedJSObject.SpecialPowers) && |
michael@0 | 99 | !(window.wrappedJSObject.SpecialPowers)) { |
michael@0 | 100 | window.wrappedJSObject.SpecialPowers = window.parent.SpecialPowers; |
michael@0 | 101 | } else { |
michael@0 | 102 | window.wrappedJSObject.SpecialPowers = new ChromePowers(window); |
michael@0 | 103 | } |
michael@0 | 104 |