2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-10-24 10:24:12 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/renderer/api/atom_api_web_frame.h"
|
|
|
|
|
2017-01-30 17:06:50 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
2016-01-13 04:46:13 +00:00
|
|
|
#include "atom/common/api/event_emitter_caller.h"
|
2016-05-12 20:56:46 +00:00
|
|
|
#include "atom/common/native_mate_converters/blink_converter.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2015-05-29 05:47:09 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2014-10-24 10:24:12 +00:00
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
2014-12-18 21:54:01 +00:00
|
|
|
#include "atom/renderer/api/atom_api_spell_check_client.h"
|
2016-05-12 21:36:49 +00:00
|
|
|
#include "base/memory/memory_pressure_listener.h"
|
2014-12-08 16:05:34 +00:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
2017-11-24 06:34:20 +00:00
|
|
|
#include "content/public/renderer/render_frame_visitor.h"
|
2015-10-06 15:33:14 +00:00
|
|
|
#include "content/public/renderer/render_view.h"
|
2014-10-24 10:24:12 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/object_template_builder.h"
|
2018-04-18 01:55:30 +00:00
|
|
|
#include "third_party/WebKit/Source/platform/weborigin/SchemeRegistry.h"
|
2017-04-11 07:18:40 +00:00
|
|
|
#include "third_party/WebKit/public/platform/WebCache.h"
|
2014-10-24 10:24:12 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebDocument.h"
|
2018-01-09 19:41:40 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebElement.h"
|
2017-01-24 07:45:26 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebFrameWidget.h"
|
2017-11-23 20:12:06 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebImeTextSpan.h"
|
2017-01-24 07:45:26 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebInputMethodController.h"
|
2014-10-24 10:24:12 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
2016-02-17 17:03:27 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebScriptExecutionCallback.h"
|
2016-01-13 04:11:46 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebScriptSource.h"
|
2014-10-24 10:24:12 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebView.h"
|
|
|
|
|
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
2017-08-30 21:31:21 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Converter<blink::WebLocalFrame::ScriptExecutionType> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
2017-11-15 10:14:41 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2017-08-30 21:31:21 +00:00
|
|
|
blink::WebLocalFrame::ScriptExecutionType* out) {
|
|
|
|
std::string execution_type;
|
|
|
|
if (!ConvertFromV8(isolate, val, &execution_type))
|
|
|
|
return false;
|
|
|
|
if (execution_type == "asynchronous") {
|
|
|
|
*out = blink::WebLocalFrame::kAsynchronous;
|
2018-04-18 01:55:30 +00:00
|
|
|
} else if (execution_type == "asynchronousBlockingOnload") {
|
2017-08-30 21:31:21 +00:00
|
|
|
*out = blink::WebLocalFrame::kAsynchronousBlockingOnload;
|
|
|
|
} else if (execution_type == "synchronous") {
|
|
|
|
*out = blink::WebLocalFrame::kSynchronous;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2017-11-15 10:14:41 +00:00
|
|
|
|
2017-08-30 21:31:21 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
2014-10-24 10:24:12 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2016-02-17 17:03:27 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
|
|
|
|
public:
|
|
|
|
using CompletionCallback =
|
2018-04-18 01:55:30 +00:00
|
|
|
base::Callback<void(const v8::Local<v8::Value>& result)>;
|
2016-02-17 17:03:27 +00:00
|
|
|
|
|
|
|
explicit ScriptExecutionCallback(const CompletionCallback& callback)
|
|
|
|
: callback_(callback) {}
|
2016-07-10 11:21:42 +00:00
|
|
|
~ScriptExecutionCallback() override {}
|
2016-02-17 17:03:27 +00:00
|
|
|
|
2017-06-16 20:42:33 +00:00
|
|
|
void Completed(
|
2016-02-17 17:03:27 +00:00
|
|
|
const blink::WebVector<v8::Local<v8::Value>>& result) override {
|
2017-06-16 20:42:33 +00:00
|
|
|
if (!callback_.is_null() && !result.IsEmpty() && !result[0].IsEmpty())
|
2016-02-22 14:00:21 +00:00
|
|
|
// Right now only single results per frame is supported.
|
|
|
|
callback_.Run(result[0]);
|
2016-02-17 17:03:27 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CompletionCallback callback_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ScriptExecutionCallback);
|
|
|
|
};
|
|
|
|
|
2017-11-24 06:34:20 +00:00
|
|
|
class FrameSpellChecker : public content::RenderFrameVisitor {
|
|
|
|
public:
|
|
|
|
explicit FrameSpellChecker(SpellCheckClient* spell_check_client,
|
|
|
|
content::RenderFrame* main_frame)
|
|
|
|
: spell_check_client_(spell_check_client), main_frame_(main_frame) {}
|
|
|
|
~FrameSpellChecker() override {
|
|
|
|
spell_check_client_ = nullptr;
|
|
|
|
main_frame_ = nullptr;
|
|
|
|
}
|
|
|
|
bool Visit(content::RenderFrame* render_frame) override {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* view = render_frame->GetRenderView();
|
2017-11-24 06:34:20 +00:00
|
|
|
if (view->GetMainRenderFrame() == main_frame_ ||
|
|
|
|
(render_frame->IsMainFrame() && render_frame == main_frame_)) {
|
|
|
|
render_frame->GetWebFrame()->SetTextCheckClient(spell_check_client_);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SpellCheckClient* spell_check_client_;
|
|
|
|
content::RenderFrame* main_frame_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FrameSpellChecker);
|
|
|
|
};
|
|
|
|
|
2016-02-17 17:03:27 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
WebFrame::WebFrame(v8::Isolate* isolate)
|
2017-06-16 20:42:33 +00:00
|
|
|
: web_frame_(blink::WebLocalFrame::FrameForCurrentContext()) {
|
2016-04-25 01:17:54 +00:00
|
|
|
Init(isolate);
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 19:41:40 +00:00
|
|
|
WebFrame::WebFrame(v8::Isolate* isolate, blink::WebLocalFrame* blink_frame)
|
|
|
|
: web_frame_(blink_frame) {
|
2016-04-25 01:17:54 +00:00
|
|
|
Init(isolate);
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
WebFrame::~WebFrame() {}
|
2014-10-24 10:24:12 +00:00
|
|
|
|
2014-10-24 10:44:15 +00:00
|
|
|
void WebFrame::SetName(const std::string& name) {
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_->SetName(blink::WebString::FromUTF8(name));
|
2014-10-24 10:44:15 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 10:24:12 +00:00
|
|
|
double WebFrame::SetZoomLevel(double level) {
|
2017-01-31 09:25:48 +00:00
|
|
|
double result = 0.0;
|
2018-03-09 09:31:09 +00:00
|
|
|
content::RenderFrame* render_frame =
|
|
|
|
content::RenderFrame::FromWebFrame(web_frame_);
|
|
|
|
render_frame->Send(new AtomFrameHostMsg_SetTemporaryZoomLevel(
|
|
|
|
render_frame->GetRoutingID(), level, &result));
|
2017-01-30 17:06:50 +00:00
|
|
|
return result;
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double WebFrame::GetZoomLevel() const {
|
2017-01-31 09:25:48 +00:00
|
|
|
double result = 0.0;
|
2018-03-09 09:31:09 +00:00
|
|
|
content::RenderFrame* render_frame =
|
|
|
|
content::RenderFrame::FromWebFrame(web_frame_);
|
|
|
|
render_frame->Send(
|
|
|
|
new AtomFrameHostMsg_GetZoomLevel(render_frame->GetRoutingID(), &result));
|
2017-01-30 17:06:50 +00:00
|
|
|
return result;
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double WebFrame::SetZoomFactor(double factor) {
|
2018-04-18 01:55:30 +00:00
|
|
|
return blink::WebView::ZoomLevelToZoomFactor(
|
|
|
|
SetZoomLevel(blink::WebView::ZoomFactorToZoomLevel(factor)));
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double WebFrame::GetZoomFactor() const {
|
2017-06-16 20:42:33 +00:00
|
|
|
return blink::WebView::ZoomLevelToZoomFactor(GetZoomLevel());
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 15:53:02 +00:00
|
|
|
void WebFrame::SetVisualZoomLevelLimits(double min_level, double max_level) {
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_->View()->SetDefaultPageScaleLimits(min_level, max_level);
|
2018-04-02 22:20:13 +00:00
|
|
|
web_frame_->View()->SetIgnoreViewportTagScaleLimits(true);
|
2015-08-27 14:08:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 19:59:27 +00:00
|
|
|
void WebFrame::SetLayoutZoomLevelLimits(double min_level, double max_level) {
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_->View()->ZoomLimitsChanged(min_level, max_level);
|
2016-11-21 19:59:27 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> WebFrame::RegisterEmbedderCustomElement(
|
2018-04-18 01:55:30 +00:00
|
|
|
const base::string16& name,
|
|
|
|
v8::Local<v8::Object> options) {
|
2017-06-16 20:42:33 +00:00
|
|
|
return web_frame_->GetDocument().RegisterEmbedderCustomElement(
|
2017-12-18 04:45:24 +00:00
|
|
|
blink::WebString::FromUTF16(name), options);
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 05:47:09 +00:00
|
|
|
void WebFrame::RegisterElementResizeCallback(
|
|
|
|
int element_instance_id,
|
|
|
|
const GuestViewContainer::ResizeCallback& callback) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* guest_view_container = GuestViewContainer::FromID(element_instance_id);
|
2015-05-29 05:47:09 +00:00
|
|
|
if (guest_view_container)
|
|
|
|
guest_view_container->RegisterElementResizeCallback(callback);
|
|
|
|
}
|
|
|
|
|
2014-12-08 16:05:34 +00:00
|
|
|
void WebFrame::AttachGuest(int id) {
|
|
|
|
content::RenderFrame::FromWebFrame(web_frame_)->AttachGuest(id);
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:01:01 +00:00
|
|
|
void WebFrame::DetachGuest(int id) {
|
|
|
|
content::RenderFrame::FromWebFrame(web_frame_)->DetachGuest(id);
|
|
|
|
}
|
|
|
|
|
2014-12-20 04:42:19 +00:00
|
|
|
void WebFrame::SetSpellCheckProvider(mate::Arguments* args,
|
|
|
|
const std::string& language,
|
2014-12-20 05:01:47 +00:00
|
|
|
bool auto_spell_correct_turned_on,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Object> provider) {
|
2014-12-20 05:01:47 +00:00
|
|
|
if (!provider->Has(mate::StringToV8(args->isolate(), "spellCheck"))) {
|
2014-12-20 04:42:19 +00:00
|
|
|
args->ThrowError("\"spellCheck\" has to be defined");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 06:34:20 +00:00
|
|
|
std::unique_ptr<SpellCheckClient> client(new SpellCheckClient(
|
2014-12-20 05:01:47 +00:00
|
|
|
language, auto_spell_correct_turned_on, args->isolate(), provider));
|
2017-11-24 06:34:20 +00:00
|
|
|
// Set spellchecker for all live frames in the same process or
|
|
|
|
// in the sandbox mode for all live sub frames to this WebFrame.
|
|
|
|
FrameSpellChecker spell_checker(
|
|
|
|
client.get(), content::RenderFrame::FromWebFrame(web_frame_));
|
|
|
|
content::RenderFrame::ForEach(&spell_checker);
|
|
|
|
spell_check_client_.swap(client);
|
2017-08-25 11:23:13 +00:00
|
|
|
web_frame_->SetSpellCheckPanelHostClient(spell_check_client_.get());
|
2014-12-18 21:54:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 11:20:50 +00:00
|
|
|
void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) {
|
2016-11-14 18:33:30 +00:00
|
|
|
// TODO(pfrazee): Remove 2.0
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSecure(
|
|
|
|
WTF::String::FromUTF8(scheme.data(), scheme.length()));
|
2015-07-29 11:20:50 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 08:03:40 +00:00
|
|
|
void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) {
|
2015-07-29 11:20:50 +00:00
|
|
|
// Register scheme to bypass pages's Content Security Policy.
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsBypassingContentSecurityPolicy(
|
|
|
|
WTF::String::FromUTF8(scheme.data(), scheme.length()));
|
2015-07-29 11:20:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 20:52:41 +00:00
|
|
|
void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme,
|
|
|
|
mate::Arguments* args) {
|
2017-12-18 09:29:28 +00:00
|
|
|
// TODO(deepak1556): blink::SchemeRegistry methods should be called
|
|
|
|
// before any renderer threads are created. Fixing this would break
|
|
|
|
// current api. Change it with 2.0.
|
|
|
|
|
2016-10-18 20:52:41 +00:00
|
|
|
// Read optional flags
|
|
|
|
bool secure = true;
|
|
|
|
bool bypassCSP = true;
|
|
|
|
bool allowServiceWorkers = true;
|
|
|
|
bool supportFetchAPI = true;
|
|
|
|
bool corsEnabled = true;
|
|
|
|
if (args->Length() == 2) {
|
|
|
|
mate::Dictionary options;
|
|
|
|
if (args->GetNext(&options)) {
|
|
|
|
options.Get("secure", &secure);
|
|
|
|
options.Get("bypassCSP", &bypassCSP);
|
|
|
|
options.Get("allowServiceWorkers", &allowServiceWorkers);
|
|
|
|
options.Get("supportFetchAPI", &supportFetchAPI);
|
|
|
|
options.Get("corsEnabled", &corsEnabled);
|
|
|
|
}
|
|
|
|
}
|
2015-09-21 17:29:59 +00:00
|
|
|
// Register scheme to privileged list (https, wss, data, chrome-extension)
|
2017-04-11 08:22:12 +00:00
|
|
|
WTF::String privileged_scheme(
|
2017-06-16 20:42:33 +00:00
|
|
|
WTF::String::FromUTF8(scheme.data(), scheme.length()));
|
2016-10-18 20:52:41 +00:00
|
|
|
if (secure) {
|
2016-11-14 18:33:30 +00:00
|
|
|
// TODO(pfrazee): Remove 2.0
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSecure(privileged_scheme);
|
2016-10-18 20:52:41 +00:00
|
|
|
}
|
|
|
|
if (bypassCSP) {
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsBypassingContentSecurityPolicy(
|
2016-10-18 20:52:41 +00:00
|
|
|
privileged_scheme);
|
|
|
|
}
|
|
|
|
if (allowServiceWorkers) {
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsAllowingServiceWorkers(
|
2016-10-18 20:52:41 +00:00
|
|
|
privileged_scheme);
|
|
|
|
}
|
|
|
|
if (supportFetchAPI) {
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSupportingFetchAPI(
|
2016-10-18 20:52:41 +00:00
|
|
|
privileged_scheme);
|
|
|
|
}
|
|
|
|
if (corsEnabled) {
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsCORSEnabled(privileged_scheme);
|
2016-10-18 20:52:41 +00:00
|
|
|
}
|
2015-09-21 17:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 03:21:16 +00:00
|
|
|
void WebFrame::InsertText(const std::string& text) {
|
2018-04-18 01:55:30 +00:00
|
|
|
web_frame_->FrameWidget()->GetActiveWebInputMethodController()->CommitText(
|
|
|
|
blink::WebString::FromUTF8(text),
|
|
|
|
blink::WebVector<blink::WebImeTextSpan>(), blink::WebRange(), 0);
|
2016-01-13 03:21:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 23:50:47 +00:00
|
|
|
void WebFrame::InsertCSS(const std::string& css) {
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_->GetDocument().InsertStyleSheet(blink::WebString::FromUTF8(css));
|
2016-12-19 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 04:17:56 +00:00
|
|
|
void WebFrame::ExecuteJavaScript(const base::string16& code,
|
|
|
|
mate::Arguments* args) {
|
|
|
|
bool has_user_gesture = false;
|
|
|
|
args->GetNext(&has_user_gesture);
|
2016-02-17 17:03:27 +00:00
|
|
|
ScriptExecutionCallback::CompletionCallback completion_callback;
|
|
|
|
args->GetNext(&completion_callback);
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<blink::WebScriptExecutionCallback> callback(
|
2016-02-17 17:03:27 +00:00
|
|
|
new ScriptExecutionCallback(completion_callback));
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_->RequestExecuteScriptAndReturnValue(
|
|
|
|
blink::WebScriptSource(blink::WebString::FromUTF16(code)),
|
2018-04-18 01:55:30 +00:00
|
|
|
has_user_gesture, callback.release());
|
2016-01-13 04:11:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 10:14:41 +00:00
|
|
|
void WebFrame::ExecuteJavaScriptInIsolatedWorld(
|
2017-12-19 01:42:36 +00:00
|
|
|
int world_id,
|
|
|
|
const std::vector<mate::Dictionary>& scripts,
|
|
|
|
mate::Arguments* args) {
|
2017-08-30 21:31:21 +00:00
|
|
|
std::vector<blink::WebScriptSource> sources;
|
2017-11-15 10:14:41 +00:00
|
|
|
|
|
|
|
for (const auto& script : scripts) {
|
|
|
|
base::string16 code;
|
|
|
|
base::string16 url;
|
|
|
|
int start_line = 1;
|
|
|
|
script.Get("url", &url);
|
|
|
|
script.Get("startLine", &start_line);
|
|
|
|
|
|
|
|
if (!script.Get("code", &code)) {
|
|
|
|
args->ThrowError("Invalid 'code'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
sources.emplace_back(
|
|
|
|
blink::WebScriptSource(blink::WebString::FromUTF16(code),
|
|
|
|
blink::WebURL(GURL(url)), start_line));
|
2017-11-15 10:14:41 +00:00
|
|
|
}
|
2017-08-30 21:31:21 +00:00
|
|
|
|
|
|
|
bool has_user_gesture = false;
|
|
|
|
args->GetNext(&has_user_gesture);
|
|
|
|
|
|
|
|
blink::WebLocalFrame::ScriptExecutionType scriptExecutionType =
|
2017-12-19 01:42:36 +00:00
|
|
|
blink::WebLocalFrame::kSynchronous;
|
2017-08-30 21:31:21 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void WebFrame::SetIsolatedWorldSecurityOrigin(int world_id,
|
|
|
|
const std::string& origin_url) {
|
2017-12-19 01:42:36 +00:00
|
|
|
web_frame_->SetIsolatedWorldSecurityOrigin(
|
2018-04-18 01:55:30 +00:00
|
|
|
world_id, blink::WebSecurityOrigin::CreateFromString(
|
|
|
|
blink::WebString::FromUTF8(origin_url)));
|
2017-11-15 10:14:41 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 01:42:36 +00:00
|
|
|
void WebFrame::SetIsolatedWorldContentSecurityPolicy(
|
|
|
|
int world_id,
|
|
|
|
const std::string& security_policy) {
|
2017-11-14 12:44:17 +00:00
|
|
|
web_frame_->SetIsolatedWorldContentSecurityPolicy(
|
2017-12-19 01:42:36 +00:00
|
|
|
world_id, blink::WebString::FromUTF8(security_policy));
|
2017-11-15 09:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void WebFrame::SetIsolatedWorldHumanReadableName(int world_id,
|
|
|
|
const std::string& name) {
|
2017-12-19 01:42:36 +00:00
|
|
|
web_frame_->SetIsolatedWorldHumanReadableName(
|
2017-11-15 09:35:04 +00:00
|
|
|
world_id, blink::WebString::FromUTF8(name));
|
2017-11-14 12:44:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
// static
|
|
|
|
mate::Handle<WebFrame> WebFrame::Create(v8::Isolate* isolate) {
|
2016-04-25 01:27:54 +00:00
|
|
|
return mate::CreateHandle(isolate, new WebFrame(isolate));
|
2016-04-25 01:17:54 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 13:40:18 +00:00
|
|
|
blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage(
|
|
|
|
v8::Isolate* isolate) {
|
2016-05-12 20:56:46 +00:00
|
|
|
blink::WebCache::ResourceTypeStats stats;
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::WebCache::GetResourceTypeStats(&stats);
|
2016-05-13 17:43:08 +00:00
|
|
|
return stats;
|
2016-05-12 20:56:46 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 13:48:25 +00:00
|
|
|
void WebFrame::ClearCache(v8::Isolate* isolate) {
|
2016-05-12 21:36:49 +00:00
|
|
|
isolate->IdleNotificationDeadline(0.5);
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::WebCache::Clear();
|
2016-05-12 21:36:49 +00:00
|
|
|
base::MemoryPressureListener::NotifyMemoryPressure(
|
2018-04-18 01:55:30 +00:00
|
|
|
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
|
2016-05-12 21:36:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 19:41:40 +00:00
|
|
|
v8::Local<v8::Value> WebFrame::Opener() const {
|
|
|
|
blink::WebFrame* frame = web_frame_->Opener();
|
|
|
|
if (frame && frame->IsWebLocalFrame())
|
|
|
|
return mate::CreateHandle(isolate(),
|
2018-04-18 01:55:30 +00:00
|
|
|
new WebFrame(isolate(), frame->ToWebLocalFrame()))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebFrame::Parent() const {
|
|
|
|
blink::WebFrame* frame = web_frame_->Parent();
|
|
|
|
if (frame && frame->IsWebLocalFrame())
|
|
|
|
return mate::CreateHandle(isolate(),
|
2018-04-18 01:55:30 +00:00
|
|
|
new WebFrame(isolate(), frame->ToWebLocalFrame()))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebFrame::Top() const {
|
|
|
|
blink::WebFrame* frame = web_frame_->Top();
|
|
|
|
if (frame && frame->IsWebLocalFrame())
|
|
|
|
return mate::CreateHandle(isolate(),
|
2018-04-18 01:55:30 +00:00
|
|
|
new WebFrame(isolate(), frame->ToWebLocalFrame()))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebFrame::FirstChild() const {
|
|
|
|
blink::WebFrame* frame = web_frame_->FirstChild();
|
|
|
|
if (frame && frame->IsWebLocalFrame())
|
|
|
|
return mate::CreateHandle(isolate(),
|
2018-04-18 01:55:30 +00:00
|
|
|
new WebFrame(isolate(), frame->ToWebLocalFrame()))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebFrame::NextSibling() const {
|
|
|
|
blink::WebFrame* frame = web_frame_->NextSibling();
|
|
|
|
if (frame && frame->IsWebLocalFrame())
|
|
|
|
return mate::CreateHandle(isolate(),
|
2018-04-18 01:55:30 +00:00
|
|
|
new WebFrame(isolate(), frame->ToWebLocalFrame()))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
2018-02-26 06:19:44 +00:00
|
|
|
v8::Local<v8::Value> WebFrame::GetFrameForSelector(
|
|
|
|
const std::string& selector) const {
|
|
|
|
blink::WebElement element = web_frame_->GetDocument().QuerySelector(
|
|
|
|
blink::WebString::FromUTF8(selector));
|
2018-01-09 19:41:40 +00:00
|
|
|
blink::WebLocalFrame* element_frame =
|
2018-02-26 06:19:44 +00:00
|
|
|
blink::WebLocalFrame::FromFrameOwnerElement(element);
|
2018-01-09 19:41:40 +00:00
|
|
|
if (element_frame)
|
2018-04-18 01:55:30 +00:00
|
|
|
return mate::CreateHandle(isolate(), new WebFrame(isolate(), element_frame))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebFrame::FindFrameByName(const std::string& name) const {
|
2018-04-18 01:55:30 +00:00
|
|
|
blink::WebLocalFrame* local_frame =
|
|
|
|
web_frame_->FindFrameByName(blink::WebString::FromUTF8(name))
|
|
|
|
->ToWebLocalFrame();
|
2018-01-09 19:41:40 +00:00
|
|
|
if (local_frame)
|
2018-04-18 01:55:30 +00:00
|
|
|
return mate::CreateHandle(isolate(), new WebFrame(isolate(), local_frame))
|
|
|
|
.ToV8();
|
2018-01-09 19:41:40 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
// static
|
2018-04-18 01:55:30 +00:00
|
|
|
void WebFrame::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "WebFrame"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2014-10-24 10:44:15 +00:00
|
|
|
.SetMethod("setName", &WebFrame::SetName)
|
2014-10-24 10:24:12 +00:00
|
|
|
.SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
|
|
|
|
.SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
|
|
|
|
.SetMethod("setZoomFactor", &WebFrame::SetZoomFactor)
|
|
|
|
.SetMethod("getZoomFactor", &WebFrame::GetZoomFactor)
|
2016-11-22 15:53:02 +00:00
|
|
|
.SetMethod("setVisualZoomLevelLimits",
|
|
|
|
&WebFrame::SetVisualZoomLevelLimits)
|
2016-11-21 20:13:34 +00:00
|
|
|
.SetMethod("setLayoutZoomLevelLimits",
|
|
|
|
&WebFrame::SetLayoutZoomLevelLimits)
|
2014-10-24 10:24:12 +00:00
|
|
|
.SetMethod("registerEmbedderCustomElement",
|
2014-12-08 16:05:34 +00:00
|
|
|
&WebFrame::RegisterEmbedderCustomElement)
|
2015-05-29 05:47:09 +00:00
|
|
|
.SetMethod("registerElementResizeCallback",
|
|
|
|
&WebFrame::RegisterElementResizeCallback)
|
2014-12-18 21:54:01 +00:00
|
|
|
.SetMethod("attachGuest", &WebFrame::AttachGuest)
|
2016-09-08 17:01:01 +00:00
|
|
|
.SetMethod("detachGuest", &WebFrame::DetachGuest)
|
2015-01-08 20:37:41 +00:00
|
|
|
.SetMethod("setSpellCheckProvider", &WebFrame::SetSpellCheckProvider)
|
2015-11-13 08:03:40 +00:00
|
|
|
.SetMethod("registerURLSchemeAsSecure",
|
2015-07-29 11:20:50 +00:00
|
|
|
&WebFrame::RegisterURLSchemeAsSecure)
|
2015-11-13 08:03:40 +00:00
|
|
|
.SetMethod("registerURLSchemeAsBypassingCSP",
|
|
|
|
&WebFrame::RegisterURLSchemeAsBypassingCSP)
|
|
|
|
.SetMethod("registerURLSchemeAsPrivileged",
|
2016-01-13 03:21:16 +00:00
|
|
|
&WebFrame::RegisterURLSchemeAsPrivileged)
|
2016-01-13 04:11:46 +00:00
|
|
|
.SetMethod("insertText", &WebFrame::InsertText)
|
2016-12-19 23:50:47 +00:00
|
|
|
.SetMethod("insertCSS", &WebFrame::InsertCSS)
|
2016-05-12 20:56:46 +00:00
|
|
|
.SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript)
|
2017-08-30 21:31:21 +00:00
|
|
|
.SetMethod("executeJavaScriptInIsolatedWorld",
|
2017-11-14 12:44:17 +00:00
|
|
|
&WebFrame::ExecuteJavaScriptInIsolatedWorld)
|
2017-11-15 10:14:41 +00:00
|
|
|
.SetMethod("setIsolatedWorldSecurityOrigin",
|
|
|
|
&WebFrame::SetIsolatedWorldSecurityOrigin)
|
2017-11-14 12:44:17 +00:00
|
|
|
.SetMethod("setIsolatedWorldContentSecurityPolicy",
|
|
|
|
&WebFrame::SetIsolatedWorldContentSecurityPolicy)
|
2017-11-15 09:35:04 +00:00
|
|
|
.SetMethod("setIsolatedWorldHumanReadableName",
|
|
|
|
&WebFrame::SetIsolatedWorldHumanReadableName)
|
2016-05-12 21:36:49 +00:00
|
|
|
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
|
2018-01-09 19:41:40 +00:00
|
|
|
.SetMethod("clearCache", &WebFrame::ClearCache)
|
2018-02-26 06:19:44 +00:00
|
|
|
.SetMethod("getFrameForSelector", &WebFrame::GetFrameForSelector)
|
|
|
|
.SetMethod("findFrameByName", &WebFrame::FindFrameByName)
|
2018-01-09 19:41:40 +00:00
|
|
|
.SetProperty("opener", &WebFrame::Opener)
|
|
|
|
.SetProperty("parent", &WebFrame::Parent)
|
|
|
|
.SetProperty("top", &WebFrame::Top)
|
|
|
|
.SetProperty("firstChild", &WebFrame::FirstChild)
|
2018-02-26 06:19:44 +00:00
|
|
|
.SetProperty("nextSibling", &WebFrame::NextSibling);
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-08-02 12:02:28 +00:00
|
|
|
using atom::api::WebFrame;
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2014-10-24 10:24:12 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
2016-08-02 12:02:28 +00:00
|
|
|
dict.Set("webFrame", WebFrame::Create(isolate));
|
|
|
|
dict.Set("WebFrame", WebFrame::GetConstructor(isolate)->GetFunction());
|
2014-10-24 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-01-06 15:58:24 +00:00
|
|
|
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_renderer_web_frame, Initialize)
|