Left: | ||
Right: |
OLD | NEW |
---|---|
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 this._wrappedListeners[idx], | 52 this._wrappedListeners[idx], |
53 this._capture | 53 this._capture |
54 ); | 54 ); |
55 | 55 |
56 this._listeners.splice(idx, 1); | 56 this._listeners.splice(idx, 1); |
57 this._wrappedListeners.splice(idx, 1); | 57 this._wrappedListeners.splice(idx, 1); |
58 } | 58 } |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 | |
63 MessageEventTarget = function(target) | 62 MessageEventTarget = function(target) |
64 { | 63 { |
65 WrappedEventTarget.call(this, target, "message", false); | 64 WrappedEventTarget.call(this, target, "message", false); |
66 }; | 65 }; |
67 MessageEventTarget.prototype = { | 66 MessageEventTarget.prototype = { |
68 __proto__: WrappedEventTarget.prototype, | 67 __proto__: WrappedEventTarget.prototype, |
69 _wrapListener: function(listener) | 68 _wrapListener: function(listener) |
70 { | 69 { |
71 return function(event) | 70 return function(event) |
72 { | 71 { |
73 if (event.name.indexOf("request-") != 0) | 72 if (event.name == "request") |
74 return; | 73 listener(event.message.payload, this._getSenderDetails(event), functio n(message) |
75 | 74 { |
76 var sender = {}; | 75 this._getResponseDispatcher(event).dispatchMessage("response", { |
Felix Dahlke
2014/01/18 13:39:19
{ should go on its own line
Sebastian Noack
2014/01/19 10:19:40
Done.
| |
77 var dispatcher; | 76 requestId: event.message.requestId, |
78 | 77 payload: message |
79 if ("SafariBrowserTab" in window && event.target instanceof SafariBrowse rTab) | 78 }); |
80 { | 79 }.bind(this)); |
81 dispatcher = event.target.page; | 80 }.bind(this); |
82 sender.tab = new Tab(event.target); | |
83 } | |
84 else | |
85 { | |
86 dispatcher = event.target.tab; | |
87 sender.tab = null; | |
88 } | |
89 | |
90 listener(event.message, sender, function(message) | |
91 { | |
92 dispatcher.dispatchMessage("response-" + event.name.substr(8), message ); | |
93 }); | |
94 }; | |
95 } | 81 } |
96 }; | 82 }; |
97 | 83 |
98 | 84 |
99 /* Message passing */ | 85 /* Message passing */ |
100 | 86 |
101 var requestCounter = 0; | 87 var requestCounter = 0; |
102 | 88 |
103 sendMessage = function(message, responseCallback) | 89 _sendMessage = function(message, responseCallback, messageDispatcher, response EventTarget, extra) |
104 { | 90 { |
105 var requestId = ++requestCounter; | 91 var requestId = ++requestCounter; |
106 | 92 |
107 if (responseCallback) | 93 if (responseCallback) |
108 { | 94 { |
109 var eventTarget = this._eventTarget; | |
110 var responseListener = function(event) | 95 var responseListener = function(event) |
111 { | 96 { |
112 if (event.name == "response-" + requestId) | 97 if (event.name == "response" && event.message.requestId == requestId) |
113 { | 98 { |
114 eventTarget.removeEventListener("message", responseListener, false); | 99 responseEventTarget.removeEventListener("message", responseListener, f alse); |
115 responseCallback(event.message); | 100 responseCallback(event.message.payload); |
116 } | 101 } |
117 }; | 102 }; |
118 eventTarget.addEventListener("message", responseListener, false); | 103 responseEventTarget.addEventListener("message", responseListener, false); |
119 } | 104 } |
120 | 105 |
121 this._messageDispatcher.dispatchMessage("request-" + requestId, message); | 106 var rawMessage = {requestId: requestId, payload: message}; |
107 for (var k in extra) | |
108 rawMessage[k] = extra[k]; | |
109 messageDispatcher.dispatchMessage("request", rawMessage); | |
122 }; | 110 }; |
123 | 111 |
124 | 112 |
125 /* I18n */ | 113 /* I18n */ |
126 | 114 |
127 var I18n = function() | 115 var I18n = function() |
128 { | 116 { |
129 this._localeCandidates = this._getLocaleCandidates(); | 117 this._localeCandidates = this._getLocaleCandidates(); |
130 this._uiLocale = this._localeCandidates[0]; | 118 this._uiLocale = this._localeCandidates[0]; |
131 }; | 119 }; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 /* API */ | 208 /* API */ |
221 | 209 |
222 ext = { | 210 ext = { |
223 getURL: function(path) | 211 getURL: function(path) |
224 { | 212 { |
225 return safari.extension.baseURI + path; | 213 return safari.extension.baseURI + path; |
226 }, | 214 }, |
227 i18n: new I18n() | 215 i18n: new I18n() |
228 }; | 216 }; |
229 })(); | 217 })(); |
OLD | NEW |