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

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: Fix typo. 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..edaecaef6c9b7fa30f9d77664b49f373120ee5b6 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;
- }
+ var response = {'doNotShowOptinMessage': true};
- if (!hotwordStatus.enabledSet) {
- sendResponse(hotwordStatus);
- return;
+ if (!tab.incognito && hotwordStatus.available) {
+ if (!hotwordStatus.enabledSet)
+ response = hotwordStatus;
+ else if (hotwordStatus.enabled)
+ chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
}
- 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,14 @@ 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));
return true;
}
break;
« no previous file with comments | « chrome/browser/extensions/hotword_browsertest.cc ('k') | chrome/browser/resources/hotword_helper/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698