| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 bindings for the tabs API. | 5 // Custom bindings for the tabs API. |
| 6 | 6 |
| 7 var Bindings = require('schema_binding_generator').Bindings; |
| 8 var bindings = new Bindings('tabs'); |
| 9 |
| 7 var tabsNatives = requireNative('tabs'); | 10 var tabsNatives = requireNative('tabs'); |
| 8 var OpenChannelToTab = tabsNatives.OpenChannelToTab; | 11 var OpenChannelToTab = tabsNatives.OpenChannelToTab; |
| 9 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled(); | 12 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled(); |
| 10 | 13 |
| 11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 12 | 15 |
| 13 chromeHidden.registerCustomHook('tabs', function(bindingsAPI, extensionId) { | 16 bindings.registerCustomHook(function(bindingsAPI, extensionId) { |
| 14 var apiFunctions = bindingsAPI.apiFunctions; | 17 var apiFunctions = bindingsAPI.apiFunctions; |
| 18 var tabs = bindingsAPI.compiledApi; |
| 15 | 19 |
| 16 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) { | 20 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) { |
| 17 var name = ''; | 21 var name = ''; |
| 18 if (connectInfo) { | 22 if (connectInfo) { |
| 19 name = connectInfo.name || name; | 23 name = connectInfo.name || name; |
| 20 } | 24 } |
| 21 var portId = OpenChannelToTab(tabId, extensionId, name); | 25 var portId = OpenChannelToTab(tabId, extensionId, name); |
| 22 return chromeHidden.Port.createPort(portId, name); | 26 return chromeHidden.Port.createPort(portId, name); |
| 23 }); | 27 }); |
| 24 | 28 |
| 25 apiFunctions.setHandleRequest('sendRequest', | 29 apiFunctions.setHandleRequest('sendRequest', |
| 26 function(tabId, request, responseCallback) { | 30 function(tabId, request, responseCallback) { |
| 27 if (sendRequestIsDisabled) | 31 if (sendRequestIsDisabled) |
| 28 throw new Error(sendRequestIsDisabled); | 32 throw new Error(sendRequestIsDisabled); |
| 29 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kRequestChannel}); | 33 var port = tabs.connect(tabId, {name: chromeHidden.kRequestChannel}); |
| 30 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); | 34 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); |
| 31 }); | 35 }); |
| 32 | 36 |
| 33 apiFunctions.setHandleRequest('sendMessage', | 37 apiFunctions.setHandleRequest('sendMessage', |
| 34 function(tabId, message, responseCallback) { | 38 function(tabId, message, responseCallback) { |
| 35 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kMessageChannel}); | 39 var port = tabs.connect(tabId, {name: chromeHidden.kMessageChannel}); |
| 36 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); | 40 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
| 37 }); | 41 }); |
| 38 }); | 42 }); |
| 43 |
| 44 exports.bindings = bindings.generate(); |
| OLD | NEW |