Chromium Code Reviews

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

Issue 10025007: Convert tabs, windows, and extension APIs to feature system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | 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 require('json_schema'); 8 require('json_schema');
9 require('event_bindings'); 9 require('event_bindings');
10 var GetExtensionAPIDefinition = 10 var GetExtensionAPIDefinition =
11 requireNative('apiDefinitions').GetExtensionAPIDefinition; 11 requireNative('apiDefinitions').GetExtensionAPIDefinition;
12 var IsMemberAllowed = requireNative('apiDefinitions').IsMemberAllowed;
12 var sendRequest = require('sendRequest').sendRequest; 13 var sendRequest = require('sendRequest').sendRequest;
13 14
14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 15 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
15 16
16 // The object to generate the bindings for "internal" APIs in, so that 17 // The object to generate the bindings for "internal" APIs in, so that
17 // extensions can't directly call them (without access to chromeHidden), 18 // extensions can't directly call them (without access to chromeHidden),
18 // but are still needed for internal mechanisms of extensions (e.g. events). 19 // but are still needed for internal mechanisms of extensions (e.g. events).
19 // 20 //
20 // This is distinct to the "*Private" APIs which are controlled via 21 // This is distinct to the "*Private" APIs which are controlled via
21 // having strict permissions and aren't generated *anywhere* unless needed. 22 // having strict permissions and aren't generated *anywhere* unless needed.
(...skipping 366 matching lines...)
388 if (t.type == 'object' && customTypes[t.id]) { 389 if (t.type == 'object' && customTypes[t.id]) {
389 customTypes[t.id].prototype.setSchema(t); 390 customTypes[t.id].prototype.setSchema(t);
390 } 391 }
391 }); 392 });
392 } 393 }
393 394
394 // Returns whether access to the content of a schema should be denied, 395 // Returns whether access to the content of a schema should be denied,
395 // based on the presence of "unprivileged" and whether this is an 396 // based on the presence of "unprivileged" and whether this is an
396 // extension process (versus e.g. a content script). 397 // extension process (versus e.g. a content script).
397 function isSchemaAccessAllowed(itemSchema) { 398 function isSchemaAccessAllowed(itemSchema) {
398 return isExtensionProcess || 399 if (apiDef.uses_feature_system) {
399 apiDef.unprivileged || 400 return IsMemberAllowed(apiDef.namespace + "." + itemSchema.name);
400 itemSchema.unprivileged; 401 } else {
402 return isExtensionProcess ||
403 apiDef.unprivileged ||
404 itemSchema.unprivileged;
405 }
401 } 406 }
402 407
403 // Adds a getter that throws an access denied error to object |mod| 408 // Adds a getter that throws an access denied error to object |mod|
404 // for property |name|. 409 // for property |name|.
405 function addUnprivilegedAccessGetter(mod, name) { 410 function addUnprivilegedAccessGetter(mod, name) {
406 mod.__defineGetter__(name, function() { 411 mod.__defineGetter__(name, function() {
407 throw new Error( 412 throw new Error('"' + name + '" cannot be used in this context.');
408 '"' + name + '" can only be used in extension processes. See ' +
409 'the content scripts documentation for more details.');
410 }); 413 });
411 } 414 }
412 415
413 // Setup Functions. 416 // Setup Functions.
414 if (apiDef.functions) { 417 if (apiDef.functions) {
415 apiDef.functions.forEach(function(functionDef) { 418 apiDef.functions.forEach(function(functionDef) {
416 if (functionDef.name in mod) { 419 if (functionDef.name in mod) {
417 throw new Error('Function ' + functionDef.name + 420 throw new Error('Function ' + functionDef.name +
418 ' already defined in ' + apiDef.namespace); 421 ' already defined in ' + apiDef.namespace);
419 } 422 }
420 423
421 var apiFunctionName = apiDef.namespace + "." + functionDef.name; 424 var apiFunctionName = apiDef.namespace + "." + functionDef.name;
422 425
423 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { 426 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) {
424 apiFunctions.registerUnavailable(apiFunctionName); 427 apiFunctions.registerUnavailable(apiFunctionName);
425 return; 428 return;
426 } 429 }
430
427 if (!isSchemaAccessAllowed(functionDef)) { 431 if (!isSchemaAccessAllowed(functionDef)) {
428 apiFunctions.registerUnavailable(apiFunctionName); 432 apiFunctions.registerUnavailable(apiFunctionName);
429 addUnprivilegedAccessGetter(mod, functionDef.name); 433 addUnprivilegedAccessGetter(mod, functionDef.name);
430 return; 434 return;
431 } 435 }
432 436
433 var apiFunction = {}; 437 var apiFunction = {};
434 apiFunction.definition = functionDef; 438 apiFunction.definition = functionDef;
435 apiFunction.name = apiFunctionName; 439 apiFunction.name = apiFunctionName;
436 440
(...skipping 143 matching lines...)
580 // beginInstallWithManifest2. 584 // beginInstallWithManifest2.
581 // See http://crbug.com/100242 585 // See http://crbug.com/100242
582 if (chrome.webstorePrivate) { 586 if (chrome.webstorePrivate) {
583 chrome.webstorePrivate.beginInstallWithManifest2 = 587 chrome.webstorePrivate.beginInstallWithManifest2 =
584 chrome.webstorePrivate.beginInstallWithManifest3; 588 chrome.webstorePrivate.beginInstallWithManifest3;
585 } 589 }
586 590
587 if (chrome.test) 591 if (chrome.test)
588 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; 592 chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
589 }); 593 });
OLDNEW

Powered by Google App Engine