| 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 // TODO(battre): cleanup the usage of packages everywhere, as described here | |
| 9 // http://codereview.chromium.org/10392008/diff/38/chrome/renderer/resources/e
xtensions/schema_generated_bindings.js | |
| 10 | |
| 11 require('json_schema'); | 8 require('json_schema'); |
| 12 require('event_bindings'); | 9 require('event_bindings'); |
| 13 var GetExtensionAPIDefinition = | 10 var GetExtensionAPIDefinition = |
| 14 requireNative('apiDefinitions').GetExtensionAPIDefinition; | 11 requireNative('apiDefinitions').GetExtensionAPIDefinition; |
| 15 var sendRequest = require('sendRequest').sendRequest; | 12 var sendRequest = require('sendRequest').sendRequest; |
| 16 var utils = require('utils'); | |
| 17 | 13 |
| 18 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 19 | 15 |
| 20 // The object to generate the bindings for "internal" APIs in, so that | 16 // The object to generate the bindings for "internal" APIs in, so that |
| 21 // extensions can't directly call them (without access to chromeHidden), | 17 // extensions can't directly call them (without access to chromeHidden), |
| 22 // but are still needed for internal mechanisms of extensions (e.g. events). | 18 // but are still needed for internal mechanisms of extensions (e.g. events). |
| 23 // | 19 // |
| 24 // This is distinct to the "*Private" APIs which are controlled via | 20 // This is distinct to the "*Private" APIs which are controlled via |
| 25 // having strict permissions and aren't generated *anywhere* unless needed. | 21 // having strict permissions and aren't generated *anywhere* unless needed. |
| 26 var internalAPIs = {}; | 22 var internalAPIs = {}; |
| 27 chromeHidden.internalAPIs = internalAPIs; | 23 chromeHidden.internalAPIs = internalAPIs; |
| 28 | 24 |
| 25 function forEach(dict, f) { |
| 26 for (key in dict) { |
| 27 if (dict.hasOwnProperty(key)) |
| 28 f(key, dict[key]); |
| 29 } |
| 30 } |
| 31 |
| 29 // Validate arguments. | 32 // Validate arguments. |
| 30 var schemaValidator = new chromeHidden.JSONSchemaValidator(); | 33 var schemaValidator = new chromeHidden.JSONSchemaValidator(); |
| 31 chromeHidden.validate = function(args, parameterSchemas) { | 34 chromeHidden.validate = function(args, parameterSchemas) { |
| 32 if (args.length > parameterSchemas.length) | 35 if (args.length > parameterSchemas.length) |
| 33 throw new Error("Too many arguments."); | 36 throw new Error("Too many arguments."); |
| 34 | 37 |
| 35 for (var i = 0; i < parameterSchemas.length; i++) { | 38 for (var i = 0; i < parameterSchemas.length; i++) { |
| 36 if (i in args && args[i] !== null && args[i] !== undefined) { | 39 if (i in args && args[i] !== null && args[i] !== undefined) { |
| 37 schemaValidator.resetErrors(); | 40 schemaValidator.resetErrors(); |
| 38 schemaValidator.validate(args[i], parameterSchemas[i]); | 41 schemaValidator.validate(args[i], parameterSchemas[i]); |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 eventName, eventDef.parameters, eventDef.options); | 503 eventName, eventDef.parameters, eventDef.options); |
| 501 } | 504 } |
| 502 }); | 505 }); |
| 503 } | 506 } |
| 504 | 507 |
| 505 function addProperties(m, parentDef) { | 508 function addProperties(m, parentDef) { |
| 506 var properties = parentDef.properties; | 509 var properties = parentDef.properties; |
| 507 if (!properties) | 510 if (!properties) |
| 508 return; | 511 return; |
| 509 | 512 |
| 510 utils.forEach(properties, function(propertyName, propertyDef) { | 513 forEach(properties, function(propertyName, propertyDef) { |
| 511 if (propertyName in m) | 514 if (propertyName in m) |
| 512 return; // TODO(kalman): be strict like functions/events somehow. | 515 return; // TODO(kalman): be strict like functions/events somehow. |
| 513 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) | 516 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) |
| 514 return; | 517 return; |
| 515 if (!isSchemaAccessAllowed(propertyDef)) { | 518 if (!isSchemaAccessAllowed(propertyDef)) { |
| 516 addUnprivilegedAccessGetter(m, propertyName); | 519 addUnprivilegedAccessGetter(m, propertyName); |
| 517 return; | 520 return; |
| 518 } | 521 } |
| 519 | 522 |
| 520 var value = propertyDef.value; | 523 var value = propertyDef.value; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // beginInstallWithManifest2. | 583 // beginInstallWithManifest2. |
| 581 // See http://crbug.com/100242 | 584 // See http://crbug.com/100242 |
| 582 if (chrome.webstorePrivate) { | 585 if (chrome.webstorePrivate) { |
| 583 chrome.webstorePrivate.beginInstallWithManifest2 = | 586 chrome.webstorePrivate.beginInstallWithManifest2 = |
| 584 chrome.webstorePrivate.beginInstallWithManifest3; | 587 chrome.webstorePrivate.beginInstallWithManifest3; |
| 585 } | 588 } |
| 586 | 589 |
| 587 if (chrome.test) | 590 if (chrome.test) |
| 588 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 591 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
| 589 }); | 592 }); |
| OLD | NEW |