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); |
+} |
+ |
+}); |