Chromium Code Reviews

Side by Side Diff: chrome/renderer/resources/renderer_extension_bindings.js

Issue 341025: Change the extension.onRequest even to include the sender info. (Closed)
Patch Set: fix args Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // This script contains unprivileged javascript APIs related to chrome 5 // This script contains unprivileged javascript APIs related to chrome
6 // extensions. It is loaded by any extension-related context, such as content 6 // extensions. It is loaded by any extension-related context, such as content
7 // scripts or toolstrips. 7 // scripts or toolstrips.
8 // See user_script_slave.cc for script that is loaded by content scripts only. 8 // See user_script_slave.cc for script that is loaded by content scripts only.
9 // TODO(mpcomplete): we also load this in regular web pages, but don't need 9 // TODO(mpcomplete): we also load this in regular web pages, but don't need
10 // to. 10 // to.
(...skipping 55 matching lines...)
66 // close both. 66 // close both.
67 if (targetExtensionId != chromeHidden.extensionId) 67 if (targetExtensionId != chromeHidden.extensionId)
68 return; // not for us 68 return; // not for us
69 if (ports[getOppositePortId(portId)]) 69 if (ports[getOppositePortId(portId)])
70 return; // this channel was opened by us, so ignore it 70 return; // this channel was opened by us, so ignore it
71 71
72 // Determine whether this is coming from another extension, so we can use 72 // Determine whether this is coming from another extension, so we can use
73 // the right event. 73 // the right event.
74 var isExternal = sourceExtensionId != chromeHidden.extensionId; 74 var isExternal = sourceExtensionId != chromeHidden.extensionId;
75 75
76 if (tab)
77 tab = JSON.parse(tab);
78 var sender = {tab: tab, id: sourceExtensionId};
79
76 // Special case for sendRequest/onRequest. 80 // Special case for sendRequest/onRequest.
77 if (channelName == chromeHidden.kRequestChannel) { 81 if (channelName == chromeHidden.kRequestChannel) {
78 var requestEvent = (isExternal ? 82 var requestEvent = (isExternal ?
79 chrome.extension.onRequestExternal : chrome.extension.onRequest); 83 chrome.extension.onRequestExternal : chrome.extension.onRequest);
80 if (requestEvent.hasListeners()) { 84 if (requestEvent.hasListeners()) {
81 var port = chromeHidden.Port.createPort(portId, channelName); 85 var port = chromeHidden.Port.createPort(portId, channelName);
82 port.onMessage.addListener(function(request) { 86 port.onMessage.addListener(function(request) {
83 requestEvent.dispatch(request, function(response) { 87 requestEvent.dispatch(request, sender, function(response) {
84 port.postMessage(response); 88 port.postMessage(response);
85 }); 89 });
86 }); 90 });
87 } 91 }
88 return; 92 return;
89 } 93 }
90 94
91 var connectEvent = (isExternal ? 95 var connectEvent = (isExternal ?
92 chrome.extension.onConnectExternal : chrome.extension.onConnect); 96 chrome.extension.onConnectExternal : chrome.extension.onConnect);
93 if (connectEvent.hasListeners()) { 97 if (connectEvent.hasListeners()) {
94 var port = chromeHidden.Port.createPort(portId, channelName); 98 var port = chromeHidden.Port.createPort(portId, channelName);
95 if (tab) { 99 port.sender = sender;
96 tab = JSON.parse(tab);
97 }
98 port.sender = {tab: tab, id: sourceExtensionId};
99 // TODO(EXTENSIONS_DEPRECATED): port.tab is obsolete. 100 // TODO(EXTENSIONS_DEPRECATED): port.tab is obsolete.
100 port.tab = port.sender.tab; 101 port.tab = port.sender.tab;
101 102
102 connectEvent.dispatch(port); 103 connectEvent.dispatch(port);
103 } 104 }
104 }; 105 };
105 106
106 // Called by native code when a channel has been closed. 107 // Called by native code when a channel has been closed.
107 chromeHidden.Port.dispatchOnDisconnect = function(portId) { 108 chromeHidden.Port.dispatchOnDisconnect = function(portId) {
108 var port = ports[portId]; 109 var port = ports[portId];
(...skipping 85 matching lines...)
194 }); 195 });
195 }; 196 };
196 197
197 // Returns a resource URL that can be used to fetch a resource from this 198 // Returns a resource URL that can be used to fetch a resource from this
198 // extension. 199 // extension.
199 chrome.extension.getURL = function(path) { 200 chrome.extension.getURL = function(path) {
200 return "chrome-extension://" + extensionId + "/" + path; 201 return "chrome-extension://" + extensionId + "/" + path;
201 }; 202 };
202 } 203 }
203 })(); 204 })();
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/extension.html ('k') | chrome/test/data/extensions/api_test/connect/page.js » ('j') | no next file with comments »

Powered by Google App Engine