Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/renderer/resources/extensions/tabs_custom_bindings.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments/TODOs Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 = new (require('schema_binding_generator').Bindings)('tabs');
8
7 var tabsNatives = requireNative('tabs'); 9 var tabsNatives = requireNative('tabs');
8 var OpenChannelToTab = tabsNatives.OpenChannelToTab; 10 var OpenChannelToTab = tabsNatives.OpenChannelToTab;
9 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled(); 11 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled();
10 12
11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 13 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
12 14
13 chromeHidden.registerCustomHook('tabs', function(bindingsAPI, extensionId) { 15 bindings.registerCustomHook(function(bindingsAPI, extensionId) {
14 var apiFunctions = bindingsAPI.apiFunctions; 16 var apiFunctions = bindingsAPI.apiFunctions;
17 var tabs = bindingsAPI.compiledApi;
15 18
16 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) { 19 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) {
17 var name = ''; 20 var name = '';
18 if (connectInfo) { 21 if (connectInfo) {
19 name = connectInfo.name || name; 22 name = connectInfo.name || name;
20 } 23 }
21 var portId = OpenChannelToTab(tabId, extensionId, name); 24 var portId = OpenChannelToTab(tabId, extensionId, name);
22 return chromeHidden.Port.createPort(portId, name); 25 return chromeHidden.Port.createPort(portId, name);
23 }); 26 });
24 27
25 apiFunctions.setHandleRequest('sendRequest', 28 apiFunctions.setHandleRequest('sendRequest',
26 function(tabId, request, responseCallback) { 29 function(tabId, request, responseCallback) {
27 if (sendRequestIsDisabled) 30 if (sendRequestIsDisabled)
28 throw new Error(sendRequestIsDisabled); 31 throw new Error(sendRequestIsDisabled);
29 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kRequestChannel}); 32 var port = tabs.connect(tabId, {name: chromeHidden.kRequestChannel});
30 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); 33 chromeHidden.Port.sendMessageImpl(port, request, responseCallback);
31 }); 34 });
32 35
33 apiFunctions.setHandleRequest('sendMessage', 36 apiFunctions.setHandleRequest('sendMessage',
34 function(tabId, message, responseCallback) { 37 function(tabId, message, responseCallback) {
35 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kMessageChannel}); 38 var port = tabs.connect(tabId, {name: chromeHidden.kMessageChannel});
36 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); 39 chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
37 }); 40 });
38 }); 41 });
42
43 exports.bindings = bindings.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698