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
3 // found in the LICENSE file.
5 // Custom binding for the desktopCapture API.
7 var binding
= require('binding').Binding
.create('desktopCapture');
8 var sendRequest
= require('sendRequest').sendRequest
;
9 var idGenerator
= requireNative('id_generator');
11 binding
.registerCustomHook(function(bindingsAPI
) {
12 var apiFunctions
= bindingsAPI
.apiFunctions
;
14 var pendingRequests
= {};
16 function onRequestResult(id
, result
) {
17 if (id
in pendingRequests
) {
18 var callback
= pendingRequests
[id
];
19 delete pendingRequests
[id
];
24 apiFunctions
.setHandleRequest('chooseDesktopMedia',
25 function(sources
, target_tab
, callback
) {
26 // |target_tab| is an optional parameter.
27 if (callback
=== undefined) {
28 callback
= target_tab
;
29 target_tab
= undefined;
31 var id
= idGenerator
.GetNextId();
32 pendingRequests
[id
] = callback
;
33 sendRequest(this.name
,
34 [id
, sources
, target_tab
, onRequestResult
.bind(null, id
)],
35 this.definition
.parameters
, {});
39 apiFunctions
.setHandleRequest('cancelChooseDesktopMedia', function(id
) {
40 if (id
in pendingRequests
) {
41 delete pendingRequests
[id
];
42 sendRequest(this.name
, [id
], this.definition
.parameters
, {});
47 exports
.binding
= binding
.generate();