Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview This extension manages communications between Chrome, | 8 * @fileoverview This extension manages communications between Chrome, |
| 9 * Google.com pages and the Chrome Hotword extension. | 9 * Google.com pages and the Chrome Hotword extension. |
| 10 * | 10 * |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @param {Tab} tab Tab to inject. | 53 * @param {Tab} tab Tab to inject. |
| 54 * @param {function(HotwordStatus)} sendResponse Callback function to respond | 54 * @param {function(HotwordStatus)} sendResponse Callback function to respond |
| 55 * to sender. | 55 * to sender. |
| 56 * @param {HotwordStatus} hotwordStatus Status of the hotword extension. | 56 * @param {HotwordStatus} hotwordStatus Status of the hotword extension. |
| 57 * @private | 57 * @private |
| 58 */ | 58 */ |
| 59 OptInManager.prototype.injectTab_ = function( | 59 OptInManager.prototype.injectTab_ = function( |
| 60 tab, sendResponse, hotwordStatus) { | 60 tab, sendResponse, hotwordStatus) { |
| 61 if (tab.incognito || !hotwordStatus.available) { | 61 try { |
| 62 if (tab.incognito || !hotwordStatus.available) { | |
| 63 sendResponse({'doNotShowOptinMessage': true}); | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 if (!hotwordStatus.enabledSet) { | |
| 68 sendResponse(hotwordStatus); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 if (hotwordStatus.enabled) | |
| 73 chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'}); | |
| 62 sendResponse({'doNotShowOptinMessage': true}); | 74 sendResponse({'doNotShowOptinMessage': true}); |
| 63 return; | 75 } catch (err) { |
| 76 // Suppress the exception thrown when the page doesn't specify a response | |
| 77 // callback. Unfortunately, there doesn't appear to be a way to detect | |
| 78 // one-way messages without explicitly saying in the message itself. | |
| 79 if (err.message == 'Attempting to use a disconnected port object') | |
|
rpetterson
2014/09/22 23:04:41
Weird question, but is this always going to be in
Anand Mistry (off Chromium)
2014/09/22 23:50:43
It's an untranslated constant in https://code.goog
rpetterson
2014/09/22 23:53:03
Understood. Please add a note to the comment listi
Anand Mistry (off Chromium)
2014/09/23 00:31:30
Done.
| |
| 80 return; | |
| 81 throw err; | |
| 64 } | 82 } |
| 65 | |
| 66 if (!hotwordStatus.enabledSet) { | |
| 67 sendResponse(hotwordStatus); | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 if (hotwordStatus.enabled) | |
| 72 chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'}); | |
| 73 sendResponse({'doNotShowOptinMessage': true}); | |
| 74 }; | 83 }; |
| 75 | 84 |
| 76 | 85 |
| 77 /** | 86 /** |
| 78 * Handles messages from the helper content script. | 87 * Handles messages from the helper content script. |
| 79 * @param {*} request Message from the sender. | 88 * @param {*} request Message from the sender. |
| 80 * @param {MessageSender} sender Information about the sender. | 89 * @param {MessageSender} sender Information about the sender. |
| 81 * @param {function(HotwordStatus)} sendResponse Callback function to respond | 90 * @param {function(HotwordStatus)} sendResponse Callback function to respond |
| 82 * to sender. | 91 * to sender. |
| 83 * @return {boolean} Whether to maintain the port open to call sendResponse. | 92 * @return {boolean} Whether to maintain the port open to call sendResponse. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 // TODO(rlp): Possibly remove the next line. It's proably not used, but | 213 // TODO(rlp): Possibly remove the next line. It's proably not used, but |
| 205 // leaving for now to be safe. We should remove it once all messsage | 214 // leaving for now to be safe. We should remove it once all messsage |
| 206 // relaying is removed form the content scripts. | 215 // relaying is removed form the content scripts. |
| 207 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); | 216 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); |
| 208 chrome.runtime.onMessageExternal.addListener( | 217 chrome.runtime.onMessageExternal.addListener( |
| 209 this.handleMessage_.bind(this)); | 218 this.handleMessage_.bind(this)); |
| 210 }; | 219 }; |
| 211 | 220 |
| 212 | 221 |
| 213 new OptInManager().initialize(); | 222 new OptInManager().initialize(); |
| OLD | NEW |