Index: chrome/renderer/extensions/dispatcher.cc |
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc |
index 13778fed54eabf40db4538b7dfb2bb6ac07dcafe..761e56e35fa03f85d2ff48cebc70533be7552623 100644 |
--- a/chrome/renderer/extensions/dispatcher.cc |
+++ b/chrome/renderer/extensions/dispatcher.cc |
@@ -99,7 +99,8 @@ namespace { |
static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
-static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
+static const char kEventModule[] = "event_bindings"; |
+static const char kEventDispatchFunction[] = "dispatchEvent"; |
static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
@@ -371,6 +372,8 @@ class LoggingNativeHandler : public ObjectBackedNativeHandler { |
base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
RouteFunction("CHECK", |
base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); |
+ RouteFunction("DCHECK_IS_ON", |
+ base::Bind(&LoggingNativeHandler::DcheckIsOn, base::Unretained(this))); |
} |
v8::Handle<v8::Value> Check(const v8::Arguments& args) { |
@@ -389,6 +392,10 @@ class LoggingNativeHandler : public ObjectBackedNativeHandler { |
return v8::Undefined(); |
} |
+ v8::Handle<v8::Value> DcheckIsOn(const v8::Arguments& args) { |
+ return v8::Boolean::New(DCHECK_IS_ON()); |
+ } |
+ |
private: |
void ParseArgs(const v8::Arguments& args, |
bool* check_value, |
@@ -429,8 +436,6 @@ 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_hidden, "app", "app", |
- "chromeHiddenApp"); |
} |
void InstallWebstoreBindings(ModuleSystem* module_system, |
@@ -550,6 +555,7 @@ void Dispatcher::OnSetChannel(int channel) { |
} |
void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
+ const std::string& module_name, |
const std::string& function_name, |
const base::ListValue& args, |
bool user_gesture) { |
@@ -558,8 +564,10 @@ void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
web_user_gesture.reset(new WebScopedUserGesture); |
} |
- v8_context_set_.DispatchChromeHiddenMethod( |
- extension_id, function_name, args, NULL); |
+ v8_context_set_.ForEach( |
+ extension_id, |
+ NULL, // all render views |
+ base::Bind(&CallModuleMethod, module_name, function_name, &args)); |
// Reset the idle handler each time there's any activity like event or message |
// dispatch, for which Invoke is the chokepoint. |
@@ -572,6 +580,7 @@ void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
// background page active. |
const Extension* extension = extensions_.GetByID(extension_id); |
if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
+ module_name == kEventModule && |
function_name == kEventDispatchFunction) { |
RenderView* background_view = |
ExtensionHelper::GetBackgroundPage(extension_id); |
@@ -877,6 +886,7 @@ void Dispatcher::PopulateSourceMap() { |
source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); |
source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
+ source_map_.RegisterSource("unload_event", IDR_UNLOAD_EVENT_JS); |
source_map_.RegisterSource("utils", IDR_UTILS_JS); |
source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
@@ -1018,7 +1028,7 @@ void Dispatcher::DidCreateScriptContext( |
new ChromeV8Context(v8_context, frame, extension, context_type); |
v8_context_set_.Add(context); |
- scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
+ scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
&source_map_)); |
// Enable natives in startup. |
ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
@@ -1069,8 +1079,6 @@ void Dispatcher::DidCreateScriptContext( |
case Feature::BLESSED_EXTENSION_CONTEXT: |
case Feature::UNBLESSED_EXTENSION_CONTEXT: |
case Feature::CONTENT_SCRIPT_CONTEXT: |
- if (extension && !extension->is_platform_app()) |
- module_system->Require("miscellaneous_bindings"); |
module_system->Require("json"); // see paranoid comment in json.js |
// TODO(kalman): move this code back out of the switch and execute it |
@@ -1354,21 +1362,12 @@ void Dispatcher::OnSuspend(const std::string& extension_id) { |
// the browser know when we are starting and stopping the event dispatch, so |
// that it still considers the extension idle despite any activity the suspend |
// event creates. |
- base::ListValue args; |
- args.Set(0, new base::StringValue(kOnSuspendEvent)); |
- args.Set(1, new base::ListValue()); |
- v8_context_set_.DispatchChromeHiddenMethod( |
- extension_id, kEventDispatchFunction, args, NULL); |
- |
+ DispatchEvent(extension_id, kOnSuspendEvent); |
RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
} |
void Dispatcher::OnCancelSuspend(const std::string& extension_id) { |
- base::ListValue args; |
- args.Set(0, new base::StringValue(kOnSuspendCanceledEvent)); |
- args.Set(1, new base::ListValue()); |
- v8_context_set_.DispatchChromeHiddenMethod( |
- extension_id, kEventDispatchFunction, args, NULL); |
+ DispatchEvent(extension_id, kOnSuspendCanceledEvent); |
} |
Feature::Context Dispatcher::ClassifyJavaScriptContext( |
@@ -1464,4 +1463,39 @@ bool Dispatcher::CheckContextAccessToExtensionAPI( |
return true; |
} |
+void Dispatcher::DispatchEvent(const std::string& extension_id, |
+ const std::string& event_name) const { |
+ base::ListValue args; |
+ args.Set(0, new base::StringValue(event_name)); |
+ args.Set(1, new base::ListValue()); |
+ v8_context_set_.ForEach( |
+ extension_id, |
+ NULL, // all render views |
+ base::Bind(&CallModuleMethod, |
+ kEventModule, |
+ kEventDispatchFunction, |
+ &args)); |
+} |
+ |
+// static |
+void Dispatcher::CallModuleMethod(const std::string& module_name, |
+ const std::string& method_name, |
+ const base::ListValue* args, |
+ ChromeV8Context* context) { |
+ v8::HandleScope handle_scope; |
+ v8::Context::Scope context_scope(context->v8_context()); |
+ |
+ scoped_ptr<content::V8ValueConverter> converter( |
+ content::V8ValueConverter::create()); |
+ |
+ std::vector<v8::Handle<v8::Value> > arguments; |
+ for (base::ListValue::const_iterator it = args->begin(); it != args->end(); |
+ ++it) { |
+ arguments.push_back(converter->ToV8Value(*it, context->v8_context())); |
+ } |
+ |
+ context->module_system()->CallModuleMethod( |
+ module_name, method_name, &arguments); |
+} |
+ |
} // namespace extensions |