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