Chromium Code Reviews| 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..7544d35a95fcf35ddfca933facf9a28419357782 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)) { |
|
Dan Beam
2014/09/24 04:58:27
nit: if (!tab.incognito && hotwordState.available)
Anand Mistry (off Chromium)
2014/09/24 06:32:40
Done.
|
| + 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; |