diff options
Diffstat (limited to 'chrome/renderer/extensions/bindings_utils.cc')
-rw-r--r-- | chrome/renderer/extensions/bindings_utils.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/chrome/renderer/extensions/bindings_utils.cc b/chrome/renderer/extensions/bindings_utils.cc index 097c8d0..81e2058 100644 --- a/chrome/renderer/extensions/bindings_utils.cc +++ b/chrome/renderer/extensions/bindings_utils.cc @@ -4,6 +4,7 @@ #include "chrome/renderer/extensions/bindings_utils.h" +#include "base/string_util.h" #include "chrome/renderer/render_view.h" #include "webkit/glue/webframe.h" @@ -21,3 +22,25 @@ RenderView* GetRenderViewForCurrentContext() { DCHECK(renderview) << "Encountered a WebView without a WebViewDelegate"; return renderview; } + +void CallFunctionInContext(v8::Handle<v8::Context> context, + const std::string& function_name, int argc, + v8::Handle<v8::Value>* argv) { + v8::Context::Scope context_scope(context); + + // Look up the function name, which may be a sub-property like + // "chrome.handleResponse_" in the global variable. + v8::Local<v8::Value> value = context->Global(); + std::vector<std::string> components; + SplitStringDontTrim(function_name, '.', &components); + for (size_t i = 0; i < components.size(); ++i) { + if (value->IsObject()) + value = value->ToObject()->Get(v8::String::New(components[i].c_str())); + } + if (!value->IsFunction()) + return; + + v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); + if (!function.IsEmpty()) + function->Call(v8::Object::New(), argc, argv); +} |