Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
| 6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
| 7 | 7 |
| 8 require('json_schema'); | 8 require('json_schema'); |
| 9 require('event_bindings'); | 9 require('event_bindings'); |
| 10 var GetExtensionAPIDefinition = | 10 var GetExtensionAPIDefinition = |
|
Aaron Boodman
2012/05/10 17:14:49
I would like to propose the following rule:
When
battre
2012/05/10 18:05:22
I like that.
I have done this for "utils" and add
| |
| 11 requireNative('apiDefinitions').GetExtensionAPIDefinition; | 11 requireNative('apiDefinitions').GetExtensionAPIDefinition; |
| 12 var sendRequest = require('sendRequest').sendRequest; | 12 var sendRequest = require('sendRequest').sendRequest; |
| 13 var forEach = require('utils').forEach; | |
| 14 var lookup = require('utils').lookup; | |
| 13 | 15 |
| 14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 16 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 15 | 17 |
| 16 // The object to generate the bindings for "internal" APIs in, so that | 18 // The object to generate the bindings for "internal" APIs in, so that |
| 17 // extensions can't directly call them (without access to chromeHidden), | 19 // extensions can't directly call them (without access to chromeHidden), |
| 18 // but are still needed for internal mechanisms of extensions (e.g. events). | 20 // but are still needed for internal mechanisms of extensions (e.g. events). |
| 19 // | 21 // |
| 20 // This is distinct to the "*Private" APIs which are controlled via | 22 // This is distinct to the "*Private" APIs which are controlled via |
| 21 // having strict permissions and aren't generated *anywhere* unless needed. | 23 // having strict permissions and aren't generated *anywhere* unless needed. |
| 22 var internalAPIs = {}; | 24 var internalAPIs = {}; |
| 23 chromeHidden.internalAPIs = internalAPIs; | 25 chromeHidden.internalAPIs = internalAPIs; |
| 24 | 26 |
| 25 function forEach(dict, f) { | |
| 26 for (key in dict) { | |
| 27 if (dict.hasOwnProperty(key)) | |
| 28 f(key, dict[key]); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 // Validate arguments. | 27 // Validate arguments. |
| 33 var schemaValidator = new chromeHidden.JSONSchemaValidator(); | 28 var schemaValidator = new chromeHidden.JSONSchemaValidator(); |
| 34 chromeHidden.validate = function(args, parameterSchemas) { | 29 chromeHidden.validate = function(args, parameterSchemas) { |
| 35 if (args.length > parameterSchemas.length) | 30 if (args.length > parameterSchemas.length) |
| 36 throw new Error("Too many arguments."); | 31 throw new Error("Too many arguments."); |
| 37 | 32 |
| 38 for (var i = 0; i < parameterSchemas.length; i++) { | 33 for (var i = 0; i < parameterSchemas.length; i++) { |
| 39 if (i in args && args[i] !== null && args[i] !== undefined) { | 34 if (i in args && args[i] !== null && args[i] !== undefined) { |
| 40 schemaValidator.resetErrors(); | 35 schemaValidator.resetErrors(); |
| 41 schemaValidator.validate(args[i], parameterSchemas[i]); | 36 schemaValidator.validate(args[i], parameterSchemas[i]); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 manifestVersion) { | 347 manifestVersion) { |
| 353 var apiDefinitions = GetExtensionAPIDefinition(); | 348 var apiDefinitions = GetExtensionAPIDefinition(); |
| 354 | 349 |
| 355 // Read api definitions and setup api functions in the chrome namespace. | 350 // Read api definitions and setup api functions in the chrome namespace. |
| 356 // TODO(rafaelw): Consider defining a json schema for an api definition | 351 // TODO(rafaelw): Consider defining a json schema for an api definition |
| 357 // and validating either here, in a unit_test or both. | 352 // and validating either here, in a unit_test or both. |
| 358 // TODO(rafaelw): Handle synchronous functions. | 353 // TODO(rafaelw): Handle synchronous functions. |
| 359 // TODO(rafaelw): Consider providing some convenient override points | 354 // TODO(rafaelw): Consider providing some convenient override points |
| 360 // for api functions that wish to insert themselves into the call. | 355 // for api functions that wish to insert themselves into the call. |
| 361 var platform = getPlatform(); | 356 var platform = getPlatform(); |
| 357 var eventsSchema = lookup(apiDefinitions, 'namespace', 'events'); | |
| 362 | 358 |
| 363 apiDefinitions.forEach(function(apiDef) { | 359 apiDefinitions.forEach(function(apiDef) { |
| 364 // TODO(kalman): Remove this, or refactor schema_generated_bindings.js so | 360 // TODO(kalman): Remove this, or refactor schema_generated_bindings.js so |
| 365 // that it isn't necessary. For now, chrome.app is entirely handwritten. | 361 // that it isn't necessary. For now, chrome.app is entirely handwritten. |
| 366 if (apiDef.namespace === 'app') | 362 if (apiDef.namespace === 'app') |
| 367 return; | 363 return; |
| 368 | 364 |
| 369 if (!isSchemaNodeSupported(apiDef, platform, manifestVersion)) | 365 if (!isSchemaNodeSupported(apiDef, platform, manifestVersion)) |
| 370 return; | 366 return; |
| 371 | 367 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 if (!isSchemaAccessAllowed(eventDef)) { | 484 if (!isSchemaAccessAllowed(eventDef)) { |
| 489 addUnprivilegedAccessGetter(mod, eventDef.name); | 485 addUnprivilegedAccessGetter(mod, eventDef.name); |
| 490 return; | 486 return; |
| 491 } | 487 } |
| 492 | 488 |
| 493 var eventName = apiDef.namespace + "." + eventDef.name; | 489 var eventName = apiDef.namespace + "." + eventDef.name; |
| 494 var customEvent = customEvents[apiDef.namespace]; | 490 var customEvent = customEvents[apiDef.namespace]; |
| 495 if (customEvent) { | 491 if (customEvent) { |
| 496 mod[eventDef.name] = new customEvent( | 492 mod[eventDef.name] = new customEvent( |
| 497 eventName, eventDef.parameters, eventDef.extraParameters, | 493 eventName, eventDef.parameters, eventDef.extraParameters, |
| 498 eventDef.options); | 494 eventDef.options, eventsSchema); |
| 499 } else if (eventDef.anonymous) { | 495 } else if (eventDef.anonymous) { |
| 500 mod[eventDef.name] = new chrome.Event(); | 496 mod[eventDef.name] = new chrome.Event(); |
| 501 } else { | 497 } else { |
| 502 mod[eventDef.name] = new chrome.Event( | 498 mod[eventDef.name] = new chrome.Event( |
| 503 eventName, eventDef.parameters, eventDef.options); | 499 eventName, eventDef.parameters, eventDef.options, eventsSchema); |
| 504 } | 500 } |
| 505 }); | 501 }); |
| 506 } | 502 } |
| 507 | 503 |
| 508 function addProperties(m, parentDef) { | 504 function addProperties(m, parentDef) { |
| 509 var properties = parentDef.properties; | 505 var properties = parentDef.properties; |
| 510 if (!properties) | 506 if (!properties) |
| 511 return; | 507 return; |
| 512 | 508 |
| 513 forEach(properties, function(propertyName, propertyDef) { | 509 forEach(properties, function(propertyName, propertyDef) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 // beginInstallWithManifest2. | 579 // beginInstallWithManifest2. |
| 584 // See http://crbug.com/100242 | 580 // See http://crbug.com/100242 |
| 585 if (chrome.webstorePrivate) { | 581 if (chrome.webstorePrivate) { |
| 586 chrome.webstorePrivate.beginInstallWithManifest2 = | 582 chrome.webstorePrivate.beginInstallWithManifest2 = |
| 587 chrome.webstorePrivate.beginInstallWithManifest3; | 583 chrome.webstorePrivate.beginInstallWithManifest3; |
| 588 } | 584 } |
| 589 | 585 |
| 590 if (chrome.test) | 586 if (chrome.test) |
| 591 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 587 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
| 592 }); | 588 }); |
| OLD | NEW |