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

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

Issue 9965005: Deprecate chrome.extension.sendRequest in favor of sendMessage, with a safer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 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
« no previous file with comments | « chrome/renderer/resources/extensions/miscellaneous_bindings.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 tabsNatives = requireNative('tabs'); 7 var tabsNatives = requireNative('tabs');
8 var OpenChannelToTab = tabsNatives.OpenChannelToTab; 8 var OpenChannelToTab = tabsNatives.OpenChannelToTab;
9 9
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
11 11
12 chromeHidden.registerCustomHook('tabs', function(bindingsAPI, extensionId) { 12 chromeHidden.registerCustomHook('tabs', function(bindingsAPI, extensionId) {
13 var apiFunctions = bindingsAPI.apiFunctions; 13 var apiFunctions = bindingsAPI.apiFunctions;
14 14
15 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) { 15 apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) {
16 var name = ''; 16 var name = '';
17 if (connectInfo) { 17 if (connectInfo) {
18 name = connectInfo.name || name; 18 name = connectInfo.name || name;
19 } 19 }
20 var portId = OpenChannelToTab(tabId, extensionId, name); 20 var portId = OpenChannelToTab(tabId, extensionId, name);
21 return chromeHidden.Port.createPort(portId, name); 21 return chromeHidden.Port.createPort(portId, name);
22 }); 22 });
23 23
24 apiFunctions.setHandleRequest('sendRequest', 24 apiFunctions.setHandleRequest('sendRequest',
25 function(tabId, request, responseCallback) { 25 function(tabId, request, responseCallback) {
26 var port = chrome.tabs.connect(tabId, 26 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kRequestChannel});
27 {name: chromeHidden.kRequestChannel}); 27 chromeHidden.Port.sendMessageImpl(port, request, responseCallback);
28 port.postMessage(request); 28 });
29 port.onDisconnect.addListener(function() { 29
30 // For onDisconnects, we only notify the callback if there was an error. 30 apiFunctions.setHandleRequest('sendMessage',
31 if (chrome.extension.lastError && responseCallback) 31 function(tabId, message, responseCallback) {
32 responseCallback(); 32 var port = chrome.tabs.connect(tabId, {name: chromeHidden.kMessageChannel});
33 }); 33 chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
34 port.onMessage.addListener(function(response) {
35 try {
36 if (responseCallback)
37 responseCallback(response);
38 } finally {
39 port.disconnect();
40 port = null;
41 }
42 });
43 }); 34 });
44 }); 35 });
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/miscellaneous_bindings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698