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

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: Add test. 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
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..0971391a91bf4c07bd54c9eea05c95792792651d 100644
--- a/chrome/browser/resources/hotword_helper/manager.js
+++ b/chrome/browser/resources/hotword_helper/manager.js
@@ -32,6 +32,14 @@ OptInManager.HOTWORD_EXTENSION_ID_ = 'bepbmhgboaologfdajaanbcjmnhjmhfn';
/**
+ * Test extension ID.
+ * @const {string}
+ * @private
+ */
+OptInManager.TEST_EXTENSION_ID_ = 'cpfhkdbjfdgdebcjlifoldbijinjfifp';
+
+
+/**
* Commands sent from the page to this content script.
* @enum {string}
*/
@@ -58,19 +66,27 @@ OptInManager.CommandFromPage = {
*/
OptInManager.prototype.injectTab_ = function(
tab, sendResponse, hotwordStatus) {
- if (tab.incognito || !hotwordStatus.available) {
- sendResponse({'doNotShowOptinMessage': true});
- return;
- }
-
- if (!hotwordStatus.enabledSet) {
- sendResponse(hotwordStatus);
- return;
- }
+ var response = {'doNotShowOptinMessage': true};
- if (hotwordStatus.enabled)
+ if (tab.incognito || !hotwordStatus.available)
+ response = {'doNotShowOptinMessage': true};
Dan Beam 2014/09/24 01:37:35 how's this different from what |response| already
Anand Mistry (off Chromium) 2014/09/24 03:44:12 Oops. Just translated that part blindly.
+ else if (!hotwordStatus.enabledSet)
+ response = hotwordStatus;
+ else if (hotwordStatus.enabled)
chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
- sendResponse({'doNotShowOptinMessage': true});
+
+ try {
+ sendResponse(response);
+ } 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')
+ return;
+ throw err;
+ }
};
@@ -88,11 +104,13 @@ OptInManager.prototype.handleMessage_ = function(
switch (request.type) {
case OptInManager.CommandFromPage.PAGE_WAKEUP:
if (((sender.tab && this.isEligibleUrl(sender.tab.url)) ||
- sender.id == OptInManager.HOTWORD_EXTENSION_ID_) &&
+ sender.id == OptInManager.HOTWORD_EXTENSION_ID_ ||
+ sender.id == OptInManager.TEST_EXTENSION_ID_) &&
chrome.hotwordPrivate && chrome.hotwordPrivate.getStatus) {
chrome.hotwordPrivate.getStatus(
- this.injectTab_.bind(this, request.tab || sender.tab,
- sendResponse));
+ this.injectTab_.bind(
+ this, request.tab || sender.tab || {incognito: true},
+ sendResponse));
Dan Beam 2014/09/24 01:37:35 nit: chrome.hotwordPrivate.getStatus(this.injec
Anand Mistry (off Chromium) 2014/09/24 03:44:12 Done.
return true;
}
break;

Powered by Google App Engine
This is Rietveld 408576698