| LEFT | RIGHT | 
|    1 /* |    1 /* | 
|    2  * This file is part of Adblock Plus <http://adblockplus.org/>, |    2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
|    3  * Copyright (C) 2006-2014 Eyeo GmbH |    3  * Copyright (C) 2006-2014 Eyeo GmbH | 
|    4  * |    4  * | 
|    5  * Adblock Plus is free software: you can redistribute it and/or modify |    5  * Adblock Plus is free software: you can redistribute it and/or modify | 
|    6  * it under the terms of the GNU General Public License version 3 as |    6  * it under the terms of the GNU General Public License version 3 as | 
|    7  * published by the Free Software Foundation. |    7  * published by the Free Software Foundation. | 
|    8  * |    8  * | 
|    9  * Adblock Plus is distributed in the hope that it will be useful, |    9  * Adblock Plus is distributed in the hope that it will be useful, | 
|   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of |   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|   12  * GNU General Public License for more details. |   12  * GNU General Public License for more details. | 
|   13  * |   13  * | 
|   14  * You should have received a copy of the GNU General Public License |   14  * You should have received a copy of the GNU General Public License | 
|   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. |   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
|   16  */ |   16  */ | 
|   17  |   17  | 
|   18 (function(global) |   18 (function(global) | 
|   19 { |   19 { | 
|   20   const Ci = Components.interfaces; |   20   const Ci = Components.interfaces; | 
|   21  |   21  | 
 |   22   if (!global.ext) | 
 |   23     global.ext = {}; | 
 |   24  | 
|   22   var holder = { |   25   var holder = { | 
|   23     get Page() |   26     get Page() | 
|   24     { |   27     { | 
|   25       delete this.Page; |   28       delete this.Page; | 
|   26       this.Page = (typeof require == "function" ? |   29       this.Page = (typeof require == "function" ? | 
|   27           require("ext_background").Page : |   30           require("ext_background").Page : | 
|   28           function() {}); |   31           function() {}); | 
|   29       return this.Page; |   32       return this.Page; | 
|   30     } |   33     } | 
|   31   }; |   34   }; | 
|   32  |   35  | 
|   33   function getSender(origin) |   36   var getSender = global.ext._getSender = function(origin) | 
|   34   { |   37   { | 
|   35     if (origin instanceof Ci.nsIDOMXULElement) |   38     if (origin instanceof Ci.nsIDOMXULElement) | 
|   36       return origin.messageManager; |   39       return origin.messageManager; | 
|   37     else if (origin instanceof Ci.nsIMessageSender) |   40     else if (origin instanceof Ci.nsIMessageSender) | 
|   38       return origin; |   41       return origin; | 
|   39     else |   42     else | 
|   40       return null; |   43       return null; | 
|   41   } |   44   } | 
|   42  |   45  | 
|   43   function MessageProxy(messageManager, messageTarget) |   46   var MessageProxy = global.ext._MessageProxy = function(messageManager, message
     Target) | 
|   44   { |   47   { | 
|   45     this._messageManager = messageManager; |   48     this._messageManager = messageManager; | 
|   46     this._messageTarget = messageTarget; |   49     this._messageTarget = messageTarget; | 
|   47     this._callbacks = new Map(); |   50     this._callbacks = new Map(); | 
|   48     this._responseCallbackCounter = 0; |   51     this._responseCallbackCounter = 0; | 
|   49  |   52  | 
|   50     this._handleRequest = this._handleRequest.bind(this); |   53     this._handleRequest = this._handleRequest.bind(this); | 
|   51     this._handleResponse = this._handleResponse.bind(this); |   54     this._handleResponse = this._handleResponse.bind(this); | 
|   52     this._messageManager.addMessageListener("AdblockPlus:Message", this._handleR
     equest); |   55     this._messageManager.addMessageListener("AdblockPlus:Message", this._handleR
     equest); | 
|   53     this._messageManager.addMessageListener("AdblockPlus:Response", this._handle
     Response); |   56     this._messageManager.addMessageListener("AdblockPlus:Response", this._handle
     Response); | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  114       if (responseCallback) |  117       if (responseCallback) | 
|  115       { |  118       { | 
|  116         request.callbackId = ++this._responseCallbackCounter; |  119         request.callbackId = ++this._responseCallbackCounter; | 
|  117         this._callbacks.set(request.callbackId, responseCallback); |  120         this._callbacks.set(request.callbackId, responseCallback); | 
|  118       } |  121       } | 
|  119  |  122  | 
|  120       this._messageManager.sendAsyncMessage("AdblockPlus:Message", request); |  123       this._messageManager.sendAsyncMessage("AdblockPlus:Message", request); | 
|  121     } |  124     } | 
|  122   }; |  125   }; | 
|  123  |  126  | 
|  124   function EventTarget() |  127   var EventTarget = global.ext._EventTarget = function() | 
|  125   { |  128   { | 
|  126     this._listeners = []; |  129     this._listeners = []; | 
|  127   }; |  130   }; | 
|  128   EventTarget.prototype = { |  131   EventTarget.prototype = { | 
|  129     addListener: function(listener) |  132     addListener: function(listener) | 
|  130     { |  133     { | 
|  131       if (this._listeners.indexOf(listener) == -1) |  134       if (this._listeners.indexOf(listener) == -1) | 
|  132         this._listeners.push(listener); |  135         this._listeners.push(listener); | 
|  133     }, |  136     }, | 
|  134     removeListener: function(listener) |  137     removeListener: function(listener) | 
|  135     { |  138     { | 
|  136       var idx = this._listeners.indexOf(listener); |  139       var idx = this._listeners.indexOf(listener); | 
|  137       if (idx != -1) |  140       if (idx != -1) | 
|  138         this._listeners.splice(idx, 1); |  141         this._listeners.splice(idx, 1); | 
|  139     }, |  142     }, | 
|  140     _dispatch: function() |  143     _dispatch: function() | 
|  141     { |  144     { | 
|  142       var result = null; |  145       var result = null; | 
|  143  |  146  | 
|  144       for (var i = 0; i < this._listeners.length; i++) |  147       for (var i = 0; i < this._listeners.length; i++) | 
|  145         result = this._listeners[i].apply(null, arguments); |  148         result = this._listeners[i].apply(null, arguments); | 
|  146  |  149  | 
|  147       return result; |  150       return result; | 
|  148     } |  151     } | 
|  149   }; |  152   }; | 
|  150  |  153  | 
|  151   if (typeof exports == "object") |  154   if (typeof exports == "object") | 
|  152   { |  155     exports = global.ext; | 
|  153     exports.MessageProxy = MessageProxy; |  | 
|  154     exports.EventTarget = EventTarget; |  | 
|  155     exports.getSender = getSender; |  | 
|  156   } |  | 
|  157   else |  | 
|  158   { |  | 
|  159     if (!global.ext) |  | 
|  160       global.ext = {}; |  | 
|  161     global.ext._MessageProxy = MessageProxy; |  | 
|  162     global.ext._EventTarget = EventTarget; |  | 
|  163   } |  | 
|  164 })(this); |  156 })(this); | 
| LEFT | RIGHT |