2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2011 The Chromium 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/browser_impl.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
#include "libcef/renderer/render_frame_util.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "libcef/renderer/render_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-12-26 16:12:11 +01:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
2022-03-26 02:12:30 +01:00
|
|
|
#include "content/renderer/document_state.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/renderer/navigation_state.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_error.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_response.h"
|
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
|
|
|
#include "third_party/blink/public/web/web_frame.h"
|
|
|
|
#include "third_party/blink/public/web/web_frame_content_dumper.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
|
|
|
#include "third_party/blink/public/web/web_security_policy.h"
|
|
|
|
#include "third_party/blink/public/web/web_view.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefBrowserImpl static methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserImpl> CefBrowserImpl::GetBrowserForView(
|
2022-07-21 19:26:10 +02:00
|
|
|
blink::WebView* view) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return CefRenderManager::Get()->GetBrowserForView(view);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserImpl> CefBrowserImpl::GetBrowserForMainFrame(
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebFrame* frame) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return CefRenderManager::Get()->GetBrowserForMainFrame(frame);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CefBrowser methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
bool CefBrowserImpl::IsValid() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
return !!GetWebView();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowserHost> CefBrowserImpl::GetHost() {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false) << "GetHost cannot be called from the render process";
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::CanGoBack() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
return blink_glue::CanGoBack(GetWebView());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GoBack() {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
blink_glue::GoBack(GetWebView());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::CanGoForward() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
return blink_glue::CanGoForward(GetWebView());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GoForward() {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
blink_glue::GoForward(GetWebView());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::IsLoading() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (main_frame) {
|
2017-04-20 21:28:17 +02:00
|
|
|
return main_frame->ToWebLocalFrame()->IsLoading();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-09-27 01:48:19 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::Reload() {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
2018-06-08 18:53:10 +02:00
|
|
|
main_frame->ToWebLocalFrame()->StartReload(
|
|
|
|
blink::WebFrameLoadType::kReload);
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::ReloadIgnoreCache() {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
2018-06-08 18:53:10 +02:00
|
|
|
main_frame->ToWebLocalFrame()->StartReload(
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebFrameLoadType::kReloadBypassingCache);
|
|
|
|
}
|
2016-04-27 22:38:52 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::StopLoad() {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
main_frame->ToWebLocalFrame()->DeprecatedStopLoading();
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefBrowserImpl::GetIdentifier() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(0);
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
return browser_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::IsSame(CefRefPtr<CefBrowser> that) {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
|
|
|
CefBrowserImpl* impl = static_cast<CefBrowserImpl*>(that.get());
|
|
|
|
return (impl == this);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::IsPopup() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
return is_popup();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::HasDocument() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
|
|
|
return !main_frame->ToWebLocalFrame()->GetDocument().IsNull();
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame() {
|
2016-11-23 21:54:29 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
|
|
|
return GetWebFrameImpl(main_frame->ToWebLocalFrame()).get();
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame() {
|
2016-11-23 21:54:29 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView() && GetWebView()->FocusedFrame()) {
|
|
|
|
return GetWebFrameImpl(GetWebView()->FocusedFrame()).get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(int64 identifier) {
|
2016-11-23 21:54:29 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return GetWebFrameImpl(identifier).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name) {
|
2016-11-23 21:54:29 +01:00
|
|
|
CEF_REQUIRE_RT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
blink::WebView* web_view = GetWebView();
|
2014-09-24 17:38:11 +02:00
|
|
|
if (web_view) {
|
2018-03-20 21:15:08 +01:00
|
|
|
const blink::WebString& frame_name =
|
|
|
|
blink::WebString::FromUTF16(name.ToString16());
|
2014-09-24 17:38:11 +02:00
|
|
|
// Search by assigned frame name (Frame::name).
|
2019-05-24 22:23:43 +02:00
|
|
|
blink::WebFrame* frame = web_view->MainFrame();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame && frame->IsWebLocalFrame()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
frame = frame->ToWebLocalFrame()->FindFrameByName(frame_name);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!frame) {
|
|
|
|
// Search by unique frame name (Frame::uniqueName).
|
2017-04-20 21:28:17 +02:00
|
|
|
const std::string& searchname = name;
|
2019-05-24 22:23:43 +02:00
|
|
|
for (blink::WebFrame* cur_frame = web_view->MainFrame(); cur_frame;
|
2017-04-20 21:28:17 +02:00
|
|
|
cur_frame = cur_frame->TraverseNext()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
if (cur_frame->IsWebLocalFrame() &&
|
2018-03-28 19:30:15 +02:00
|
|
|
render_frame_util::GetName(cur_frame->ToWebLocalFrame()) ==
|
2017-07-27 01:19:27 +02:00
|
|
|
searchname) {
|
2017-04-20 21:28:17 +02:00
|
|
|
frame = cur_frame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame && frame->IsWebLocalFrame()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
return GetWebFrameImpl(frame->ToWebLocalFrame()).get();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefBrowserImpl::GetFrameCount() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(0);
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
for (blink::WebFrame* frame = GetWebView()->MainFrame(); frame;
|
|
|
|
frame = frame->TraverseNext()) {
|
2016-11-23 21:54:29 +01:00
|
|
|
count++;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GetFrameIdentifiers(std::vector<int64>& identifiers) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (identifiers.size() > 0) {
|
2014-09-24 17:38:11 +02:00
|
|
|
identifiers.clear();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
for (blink::WebFrame* frame = GetWebView()->MainFrame(); frame;
|
|
|
|
frame = frame->TraverseNext()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame->IsWebLocalFrame()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
identifiers.push_back(
|
|
|
|
render_frame_util::GetIdentifier(frame->ToWebLocalFrame()));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (names.size() > 0) {
|
2014-09-24 17:38:11 +02:00
|
|
|
names.clear();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
for (blink::WebFrame* frame = GetWebView()->MainFrame(); frame;
|
|
|
|
frame = frame->TraverseNext()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame->IsWebLocalFrame()) {
|
2018-03-28 19:30:15 +02:00
|
|
|
names.push_back(render_frame_util::GetName(frame->ToWebLocalFrame()));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CefBrowserImpl public methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2022-07-21 19:26:10 +02:00
|
|
|
CefBrowserImpl::CefBrowserImpl(blink::WebView* web_view,
|
2012-11-20 21:08:36 +01:00
|
|
|
int browser_id,
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_popup,
|
|
|
|
bool is_windowless)
|
2022-07-21 19:26:10 +02:00
|
|
|
: blink::WebViewObserver(web_view),
|
2012-12-30 12:17:49 +01:00
|
|
|
browser_id_(browser_id),
|
2012-11-20 21:08:36 +01:00
|
|
|
is_popup_(is_popup),
|
2019-05-24 22:23:43 +02:00
|
|
|
is_windowless_(is_windowless) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserImpl::~CefBrowserImpl() {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefFrameImpl> CefBrowserImpl::GetWebFrameImpl(
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* frame) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(frame);
|
2017-07-06 22:39:37 +02:00
|
|
|
int64_t frame_id = render_frame_util::GetIdentifier(frame);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Frames are re-used between page loads. Only add the frame to the map once.
|
|
|
|
FrameMap::const_iterator it = frames_.find(frame_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != frames_.end()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-07-09 20:36:37 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr(new CefFrameImpl(this, frame, frame_id));
|
2012-04-03 03:34:16 +02:00
|
|
|
frames_.insert(std::make_pair(frame_id, framePtr));
|
|
|
|
|
|
|
|
return framePtr;
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefFrameImpl> CefBrowserImpl::GetWebFrameImpl(int64_t frame_id) {
|
2018-04-19 17:44:42 +02:00
|
|
|
if (frame_id == blink_glue::kInvalidFrameId) {
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
|
|
|
blink::WebFrame* main_frame = GetWebView()->MainFrame();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (main_frame && main_frame->IsWebLocalFrame()) {
|
|
|
|
return GetWebFrameImpl(main_frame->ToWebLocalFrame());
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we already know about the frame.
|
|
|
|
FrameMap::const_iterator it = frames_.find(frame_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != frames_.end()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (GetWebView()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Check if the frame exists but we don't know about it yet.
|
2021-03-04 23:36:57 +01:00
|
|
|
for (blink::WebFrame* frame = GetWebView()->MainFrame(); frame;
|
|
|
|
frame = frame->TraverseNext()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
if (frame->IsWebLocalFrame() &&
|
|
|
|
render_frame_util::GetIdentifier(frame->ToWebLocalFrame()) ==
|
|
|
|
frame_id) {
|
|
|
|
return GetWebFrameImpl(frame->ToWebLocalFrame());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void CefBrowserImpl::AddFrameObject(int64_t frame_id,
|
2012-04-27 23:19:06 +02:00
|
|
|
CefTrackNode* tracked_object) {
|
|
|
|
CefRefPtr<CefTrackManager> manager;
|
|
|
|
|
|
|
|
if (!frame_objects_.empty()) {
|
|
|
|
FrameObjectMap::const_iterator it = frame_objects_.find(frame_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != frame_objects_.end()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
manager = it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!manager.get()) {
|
|
|
|
manager = new CefTrackManager();
|
|
|
|
frame_objects_.insert(std::make_pair(frame_id, manager));
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->Add(tracked_object);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// RenderViewObserver methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void CefBrowserImpl::OnDestruct() {
|
|
|
|
// Notify that the browser window has been destroyed.
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (app.get()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler = app->GetRenderProcessHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (handler.get()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->OnBrowserDestroyed(this);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
CefRenderManager::Get()->OnBrowserDestroyed(this);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void CefBrowserImpl::FrameDetached(int64_t frame_id) {
|
2013-08-16 19:05:26 +02:00
|
|
|
if (!frames_.empty()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
// Remove the frame from the map.
|
|
|
|
FrameMap::iterator it = frames_.find(frame_id);
|
2013-08-16 19:05:26 +02:00
|
|
|
if (it != frames_.end()) {
|
|
|
|
frames_.erase(it);
|
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame_objects_.empty()) {
|
|
|
|
// Remove any tracked objects associated with the frame.
|
|
|
|
FrameObjectMap::iterator it = frame_objects_.find(frame_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != frame_objects_.end()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
frame_objects_.erase(it);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
void CefBrowserImpl::OnLoadingStateChange(bool isLoading) {
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
|
2013-09-13 01:36:54 +02:00
|
|
|
if (app.get()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler = app->GetRenderProcessHandler();
|
2013-09-13 01:36:54 +02:00
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
|
|
|
if (load_handler.get()) {
|
2021-03-04 23:36:57 +01:00
|
|
|
blink::WebView* web_view = GetWebView();
|
2018-04-19 17:44:42 +02:00
|
|
|
const bool canGoBack = blink_glue::CanGoBack(web_view);
|
|
|
|
const bool canGoForward = blink_glue::CanGoForward(web_view);
|
2013-09-13 01:36:54 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Don't call OnLoadingStateChange multiple times with the same status.
|
|
|
|
// This can occur in cases where there are multiple highest-level
|
|
|
|
// LocalFrames in-process for the same browser.
|
|
|
|
if (last_loading_state_ &&
|
|
|
|
last_loading_state_->IsMatch(isLoading, canGoBack, canGoForward)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
if (was_in_bfcache_) {
|
|
|
|
// Send the expected callbacks when exiting the BFCache.
|
|
|
|
DCHECK(!isLoading);
|
|
|
|
load_handler->OnLoadingStateChange(this, /*isLoading=*/true,
|
|
|
|
canGoBack, canGoForward);
|
|
|
|
|
|
|
|
auto main_frame = GetMainFrame();
|
|
|
|
load_handler->OnLoadStart(this, main_frame, TT_EXPLICIT);
|
|
|
|
load_handler->OnLoadEnd(this, main_frame, 0);
|
|
|
|
|
|
|
|
was_in_bfcache_ = false;
|
|
|
|
}
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
load_handler->OnLoadingStateChange(this, isLoading, canGoBack,
|
|
|
|
canGoForward);
|
2019-05-24 22:23:43 +02:00
|
|
|
last_loading_state_.reset(
|
|
|
|
new LoadingState(isLoading, canGoBack, canGoForward));
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 19:22:32 +02:00
|
|
|
|
|
|
|
void CefBrowserImpl::OnEnterBFCache() {
|
|
|
|
// Reset loading state so that notifications will be resent if/when exiting
|
|
|
|
// BFCache.
|
|
|
|
was_in_bfcache_ = true;
|
|
|
|
last_loading_state_.reset();
|
|
|
|
}
|