Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: polyfill.js

Issue 29585594: Issue 4579 - Wrap runtime.onMessage (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Oct. 23, 2017, 2:25 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: polyfill.js
===================================================================
--- a/polyfill.js
+++ b/polyfill.js
@@ -120,24 +120,40 @@
{
}
return true;
}
if (shouldWrapAPIs())
{
- // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser" object,
- // but provides the extension API through the "chrome" namespace
+ // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser"
Manish Jethani 2017/10/23 02:32:45 Unrelated, but there's an ESLint error here becaus
+ // object, but provides the extension API through the "chrome" namespace
// (non-standard).
if (typeof browser == "undefined")
window.browser = chrome;
for (let api of asyncAPIs)
wrapAPI(api);
+
+ let {addListener} = browser.runtime.onMessage;
+ browser.runtime.onMessage.addListener = function(listener)
+ {
+ addListener.call(browser.runtime.onMessage, (
+ message, sender, sendResponse
+ ) =>
+ {
+ let wait = listener(message, sender, sendResponse);
+
+ if (wait instanceof Promise)
Manish Jethani 2017/10/23 02:32:45 There's no need to add a catch handler, Chrome (an
Wladimir Palant 2017/10/23 08:53:26 Not really, the message clearly says that not hand
Manish Jethani 2017/10/23 12:21:04 Did you mean that Chrome will no longer do this au
+ wait.then(sendResponse);
+
+ return !!wait;
+ });
+ };
Wladimir Palant 2017/10/23 08:53:26 You have a problem here, removeListener will no lo
Manish Jethani 2017/10/23 12:21:04 Done.
}
// Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
// didn't have iterator support before Chrome 51.
// https://bugs.chromium.org/p/chromium/issues/detail?id=401699
for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
{
if (!(Symbol.iterator in object.prototype))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld