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

Unified Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 9835039: Make app_custom_bindings.js lazily evaluated so it doesn't execute on every page load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 years, 9 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
« no previous file with comments | « no previous file | chrome/renderer/module_system.h » ('j') | chrome/renderer/module_system.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/extension_dispatcher.cc
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index 1833d64cfa85c23499ccefccec4af4b16bba2fd4..324e93e5c50792370fad2a3bc2d98b07edec22ad 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -118,6 +118,24 @@ class PrintNativeHandler : public NativeHandler {
}
};
+void InstallAppBindings(ModuleSystem* module_system,
+ v8::Handle<v8::Object> chrome,
+ v8::Handle<v8::Object> chrome_hidden) {
+ module_system->SetLazyField(chrome, "app", "app", "chromeApp");
+ module_system->SetLazyField(chrome, "appNotifications", "app",
+ "chromeAppNotifications");
+ module_system->SetLazyField(chrome_hidden, "app", "app",
+ "chromeHiddenApp");
+}
+
+void InstallWebstoreBindings(ModuleSystem* module_system,
+ v8::Handle<v8::Object> chrome,
+ v8::Handle<v8::Object> chrome_hidden) {
+ module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore");
+ module_system->SetLazyField(chrome_hidden, "webstore", "webstore",
+ "chromeHiddenWebstore");
+}
+
}
ExtensionDispatcher::ExtensionDispatcher()
@@ -460,6 +478,9 @@ void ExtensionDispatcher::DidCreateScriptContext(
v8_context_set_.Add(context);
scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_));
+ // Enable natives in startup.
+ ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get());
+
RegisterNativeHandlers(module_system.get(), context);
module_system->RegisterNativeHandler("chrome_hidden",
@@ -471,6 +492,13 @@ void ExtensionDispatcher::DidCreateScriptContext(
if (extension)
manifest_version = extension->manifest_version();
+ typedef void (*BindingInstaller)(ModuleSystem* module_system,
+ v8::Handle<v8::Object> chrome,
+ v8::Handle<v8::Object> chrome_hidden);
+ std::map<std::string, BindingInstaller> lazy_bindings;
+ lazy_bindings["app"] = InstallAppBindings;
+ lazy_bindings["webstore"] = InstallWebstoreBindings;
+
// Create the 'chrome' variable if it doesn't already exist.
{
v8::HandleScope handle_scope;
@@ -513,11 +541,20 @@ void ExtensionDispatcher::DidCreateScriptContext(
for (std::set<std::string>::iterator i = apis->begin(); i != apis->end();
++i) {
- module_system->Require(*i);
+ std::map<std::string, BindingInstaller>::const_iterator lazy_binding =
+ lazy_bindings.find(*i);
+ if (lazy_binding != lazy_bindings.end()) {
+ v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
+ v8::Handle<v8::Object> chrome =
+ global->Get(v8::String::New("chrome"))->ToObject();
+ v8::Handle<v8::Object> chrome_hidden =
+ ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject();
+ (*lazy_binding->second)(module_system.get(), chrome, chrome_hidden);
+ } else {
+ module_system->Require(*i);
+ }
}
- module_system->set_natives_enabled(false);
-
context->set_module_system(module_system.Pass());
context->DispatchOnLoadEvent(
« no previous file with comments | « no previous file | chrome/renderer/module_system.h » ('j') | chrome/renderer/module_system.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698