From: Cheng Zhao Date: Fri, 25 Apr 2014 02:34:40 +0000 (+0800) Subject: Add executeJavaScript method for webContents. X-Git-Tag: v0.12.0~11^2~15 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=00ed814962419e0714bec1050513ca6399f441ba;p=electron.git Add executeJavaScript method for webContents. --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 37b81f4e..d7379140 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 8b8a5266..c1311f9b 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);