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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/extensions/module_system.cc
diff --git a/chrome/renderer/extensions/module_system.cc b/chrome/renderer/extensions/module_system.cc
index 69b2c78fddf1b215350b554030c2f7bd7149c871..7678569f4fb815bc9491d907ec45964cad83a5aa 100644
--- a/chrome/renderer/extensions/module_system.cc
+++ b/chrome/renderer/extensions/module_system.cc
@@ -9,6 +9,7 @@
namespace {
+const char* kArgument = "argument";
const char* kModuleSystem = "module_system";
const char* kModuleName = "module_name";
const char* kModuleField = "module_field";
@@ -168,20 +169,33 @@ void ModuleSystem::CallModuleMethod(const std::string& module_name,
v8::Local<v8::Value> value =
v8::Handle<v8::Object>::Cast(module)->Get(
v8::String::New(method_name.c_str()));
+ CallModuleMethod(value, 0, NULL);
+}
+
+v8::Handle<v8::Value> ModuleSystem::CallModuleMethod(
+ v8::Local<v8::Value> value,
+ int argc,
+ v8::Handle<v8::Value> argv[]) {
if (value.IsEmpty() || !value->IsFunction())
- return;
+ return v8::Handle<v8::Value>();
v8::Handle<v8::Function> func =
v8::Handle<v8::Function>::Cast(value);
// TODO(jeremya/koz): refer to context_ here, not the current context.
v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
+ v8::Handle<v8::Value> ret;
{
WebKit::WebScopedMicrotaskSuppression suppression;
v8::TryCatch try_catch;
try_catch.SetCaptureMessage(true);
- func->Call(global, 0, NULL);
+ ret = func->Call(global, argc, argv);
if (try_catch.HasCaught())
HandleException(try_catch);
}
+ return ret;
+}
+
+bool ModuleSystem::HasNativeHandler(const std::string& name) {
+ return native_handler_map_.find(name) != native_handler_map_.end();
}
void ModuleSystem::RegisterNativeHandler(const std::string& name,
@@ -228,19 +242,37 @@ v8::Handle<v8::Value> ModuleSystem::LazyFieldGetter(
v8::Handle<v8::String> field =
parameters->Get(v8::String::New(kModuleField))->ToString();
- return handle_scope.Close(module->Get(field));
+ v8::Local<v8::Value> value = module->Get(field);
not at google - send to devlin 2012/12/13 22:26:40 Something to add a TODO about - it seems like we c
+ if (!parameters->Has(v8::String::New(kArgument)))
+ return handle_scope.Close(module->Get(field));
+ v8::Handle<v8::Value> argv[] = {parameters->Get(v8::String::New(kArgument))};
+
+ NativesEnabledScope scope(module_system);
+ return handle_scope.Close(module_system->CallModuleMethod(value, 1, argv));
not at google - send to devlin 2012/12/13 22:26:40 Yeah, all this stuff - can it go in schema_binding
}
void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
const std::string& field,
const std::string& module_name,
const std::string& module_field) {
+ SetLazyField(object, field, module_name, module_field, "");
+}
+
+void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
+ const std::string& field,
+ const std::string& module_name,
+ const std::string& module_field,
+ const std::string& arg) {
v8::HandleScope handle_scope;
v8::Handle<v8::Object> parameters = v8::Object::New();
parameters->Set(v8::String::New(kModuleName),
v8::String::New(module_name.c_str()));
parameters->Set(v8::String::New(kModuleField),
v8::String::New(module_field.c_str()));
+ if (arg.size()) {
+ parameters->Set(v8::String::New(kArgument),
+ v8::String::New(arg.c_str()));
+ }
object->SetAccessor(v8::String::New(field.c_str()),
&ModuleSystem::LazyFieldGetter,

Powered by Google App Engine
This is Rietveld 408576698