Handle executeJavaScript in JavaScript
This commit is contained in:
parent
5b7d1a9890
commit
55dfddba77
8 changed files with 28 additions and 52 deletions
|
@ -756,11 +756,6 @@ bool WebContents::SavePage(const base::FilePath& full_file_path,
|
|||
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;
|
||||
|
@ -1093,7 +1088,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
|||
.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)
|
||||
|
|
|
@ -74,8 +74,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
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();
|
||||
|
|
|
@ -57,6 +57,7 @@ PDFPageSize = {
|
|||
|
||||
// Following methods are mapped to webFrame.
|
||||
const webFrameMethods = [
|
||||
'executeJavaScript',
|
||||
'insertText',
|
||||
];
|
||||
|
||||
|
@ -73,21 +74,6 @@ wrapWebContents = function(webContents) {
|
|||
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;
|
||||
|
@ -110,6 +96,20 @@ wrapWebContents = function(webContents) {
|
|||
};
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue