summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/resources
diff options
context:
space:
mode:
authorrob <rob@robwu.nl>2016-01-08 16:07:45 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-09 00:08:43 +0000
commit3607f1773518f29bc704daf7de5a89961c2c4730 (patch)
tree2867eec433b247f632eded23186142d0a177aec3 /extensions/renderer/resources
parent0ed4f6567c1b77cea282fac1773dfbaa2ac0c939 (diff)
downloadchromium_src-3607f1773518f29bc704daf7de5a89961c2c4730.zip
chromium_src-3607f1773518f29bc704daf7de5a89961c2c4730.tar.gz
chromium_src-3607f1773518f29bc704daf7de5a89961c2c4730.tar.bz2
Ensure that sendMessage's callback is called.
Also: unchecked errors are now also reported to the extension's console. Unchecked errors were silenced before because the internal disconnect handler accessed chrome.runtime.lastError. BUG=439780 TEST=browser_tests --gtest_filter=ExtensionApiTest.MessagingCrash Review URL: https://codereview.chromium.org/1567423002 Cr-Commit-Position: refs/heads/master@{#368469}
Diffstat (limited to 'extensions/renderer/resources')
-rw-r--r--extensions/renderer/resources/messaging.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js
index a15497d..ef56277 100644
--- a/extensions/renderer/resources/messaging.js
+++ b/extensions/renderer/resources/messaging.js
@@ -335,9 +335,13 @@
return;
}
- // Ensure the callback exists for the older sendRequest API.
- if (!responseCallback)
- responseCallback = function() {};
+ function sendResponseAndClearCallback(response) {
+ // Save a reference so that we don't re-entrantly call responseCallback.
+ var sendResponse = responseCallback;
+ responseCallback = null;
+ sendResponse(response);
+ }
+
// Note: make sure to manually remove the onMessage/onDisconnect listeners
// that we added before destroying the Port, a workaround to a bug in Port
@@ -346,14 +350,27 @@
// http://crbug.com/320723 tracks a sustainable fix.
function disconnectListener() {
- // For onDisconnects, we only notify the callback if there was an error.
- if (chrome.runtime && chrome.runtime.lastError)
- responseCallback();
+ if (!responseCallback)
+ return;
+
+ if (lastError.hasError(chrome)) {
+ sendResponseAndClearCallback();
+ } else {
+ lastError.set(
+ port.name, 'The message port closed before a reponse was received.',
+ null, chrome);
+ try {
+ sendResponseAndClearCallback();
+ } finally {
+ lastError.clear(chrome);
+ }
+ }
}
function messageListener(response) {
try {
- responseCallback(response);
+ if (responseCallback)
+ sendResponseAndClearCallback(response);
} finally {
port.disconnect();
}