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

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

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
(Empty)
1 (function(browser, extensionId, isExtensionProcess, isIncognitoProcess,
2 manifestVersion, allowExtensionAPIs) {
3
4 var GetExtensionAPIDefinition = browser.natives.GetExtensionAPIDefinition;
5 var GetChromeHidden = browser.natives.GetChromeHidden;
6
7 function wrap(source) {
8 return "(function(require, exports, natives) {" + source + "\n})";
9 }
10
11 function ModuleLoader() {
12 this.cache_ = {};
13 };
14
15 ModuleLoader.prototype.execute = function(id) {
16 var source = browser.GetSource(id);
17 if (!source) {
18 return null;
19 }
20 var wrappedSource = wrap(source);
21 var f = browser.Execute(wrappedSource);
22 var exports = {};
23 f(require, exports, browser.natives);
24 return exports;
25 };
26
27 ModuleLoader.prototype.load = function(id) {
28 var exports = this.cache_[id];
29 if (exports) {
30 return exports;
31 }
32 var exports = this.execute(id);
33 this.cache_[id] = exports;
34 return exports;
35 };
36
37 var moduleLoader = new ModuleLoader();
38
39 function require(moduleId) {
40 return moduleLoader.load(moduleId);
41 }
42
43 require('app');
44 require('webstore');
45
46 if (allowExtensionAPIs) {
47 require('event_bindings');
48 require('miscellaneous_bindings');
49 require('json_schema');
50 require('schema_generated_bindings');
51 require('apitest');
52
53 GetExtensionAPIDefinition().forEach(function(apiDef) {
54 var apiName = apiDef.namespace;
55 if (browser.natives.AllowAPI(apiName)) {
56 require('custom/' + apiName);
57 }
58 });
59
60 GetChromeHidden().dispatchOnLoad(extensionId, isExtensionProcess,
61 isIncognitoProcess, manifestVersion);
62 }
63
64 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698