Index: chrome/renderer/extensions/dispatcher.cc |
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc |
index a1fd9c5d3ef5f6f757ece3a37bf72c679fb7da49..1c7d80015bdb4c0b3141e6e56f49adc4078e9130 100644 |
--- a/chrome/renderer/extensions/dispatcher.cc |
+++ b/chrome/renderer/extensions/dispatcher.cc |
@@ -12,6 +12,7 @@ |
#include "base/string_util.h" |
#include "base/strings/string_piece.h" |
#include "base/strings/string_split.h" |
+#include "base/values.h" |
#include "chrome/common/child_process_logging.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
@@ -99,7 +100,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"; |
@@ -328,6 +330,8 @@ class ProcessInfoNativeHandler : public ChromeV8Extension { |
RouteFunction("IsSendRequestDisabled", |
base::Bind(&ProcessInfoNativeHandler::IsSendRequestDisabled, |
base::Unretained(this))); |
+ RouteFunction("Log", |
+ base::Bind(&ProcessInfoNativeHandler::Log, base::Unretained(this))); |
} |
v8::Handle<v8::Value> GetExtensionId(const v8::Arguments& args) { |
@@ -355,6 +359,11 @@ class ProcessInfoNativeHandler : public ChromeV8Extension { |
return v8::Undefined(); |
} |
+ v8::Handle<v8::Value> Log(const v8::Arguments& args) { |
+ LOG(WARNING) << *v8::String::AsciiValue(args[0]); |
+ return v8::Undefined(); |
+ } |
+ |
private: |
std::string extension_id_; |
std::string context_type_; |
@@ -371,6 +380,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 +400,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 +444,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 +563,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 +572,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, |
+ 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 +588,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); |
@@ -595,7 +612,7 @@ void Dispatcher::OnDispatchOnConnect( |
} |
void Dispatcher::OnDeliverMessage(int target_port_id, |
- const std::string& message) { |
+ const base::ListValue& message) { |
MiscellaneousBindings::DeliverMessage( |
v8_context_set_.GetAll(), |
target_port_id, |
@@ -791,9 +808,9 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
ChromeV8Context* context) { |
v8::Handle<v8::Context> v8_context = context->v8_context(); |
- module_system->RegisterNativeHandler("event_bindings", |
+ module_system->RegisterNativeHandler("event_natives", |
scoped_ptr<NativeHandler>(EventBindings::Create(this, v8_context))); |
- module_system->RegisterNativeHandler("miscellaneous_bindings", |
+ module_system->RegisterNativeHandler("miscellaneous_bindings_natives", |
scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, v8_context))); |
module_system->RegisterNativeHandler("apiDefinitions", |
scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); |
@@ -819,7 +836,7 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
module_system->RegisterNativeHandler("app_runtime", |
scoped_ptr<NativeHandler>( |
new AppRuntimeCustomBindings(this, v8_context))); |
- module_system->RegisterNativeHandler("app_window", |
+ module_system->RegisterNativeHandler("app_window_natives", |
scoped_ptr<NativeHandler>( |
new AppWindowCustomBindings(this, v8_context))); |
module_system->RegisterNativeHandler("context_menus", |
@@ -863,22 +880,22 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
} |
void Dispatcher::PopulateSourceMap() { |
- source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
- source_map_.RegisterSource("miscellaneous_bindings", |
- IDR_MISCELLANEOUS_BINDINGS_JS); |
- source_map_.RegisterSource("json", IDR_JSON_JS); |
- source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
- source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); |
- |
// Libraries. |
source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
+ source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
+ source_map_.RegisterSource(kEventModule, IDR_EVENT_BINDINGS_JS); |
source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); |
+ source_map_.RegisterSource("json", IDR_JSON_JS); |
+ source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
+ source_map_.RegisterSource("miscellaneous_bindings", |
+ IDR_MISCELLANEOUS_BINDINGS_JS); |
+ source_map_.RegisterSource("on_unload", IDR_ON_UNLOAD_JS); |
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("test", IDR_TEST_CUSTOM_BINDINGS_JS); |
source_map_.RegisterSource("utils", IDR_UTILS_JS); |
- source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
// Custom bindings. |
source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); |
@@ -1018,8 +1035,8 @@ 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, |
- &source_map_)); |
+ scoped_ptr<ModuleSystem> module_system( |
+ new ModuleSystem(context, &source_map_)); |
// Enable natives in startup. |
ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
@@ -1069,8 +1086,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 |
@@ -1357,9 +1372,13 @@ void Dispatcher::OnSuspend(const std::string& extension_id) { |
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); |
- |
+ v8_context_set_.ForEach( |
+ extension_id, |
+ NULL, |
+ base::Bind(&CallModuleMethod, |
+ kEventModule, |
+ kEventDispatchFunction, |
+ &args)); |
RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
} |
@@ -1367,8 +1386,13 @@ 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); |
+ v8_context_set_.ForEach( |
+ extension_id, |
+ NULL, |
+ base::Bind(&CallModuleMethod, |
+ kEventModule, |
+ kEventDispatchFunction, |
+ &args)); |
} |
Feature::Context Dispatcher::ClassifyJavaScriptContext( |
@@ -1464,4 +1488,25 @@ bool Dispatcher::CheckContextAccessToExtensionAPI( |
return true; |
} |
+// 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 |