Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / webrtc_desktop_capture_private_custom_bindings.js
blobce2fbf853c535c97873d4014e018930d65cb0432
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
3 // found in the LICENSE file.
5 // Custom binding for the webrtcDesktopCapturePrivate API.
7 var binding = require('binding').Binding.create('webrtcDesktopCapturePrivate');
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];
20       callback(result);
21     }
22   }
24   apiFunctions.setHandleRequest('chooseDesktopMedia',
25                                 function(sources, request, callback) {
26     var id = idGenerator.GetNextId();
27     pendingRequests[id] = callback;
28     sendRequest(this.name,
29                 [id, sources, request, onRequestResult.bind(null, id)],
30                 this.definition.parameters, {});
31     return id;
32   });
34   apiFunctions.setHandleRequest('cancelChooseDesktopMedia', function(id) {
35     if (id in pendingRequests) {
36       delete pendingRequests[id];
37       sendRequest(this.name, [id], this.definition.parameters, {});
38     }
39   });
40 });
42 exports.binding = binding.generate();