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

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

Issue 3005022: Print a better error message when someone passes the wrong parameters to (Closed)
Patch Set: Created 10 years, 5 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
« no previous file with comments | « no previous file | 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) 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // Opens a message channel to the given target extension, or the current one 161 // Opens a message channel to the given target extension, or the current one
162 // if unspecified. Returns a Port for message passing. 162 // if unspecified. Returns a Port for message passing.
163 chrome.extension.connect = function(targetId_opt, connectInfo_opt) { 163 chrome.extension.connect = function(targetId_opt, connectInfo_opt) {
164 var name = ""; 164 var name = "";
165 var targetId = extensionId; 165 var targetId = extensionId;
166 var nextArg = 0; 166 var nextArg = 0;
167 if (typeof(arguments[nextArg]) == "string") 167 if (typeof(arguments[nextArg]) == "string")
168 targetId = arguments[nextArg++]; 168 targetId = arguments[nextArg++];
169 if (typeof(arguments[nextArg]) == "object") 169 if (typeof(arguments[nextArg]) == "object")
170 name = arguments[nextArg++].name || name; 170 name = arguments[nextArg++].name || name;
171 if (nextArg != arguments.length)
172 throw new Error("Invalid arguments to connect.");
171 173
172 var portId = OpenChannelToExtension(extensionId, targetId, name); 174 var portId = OpenChannelToExtension(extensionId, targetId, name);
173 if (portId >= 0) 175 if (portId >= 0)
174 return chromeHidden.Port.createPort(portId, name); 176 return chromeHidden.Port.createPort(portId, name);
175 throw new Error("Error connecting to extension '" + targetId + "'"); 177 throw new Error("Error connecting to extension '" + targetId + "'");
176 }; 178 };
177 179
178 chrome.extension.sendRequest = 180 chrome.extension.sendRequest =
179 function(targetId_opt, request, responseCallback_opt) { 181 function(targetId_opt, request, responseCallback_opt) {
180 var targetId = extensionId; 182 var targetId = extensionId;
181 var responseCallback = null; 183 var responseCallback = null;
182 var lastArg = arguments.length - 1; 184 var lastArg = arguments.length - 1;
183 if (typeof(arguments[lastArg]) == "function") 185 if (typeof(arguments[lastArg]) == "function")
184 responseCallback = arguments[lastArg--]; 186 responseCallback = arguments[lastArg--];
185 request = arguments[lastArg--]; 187 request = arguments[lastArg--];
186 if (lastArg >= 0) 188 if (lastArg >= 0 && typeof(arguments[lastArg]) == "string")
187 targetId = arguments[lastArg--]; 189 targetId = arguments[lastArg--];
190 if (lastArg != -1)
191 throw new Error("Invalid arguments to sendRequest.");
188 192
189 var port = chrome.extension.connect(targetId, 193 var port = chrome.extension.connect(targetId,
190 {name: chromeHidden.kRequestChannel}); 194 {name: chromeHidden.kRequestChannel});
191 port.postMessage(request); 195 port.postMessage(request);
192 port.onMessage.addListener(function(response) { 196 port.onMessage.addListener(function(response) {
193 if (responseCallback) 197 if (responseCallback)
194 responseCallback(response); 198 responseCallback(response);
195 port.disconnect(); 199 port.disconnect();
196 }); 200 });
197 }; 201 };
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 "extension.onConnectExternal", 278 "extension.onConnectExternal",
275 "extension.onRequestExternal", 279 "extension.onRequestExternal",
276 "i18n.getAcceptLanguages" 280 "i18n.getAcceptLanguages"
277 ]; 281 ];
278 for (var i = 0; i < privileged.length; i++) { 282 for (var i = 0; i < privileged.length; i++) {
279 createStub(privileged[i]); 283 createStub(privileged[i]);
280 } 284 }
281 } 285 }
282 286
283 })(); 287 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698