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 sendRequest = require('sendRequest').sendRequest; | 12 var sendRequest = require('sendRequest').sendRequest; |
13 | 13 var isDevChannel = requireNative('channel').IsDevChannel; |
14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 14 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
15 | 15 |
16 // The object to generate the bindings for "internal" APIs in, so that | 16 // The object to generate the bindings for "internal" APIs in, so that |
17 // extensions can't directly call them (without access to chromeHidden), | 17 // extensions can't directly call them (without access to chromeHidden), |
18 // but are still needed for internal mechanisms of extensions (e.g. events). | 18 // but are still needed for internal mechanisms of extensions (e.g. events). |
19 // | 19 // |
20 // This is distinct to the "*Private" APIs which are controlled via | 20 // This is distinct to the "*Private" APIs which are controlled via |
21 // having strict permissions and aren't generated *anywhere* unless needed. | 21 // having strict permissions and aren't generated *anywhere* unless needed. |
22 var internalAPIs = {}; | 22 var internalAPIs = {}; |
23 chromeHidden.internalAPIs = internalAPIs; | 23 chromeHidden.internalAPIs = internalAPIs; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 function isPlatformSupported(schemaNode, platform) { | 334 function isPlatformSupported(schemaNode, platform) { |
335 return !schemaNode.platforms || | 335 return !schemaNode.platforms || |
336 schemaNode.platforms.indexOf(platform) > -1; | 336 schemaNode.platforms.indexOf(platform) > -1; |
337 } | 337 } |
338 | 338 |
339 function isManifestVersionSupported(schemaNode, manifestVersion) { | 339 function isManifestVersionSupported(schemaNode, manifestVersion) { |
340 return !schemaNode.maximumManifestVersion || | 340 return !schemaNode.maximumManifestVersion || |
341 manifestVersion <= schemaNode.maximumManifestVersion; | 341 manifestVersion <= schemaNode.maximumManifestVersion; |
342 } | 342 } |
343 | 343 |
| 344 // Temporary hack to check if the runtime API is supported. |
| 345 // TODO(aa): Remove when we can restrict non-permission APIs to dev-only. |
| 346 function isRuntimeAPISupported(schemaNode) { |
| 347 if (schemaNode.namespace == "runtime") |
| 348 return isDevChannel(); |
| 349 return true; |
| 350 } |
| 351 |
344 function isSchemaNodeSupported(schemaNode, platform, manifestVersion) { | 352 function isSchemaNodeSupported(schemaNode, platform, manifestVersion) { |
345 return isPlatformSupported(schemaNode, platform) && | 353 return isPlatformSupported(schemaNode, platform) && |
346 isManifestVersionSupported(schemaNode, manifestVersion); | 354 isManifestVersionSupported(schemaNode, manifestVersion) && |
| 355 isRuntimeAPISupported(schemaNode); |
347 } | 356 } |
348 | 357 |
349 chromeHidden.onLoad.addListener(function(extensionId, | 358 chromeHidden.onLoad.addListener(function(extensionId, |
350 isExtensionProcess, | 359 isExtensionProcess, |
351 isIncognitoProcess, | 360 isIncognitoProcess, |
352 manifestVersion) { | 361 manifestVersion) { |
353 var apiDefinitions = GetExtensionAPIDefinition(); | 362 var apiDefinitions = GetExtensionAPIDefinition(); |
354 | 363 |
355 // Read api definitions and setup api functions in the chrome namespace. | 364 // Read api definitions and setup api functions in the chrome namespace. |
356 // TODO(rafaelw): Consider defining a json schema for an api definition | 365 // TODO(rafaelw): Consider defining a json schema for an api definition |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // beginInstallWithManifest2. | 592 // beginInstallWithManifest2. |
584 // See http://crbug.com/100242 | 593 // See http://crbug.com/100242 |
585 if (chrome.webstorePrivate) { | 594 if (chrome.webstorePrivate) { |
586 chrome.webstorePrivate.beginInstallWithManifest2 = | 595 chrome.webstorePrivate.beginInstallWithManifest2 = |
587 chrome.webstorePrivate.beginInstallWithManifest3; | 596 chrome.webstorePrivate.beginInstallWithManifest3; |
588 } | 597 } |
589 | 598 |
590 if (chrome.test) | 599 if (chrome.test) |
591 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 600 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
592 }); | 601 }); |
OLD | NEW |