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"
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
#include "build/build_config.h"
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_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
|
|
|
|
2023-02-27 19:33:56 +01:00
|
|
|
#include "include/cef_urlrequest.h"
|
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"
|
2022-07-04 11:49:15 +02:00
|
|
|
#include "libcef/common/process_message_smr_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"
|
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
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "base/strings/utf_string_conversions.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"
|
2022-04-05 19:22:32 +02:00
|
|
|
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink.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"
|
2022-06-22 17:57:49 +02:00
|
|
|
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Maximum number of times to retry the browser connection.
|
|
|
|
constexpr size_t kConnectionRetryMaxCt = 3U;
|
|
|
|
|
|
|
|
// Length of time to wait before initiating a browser connection retry.
|
|
|
|
constexpr auto kConnectionRetryDelay = base::Seconds(1);
|
|
|
|
|
|
|
|
// Length of time to wait for the browser connection ACK before timing out.
|
2022-07-13 11:17:19 +02:00
|
|
|
constexpr auto kConnectionTimeout = base::Seconds(10);
|
2022-02-10 22:52:36 +01:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
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() {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "ViewSource cannot be called from the renderer process";
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame_) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return (frame_->Parent() == nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefFrameImpl::IsFocused() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame_ && frame_->View()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
return (frame_->View()->FocusedFrame() == frame_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetName() {
|
|
|
|
CefString name;
|
|
|
|
CEF_REQUIRE_RT_RETURN(name);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame_) {
|
2018-03-28 19:30:15 +02:00
|
|
|
name = render_frame_util::GetName(frame_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (parent && parent->IsWebLocalFrame()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
return browser_->GetWebFrameImpl(parent->ToWebLocalFrame()).get();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame_) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
// 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();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!document.IsNull()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
documentImpl = new CefDOMDocumentImpl(browser_, frame_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
visitor->Visit(documentImpl.get());
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (documentImpl.get()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
documentImpl->Detach();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefURLRequest> CefFrameImpl::CreateURLRequest(
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "CreateURLRequest cannot be called from the render process";
|
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());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!message || !message->IsValid()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
if (message->GetArgumentList() != nullptr) {
|
|
|
|
// Invalidate the message object immediately by taking the argument list.
|
|
|
|
auto argument_list =
|
|
|
|
static_cast<CefProcessMessageImpl*>(message.get())->TakeArgumentList();
|
|
|
|
SendToBrowserFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
2023-01-30 22:42:40 +01:00
|
|
|
[](const CefString& name, base::Value::List argument_list,
|
2022-07-04 11:49:15 +02:00
|
|
|
const BrowserFrameType& render_frame) {
|
|
|
|
render_frame->SendMessage(name, std::move(argument_list));
|
|
|
|
},
|
|
|
|
message->GetName(), std::move(argument_list)));
|
|
|
|
} else {
|
|
|
|
auto region =
|
|
|
|
static_cast<CefProcessMessageSMRImpl*>(message.get())->TakeRegion();
|
|
|
|
SendToBrowserFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](const CefString& name, base::ReadOnlySharedMemoryRegion region,
|
|
|
|
const BrowserFrameType& render_frame) {
|
|
|
|
render_frame->SendSharedMemoryRegion(name, std::move(region));
|
|
|
|
},
|
|
|
|
message->GetName(), std::move(region)));
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void CefFrameImpl::OnAttached() {
|
2021-05-14 18:58:55 +02:00
|
|
|
// Called indirectly from RenderFrameCreated.
|
2022-08-16 19:10:43 +02:00
|
|
|
ConnectBrowserFrame(ConnectReason::RENDER_FRAME_CREATED);
|
2022-02-10 22:52:36 +01:00
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void CefFrameImpl::OnWasShown() {
|
|
|
|
if (browser_connection_state_ == ConnectionState::DISCONNECTED) {
|
|
|
|
// Reconnect a frame that has exited the bfcache.
|
2022-08-16 19:10:43 +02:00
|
|
|
ConnectBrowserFrame(ConnectReason::WAS_SHOWN);
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
void CefFrameImpl::OnDidCommitProvisionalLoad() {
|
|
|
|
did_commit_provisional_load_ = true;
|
|
|
|
MaybeInitializeScriptContext();
|
|
|
|
}
|
|
|
|
|
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.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::HasPluginFrameOwner(frame_)) {
|
2020-01-23 22:58:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
2022-06-22 17:57:49 +02:00
|
|
|
if (!blink::RuntimeEnabledFeatures::BackForwardCacheEnabled() && IsMain()) {
|
|
|
|
// Refresh draggable regions. Otherwise, we may not receive updated regions
|
|
|
|
// after navigation because LocalFrameView::UpdateDocumentAnnotatedRegion
|
|
|
|
// lacks sufficient context. When bfcache is disabled we use this method
|
|
|
|
// instead of DidStopLoading() because it provides more accurate timing.
|
|
|
|
OnDraggableRegionsChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
blink::WebDocumentLoader* dl = frame_->GetDocumentLoader();
|
2022-05-19 12:28:44 +02:00
|
|
|
const int http_status_code = dl->GetWebResponse().HttpStatusCode();
|
2022-02-10 22:52:36 +01: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.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame_->Parent() != nullptr) {
|
2021-09-15 13:40:08 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-09-15 13:40:08 +02:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
using RegionsArg =
|
|
|
|
absl::optional<std::vector<cef::mojom::DraggableRegionEntryPtr>>;
|
|
|
|
RegionsArg regions_arg =
|
|
|
|
regions.empty() ? absl::nullopt : absl::make_optional(std::move(regions));
|
|
|
|
|
|
|
|
SendToBrowserFrame(
|
|
|
|
__FUNCTION__,
|
|
|
|
base::BindOnce(
|
|
|
|
[](RegionsArg regions_arg, const BrowserFrameType& browser_frame) {
|
|
|
|
browser_frame->UpdateDraggableRegions(std::move(regions_arg));
|
|
|
|
},
|
|
|
|
std::move(regions_arg)));
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
void CefFrameImpl::OnContextCreated(v8::Local<v8::Context> context) {
|
2021-05-21 03:42:58 +02:00
|
|
|
context_created_ = true;
|
|
|
|
|
|
|
|
CHECK(frame_);
|
2022-02-10 22:52:36 +01:00
|
|
|
while (!queued_context_actions_.empty()) {
|
|
|
|
auto& action = queued_context_actions_.front();
|
2021-05-21 03:42:58 +02:00
|
|
|
std::move(action.second).Run(frame_);
|
2022-02-10 22:52:36 +01:00
|
|
|
queued_context_actions_.pop();
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
2022-04-05 19:22:32 +02:00
|
|
|
|
|
|
|
execution_context_lifecycle_state_observer_ =
|
|
|
|
blink_glue::RegisterExecutionContextLifecycleStateObserver(context, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::OnContextReleased() {
|
|
|
|
execution_context_lifecycle_state_observer_.reset();
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
frame_ = nullptr;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
browser_->FrameDetached(frame_id_);
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
OnDisconnect(DisconnectReason::DETACHED);
|
2022-02-10 22:52:36 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
browser_ = nullptr;
|
2021-05-21 03:42:58 +02:00
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// In case we never attached.
|
|
|
|
while (!queued_browser_actions_.empty()) {
|
|
|
|
auto& action = queued_browser_actions_.front();
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(WARNING) << action.first << " sent to detached " << GetDebugString()
|
2022-02-10 22:52:36 +01:00
|
|
|
<< " will be ignored";
|
|
|
|
queued_browser_actions_.pop();
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// In case we're destroyed without the context being created.
|
2022-02-10 22:52:36 +01:00
|
|
|
while (!queued_context_actions_.empty()) {
|
|
|
|
auto& action = queued_context_actions_.front();
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(WARNING) << action.first << " sent to detached " << GetDebugString()
|
2021-05-21 03:42:58 +02:00
|
|
|
<< " will be ignored";
|
2022-02-10 22:52:36 +01:00
|
|
|
queued_context_actions_.pop();
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ExecuteOnLocalFrame(const std::string& function_name,
|
|
|
|
LocalFrameAction action) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!context_created_) {
|
2022-02-10 22:52:36 +01:00
|
|
|
queued_context_actions_.push(
|
|
|
|
std::make_pair(function_name, std::move(action)));
|
2022-06-17 15:28:55 +02:00
|
|
|
MaybeInitializeScriptContext();
|
2021-05-21 03:42:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_) {
|
|
|
|
std::move(action).Run(frame_);
|
|
|
|
} else {
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(WARNING) << function_name << " sent to detached " << GetDebugString()
|
2021-05-21 03:42:58 +02:00
|
|
|
<< " will be ignored";
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
void CefFrameImpl::ConnectBrowserFrame(ConnectReason reason) {
|
2022-02-10 22:52:36 +01:00
|
|
|
DCHECK(browser_connection_state_ == ConnectionState::DISCONNECTED ||
|
|
|
|
browser_connection_state_ == ConnectionState::RECONNECT_PENDING);
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
if (VLOG_IS_ON(1)) {
|
|
|
|
std::string reason_str;
|
|
|
|
switch (reason) {
|
|
|
|
case ConnectReason::RENDER_FRAME_CREATED:
|
|
|
|
reason_str = "RENDER_FRAME_CREATED";
|
|
|
|
break;
|
|
|
|
case ConnectReason::WAS_SHOWN:
|
|
|
|
reason_str = "WAS_SHOWN";
|
|
|
|
break;
|
|
|
|
case ConnectReason::RETRY:
|
|
|
|
reason_str = base::StringPrintf(
|
|
|
|
"RETRY %zu/%zu", browser_connect_retry_ct_, kConnectionRetryMaxCt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
VLOG(1) << GetDebugString() << " connection request (reason=" << reason_str
|
|
|
|
<< ")";
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// Don't attempt to connect an invalid or bfcache'd frame. If a bfcache'd
|
|
|
|
// frame returns to active status a reconnect will be triggered via
|
|
|
|
// OnWasShown().
|
|
|
|
if (!frame_ || blink_glue::IsInBackForwardCache(frame_)) {
|
|
|
|
browser_connection_state_ = ConnectionState::DISCONNECTED;
|
|
|
|
browser_connect_timer_.Stop();
|
2022-08-16 19:10:43 +02:00
|
|
|
VLOG(1) << GetDebugString() << " connection retry canceled (reason="
|
|
|
|
<< (frame_ ? "BFCACHED" : "INVALID") << ")";
|
2022-02-10 22:52:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_connection_state_ = ConnectionState::CONNECTION_PENDING;
|
|
|
|
browser_connect_timer_.Start(FROM_HERE, kConnectionTimeout, this,
|
|
|
|
&CefFrameImpl::OnBrowserFrameTimeout);
|
|
|
|
|
|
|
|
auto& browser_frame = GetBrowserFrame(/*expect_acked=*/false);
|
|
|
|
CHECK(browser_frame);
|
|
|
|
|
2022-08-16 20:47:47 +02:00
|
|
|
// True if this connection is a retry or if the frame just exited the
|
|
|
|
// BackForwardCache.
|
|
|
|
const bool reattached =
|
|
|
|
browser_connect_retry_ct_ > 0 || reason == ConnectReason::WAS_SHOWN;
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// If the channel is working we should get a call to FrameAttachedAck().
|
2022-08-16 19:10:43 +02:00
|
|
|
// Otherwise, OnDisconnect() should be called to retry the
|
2022-02-10 22:52:36 +01:00
|
|
|
// connection.
|
|
|
|
browser_frame->FrameAttached(receiver_.BindNewPipeAndPassRemote(),
|
2022-08-16 20:47:47 +02:00
|
|
|
reattached);
|
2022-02-10 22:52:36 +01:00
|
|
|
receiver_.set_disconnect_handler(
|
2022-08-16 19:10:43 +02:00
|
|
|
base::BindOnce(&CefFrameImpl::OnDisconnect, this,
|
|
|
|
DisconnectReason::RENDER_FRAME_DISCONNECT));
|
2022-02-10 22:52:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mojo::Remote<cef::mojom::BrowserFrame>& CefFrameImpl::GetBrowserFrame(
|
|
|
|
bool expect_acked) {
|
|
|
|
DCHECK_EQ(expect_acked,
|
|
|
|
browser_connection_state_ == ConnectionState::CONNECTION_ACKED);
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
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());
|
2022-02-10 22:52:36 +01:00
|
|
|
browser_frame_.set_disconnect_handler(
|
2022-08-16 19:10:43 +02:00
|
|
|
base::BindOnce(&CefFrameImpl::OnDisconnect, this,
|
|
|
|
DisconnectReason::BROWSER_FRAME_DISCONNECT));
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return browser_frame_;
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void CefFrameImpl::OnBrowserFrameTimeout() {
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(ERROR) << GetDebugString() << " connection timeout";
|
|
|
|
OnDisconnect(DisconnectReason::CONNECT_TIMEOUT);
|
2022-02-10 22:52:36 +01:00
|
|
|
}
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
void CefFrameImpl::OnDisconnect(DisconnectReason reason) {
|
2022-02-10 22:52:36 +01:00
|
|
|
// Ignore multiple calls in close proximity (which may occur if both
|
|
|
|
// |browser_frame_| and |receiver_| disconnect). |frame_| will be nullptr
|
|
|
|
// when called from/after OnDetached().
|
|
|
|
if (frame_ &&
|
|
|
|
browser_connection_state_ == ConnectionState::RECONNECT_PENDING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
if (VLOG_IS_ON(1)) {
|
|
|
|
std::string reason_str;
|
|
|
|
switch (reason) {
|
|
|
|
case DisconnectReason::DETACHED:
|
|
|
|
reason_str = "DETACHED";
|
|
|
|
break;
|
2022-08-16 20:47:47 +02:00
|
|
|
case DisconnectReason::BROWSER_FRAME_DETACHED:
|
|
|
|
reason_str = "BROWSER_FRAME_DETACHED";
|
|
|
|
break;
|
2022-08-16 19:10:43 +02:00
|
|
|
case DisconnectReason::CONNECT_TIMEOUT:
|
|
|
|
reason_str = "CONNECT_TIMEOUT";
|
|
|
|
break;
|
|
|
|
case DisconnectReason::RENDER_FRAME_DISCONNECT:
|
|
|
|
reason_str = "RENDER_FRAME_DISCONNECT";
|
|
|
|
break;
|
|
|
|
case DisconnectReason::BROWSER_FRAME_DISCONNECT:
|
|
|
|
reason_str = "BROWSER_FRAME_DISCONNECT";
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string state_str;
|
|
|
|
switch (browser_connection_state_) {
|
|
|
|
case ConnectionState::DISCONNECTED:
|
|
|
|
state_str = "DISCONNECTED";
|
|
|
|
break;
|
|
|
|
case ConnectionState::CONNECTION_PENDING:
|
|
|
|
state_str = "CONNECTION_PENDING";
|
|
|
|
break;
|
|
|
|
case ConnectionState::CONNECTION_ACKED:
|
|
|
|
state_str = "CONNECTION_ACKED";
|
|
|
|
break;
|
|
|
|
case ConnectionState::RECONNECT_PENDING:
|
|
|
|
state_str = "RECONNECT_PENDING";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame_) {
|
2022-08-16 19:10:43 +02:00
|
|
|
state_str += ", FRAME_INVALID";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-08-16 19:10:43 +02:00
|
|
|
|
|
|
|
VLOG(1) << GetDebugString() << " disconnected (reason=" << reason_str
|
|
|
|
<< ", current_state=" << state_str << ")";
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
browser_frame_.reset();
|
|
|
|
receiver_.reset();
|
|
|
|
browser_connection_state_ = ConnectionState::DISCONNECTED;
|
|
|
|
browser_connect_timer_.Stop();
|
|
|
|
|
2022-08-16 20:47:47 +02:00
|
|
|
// Only retry if the frame is still valid and the browser process has not
|
|
|
|
// intentionally detached.
|
|
|
|
if (frame_ && reason != DisconnectReason::BROWSER_FRAME_DETACHED) {
|
2022-02-10 22:52:36 +01:00
|
|
|
if (browser_connect_retry_ct_++ < kConnectionRetryMaxCt) {
|
2022-08-16 19:10:43 +02:00
|
|
|
VLOG(1) << GetDebugString() << " connection retry scheduled";
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
// Retry after a delay in case the frame is currently navigating, being
|
|
|
|
// destroyed, or entering the bfcache. In the navigation case the retry
|
|
|
|
// will likely succeed. In the destruction case the retry will be
|
|
|
|
// ignored/canceled due to OnDetached(). In the bfcache case the status
|
|
|
|
// may not be updated immediately, so we allow the reconnect timer to
|
|
|
|
// trigger and check the status in ConnectBrowserFrame() instead.
|
|
|
|
browser_connection_state_ = ConnectionState::RECONNECT_PENDING;
|
2022-08-16 19:10:43 +02:00
|
|
|
browser_connect_timer_.Start(
|
|
|
|
FROM_HERE, kConnectionRetryDelay,
|
|
|
|
base::BindOnce(&CefFrameImpl::ConnectBrowserFrame, this,
|
|
|
|
ConnectReason::RETRY));
|
2022-02-10 22:52:36 +01:00
|
|
|
} else {
|
|
|
|
// Trigger a crash in official builds.
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(FATAL) << GetDebugString() << " connection retry failed";
|
2022-02-10 22:52:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::SendToBrowserFrame(const std::string& function_name,
|
|
|
|
BrowserFrameAction action) {
|
|
|
|
if (!frame_) {
|
|
|
|
// We've been detached.
|
2022-08-16 19:10:43 +02:00
|
|
|
LOG(WARNING) << function_name << " sent to detached " << GetDebugString()
|
2022-02-10 22:52:36 +01:00
|
|
|
<< " will be ignored";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser_connection_state_ != ConnectionState::CONNECTION_ACKED) {
|
|
|
|
// Queue actions until we're notified by the browser that it's ready to
|
|
|
|
// handle them.
|
|
|
|
queued_browser_actions_.push(
|
|
|
|
std::make_pair(function_name, std::move(action)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
CHECK(browser_frame);
|
|
|
|
|
|
|
|
std::move(action).Run(browser_frame);
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
void CefFrameImpl::MaybeInitializeScriptContext() {
|
|
|
|
if (did_initialize_script_context_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!did_commit_provisional_load_) {
|
|
|
|
// Too soon for context initialization.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (queued_context_actions_.empty()) {
|
|
|
|
// Don't need early context initialization. Avoid it due to performance
|
|
|
|
// consequences.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
did_initialize_script_context_ = true;
|
|
|
|
|
|
|
|
// Explicitly force creation of the script context. This occurred implicitly
|
|
|
|
// via DidCommitProvisionalLoad prior to https://crrev.com/5150754880a.
|
|
|
|
// Otherwise, a script context may never be created for a frame that doesn't
|
|
|
|
// contain JS code.
|
|
|
|
v8::HandleScope handle_scope(blink::MainThreadIsolate());
|
|
|
|
frame_->MainWorldScriptContext();
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void CefFrameImpl::FrameAttachedAck() {
|
|
|
|
// Sent from the browser process in response to ConnectBrowserFrame() sending
|
|
|
|
// FrameAttached().
|
|
|
|
CHECK_EQ(ConnectionState::CONNECTION_PENDING, browser_connection_state_);
|
|
|
|
browser_connection_state_ = ConnectionState::CONNECTION_ACKED;
|
|
|
|
browser_connect_retry_ct_ = 0;
|
|
|
|
browser_connect_timer_.Stop();
|
|
|
|
|
|
|
|
auto& browser_frame = GetBrowserFrame();
|
|
|
|
CHECK(browser_frame);
|
|
|
|
|
|
|
|
while (!queued_browser_actions_.empty()) {
|
|
|
|
std::move(queued_browser_actions_.front().second).Run(browser_frame);
|
|
|
|
queued_browser_actions_.pop();
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 20:47:47 +02:00
|
|
|
void CefFrameImpl::FrameDetached() {
|
|
|
|
// Sent from the browser process in response to CefFrameHostImpl::Detach().
|
|
|
|
CHECK_EQ(ConnectionState::CONNECTION_ACKED, browser_connection_state_);
|
|
|
|
OnDisconnect(DisconnectReason::BROWSER_FRAME_DETACHED);
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
void CefFrameImpl::SendMessage(const std::string& name,
|
|
|
|
base::Value::List arguments) {
|
2021-05-14 18:58:55 +02:00
|
|
|
if (auto app = CefAppManager::Get()->GetApplication()) {
|
|
|
|
if (auto handler = app->GetRenderProcessHandler()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
CefRefPtr<CefProcessMessageImpl> message(
|
|
|
|
new CefProcessMessageImpl(name, std::move(arguments),
|
|
|
|
/*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
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
void CefFrameImpl::SendSharedMemoryRegion(
|
|
|
|
const std::string& name,
|
|
|
|
base::ReadOnlySharedMemoryRegion region) {
|
|
|
|
if (auto app = CefAppManager::Get()->GetApplication()) {
|
|
|
|
if (auto handler = app->GetRenderProcessHandler()) {
|
|
|
|
CefRefPtr<CefProcessMessage> message(
|
|
|
|
new CefProcessMessageSMRImpl(name, std::move(region)));
|
|
|
|
handler->OnProcessMessageReceived(browser_, this, PID_BROWSER, message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(command, "getsource")) {
|
2021-05-21 03:42:58 +02:00
|
|
|
response = blink_glue::DumpDocumentMarkup(frame);
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(command, "gettext")) {
|
2021-05-21 03:42:58 +02:00
|
|
|
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,
|
2021-12-16 23:35:54 +01:00
|
|
|
blink::WebLocalFrame* frame) {
|
|
|
|
frame->ExecuteScript(blink::WebScriptSource(
|
|
|
|
blink::WebString::FromUTF16(jsCode), GURL(scriptUrl)));
|
2021-05-21 03:42:58 +02:00
|
|
|
},
|
2021-12-16 23:35:54 +01:00
|
|
|
jsCode, scriptUrl));
|
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
|
|
|
|
2022-06-22 17:57:49 +02:00
|
|
|
if (blink::RuntimeEnabledFeatures::BackForwardCacheEnabled()) {
|
|
|
|
// Refresh draggable regions. Otherwise, we may not receive updated regions
|
|
|
|
// after navigation because LocalFrameView::UpdateDocumentAnnotatedRegion
|
|
|
|
// lacks sufficient context. When bfcache is enabled we can't rely on
|
|
|
|
// OnDidFinishLoad() as the frame may not actually be reloaded.
|
|
|
|
OnDraggableRegionsChanged();
|
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
2023-01-06 19:33:32 +01:00
|
|
|
void CefFrameImpl::MoveOrResizeStarted() {
|
|
|
|
if (frame_) {
|
|
|
|
auto web_view = frame_->View();
|
2023-01-30 22:42:40 +01:00
|
|
|
if (web_view) {
|
2023-01-06 19:33:32 +01:00
|
|
|
web_view->CancelPagePopup();
|
2023-01-30 22:42:40 +01:00
|
|
|
}
|
2023-01-06 19:33:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
void CefFrameImpl::ContextLifecycleStateChanged(
|
|
|
|
blink::mojom::blink::FrameLifecycleState state) {
|
|
|
|
if (state == blink::mojom::FrameLifecycleState::kFrozen && IsMain() &&
|
|
|
|
blink_glue::IsInBackForwardCache(frame_)) {
|
|
|
|
browser_->OnEnterBFCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 19:10:43 +02:00
|
|
|
std::string CefFrameImpl::GetDebugString() const {
|
|
|
|
return "frame " + frame_util::GetFrameDebugString(frame_id_);
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_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
|