webContents: provide responses for executeJavscript method
This commit is contained in:
parent
d00490271b
commit
2b547bd44a
9 changed files with 113 additions and 13 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "atom/common/native_mate_converters/blink_converter.h"
|
||||
#include "atom/renderer/api/atom_api_spell_check_client.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
|
@ -15,7 +16,7 @@
|
|||
#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/WebScriptExecutionCallback.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"
|
||||
|
@ -26,6 +27,33 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
|
||||
public:
|
||||
using CompletionCallback =
|
||||
base::Callback<void(
|
||||
const blink::WebVector<v8::Local<v8::Value>>& result)>;
|
||||
|
||||
explicit ScriptExecutionCallback(const CompletionCallback& callback)
|
||||
: callback_(callback) {}
|
||||
~ScriptExecutionCallback() {}
|
||||
|
||||
void completed(
|
||||
const blink::WebVector<v8::Local<v8::Value>>& result) override {
|
||||
if (!callback_.is_null())
|
||||
callback_.Run(result);
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
CompletionCallback callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ScriptExecutionCallback);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
WebFrame::WebFrame()
|
||||
: web_frame_(blink::WebLocalFrame::frameForCurrentContext()) {
|
||||
}
|
||||
|
@ -124,9 +152,14 @@ void WebFrame::ExecuteJavaScript(const base::string16& code,
|
|||
mate::Arguments* args) {
|
||||
bool has_user_gesture = false;
|
||||
args->GetNext(&has_user_gesture);
|
||||
scoped_ptr<blink::WebScopedUserGesture> gesture(
|
||||
has_user_gesture ? new blink::WebScopedUserGesture : nullptr);
|
||||
web_frame_->executeScriptAndReturnValue(blink::WebScriptSource(code));
|
||||
ScriptExecutionCallback::CompletionCallback completion_callback;
|
||||
args->GetNext(&completion_callback);
|
||||
scoped_ptr<blink::WebScriptExecutionCallback> callback(
|
||||
new ScriptExecutionCallback(completion_callback));
|
||||
web_frame_->requestExecuteScriptAndReturnValue(
|
||||
blink::WebScriptSource(code),
|
||||
has_user_gesture,
|
||||
callback.release());
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue