Add webframe. executeJavaScriptInIsolatedWorld
Attempt runInIsolatedWorldContext Replace RunInIsolatedWorldContext by GetIsolatedWorldGlobalObject Fix linting Remove useless getIsolatedWorldGlobalObject Add support for scriptExecutionType
This commit is contained in:
parent
f01cbf0482
commit
936d8c1117
2 changed files with 54 additions and 0 deletions
|
@ -28,6 +28,31 @@
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<blink::WebLocalFrame::ScriptExecutionType> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Handle<v8::Value> val,
|
||||||
|
blink::WebLocalFrame::ScriptExecutionType* out) {
|
||||||
|
std::string execution_type;
|
||||||
|
if (!ConvertFromV8(isolate, val, &execution_type))
|
||||||
|
return false;
|
||||||
|
if (execution_type == "asynchronous") {
|
||||||
|
*out = blink::WebLocalFrame::kAsynchronous;
|
||||||
|
} else if (execution_type ==
|
||||||
|
"asynchronousBlockingOnload") {
|
||||||
|
*out = blink::WebLocalFrame::kAsynchronousBlockingOnload;
|
||||||
|
} else if (execution_type == "synchronous") {
|
||||||
|
*out = blink::WebLocalFrame::kSynchronous;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace mate
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -226,6 +251,29 @@ void WebFrame::ExecuteJavaScript(const base::string16& code,
|
||||||
callback.release());
|
callback.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebFrame::ExecuteJavaScriptInIsolatedWorld(int world_id,
|
||||||
|
const base::string16& code,
|
||||||
|
mate::Arguments* args) {
|
||||||
|
std::vector<blink::WebScriptSource> sources;
|
||||||
|
sources.push_back(blink::WebScriptSource(blink::WebString::FromUTF16(code)));
|
||||||
|
|
||||||
|
bool has_user_gesture = false;
|
||||||
|
args->GetNext(&has_user_gesture);
|
||||||
|
|
||||||
|
blink::WebLocalFrame::ScriptExecutionType scriptExecutionType =
|
||||||
|
blink::WebLocalFrame::kSynchronous;
|
||||||
|
args->GetNext(&scriptExecutionType);
|
||||||
|
|
||||||
|
ScriptExecutionCallback::CompletionCallback completion_callback;
|
||||||
|
args->GetNext(&completion_callback);
|
||||||
|
std::unique_ptr<blink::WebScriptExecutionCallback> callback(
|
||||||
|
new ScriptExecutionCallback(completion_callback));
|
||||||
|
|
||||||
|
web_frame_->RequestExecuteScriptInIsolatedWorld(
|
||||||
|
world_id, &sources.front(), sources.size(), has_user_gesture,
|
||||||
|
scriptExecutionType, callback.release());
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebFrame> WebFrame::Create(v8::Isolate* isolate) {
|
mate::Handle<WebFrame> WebFrame::Create(v8::Isolate* isolate) {
|
||||||
return mate::CreateHandle(isolate, new WebFrame(isolate));
|
return mate::CreateHandle(isolate, new WebFrame(isolate));
|
||||||
|
@ -275,6 +323,8 @@ void WebFrame::BuildPrototype(
|
||||||
.SetMethod("insertText", &WebFrame::InsertText)
|
.SetMethod("insertText", &WebFrame::InsertText)
|
||||||
.SetMethod("insertCSS", &WebFrame::InsertCSS)
|
.SetMethod("insertCSS", &WebFrame::InsertCSS)
|
||||||
.SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript)
|
.SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript)
|
||||||
|
.SetMethod("executeJavaScriptInIsolatedWorld",
|
||||||
|
&WebFrame::ExecuteJavaScriptInIsolatedWorld)
|
||||||
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
|
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
|
||||||
.SetMethod("clearCache", &WebFrame::ClearCache)
|
.SetMethod("clearCache", &WebFrame::ClearCache)
|
||||||
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
|
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/renderer/guest_view_container.h"
|
#include "atom/renderer/guest_view_container.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
@ -73,6 +74,9 @@ class WebFrame : public mate::Wrappable<WebFrame> {
|
||||||
|
|
||||||
// Excecuting scripts.
|
// Excecuting scripts.
|
||||||
void ExecuteJavaScript(const base::string16& code, mate::Arguments* args);
|
void ExecuteJavaScript(const base::string16& code, mate::Arguments* args);
|
||||||
|
void ExecuteJavaScriptInIsolatedWorld(int world_id,
|
||||||
|
const base::string16& code,
|
||||||
|
mate::Arguments* args);
|
||||||
|
|
||||||
// Resource related methods
|
// Resource related methods
|
||||||
blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate);
|
blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate);
|
||||||
|
|
Loading…
Reference in a new issue