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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/bootstrap.js
diff --git a/chrome/renderer/resources/extensions/bootstrap.js b/chrome/renderer/resources/extensions/bootstrap.js
new file mode 100644
index 0000000000000000000000000000000000000000..8ae56f2f4f8a0654589053f3fb8b0df96abe0afd
--- /dev/null
+++ b/chrome/renderer/resources/extensions/bootstrap.js
@@ -0,0 +1,64 @@
+(function(browser, extensionId, isExtensionProcess, isIncognitoProcess,
+ manifestVersion, allowExtensionAPIs) {
+
+var GetExtensionAPIDefinition = browser.natives.GetExtensionAPIDefinition;
+var GetChromeHidden = browser.natives.GetChromeHidden;
+
+function wrap(source) {
+ return "(function(require, exports, natives) {" + source + "\n})";
+}
+
+function ModuleLoader() {
+ this.cache_ = {};
+};
+
+ModuleLoader.prototype.execute = function(id) {
+ var source = browser.GetSource(id);
+ if (!source) {
+ return null;
+ }
+ var wrappedSource = wrap(source);
+ var f = browser.Execute(wrappedSource);
+ var exports = {};
+ f(require, exports, browser.natives);
+ return exports;
+};
+
+ModuleLoader.prototype.load = function(id) {
+ var exports = this.cache_[id];
+ if (exports) {
+ return exports;
+ }
+ var exports = this.execute(id);
+ this.cache_[id] = exports;
+ return exports;
+};
+
+var moduleLoader = new ModuleLoader();
+
+function require(moduleId) {
+ return moduleLoader.load(moduleId);
+}
+
+require('app');
+require('webstore');
+
+if (allowExtensionAPIs) {
+ require('event_bindings');
+ require('miscellaneous_bindings');
+ require('json_schema');
+ require('schema_generated_bindings');
+ require('apitest');
+
+ GetExtensionAPIDefinition().forEach(function(apiDef) {
+ var apiName = apiDef.namespace;
+ if (browser.natives.AllowAPI(apiName)) {
+ require('custom/' + apiName);
+ }
+ });
+
+ GetChromeHidden().dispatchOnLoad(extensionId, isExtensionProcess,
+ isIncognitoProcess, manifestVersion);
+}
+
+});

Powered by Google App Engine
This is Rietveld 408576698