OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 chrome.runtime.onMessageExternal.addListener( | 5 chrome.runtime.onMessageExternal.addListener( |
6 function(message, sender, sendResponse) { | 6 function(message, sender, sendResponse) { |
7 function doSendResponse(value, error) { | 7 function doSendResponse(value, error) { |
8 var errorMessage = error || chrome.extension.lastError; | 8 var errorMessage = error || chrome.extension.lastError; |
9 sendResponse({'value': value, 'error': errorMessage}); | 9 sendResponse({'value': value, 'error': errorMessage}); |
10 } | 10 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return false; | 68 return false; |
69 } else if (method == 'logging.stop') { | 69 } else if (method == 'logging.stop') { |
70 chrome.webrtcLoggingPrivate.stop( | 70 chrome.webrtcLoggingPrivate.stop( |
71 sender.tab.id, origin, doSendResponse); | 71 sender.tab.id, origin, doSendResponse); |
72 return true; | 72 return true; |
73 } else if (method == 'logging.upload') { | 73 } else if (method == 'logging.upload') { |
74 chrome.webrtcLoggingPrivate.upload( | 74 chrome.webrtcLoggingPrivate.upload( |
75 sender.tab.id, origin, doSendResponse); | 75 sender.tab.id, origin, doSendResponse); |
76 return true; | 76 return true; |
77 } else if (method == 'logging.stopAndUpload') { | 77 } else if (method == 'logging.stopAndUpload') { |
78 stopAllRtpDump(sender.tab.id, origin, function() { | 78 chrome.webrtcLoggingPrivate.stop(sender.tab.id, origin, function() { |
79 chrome.webrtcLoggingPrivate.stop(sender.tab.id, origin, function() { | 79 chrome.webrtcLoggingPrivate.upload( |
80 chrome.webrtcLoggingPrivate.upload( | 80 sender.tab.id, origin, doSendResponse); |
81 sender.tab.id, origin, doSendResponse); | |
82 }); | |
83 }); | 81 }); |
84 return true; | 82 return true; |
85 } else if (method == 'logging.discard') { | 83 } else if (method == 'logging.discard') { |
86 chrome.webrtcLoggingPrivate.discard( | 84 chrome.webrtcLoggingPrivate.discard( |
87 sender.tab.id, origin, doSendResponse); | 85 sender.tab.id, origin, doSendResponse); |
88 return true; | 86 return true; |
89 } else if (method == 'getSinks') { | 87 } else if (method == 'getSinks') { |
90 chrome.webrtcAudioPrivate.getSinks(doSendResponse); | 88 chrome.webrtcAudioPrivate.getSinks(doSendResponse); |
91 return true; | 89 return true; |
92 } else if (method == 'getActiveSink') { | 90 } else if (method == 'getActiveSink') { |
(...skipping 17 matching lines...) Expand all Loading... |
110 // check if it's loaded; if it's not, the extension system will | 108 // check if it's loaded; if it's not, the extension system will |
111 // call the callback with no arguments and set | 109 // call the callback with no arguments and set |
112 // chrome.runtime.lastError. | 110 // chrome.runtime.lastError. |
113 doSendResponse(); | 111 doSendResponse(); |
114 return false; | 112 return false; |
115 } else if (method == 'getNaclArchitecture') { | 113 } else if (method == 'getNaclArchitecture') { |
116 chrome.runtime.getPlatformInfo(function(obj) { | 114 chrome.runtime.getPlatformInfo(function(obj) { |
117 doSendResponse(obj.nacl_arch); | 115 doSendResponse(obj.nacl_arch); |
118 }); | 116 }); |
119 return true; | 117 return true; |
120 } else if (method == 'logging.startRtpDump') { | |
121 var incoming = message['incoming'] || false; | |
122 var outgoing = message['outgoing'] || false; | |
123 chrome.webrtcLoggingPrivate.startRtpDump( | |
124 sender.tab.id, origin, incoming, outgoing, doSendResponse); | |
125 return true; | |
126 } else if (method == 'logging.stopRtpDump') { | |
127 var incoming = message['incoming'] || false; | |
128 var outgoing = message['outgoing'] || false; | |
129 chrome.webrtcLoggingPrivate.stopRtpDump( | |
130 sender.tab.id, origin, incoming, outgoing, doSendResponse); | |
131 return true; | |
132 } | 118 } |
133 throw new Error('Unknown method: ' + method); | 119 throw new Error('Unknown method: ' + method); |
134 } catch (e) { | 120 } catch (e) { |
135 doSendResponse(null, e.name + ': ' + e.message); | 121 doSendResponse(null, e.name + ': ' + e.message); |
136 } | 122 } |
137 } | 123 } |
138 ); | 124 ); |
139 | 125 |
140 // If Hangouts connects with a port named 'onSinksChangedListener', we | 126 // If Hangouts connects with a port named 'onSinksChangedListener', we |
141 // will register a listener and send it a message {'eventName': | 127 // will register a listener and send it a message {'eventName': |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 'pluginCpuUsage': pluginProcessCpu | 201 'pluginCpuUsage': pluginProcessCpu |
216 }); | 202 }); |
217 } | 203 } |
218 | 204 |
219 chrome.processes.onUpdated.addListener(processListener); | 205 chrome.processes.onUpdated.addListener(processListener); |
220 port.onDisconnect.addListener(function() { | 206 port.onDisconnect.addListener(function() { |
221 chrome.processes.onUpdated.removeListener(processListener); | 207 chrome.processes.onUpdated.removeListener(processListener); |
222 }); | 208 }); |
223 } | 209 } |
224 | 210 |
225 function stopAllRtpDump(tabId, origin, callback) { | |
226 // Stops incoming and outgoing separately, otherwise stopRtpDump will fail if | |
227 // either type of dump has not been started. | |
228 chrome.webrtcLoggingPrivate.stopRtpDump( | |
229 tabId, origin, true, false, | |
230 function() { | |
231 chrome.webrtcLoggingPrivate.stopRtpDump( | |
232 tabId, origin, false, true, callback); | |
233 }); | |
234 } | |
235 | |
236 chrome.runtime.onConnectExternal.addListener(function(port) { | 211 chrome.runtime.onConnectExternal.addListener(function(port) { |
237 if (port.name == 'onSinksChangedListener') { | 212 if (port.name == 'onSinksChangedListener') { |
238 onSinksChangedPort(port); | 213 onSinksChangedPort(port); |
239 } else if (port.name == 'chooseDesktopMedia') { | 214 } else if (port.name == 'chooseDesktopMedia') { |
240 onChooseDesktopMediaPort(port); | 215 onChooseDesktopMediaPort(port); |
241 } else if (port.name == 'processCpu') { | 216 } else if (port.name == 'processCpu') { |
242 onProcessCpu(port); | 217 onProcessCpu(port); |
243 } else { | 218 } else { |
244 // Unknown port type. | 219 // Unknown port type. |
245 port.disconnect(); | 220 port.disconnect(); |
246 } | 221 } |
247 }); | 222 }); |
OLD | NEW |