| Left: | ||
| Right: |
| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 var sent = false; | 42 var sent = false; |
| 43 var sendResponse = function(message) | 43 var sendResponse = function(message) |
| 44 { | 44 { |
| 45 this._sendResponse(request, message); | 45 this._sendResponse(request, message); |
| 46 sent = true; | 46 sent = true; |
| 47 }.bind(this); | 47 }.bind(this); |
| 48 | 48 |
| 49 var results = ext.onMessage._dispatch(request.payload, sender, sendRespo nse); | 49 var results = ext.onMessage._dispatch(request.payload, sender, sendRespo nse); |
| 50 | 50 |
| 51 // The onMessage listener has to return true to indicate that a response | 51 // The onMessage listener has to return true to indicate that a response |
| 52 // is sent later asynchronously. Otherwise if no response were sent yet, | 52 // is sent later asynchronously. Otherwise if no response was sent yet, |
|
Sebastian Noack
2015/01/08 14:36:13
Done.
| |
| 53 // we sent a response indicating that there is no response, that | 53 // we sent a response indicating that there is no response, that |
| 54 // the other end, can remove the callback and doesn't leak memory. | 54 // the other end can remove the callback and doesn't leak memory. |
| 55 if (!sent && results.indexOf(true) != -1) | 55 if (!sent && results.indexOf(true) == -1) |
|
Wladimir Palant
2015/01/08 14:28:19
Shouldn't this be .indexOf(true) == -1?
| |
| 56 this._sendResponse(request, null); | 56 this._sendResponse(request, undefined); |
|
Wladimir Palant
2015/01/08 14:28:19
I'd rather go with undefined here, that's what the
| |
| 57 } | 57 } |
| 58 else | 58 else |
| 59 { | 59 { |
| 60 ext.onMessage._dispatch(request.payload, sender, function() {}); | 60 ext.onMessage._dispatch(request.payload, sender, function() {}); |
| 61 } | 61 } |
| 62 }, | 62 }, |
| 63 handleResponse: function(response) | 63 handleResponse: function(response) |
| 64 { | 64 { |
| 65 var callbackId = response.callbackId; | 65 var callbackId = response.callbackId; |
| 66 var callback = this._responseCallbacks[callbackId]; | 66 var callback = this._responseCallbacks[callbackId]; |
| 67 if (callback) | 67 if (callback) |
| 68 { | 68 { |
| 69 delete this._responseCallbacks[callbackId]; | 69 delete this._responseCallbacks[callbackId]; |
| 70 | 70 |
| 71 if (response.payload !== null) | 71 if (typeof response.payload != "undefined") |
| 72 callback(response.payload); | 72 callback(response.payload); |
| 73 } | 73 } |
| 74 }, | 74 }, |
| 75 sendMessage: function(message, responseCallback, extra) | 75 sendMessage: function(message, responseCallback, extra) |
| 76 { | 76 { |
| 77 var request = {payload: message}; | 77 var request = {payload: message}; |
| 78 | 78 |
| 79 if (responseCallback) | 79 if (responseCallback) |
| 80 { | 80 { |
| 81 request.callbackId = ++this._responseCallbackCounter; | 81 request.callbackId = ++this._responseCallbackCounter; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 | 213 |
| 214 /* Utils */ | 214 /* Utils */ |
| 215 | 215 |
| 216 ext.getURL = function(path) | 216 ext.getURL = function(path) |
| 217 { | 217 { |
| 218 return safari.extension.baseURI + path; | 218 return safari.extension.baseURI + path; |
| 219 }; | 219 }; |
| 220 })(); | 220 })(); |
| LEFT | RIGHT |