2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/renderer/frame_impl.h"
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(push)
|
2017-05-17 11:29:28 +02:00
|
|
|
#pragma warning(default : 4996)
|
2016-03-16 03:55:59 +01:00
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2021-05-21 03:42:58 +02:00
|
|
|
#include "libcef/common/frame_util.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/http_header_utils.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "libcef/common/process_message_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/request_impl.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "libcef/common/string_util.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "libcef/renderer/dom_document_impl.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
#include "libcef/renderer/render_frame_util.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "libcef/renderer/render_urlrequest_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
#include "libcef/renderer/v8_impl.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "content/public/renderer/render_view.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "content/renderer/render_frame_impl.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
#include "third_party/blink/public/mojom/frame/frame.mojom-blink.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "third_party/blink/public/platform/web_back_forward_cache_loader_helper.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_data.h"
|
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url.h"
|
|
|
|
#include "third_party/blink/public/web/blink.h"
|
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
2018-07-09 22:12:39 +02:00
|
|
|
#include "third_party/blink/public/web/web_document_loader.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_frame_content_dumper.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2018-12-26 16:12:11 +01:00
|
|
|
#include "third_party/blink/public/web/web_navigation_control.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_script_source.h"
|
|
|
|
#include "third_party/blink/public/web/web_view.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-07-09 20:36:37 +02:00
|
|
|
CefFrameImpl::CefFrameImpl(CefBrowserImpl* browser,
|
|
|
|
blink::WebLocalFrame* frame,
|
|
|
|
int64_t frame_id)
|
2021-05-14 18:58:55 +02:00
|
|
|
: browser_(browser), frame_(frame), frame_id_(frame_id) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefFrameImpl::~CefFrameImpl() {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
bool CefFrameImpl::IsValid() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return (frame_ != nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Undo() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Undo");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Redo() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Redo");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Cut() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Cut");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Copy() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Copy");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Paste() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Paste");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Delete() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("Delete");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::SelectAll() {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendCommand("SelectAll");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ViewSource() {
|
|
|
|
NOTREACHED() << "ViewSource cannot be called from the renderer process";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::GetSource(CefRefPtr<CefStringVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (frame_) {
|
2021-05-14 18:58:55 +02:00
|
|
|
CefString content;
|
|
|
|
string_util::GetCefString(blink_glue::DumpDocumentMarkup(frame_), content);
|
2012-04-03 03:34:16 +02:00
|
|
|
visitor->Visit(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::GetText(CefRefPtr<CefStringVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
if (frame_) {
|
2021-05-14 18:58:55 +02:00
|
|
|
CefString content;
|
|
|
|
string_util::GetCefString(blink_glue::DumpDocumentText(frame_), content);
|
2012-04-03 03:34:16 +02:00
|
|
|
visitor->Visit(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::LoadRequest(CefRefPtr<CefRequest> request) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!frame_)
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
auto params = cef::mojom::RequestParams::New();
|
|
|
|
static_cast<CefRequestImpl*>(request.get())->Get(params);
|
|
|
|
LoadRequest(std::move(params));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::LoadURL(const CefString& url) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!frame_)
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
auto params = cef::mojom::RequestParams::New();
|
|
|
|
params->url = GURL(url.ToString());
|
|
|
|
params->method = "GET";
|
|
|
|
LoadRequest(std::move(params));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ExecuteJavaScript(const CefString& jsCode,
|
|
|
|
const CefString& scriptUrl,
|
|
|
|
int startLine) {
|
2021-05-14 18:58:55 +02:00
|
|
|
SendJavaScript(jsCode, scriptUrl, startLine);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefFrameImpl::IsMain() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
|
|
|
if (frame_)
|
2020-01-15 14:36:24 +01:00
|
|
|
return (frame_->Parent() == nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefFrameImpl::IsFocused() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (frame_ && frame_->View())
|
|
|
|
return (frame_->View()->FocusedFrame() == frame_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetName() {
|
|
|
|
CefString name;
|
|
|
|
CEF_REQUIRE_RT_RETURN(name);
|
|
|
|
|
|
|
|
if (frame_)
|
2018-03-28 19:30:15 +02:00
|
|
|
name = render_frame_util::GetName(frame_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 CefFrameImpl::GetIdentifier() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(0);
|
|
|
|
|
|
|
|
return frame_id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefFrameImpl::GetParent() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebFrame* parent = frame_->Parent();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (parent && parent->IsWebLocalFrame())
|
|
|
|
return browser_->GetWebFrameImpl(parent->ToWebLocalFrame()).get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetURL() {
|
|
|
|
CefString url;
|
|
|
|
CEF_REQUIRE_RT_RETURN(url);
|
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
GURL gurl = frame_->GetDocument().Url();
|
2012-04-03 03:34:16 +02:00
|
|
|
url = gurl.spec();
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> CefFrameImpl::GetBrowser() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return browser_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> CefFrameImpl::GetV8Context() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
v8::Isolate* isolate = blink::MainThreadIsolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2017-04-20 21:28:17 +02:00
|
|
|
return new CefV8ContextImpl(isolate, frame_->MainWorldScriptContext());
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
void CefFrameImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!frame_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a CefDOMDocumentImpl object that is valid only for the scope of this
|
|
|
|
// method.
|
|
|
|
CefRefPtr<CefDOMDocumentImpl> documentImpl;
|
2017-04-20 21:28:17 +02:00
|
|
|
const blink::WebDocument& document = frame_->GetDocument();
|
|
|
|
if (!document.IsNull())
|
2012-04-27 23:19:06 +02:00
|
|
|
documentImpl = new CefDOMDocumentImpl(browser_, frame_);
|
|
|
|
|
|
|
|
visitor->Visit(documentImpl.get());
|
|
|
|
|
|
|
|
if (documentImpl.get())
|
|
|
|
documentImpl->Detach();
|
|
|
|
}
|
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefURLRequest> CefFrameImpl::CreateURLRequest(
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2019-05-11 00:14:48 +02:00
|
|
|
|
|
|
|
if (!request || !client || !frame_)
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2019-05-11 00:14:48 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRenderURLRequest> impl =
|
|
|
|
new CefRenderURLRequest(this, request, client);
|
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2019-05-11 00:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void CefFrameImpl::SendProcessMessage(CefProcessId target_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
2021-05-14 18:58:55 +02:00
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
DCHECK_EQ(PID_BROWSER, target_process);
|
|
|
|
DCHECK(message && message->IsValid());
|
|
|
|
if (!message || !message->IsValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!frame_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
if (!browser_frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto impl = static_cast<CefProcessMessageImpl*>(message.get());
|
|
|
|
browser_frame->SendMessage(impl->GetName(), impl->TakeArgumentList());
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:31:49 +01:00
|
|
|
std::unique_ptr<blink::WebURLLoader> CefFrameImpl::CreateURLLoader() {
|
2019-05-11 00:14:48 +02:00
|
|
|
CEF_REQUIRE_RT();
|
2020-12-02 23:31:49 +01:00
|
|
|
if (!frame_)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!url_loader_factory_) {
|
2019-05-11 00:14:48 +02:00
|
|
|
auto render_frame = content::RenderFrameImpl::FromWebFrame(frame_);
|
|
|
|
if (render_frame) {
|
|
|
|
url_loader_factory_ = render_frame->CreateURLLoaderFactory();
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 23:31:49 +01:00
|
|
|
if (!url_loader_factory_)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return url_loader_factory_->CreateURLLoader(
|
|
|
|
blink::WebURLRequest(),
|
|
|
|
blink_glue::CreateResourceLoadingTaskRunnerHandle(frame_),
|
2021-01-28 00:13:12 +01:00
|
|
|
blink_glue::CreateResourceLoadingMaybeUnfreezableTaskRunnerHandle(frame_),
|
2021-07-23 18:40:13 +02:00
|
|
|
/*keep_alive_handle=*/mojo::NullRemote(),
|
|
|
|
blink::WebBackForwardCacheLoaderHelper());
|
2020-12-02 23:31:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
|
|
|
|
CefFrameImpl::CreateResourceLoadInfoNotifierWrapper() {
|
|
|
|
CEF_REQUIRE_RT();
|
|
|
|
if (frame_) {
|
|
|
|
auto render_frame = content::RenderFrameImpl::FromWebFrame(frame_);
|
|
|
|
if (render_frame)
|
|
|
|
return render_frame->CreateResourceLoadInfoNotifierWrapper();
|
|
|
|
}
|
|
|
|
return nullptr;
|
2019-05-11 00:14:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::OnAttached(service_manager::BinderRegistry* registry) {
|
|
|
|
// Called indirectly from RenderFrameCreated.
|
|
|
|
registry->AddInterface(base::BindRepeating(
|
|
|
|
&CefFrameImpl::BindRenderFrameReceiver, weak_ptr_factory_.GetWeakPtr()));
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
if (browser_frame) {
|
|
|
|
browser_frame->FrameAttached();
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::OnDidFinishLoad() {
|
2020-01-23 22:58:01 +01:00
|
|
|
// Ignore notifications from the embedded frame hosting a mime-type plugin.
|
|
|
|
// We'll eventually receive a notification from the owner frame.
|
|
|
|
if (blink_glue::HasPluginFrameOwner(frame_))
|
|
|
|
return;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
blink::WebDocumentLoader* dl = frame_->GetDocumentLoader();
|
|
|
|
const int http_status_code = dl->GetResponse().HttpStatusCode();
|
2021-05-14 18:58:55 +02:00
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
if (browser_frame) {
|
|
|
|
browser_frame->DidFinishFrameLoad(dl->GetUrl(), http_status_code);
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (app) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler = app->GetRenderProcessHandler();
|
|
|
|
if (handler) {
|
|
|
|
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
|
|
|
if (load_handler) {
|
|
|
|
load_handler->OnLoadEnd(browser_, this, http_status_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::OnDraggableRegionsChanged() {
|
2021-09-15 13:40:08 +02:00
|
|
|
// Match the behavior in ChromeRenderFrameObserver::DraggableRegionsChanged.
|
|
|
|
// Only the main frame is allowed to control draggable regions, to avoid other
|
|
|
|
// frames manipulate the regions in the browser process.
|
|
|
|
if (frame_->Parent() != nullptr)
|
|
|
|
return;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
blink::WebVector<blink::WebDraggableRegion> webregions =
|
|
|
|
frame_->GetDocument().DraggableRegions();
|
2021-05-14 18:58:55 +02:00
|
|
|
std::vector<cef::mojom::DraggableRegionEntryPtr> regions;
|
|
|
|
if (!webregions.empty()) {
|
2019-11-12 17:11:44 +01:00
|
|
|
auto render_frame = content::RenderFrameImpl::FromWebFrame(frame_);
|
2021-05-14 18:58:55 +02:00
|
|
|
|
|
|
|
regions.reserve(webregions.size());
|
|
|
|
for (const auto& webregion : webregions) {
|
|
|
|
auto region = cef::mojom::DraggableRegionEntry::New(webregion.bounds,
|
|
|
|
webregion.draggable);
|
|
|
|
render_frame->ConvertViewportToWindow(®ion->bounds);
|
|
|
|
regions.push_back(std::move(region));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
if (browser_frame) {
|
|
|
|
browser_frame->UpdateDraggableRegions(
|
2021-06-04 03:34:56 +02:00
|
|
|
regions.empty() ? absl::nullopt
|
2021-07-23 18:40:13 +02:00
|
|
|
: absl::make_optional(std::move(regions)));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
void CefFrameImpl::OnContextCreated() {
|
|
|
|
context_created_ = true;
|
|
|
|
|
|
|
|
CHECK(frame_);
|
|
|
|
while (!queued_actions_.empty()) {
|
|
|
|
auto& action = queued_actions_.front();
|
|
|
|
std::move(action.second).Run(frame_);
|
|
|
|
queued_actions_.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void CefFrameImpl::OnDetached() {
|
2021-05-14 18:58:55 +02:00
|
|
|
// Called when this frame has been detached from the view. This *will* be
|
|
|
|
// called for child frames when a parent frame is detached.
|
2019-05-24 22:23:43 +02:00
|
|
|
// The browser may hold the last reference to |this|. Take a reference here to
|
|
|
|
// keep |this| alive until after this method returns.
|
|
|
|
CefRefPtr<CefFrameImpl> self = this;
|
|
|
|
|
|
|
|
browser_->FrameDetached(frame_id_);
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
receivers_.Clear();
|
|
|
|
browser_frame_.reset();
|
2019-05-24 22:23:43 +02:00
|
|
|
browser_ = nullptr;
|
|
|
|
frame_ = nullptr;
|
2019-05-11 00:14:48 +02:00
|
|
|
url_loader_factory_.reset();
|
2021-05-21 03:42:58 +02:00
|
|
|
|
|
|
|
// In case we're destroyed without the context being created.
|
|
|
|
while (!queued_actions_.empty()) {
|
|
|
|
auto& action = queued_actions_.front();
|
|
|
|
LOG(WARNING) << action.first << " sent to detached frame "
|
|
|
|
<< frame_util::GetFrameDebugString(frame_id_)
|
|
|
|
<< " will be ignored";
|
|
|
|
queued_actions_.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ExecuteOnLocalFrame(const std::string& function_name,
|
|
|
|
LocalFrameAction action) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!context_created_) {
|
|
|
|
queued_actions_.push(std::make_pair(function_name, std::move(action)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_) {
|
|
|
|
std::move(action).Run(frame_);
|
|
|
|
} else {
|
|
|
|
LOG(WARNING) << function_name << " sent to detached frame "
|
|
|
|
<< frame_util::GetFrameDebugString(frame_id_)
|
|
|
|
<< " will be ignored";
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
const mojo::Remote<cef::mojom::BrowserFrame>& CefFrameImpl::GetBrowserFrame() {
|
|
|
|
if (!browser_frame_.is_bound()) {
|
|
|
|
auto render_frame = content::RenderFrameImpl::FromWebFrame(frame_);
|
|
|
|
if (render_frame) {
|
|
|
|
// Triggers creation of a CefBrowserFrame in the browser process.
|
|
|
|
render_frame->GetBrowserInterfaceBroker()->GetInterface(
|
|
|
|
browser_frame_.BindNewPipeAndPassReceiver());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return browser_frame_;
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::BindRenderFrameReceiver(
|
|
|
|
mojo::PendingReceiver<cef::mojom::RenderFrame> receiver) {
|
|
|
|
receivers_.Add(this, std::move(receiver));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::SendMessage(const std::string& name, base::Value arguments) {
|
|
|
|
if (auto app = CefAppManager::Get()->GetApplication()) {
|
|
|
|
if (auto handler = app->GetRenderProcessHandler()) {
|
|
|
|
auto& list_value = base::Value::AsListValue(arguments);
|
|
|
|
CefRefPtr<CefProcessMessageImpl> message(new CefProcessMessageImpl(
|
2021-05-20 18:26:36 +02:00
|
|
|
name, std::move(const_cast<base::ListValue&>(list_value)),
|
|
|
|
/*read_only=*/true));
|
2021-05-14 18:58:55 +02:00
|
|
|
handler->OnProcessMessageReceived(browser_, this, PID_BROWSER,
|
|
|
|
message.get());
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::SendCommand(const std::string& command) {
|
2021-05-21 03:42:58 +02:00
|
|
|
ExecuteOnLocalFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](const std::string& command, blink::WebLocalFrame* frame) {
|
|
|
|
frame->ExecuteCommand(blink::WebString::FromUTF8(command));
|
|
|
|
},
|
|
|
|
command));
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::SendCommandWithResponse(
|
|
|
|
const std::string& command,
|
|
|
|
cef::mojom::RenderFrame::SendCommandWithResponseCallback callback) {
|
2021-05-21 03:42:58 +02:00
|
|
|
ExecuteOnLocalFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](const std::string& command,
|
|
|
|
cef::mojom::RenderFrame::SendCommandWithResponseCallback callback,
|
|
|
|
blink::WebLocalFrame* frame) {
|
|
|
|
blink::WebString response;
|
|
|
|
|
|
|
|
if (base::LowerCaseEqualsASCII(command, "getsource")) {
|
|
|
|
response = blink_glue::DumpDocumentMarkup(frame);
|
|
|
|
} else if (base::LowerCaseEqualsASCII(command, "gettext")) {
|
|
|
|
response = blink_glue::DumpDocumentText(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::move(callback).Run(
|
|
|
|
string_util::CreateSharedMemoryRegion(response));
|
|
|
|
},
|
|
|
|
command, std::move(callback)));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::SendJavaScript(const std::u16string& jsCode,
|
|
|
|
const std::string& scriptUrl,
|
|
|
|
int32_t startLine) {
|
2021-05-21 03:42:58 +02:00
|
|
|
ExecuteOnLocalFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](const std::u16string& jsCode, const std::string& scriptUrl,
|
|
|
|
int32_t startLine, blink::WebLocalFrame* frame) {
|
|
|
|
frame->ExecuteScript(
|
|
|
|
blink::WebScriptSource(blink::WebString::FromUTF16(jsCode),
|
|
|
|
GURL(scriptUrl), startLine));
|
|
|
|
},
|
|
|
|
jsCode, scriptUrl, startLine));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::LoadRequest(cef::mojom::RequestParamsPtr params) {
|
2021-05-21 03:42:58 +02:00
|
|
|
ExecuteOnLocalFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](cef::mojom::RequestParamsPtr params, blink::WebLocalFrame* frame) {
|
|
|
|
blink::WebURLRequest request;
|
|
|
|
CefRequestImpl::Get(params, request);
|
|
|
|
blink_glue::StartNavigation(frame, request);
|
|
|
|
},
|
|
|
|
std::move(params)));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::DidStopLoading() {
|
2019-05-24 22:23:43 +02:00
|
|
|
// We should only receive this notification for the highest-level LocalFrame
|
2021-05-14 18:58:55 +02:00
|
|
|
// in this frame's in-process subtree. If there are multiple of these for
|
|
|
|
// the same browser then the other occurrences will be discarded in
|
2019-05-24 22:23:43 +02:00
|
|
|
// OnLoadingStateChange.
|
|
|
|
browser_->OnLoadingStateChange(false);
|
2021-09-15 13:40:08 +02:00
|
|
|
|
|
|
|
// Refresh draggable regions. Otherwise, we may not receive updated regions
|
|
|
|
// after navigation because LocalFrameView::UpdateDocumentAnnotatedRegion
|
|
|
|
// lacks sufficient context.
|
|
|
|
OnDraggableRegionsChanged();
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefFrameImpl::MoveOrResizeStarted() {
|
2020-12-02 23:31:49 +01:00
|
|
|
if (frame_) {
|
|
|
|
auto web_view = frame_->View();
|
|
|
|
if (web_view)
|
|
|
|
web_view->CancelPagePopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|