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 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...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // TODO(aa): Remove this when all APIs are ported to feature system. |
| 403 return isExtensionProcess || |
| 404 apiDef.unprivileged || |
| 405 itemSchema.unprivileged; |
| 406 } |
401 } | 407 } |
402 | 408 |
403 // Adds a getter that throws an access denied error to object |mod| | 409 // Adds a getter that throws an access denied error to object |mod| |
404 // for property |name|. | 410 // for property |name|. |
405 function addUnprivilegedAccessGetter(mod, name) { | 411 function addUnprivilegedAccessGetter(mod, name) { |
406 mod.__defineGetter__(name, function() { | 412 mod.__defineGetter__(name, function() { |
407 throw new Error( | 413 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 }); | 414 }); |
411 } | 415 } |
412 | 416 |
413 // Setup Functions. | 417 // Setup Functions. |
414 if (apiDef.functions) { | 418 if (apiDef.functions) { |
415 apiDef.functions.forEach(function(functionDef) { | 419 apiDef.functions.forEach(function(functionDef) { |
416 if (functionDef.name in mod) { | 420 if (functionDef.name in mod) { |
417 throw new Error('Function ' + functionDef.name + | 421 throw new Error('Function ' + functionDef.name + |
418 ' already defined in ' + apiDef.namespace); | 422 ' already defined in ' + apiDef.namespace); |
419 } | 423 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }); |
OLD | NEW |