return handler->Handle(full_file_path, save_type);
}
-void WebContents::ExecuteJavaScript(const base::string16& code,
- bool has_user_gesture) {
- Send(new AtomViewMsg_ExecuteJavaScript(routing_id(), code, has_user_gesture));
-}
-
void WebContents::OpenDevTools(mate::Arguments* args) {
if (type_ == REMOTE)
return;
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
.SetMethod("insertCSS", &WebContents::InsertCSS)
.SetMethod("savePage", &WebContents::SavePage)
- .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
.SetMethod("openDevTools", &WebContents::OpenDevTools)
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
bool SavePage(const base::FilePath& full_file_path,
const content::SavePageType& save_type,
const SavePageHandler::SavePageCallback& callback);
- void ExecuteJavaScript(const base::string16& code,
- bool has_user_gesture);
void OpenDevTools(mate::Arguments* args);
void CloseDevTools();
bool IsDevToolsOpened();
// Following methods are mapped to webFrame.
const webFrameMethods = [
+ 'executeJavaScript',
'insertText',
];
return this._send(channel, slice.call(args));
};
- /*
- Make sure webContents.executeJavaScript would run the code only when the
- web contents has been loaded.
- */
- webContents.executeJavaScript = function(code, hasUserGesture) {
- if (hasUserGesture == null) {
- hasUserGesture = false;
- }
- if (this.getURL() && !this.isLoading()) {
- return this._executeJavaScript(code, hasUserGesture);
- } else {
- return webContents.once('did-finish-load', this._executeJavaScript.bind(this, code, hasUserGesture));
- }
- };
-
/* The navigation controller. */
controller = new NavigationController(webContents);
ref1 = NavigationController.prototype;
};
}
+ // Make sure webContents.executeJavaScript would run the code only when the
+ // webContents has been loaded.
+ const executeJavaScript = webContents.executeJavaScript;
+ webContents.executeJavaScript = function(code, hasUserGesture) {
+ // TODO(zcbenz): Use default parameter after Chrome 49.
+ if (hasUserGesture === undefined)
+ hasUserGesture = false;
+
+ if (this.getURL() && !this.isLoading())
+ return executeJavaScript.call(this, code, hasUserGesture);
+ else
+ return this.once('did-finish-load', executeJavaScript.bind(this, code, hasUserGesture));
+ };
+
/* Dispatch IPC messages to the ipc module. */
webContents.on('ipc-message', function(event, packed) {
var args, channel;
base::string16 /* channel */,
base::ListValue /* arguments */)
-IPC_MESSAGE_ROUTED2(AtomViewMsg_ExecuteJavaScript,
- base::string16 /* code */,
- bool /* has user gesture */)
-
// Sent by the renderer when the draggable regions are updated.
IPC_MESSAGE_ROUTED1(AtomViewHostMsg_UpdateDraggableRegions,
std::vector<atom::DraggableRegion> /* regions */)
#include "native_mate/object_template_builder.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
+#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebView.h"
web_frame_->insertText(blink::WebString::fromUTF8(text));
}
+void WebFrame::ExecuteJavaScript(const base::string16& code, bool by_user) {
+ scoped_ptr<blink::WebScopedUserGesture> gesture(
+ by_user ? new blink::WebScopedUserGesture : nullptr);
+ web_frame_->executeScriptAndReturnValue(blink::WebScriptSource(code));
+}
+
mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return mate::ObjectTemplateBuilder(isolate)
&WebFrame::RegisterURLSchemeAsBypassingCSP)
.SetMethod("registerURLSchemeAsPrivileged",
&WebFrame::RegisterURLSchemeAsPrivileged)
- .SetMethod("insertText", &WebFrame::InsertText);
+ .SetMethod("insertText", &WebFrame::InsertText)
+ .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript);
}
// static
// Editing.
void InsertText(const std::string& text);
+ // Excecuting scripts.
+ void ExecuteJavaScript(const base::string16& code, bool by_user);
+
// mate::Wrappable:
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate);
#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"
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()
}
}
-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
void OnBrowserMessage(const base::string16& channel,
const base::ListValue& args);
- void OnJavaScriptExecuteRequest(const base::string16& code,
- bool has_user_gesture);
// Weak reference to renderer client.
AtomRendererClient* renderer_client_;