Handle executeJavaScript in JavaScript

This commit is contained in:
Cheng Zhao 2016-01-13 12:11:46 +08:00
parent 5b7d1a9890
commit 55dfddba77
8 changed files with 28 additions and 52 deletions

View file

@ -27,8 +27,6 @@
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "ui/base/resource/resource_bundle.h"
#include "native_mate/dictionary.h"
@ -115,8 +113,6 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage)
IPC_MESSAGE_HANDLER(AtomViewMsg_ExecuteJavaScript,
OnJavaScriptExecuteRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@ -152,22 +148,4 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
}
}
void AtomRenderViewObserver::OnJavaScriptExecuteRequest(
const base::string16& code, bool has_user_gesture) {
if (!document_created_)
return;
if (!render_view()->GetWebView())
return;
scoped_ptr<blink::WebScopedUserGesture> gesture(
has_user_gesture ? new blink::WebScopedUserGesture : nullptr);
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
blink::WebFrame* frame = render_view()->GetWebView()->mainFrame();
frame->executeScriptAndReturnValue(blink::WebScriptSource(code));
}
} // namespace atom