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

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

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

Powered by Google App Engine
This is Rietveld 408576698