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 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | const Cc = Components.classes; |
michael@0 | 8 | const Ci = Components.interfaces; |
michael@0 | 9 | |
michael@0 | 10 | const CATEGORY_WAKEUP_REQUEST = "wakeup-request"; |
michael@0 | 11 | |
michael@0 | 12 | function MessageWakeupService() { }; |
michael@0 | 13 | |
michael@0 | 14 | MessageWakeupService.prototype = |
michael@0 | 15 | { |
michael@0 | 16 | classID: Components.ID("{f9798742-4f7b-4188-86ba-48b116412b29}"), |
michael@0 | 17 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), |
michael@0 | 18 | |
michael@0 | 19 | messagesData: [], |
michael@0 | 20 | |
michael@0 | 21 | get messageManager() { |
michael@0 | 22 | if (!this._messageManager) |
michael@0 | 23 | this._messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]. |
michael@0 | 24 | getService(Ci.nsIMessageListenerManager); |
michael@0 | 25 | return this._messageManager; |
michael@0 | 26 | }, |
michael@0 | 27 | |
michael@0 | 28 | requestWakeup: function(aMessageName, aCid, aIid, aMethod) { |
michael@0 | 29 | this.messagesData[aMessageName] = { |
michael@0 | 30 | cid: aCid, |
michael@0 | 31 | iid: aIid, |
michael@0 | 32 | method: aMethod, |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | this.messageManager.addMessageListener(aMessageName, this); |
michael@0 | 36 | }, |
michael@0 | 37 | |
michael@0 | 38 | receiveMessage: function(aMessage) { |
michael@0 | 39 | let data = this.messagesData[aMessage.name]; |
michael@0 | 40 | // TODO: When bug 593407 is ready, stop doing the wrappedJSObject hack |
michael@0 | 41 | // and use this line instead: |
michael@0 | 42 | // QueryInterface(Ci.nsIMessageListener); |
michael@0 | 43 | let service = Cc[data.cid][data.method](Ci[data.iid]). |
michael@0 | 44 | wrappedJSObject; |
michael@0 | 45 | |
michael@0 | 46 | // The receiveMessage() call itself may spin an event loop, and we |
michael@0 | 47 | // do not want to swap listeners in that - it would cause the current |
michael@0 | 48 | // message to be answered by two listeners. So, we call that first, |
michael@0 | 49 | // then queue the swap for the next event loop |
michael@0 | 50 | let ret = service.receiveMessage(aMessage); |
michael@0 | 51 | |
michael@0 | 52 | if (data.timer) { |
michael@0 | 53 | // Handle the case of two such messages happening in quick succession |
michael@0 | 54 | data.timer.cancel(); |
michael@0 | 55 | data.timer = null; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | data.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
michael@0 | 59 | let self = this; |
michael@0 | 60 | data.timer.initWithCallback(function() { |
michael@0 | 61 | self.messageManager.addMessageListener(aMessage.name, service); |
michael@0 | 62 | self.messageManager.removeMessageListener(aMessage.name, self); |
michael@0 | 63 | delete self.messagesData[aMessage.name]; |
michael@0 | 64 | }, 0, Ci.nsITimer.TYPE_ONE_SHOT); |
michael@0 | 65 | |
michael@0 | 66 | return ret; |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | observe: function TM_observe(aSubject, aTopic, aData) { |
michael@0 | 70 | switch (aTopic) { |
michael@0 | 71 | case "profile-after-change": |
michael@0 | 72 | { |
michael@0 | 73 | var catMan = Cc["@mozilla.org/categorymanager;1"]. |
michael@0 | 74 | getService(Ci.nsICategoryManager); |
michael@0 | 75 | var entries = catMan.enumerateCategory(CATEGORY_WAKEUP_REQUEST); |
michael@0 | 76 | while (entries.hasMoreElements()) { |
michael@0 | 77 | var entry = entries.getNext().QueryInterface(Ci.nsISupportsCString).data; |
michael@0 | 78 | var value = catMan.getCategoryEntry(CATEGORY_WAKEUP_REQUEST, entry); |
michael@0 | 79 | var parts = value.split(","); |
michael@0 | 80 | var cid = parts[0]; |
michael@0 | 81 | var iid = parts[1]; |
michael@0 | 82 | var method = parts[2]; |
michael@0 | 83 | var messages = parts.slice(3); |
michael@0 | 84 | messages.forEach(function(messageName) { |
michael@0 | 85 | this.requestWakeup(messageName, cid, iid, method); |
michael@0 | 86 | }, this); |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | break; |
michael@0 | 90 | } |
michael@0 | 91 | }, |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | var components = [MessageWakeupService]; |
michael@0 | 95 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); |
michael@0 | 96 |