Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: chrome/browser/resources/hotword_helper/manager.js

Issue 587153002: Suppress the exception thrown when responding to message with no response callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comment. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
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: chrome/browser/resources/hotword_helper/manager.js
diff --git a/chrome/browser/resources/hotword_helper/manager.js b/chrome/browser/resources/hotword_helper/manager.js
index 4ce86db62959d7fb42ade923a8d80fb11daa24f2..03739fa64d68950ce5b6f5eea424db448a67d68b 100644
--- a/chrome/browser/resources/hotword_helper/manager.js
+++ b/chrome/browser/resources/hotword_helper/manager.js
@@ -58,19 +58,30 @@ OptInManager.CommandFromPage = {
*/
OptInManager.prototype.injectTab_ = function(
tab, sendResponse, hotwordStatus) {
- if (tab.incognito || !hotwordStatus.available) {
- sendResponse({'doNotShowOptinMessage': true});
- return;
- }
+ try {
Dan Beam 2014/09/23 04:14:00 nit: if sendReponse() is what throws, i'd think it
Anand Mistry (off Chromium) 2014/09/24 01:11:40 Done.
+ if (tab.incognito || !hotwordStatus.available) {
+ sendResponse({'doNotShowOptinMessage': true});
+ return;
+ }
- if (!hotwordStatus.enabledSet) {
- sendResponse(hotwordStatus);
- return;
- }
+ if (!hotwordStatus.enabledSet) {
+ sendResponse(hotwordStatus);
+ return;
+ }
- if (hotwordStatus.enabled)
- chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
- sendResponse({'doNotShowOptinMessage': true});
+ if (hotwordStatus.enabled)
+ chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
Dan Beam 2014/09/23 04:14:00 nit: \n
Anand Mistry (off Chromium) 2014/09/24 01:11:41 Done.
+ sendResponse({'doNotShowOptinMessage': true});
+ } catch (err) {
+ // Suppress the exception thrown by sendResponse() when the page doesn't
+ // specify a response callback in the call to chrome.runtime.sendMessage().
+ // Unfortunately, there doesn't appear to be a way to detect one-way
+ // messages without explicitly saying in the message itself. This message
+ // is defined as a constant in extensions/renderer/messaging_bindings.cc
+ if (err.message == 'Attempting to use a disconnected port object')
Dan Beam 2014/09/23 04:14:00 can you write a test that exercises this case? (so
Anand Mistry (off Chromium) 2014/09/24 01:11:41 I've given it a shot.
+ return;
+ throw err;
+ }
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698