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

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

Issue 9309114: Allow "internal" APIs to be specified in extension API schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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();
11 native function GetExtensionAPIDefinition(); 11 native function GetExtensionAPIDefinition();
12 native function GetNextRequestId(); 12 native function GetNextRequestId();
13 native function StartRequest(); 13 native function StartRequest();
14 native function SetIconCommon(); 14 native function SetIconCommon();
15 15
16 var chromeHidden = GetChromeHidden(); 16 var chromeHidden = GetChromeHidden();
17 17
18 if (!chrome) 18 // The object to generate the bindings for "internal" APIs in, so that
19 chrome = {}; 19 // extensions can't directly call them (without access to chromeHidden),
20 20 // but are still needed for internal mechanisms of extensions (e.g. events).
21 function apiExists(path) { 21 //
22 var resolved = chrome; 22 // This is distinct to the "*Private" APIs which are controlled via
23 path.split(".").forEach(function(next) { 23 // having strict permissions and aren't generated *anywhere* unless needed.
24 if (resolved) 24 var internalAPIs = {};
25 resolved = resolved[next]; 25 chromeHidden.internalAPIs = internalAPIs;
26 });
27 return !!resolved;
28 }
29 26
30 function forEach(dict, f) { 27 function forEach(dict, f) {
31 for (key in dict) { 28 for (key in dict) {
32 if (dict.hasOwnProperty(key)) 29 if (dict.hasOwnProperty(key))
33 f(key, dict[key]); 30 f(key, dict[key]);
34 } 31 }
35 } 32 }
36 33
37 // Validate arguments. 34 // Validate arguments.
38 chromeHidden.validationTypes = []; 35 chromeHidden.validationTypes = [];
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // and validating either here, in a unit_test or both. 375 // and validating either here, in a unit_test or both.
379 // TODO(rafaelw): Handle synchronous functions. 376 // TODO(rafaelw): Handle synchronous functions.
380 // TODO(rafaelw): Consider providing some convenient override points 377 // TODO(rafaelw): Consider providing some convenient override points
381 // for api functions that wish to insert themselves into the call. 378 // for api functions that wish to insert themselves into the call.
382 var platform = getPlatform(); 379 var platform = getPlatform();
383 380
384 apiDefinitions.forEach(function(apiDef) { 381 apiDefinitions.forEach(function(apiDef) {
385 if (!isSchemaNodeSupported(apiDef, platform, manifestVersion)) 382 if (!isSchemaNodeSupported(apiDef, platform, manifestVersion))
386 return; 383 return;
387 384
388 var module = chrome; 385 // See comment on internalAPIs at the top.
386 var module = apiDef.internal ? internalAPIs : chrome;
387
389 var namespaces = apiDef.namespace.split('.'); 388 var namespaces = apiDef.namespace.split('.');
390 for (var index = 0, name; name = namespaces[index]; index++) { 389 for (var index = 0, name; name = namespaces[index]; index++) {
391 module[name] = module[name] || {}; 390 module[name] = module[name] || {};
392 module = module[name]; 391 module = module[name];
393 } 392 }
394 393
395 // Add types to global validationTypes 394 // Add types to global validationTypes
396 if (apiDef.types) { 395 if (apiDef.types) {
397 apiDef.types.forEach(function(t) { 396 apiDef.types.forEach(function(t) {
398 if (!isSchemaNodeSupported(t, platform, manifestVersion)) 397 if (!isSchemaNodeSupported(t, platform, manifestVersion))
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 apiFunctions: apiFunctions, 566 apiFunctions: apiFunctions,
568 sendRequest: sendRequest, 567 sendRequest: sendRequest,
569 setIcon: setIcon, 568 setIcon: setIcon,
570 apiDefinitions: apiDefinitions, 569 apiDefinitions: apiDefinitions,
571 }, extensionId); 570 }, extensionId);
572 }); 571 });
573 572
574 // TOOD(mihaip): remove this alias once the webstore stops calling 573 // TOOD(mihaip): remove this alias once the webstore stops calling
575 // beginInstallWithManifest2. 574 // beginInstallWithManifest2.
576 // See http://crbug.com/100242 575 // See http://crbug.com/100242
577 if (apiExists("webstorePrivate")) { 576 if (chrome.webstorePrivate) {
578 chrome.webstorePrivate.beginInstallWithManifest2 = 577 chrome.webstorePrivate.beginInstallWithManifest2 =
579 chrome.webstorePrivate.beginInstallWithManifest3; 578 chrome.webstorePrivate.beginInstallWithManifest3;
580 } 579 }
581 580
582 if (apiExists("test")) 581 if (chrome.test)
583 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; 582 chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
584 }); 583 });
585 })(); 584 })();
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/event.js ('k') | chrome/test/data/extensions/api_test/declarative/api/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698