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

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: Fix some stuff that apitests in followup CL discovered Created 8 years, 10 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 var requestId = GetNextRequestId(); 177 var requestId = GetNextRequestId();
178 request.id = requestId; 178 request.id = requestId;
179 requests[requestId] = request; 179 requests[requestId] = request;
180 var hasCallback = 180 var hasCallback =
181 (request.callback || opt_args.customCallback) ? true : false; 181 (request.callback || opt_args.customCallback) ? true : false;
182 return nativeFunction(functionName, sargs, requestId, hasCallback, 182 return nativeFunction(functionName, sargs, requestId, hasCallback,
183 opt_args.forIOThread); 183 opt_args.forIOThread);
184 } 184 }
185 185
186 function getFunctionDefinition(namespace, functionName) {
187 var filterNamespace = function(val) {return val.namespace === namespace;};
188 var apiSchema = chromeHidden.apiDefinitions.filter(filterNamespace)[0];
189 var filterFunctionName = function (val) {return val.name === functionName;};
not at google - send to devlin 2012/02/01 07:23:12 This is expensive, O(number of APIs * number of fu
battre 2012/02/01 17:35:39 I have moved this logic into the custom bindings.
190 return apiSchema.functions.filter(filterFunctionName)[0];
191 }
192
193 // Sends an API request like sendRequest() but performs schema validation
194 // first.
195 // |qualifiedFunctionName| is the full function name including the api name.
196 chromeHidden.validatingSendRequest = function(qualifiedFunctionName, args) {
Aaron Boodman 2012/02/01 00:27:25 I don't think this really validates. sendRequest d
not at google - send to devlin 2012/02/01 00:47:57 I think we should get sendRequest to do the lookup
battre 2012/02/01 17:35:39 Please have a look at the new implementation. This
197 var lastSeparator = qualifiedFunctionName.lastIndexOf(".");
198 var functionName = qualifiedFunctionName.substr(lastSeparator + 1);
199 var namespace = qualifiedFunctionName.substr(0, lastSeparator);
200 var functionDef = getFunctionDefinition(namespace, functionName);
201 return sendRequest(qualifiedFunctionName, args, functionDef.parameters);
202 };
203
186 // TODO(kalman): It's a shame to need to define this function here, since it's 204 // 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 205 // 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. 206 // 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 207 // That said, both of those APIs are always injected into pages anyway (see
190 // chrome/common/extensions/extension_permission_set.cc). 208 // chrome/common/extensions/extension_permission_set.cc).
191 function setIcon(details, name, parameters, actionType) { 209 function setIcon(details, name, parameters, actionType) {
192 var iconSize = 19; 210 var iconSize = 19;
193 if ("iconIndex" in details) { 211 if ("iconIndex" in details) {
194 sendRequest(name, [details], parameters); 212 sendRequest(name, [details], parameters);
195 } else if ("imageData" in details) { 213 } else if ("imageData" in details) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (platforms[i][0].test(navigator.appVersion)) { 366 if (platforms[i][0].test(navigator.appVersion)) {
349 return platforms[i][1]; 367 return platforms[i][1];
350 } 368 }
351 } 369 }
352 return "unknown"; 370 return "unknown";
353 } 371 }
354 372
355 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, 373 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess,
356 isIncognitoProcess) { 374 isIncognitoProcess) {
357 var apiDefinitions = GetExtensionAPIDefinition(); 375 var apiDefinitions = GetExtensionAPIDefinition();
376 chromeHidden.apiDefinitions = apiDefinitions;
not at google - send to devlin 2012/02/01 07:23:12 When the logic from event.js is moved into experim
358 377
359 // Read api definitions and setup api functions in the chrome namespace. 378 // Read api definitions and setup api functions in the chrome namespace.
360 // TODO(rafaelw): Consider defining a json schema for an api definition 379 // TODO(rafaelw): Consider defining a json schema for an api definition
361 // and validating either here, in a unit_test or both. 380 // and validating either here, in a unit_test or both.
362 // TODO(rafaelw): Handle synchronous functions. 381 // TODO(rafaelw): Handle synchronous functions.
363 // TODO(rafaelw): Consider providing some convenient override points 382 // TODO(rafaelw): Consider providing some convenient override points
364 // for api functions that wish to insert themselves into the call. 383 // for api functions that wish to insert themselves into the call.
365 var platform = getPlatform(); 384 var platform = getPlatform();
366 385
367 apiDefinitions.forEach(function(apiDef) { 386 apiDefinitions.forEach(function(apiDef) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (eventDef.name in module || 471 if (eventDef.name in module ||
453 addUnprivilegedAccessGetter(module, eventDef.name, 472 addUnprivilegedAccessGetter(module, eventDef.name,
454 eventDef.unprivileged)) { 473 eventDef.unprivileged)) {
455 return; 474 return;
456 } 475 }
457 476
458 var eventName = apiDef.namespace + "." + eventDef.name; 477 var eventName = apiDef.namespace + "." + eventDef.name;
459 var customEvent = customEvents[apiDef.namespace]; 478 var customEvent = customEvents[apiDef.namespace];
460 if (customEvent) { 479 if (customEvent) {
461 module[eventDef.name] = new customEvent( 480 module[eventDef.name] = new customEvent(
462 eventName, eventDef.parameters, eventDef.extraParameters); 481 eventName, eventDef.parameters, eventDef.extraParameters,
482 eventDef.options);
463 } else { 483 } else {
464 module[eventDef.name] = new chrome.Event( 484 module[eventDef.name] = new chrome.Event(
465 eventName, eventDef.parameters); 485 eventName, eventDef.parameters, eventDef.options);
466 } 486 }
467 }); 487 });
468 } 488 }
469 489
470 function addProperties(m, def) { 490 function addProperties(m, def) {
471 // Parse any values defined for properties. 491 // Parse any values defined for properties.
472 if (def.properties) { 492 if (def.properties) {
473 forEach(def.properties, function(prop, property) { 493 forEach(def.properties, function(prop, property) {
474 if (prop in m || 494 if (prop in m ||
475 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) { 495 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // See http://crbug.com/100242 566 // See http://crbug.com/100242
547 if (apiExists("webstorePrivate")) { 567 if (apiExists("webstorePrivate")) {
548 chrome.webstorePrivate.beginInstallWithManifest2 = 568 chrome.webstorePrivate.beginInstallWithManifest2 =
549 chrome.webstorePrivate.beginInstallWithManifest3; 569 chrome.webstorePrivate.beginInstallWithManifest3;
550 } 570 }
551 571
552 if (apiExists("test")) 572 if (apiExists("test"))
553 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; 573 chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
554 }); 574 });
555 })(); 575 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698