From 00ed814962419e0714bec1050513ca6399f441ba Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Apr 2014 10:34:40 +0800 Subject: [PATCH] Add executeJavaScript method for webContents. --- atom/browser/api/atom_api_web_contents.cc | 9 ++++++++- atom/browser/api/atom_api_web_contents.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 37b81f4e4..d73791401 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -7,6 +7,7 @@ #include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "native_mate/object_template_builder.h" @@ -53,6 +54,11 @@ bool WebContents::IsCrashed() const { return web_contents_->IsCrashed(); } +void WebContents::ExecuteJavaScript(const string16& code) { + web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( + string16(), code); +} + mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( v8::Isolate* isolate) { return mate::ObjectTemplateBuilder(isolate) @@ -63,7 +69,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("stop", &WebContents::Stop) .SetMethod("getRoutingId", &WebContents::GetRoutingID) .SetMethod("getProcessId", &WebContents::GetProcessID) - .SetMethod("isCrashed", &WebContents::IsCrashed); + .SetMethod("isCrashed", &WebContents::IsCrashed) + .SetMethod("executeJavaScript", &WebContents::ExecuteJavaScript); } // static diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 8b8a5266d..c1311f9bb 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -31,6 +31,7 @@ class WebContents : public mate::EventEmitter { int GetRoutingID() const; int GetProcessID() const; bool IsCrashed() const; + void ExecuteJavaScript(const string16& code); protected: explicit WebContents(content::WebContents* web_contents);