| 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;
|
|
|