Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / tabs_custom_bindings.js
blobb6501466ea8368bc38503ed6a46db4469b1c7142
1 // Copyright (c) 2012 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 tabs API.
7 var binding = require('binding').Binding.create('tabs');
9 var messaging = require('messaging');
10 var tabsNatives = requireNative('tabs');
11 var OpenChannelToTab = tabsNatives.OpenChannelToTab;
12 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled();
14 binding.registerCustomHook(function(bindingsAPI, extensionId) {
15   var apiFunctions = bindingsAPI.apiFunctions;
16   var tabs = bindingsAPI.compiledApi;
18   apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) {
19     var name = '';
20     if (connectInfo) {
21       name = connectInfo.name || name;
22     }
23     var portId = OpenChannelToTab(tabId, extensionId, name);
24     return messaging.createPort(portId, name);
25   });
27   apiFunctions.setHandleRequest('sendRequest',
28                                 function(tabId, request, responseCallback) {
29     if (sendRequestIsDisabled)
30       throw new Error(sendRequestIsDisabled);
31     var port = tabs.connect(tabId, {name: messaging.kRequestChannel});
32     messaging.sendMessageImpl(port, request, responseCallback);
33   });
35   apiFunctions.setHandleRequest('sendMessage',
36                                 function(tabId, message, responseCallback) {
37     var port = tabs.connect(tabId, {name: messaging.kMessageChannel});
38     messaging.sendMessageImpl(port, message, responseCallback);
39   });
40 });
42 exports.binding = binding.generate();