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

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

Issue 15841013: Make miscellaneous_bindings and event_bindings Required as needed. Previously (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 require('json_schema');
6 require('event_bindings');
7 var chrome = requireNative('chrome').GetChrome(); 5 var chrome = requireNative('chrome').GetChrome();
8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 6 var Event = require('event_bindings').Event;
9 var forEach = require('utils').forEach; 7 var forEach = require('utils').forEach;
10 var GetAvailability = requireNative('v8_context').GetAvailability; 8 var GetAvailability = requireNative('v8_context').GetAvailability;
11 var logging = requireNative('logging'); 9 var logging = requireNative('logging');
12 var process = requireNative('process'); 10 var process = requireNative('process');
13 var contextType = process.GetContextType(); 11 var contextType = process.GetContextType();
14 var extensionId = process.GetExtensionId(); 12 var extensionId = process.GetExtensionId();
15 var manifestVersion = process.GetManifestVersion(); 13 var manifestVersion = process.GetManifestVersion();
16 var schemaRegistry = requireNative('schema_registry'); 14 var schemaRegistry = requireNative('schema_registry');
17 var schemaUtils = require('schemaUtils'); 15 var schemaUtils = require('schemaUtils');
18 var utils = require('utils'); 16 var utils = require('utils');
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 284
287 if (!GetAvailability(apiFunction.name).is_available || 285 if (!GetAvailability(apiFunction.name).is_available ||
288 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { 286 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) {
289 this.apiFunctions_.registerUnavailable(functionDef.name); 287 this.apiFunctions_.registerUnavailable(functionDef.name);
290 return; 288 return;
291 } 289 }
292 290
293 // TODO(aa): It would be best to run this in a unit test, but in order 291 // TODO(aa): It would be best to run this in a unit test, but in order
294 // to do that we would need to better factor this code so that it 292 // to do that we would need to better factor this code so that it
295 // doesn't depend on so much v8::Extension machinery. 293 // doesn't depend on so much v8::Extension machinery.
296 if (chromeHidden.validateAPI && 294 if (logging.DCHECK_IS_ON() &&
297 schemaUtils.isFunctionSignatureAmbiguous( 295 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) {
298 apiFunction.definition)) {
299 throw new Error( 296 throw new Error(
300 apiFunction.name + ' has ambiguous optional arguments. ' + 297 apiFunction.name + ' has ambiguous optional arguments. ' +
301 'To implement custom disambiguation logic, add ' + 298 'To implement custom disambiguation logic, add ' +
302 '"allowAmbiguousOptionalArguments" to the function\'s schema.'); 299 '"allowAmbiguousOptionalArguments" to the function\'s schema.');
303 } 300 }
304 301
305 this.apiFunctions_.register(functionDef.name, apiFunction); 302 this.apiFunctions_.register(functionDef.name, apiFunction);
306 303
307 mod[functionDef.name] = (function() { 304 mod[functionDef.name] = (function() {
308 var args = Array.prototype.slice.call(arguments); 305 var args = Array.prototype.slice.call(arguments);
(...skipping 12 matching lines...) Expand all
321 } else { 318 } else {
322 var optArgs = { 319 var optArgs = {
323 customCallback: this.customCallback 320 customCallback: this.customCallback
324 }; 321 };
325 retval = sendRequest(this.name, args, 322 retval = sendRequest(this.name, args,
326 this.definition.parameters, 323 this.definition.parameters,
327 optArgs); 324 optArgs);
328 } 325 }
329 sendRequestHandler.clearCalledSendRequest(); 326 sendRequestHandler.clearCalledSendRequest();
330 327
331 // Validate return value if defined - only in debug. 328 // Validate return value if in sanity check mode.
332 if (chromeHidden.validateCallbacks && 329 if (logging.DCHECK_IS_ON() && this.definition.returns) {
333 this.definition.returns) {
334 schemaUtils.validate([retval], [this.definition.returns]); 330 schemaUtils.validate([retval], [this.definition.returns]);
335 } 331 }
336 return retval; 332 return retval;
337 }).bind(apiFunction); 333 }).bind(apiFunction);
338 }, this); 334 }, this);
339 } 335 }
340 336
341 // Setup Events 337 // Setup Events
342 if (schema.events) { 338 if (schema.events) {
343 forEach(schema.events, function(i, eventDef) { 339 forEach(schema.events, function(i, eventDef) {
(...skipping 12 matching lines...) Expand all
356 352
357 var options = eventDef.options || {}; 353 var options = eventDef.options || {};
358 if (eventDef.filters && eventDef.filters.length > 0) 354 if (eventDef.filters && eventDef.filters.length > 0)
359 options.supportsFilters = true; 355 options.supportsFilters = true;
360 356
361 if (this.customEvent_) { 357 if (this.customEvent_) {
362 mod[eventDef.name] = new this.customEvent_( 358 mod[eventDef.name] = new this.customEvent_(
363 eventName, eventDef.parameters, eventDef.extraParameters, 359 eventName, eventDef.parameters, eventDef.extraParameters,
364 options); 360 options);
365 } else if (eventDef.anonymous) { 361 } else if (eventDef.anonymous) {
366 mod[eventDef.name] = new chrome.Event(); 362 mod[eventDef.name] = new Event();
367 } else { 363 } else {
368 mod[eventDef.name] = new chrome.Event( 364 mod[eventDef.name] = new Event(
369 eventName, eventDef.parameters, options); 365 eventName, eventDef.parameters, options);
370 } 366 }
371 }, this); 367 }, this);
372 } 368 }
373 369
374 function addProperties(m, parentDef) { 370 function addProperties(m, parentDef) {
375 var properties = parentDef.properties; 371 var properties = parentDef.properties;
376 if (!properties) 372 if (!properties)
377 return; 373 return;
378 374
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 availability.message); 428 availability.message);
433 return; 429 return;
434 } 430 }
435 431
436 this.runHooks_(mod); 432 this.runHooks_(mod);
437 return mod; 433 return mod;
438 } 434 }
439 }; 435 };
440 436
441 exports.Binding = Binding; 437 exports.Binding = Binding;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698