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}); |
Dan Beam
2014/09/23 03:35:38
^ which of these lines actually throw?
Anand Mistry (off Chromium)
2014/09/23 03:55:07
In theory, any of these calls to sendResponse() co
| |
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 // This message is defined as a constant in | |
80 // extensions/renderer/messaging_bindings.cc | |
81 if (err.message == 'Attempting to use a disconnected port object') | |
Dan Beam
2014/09/23 03:35:38
does sendResponse() need to be invoked here?
Anand Mistry (off Chromium)
2014/09/23 03:55:07
No. It's the sendResponse() that threw the excepti
| |
82 return; | |
83 throw err; | |
64 } | 84 } |
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 }; | 85 }; |
75 | 86 |
76 | 87 |
77 /** | 88 /** |
78 * Handles messages from the helper content script. | 89 * Handles messages from the helper content script. |
79 * @param {*} request Message from the sender. | 90 * @param {*} request Message from the sender. |
80 * @param {MessageSender} sender Information about the sender. | 91 * @param {MessageSender} sender Information about the sender. |
81 * @param {function(HotwordStatus)} sendResponse Callback function to respond | 92 * @param {function(HotwordStatus)} sendResponse Callback function to respond |
82 * to sender. | 93 * to sender. |
83 * @return {boolean} Whether to maintain the port open to call sendResponse. | 94 * @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 | 215 // 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 | 216 // leaving for now to be safe. We should remove it once all messsage |
206 // relaying is removed form the content scripts. | 217 // relaying is removed form the content scripts. |
207 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); | 218 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); |
208 chrome.runtime.onMessageExternal.addListener( | 219 chrome.runtime.onMessageExternal.addListener( |
209 this.handleMessage_.bind(this)); | 220 this.handleMessage_.bind(this)); |
210 }; | 221 }; |
211 | 222 |
212 | 223 |
213 new OptInManager().initialize(); | 224 new OptInManager().initialize(); |
OLD | NEW |