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

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

Issue 9192029: Bindings layer for declarative events API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed rules_registry_dispatcher.* to declarative_api.* Created 8 years, 11 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 var chrome = chrome || {}; 8 var chrome = chrome || {};
9 (function() { 9 (function() {
10 native function GetChromeHidden(); 10 native function GetChromeHidden();
(...skipping 16 matching lines...) Expand all
27 return !!resolved; 27 return !!resolved;
28 } 28 }
29 29
30 function forEach(dict, f) { 30 function forEach(dict, f) {
31 for (key in dict) { 31 for (key in dict) {
32 if (dict.hasOwnProperty(key)) 32 if (dict.hasOwnProperty(key))
33 f(key, dict[key]); 33 f(key, dict[key]);
34 } 34 }
35 } 35 }
36 36
37 chromeHidden.GetExtensionAPIDefinition = GetExtensionAPIDefinition;
38
37 // Validate arguments. 39 // Validate arguments.
38 chromeHidden.validationTypes = []; 40 chromeHidden.validationTypes = [];
39 chromeHidden.validate = function(args, schemas) { 41 chromeHidden.validate = function(args, schemas) {
40 if (args.length > schemas.length) 42 if (args.length > schemas.length)
41 throw new Error("Too many arguments."); 43 throw new Error("Too many arguments.");
42 44
43 for (var i = 0; i < schemas.length; i++) { 45 for (var i = 0; i < schemas.length; i++) {
44 if (i in args && args[i] !== null && args[i] !== undefined) { 46 if (i in args && args[i] !== null && args[i] !== undefined) {
45 var validator = new chromeHidden.JSONSchemaValidator(); 47 var validator = new chromeHidden.JSONSchemaValidator();
46 validator.addTypes(chromeHidden.validationTypes); 48 validator.addTypes(chromeHidden.validationTypes);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 178
177 var requestId = GetNextRequestId(); 179 var requestId = GetNextRequestId();
178 request.id = requestId; 180 request.id = requestId;
179 requests[requestId] = request; 181 requests[requestId] = request;
180 var hasCallback = 182 var hasCallback =
181 (request.callback || opt_args.customCallback) ? true : false; 183 (request.callback || opt_args.customCallback) ? true : false;
182 return nativeFunction(functionName, sargs, requestId, hasCallback, 184 return nativeFunction(functionName, sargs, requestId, hasCallback,
183 opt_args.forIOThread); 185 opt_args.forIOThread);
184 } 186 }
185 187
188 chromeHidden.sendRequest = sendRequest;
189
186 // TODO(kalman): It's a shame to need to define this function here, since it's 190 // TODO(kalman): It's a shame to need to define this function here, since it's
187 // only used in 2 APIs (browserAction and pageAction). It would be nice to 191 // only used in 2 APIs (browserAction and pageAction). It would be nice to
188 // only load this if one of those APIs has been loaded. 192 // only load this if one of those APIs has been loaded.
189 // That said, both of those APIs are always injected into pages anyway (see 193 // That said, both of those APIs are always injected into pages anyway (see
190 // chrome/common/extensions/extension_permission_set.cc). 194 // chrome/common/extensions/extension_permission_set.cc).
191 function setIcon(details, name, parameters, actionType) { 195 function setIcon(details, name, parameters, actionType) {
192 var iconSize = 19; 196 var iconSize = 19;
193 if ("iconIndex" in details) { 197 if ("iconIndex" in details) {
194 sendRequest(name, [details], parameters); 198 sendRequest(name, [details], parameters);
195 } else if ("imageData" in details) { 199 } else if ("imageData" in details) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 for (var i = 0; i < platforms.length; i++) { 351 for (var i = 0; i < platforms.length; i++) {
348 if (platforms[i][0].test(navigator.appVersion)) { 352 if (platforms[i][0].test(navigator.appVersion)) {
349 return platforms[i][1]; 353 return platforms[i][1];
350 } 354 }
351 } 355 }
352 return "unknown"; 356 return "unknown";
353 } 357 }
354 358
355 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, 359 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess,
356 isIncognitoProcess) { 360 isIncognitoProcess) {
357 var apiDefinitions = GetExtensionAPIDefinition(); 361 var apiDefinitions = GetExtensionAPIDefinition();
Matt Perry 2012/01/27 19:27:15 Just put the result from here on chromeHidden, rat
battre 2012/01/27 19:42:18 Done.
Aaron Boodman 2012/01/31 00:11:17 That isn't completely true. A new object is create
358 362
359 // Read api definitions and setup api functions in the chrome namespace. 363 // Read api definitions and setup api functions in the chrome namespace.
360 // TODO(rafaelw): Consider defining a json schema for an api definition 364 // TODO(rafaelw): Consider defining a json schema for an api definition
361 // and validating either here, in a unit_test or both. 365 // and validating either here, in a unit_test or both.
362 // TODO(rafaelw): Handle synchronous functions. 366 // TODO(rafaelw): Handle synchronous functions.
363 // TODO(rafaelw): Consider providing some convenient override points 367 // TODO(rafaelw): Consider providing some convenient override points
364 // for api functions that wish to insert themselves into the call. 368 // for api functions that wish to insert themselves into the call.
365 var platform = getPlatform(); 369 var platform = getPlatform();
366 370
367 apiDefinitions.forEach(function(apiDef) { 371 apiDefinitions.forEach(function(apiDef) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (eventDef.name in module || 456 if (eventDef.name in module ||
453 addUnprivilegedAccessGetter(module, eventDef.name, 457 addUnprivilegedAccessGetter(module, eventDef.name,
454 eventDef.unprivileged)) { 458 eventDef.unprivileged)) {
455 return; 459 return;
456 } 460 }
457 461
458 var eventName = apiDef.namespace + "." + eventDef.name; 462 var eventName = apiDef.namespace + "." + eventDef.name;
459 var customEvent = customEvents[apiDef.namespace]; 463 var customEvent = customEvents[apiDef.namespace];
460 if (customEvent) { 464 if (customEvent) {
461 module[eventDef.name] = new customEvent( 465 module[eventDef.name] = new customEvent(
462 eventName, eventDef.parameters, eventDef.extraParameters); 466 eventName, eventDef.parameters, eventDef.extraParameters,
467 eventDef.options);
463 } else { 468 } else {
464 module[eventDef.name] = new chrome.Event( 469 module[eventDef.name] = new chrome.Event(
465 eventName, eventDef.parameters); 470 eventName, eventDef.parameters, eventDef.options);
466 } 471 }
467 }); 472 });
468 } 473 }
469 474
470 function addProperties(m, def) { 475 function addProperties(m, def) {
471 // Parse any values defined for properties. 476 // Parse any values defined for properties.
472 if (def.properties) { 477 if (def.properties) {
473 forEach(def.properties, function(prop, property) { 478 forEach(def.properties, function(prop, property) {
474 if (prop in m || 479 if (prop in m ||
475 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) { 480 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // See http://crbug.com/100242 551 // See http://crbug.com/100242
547 if (apiExists("webstorePrivate")) { 552 if (apiExists("webstorePrivate")) {
548 chrome.webstorePrivate.beginInstallWithManifest2 = 553 chrome.webstorePrivate.beginInstallWithManifest2 =
549 chrome.webstorePrivate.beginInstallWithManifest3; 554 chrome.webstorePrivate.beginInstallWithManifest3;
550 } 555 }
551 556
552 if (apiExists("test")) 557 if (apiExists("test"))
553 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; 558 chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
554 }); 559 });
555 })(); 560 })();
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/event.js ('k') | chrome/renderer/resources/extensions/web_request_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698