OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Custom binding for the Display Source API. | 5 // Custom binding for the Display Source API. |
6 | 6 |
7 var binding = require('binding').Binding.create('displaySource'); | 7 var binding = require('binding').Binding.create('displaySource'); |
8 var chrome = requireNative('chrome').GetChrome(); | 8 var chrome = requireNative('chrome').GetChrome(); |
9 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
10 var natives = requireNative('display_source'); | 10 var natives = requireNative('display_source'); |
11 | 11 |
12 binding.registerCustomHook(function(bindingsAPI, extensionId) { | 12 binding.registerCustomHook(function(bindingsAPI, extensionId) { |
13 var apiFunctions = bindingsAPI.apiFunctions; | 13 var apiFunctions = bindingsAPI.apiFunctions; |
14 apiFunctions.setHandleRequest('startSession', | 14 apiFunctions.setHandleRequest( |
15 function(sessionInfo, callback) { | 15 'startSession', function(sessionInfo, callback) { |
16 function callbackWrapper(message) { | |
17 if (callback === undefined) | |
18 return; | |
19 | |
20 try { | |
21 if (message !== null) | |
22 lastError.set( | |
23 'displaySource.startSession', message, null, chrome); | |
24 callback(); | |
25 } finally { | |
26 lastError.clear(chrome); | |
27 } | |
28 } | |
29 | |
16 try { | 30 try { |
17 natives.StartSession(sessionInfo); | 31 natives.StartSession(sessionInfo, callbackWrapper); |
asargent_no_longer_on_chrome
2016/02/09 00:07:56
Instead of having the callback wrapper handling sp
Mikhail
2016/02/09 14:26:42
I should have a look at this, thanks!
Mikhail
2016/02/10 15:58:51
Done.
| |
18 } catch (e) { | 32 } catch (e) { |
19 lastError.set('displaySource.startSession', e.message, null, chrome); | 33 callbackWrapper(e.message); |
20 } finally { | |
21 if (callback !== undefined) | |
22 callback(); | |
23 lastError.clear(chrome); | |
24 } | 34 } |
25 }); | 35 }); |
26 apiFunctions.setHandleRequest('terminateSession', | 36 apiFunctions.setHandleRequest( |
27 function(sink_id, callback) { | 37 'terminateSession', function(sink_id, callback) { |
38 function callbackWrapper(message) { | |
39 if (callback === undefined) | |
40 return; | |
41 | |
42 try { | |
43 if (message !== null) | |
44 lastError.set( | |
45 'displaySource.terminateSession', message, null, chrome); | |
46 callback(); | |
47 } finally { | |
48 lastError.clear(chrome); | |
49 } | |
50 } | |
51 | |
28 try { | 52 try { |
29 natives.TerminateSession(sink_id); | 53 natives.TerminateSession(sink_id, callbackWrapper); |
30 } catch (e) { | 54 } catch (e) { |
31 lastError.set( | 55 callbackWrapper(e.message); |
32 'displaySource.terminateSession', e.message, null, chrome); | |
33 } finally { | |
34 if (callback !== undefined) | |
35 callback(); | |
36 lastError.clear(chrome); | |
37 } | 56 } |
38 }); | 57 }); |
39 }); | 58 }); |
40 | 59 |
41 exports.$set('binding', binding.generate()); | 60 exports.$set('binding', binding.generate()); |
OLD | NEW |