2012-12-30 12:17:49 +01: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/browser/browser_info.h"
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/browser_host_base.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2021-08-19 23:07:44 +02:00
|
|
|
#include "libcef/common/frame_util.h"
|
2019-03-19 10:42:54 +01:00
|
|
|
#include "libcef/common/values_impl.h"
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "base/logging.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "content/browser/renderer_host/frame_tree_node.h"
|
|
|
|
#include "content/browser/renderer_host/render_frame_host_impl.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2015-10-21 20:17:09 +02:00
|
|
|
#include "ipc/ipc_message.h"
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfo::FrameInfo::~FrameInfo() {
|
2021-05-21 03:42:58 +02:00
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
if (frame_ && !IsCurrentMainFrame()) {
|
|
|
|
// Should already be Detached.
|
|
|
|
DCHECK(!frame_->GetRenderFrameHost());
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
#endif
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfo::CefBrowserInfo(int browser_id,
|
|
|
|
bool is_popup,
|
|
|
|
bool is_windowless,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info)
|
|
|
|
: browser_id_(browser_id),
|
|
|
|
is_popup_(is_popup),
|
|
|
|
is_windowless_(is_windowless),
|
|
|
|
extra_info_(extra_info) {
|
|
|
|
DCHECK_GT(browser_id, 0);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
CefBrowserInfo::~CefBrowserInfo() {
|
|
|
|
DCHECK(frame_info_set_.empty());
|
|
|
|
}
|
2014-01-02 23:41:11 +01:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> CefBrowserInfo::browser() const {
|
2019-05-24 22:23:43 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2021-09-15 20:40:53 +02:00
|
|
|
if (!is_closing_)
|
|
|
|
return browser_;
|
|
|
|
return nullptr;
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
void CefBrowserInfo::SetBrowser(CefRefPtr<CefBrowserHostBase> browser) {
|
2021-05-21 03:42:58 +02:00
|
|
|
NotificationStateLock lock_scope(this);
|
|
|
|
|
|
|
|
if (browser) {
|
|
|
|
DCHECK(!browser_);
|
|
|
|
|
|
|
|
// Cache the associated frame handler.
|
|
|
|
if (auto client = browser->GetClient()) {
|
|
|
|
frame_handler_ = client->GetFrameHandler();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DCHECK(browser_);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto old_browser = browser_;
|
2019-05-24 22:23:43 +02:00
|
|
|
browser_ = browser;
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
if (!browser_) {
|
|
|
|
RemoveAllFrames(old_browser);
|
|
|
|
|
|
|
|
// Any future calls to MaybeExecuteFrameNotification will now fail.
|
|
|
|
// NotificationStateLock already took a reference for the delivery of any
|
|
|
|
// notifications that are currently queued due to RemoveAllFrames.
|
|
|
|
frame_handler_ = nullptr;
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:53 +02:00
|
|
|
void CefBrowserInfo::SetClosing() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
DCHECK(!is_closing_);
|
|
|
|
is_closing_ = true;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
|
|
|
|
bool is_guest_view) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
const auto global_id = host->GetGlobalId();
|
2019-05-24 22:23:43 +02:00
|
|
|
const bool is_main_frame = (host->GetParent() == nullptr);
|
|
|
|
|
|
|
|
// A speculative RFH will be created in response to a browser-initiated
|
|
|
|
// cross-origin navigation (e.g. via LoadURL) and eventually either discarded
|
|
|
|
// or swapped in based on whether the navigation is committed. We'll create a
|
|
|
|
// frame object for the speculative RFH so that it can be found by
|
|
|
|
// frame/routing ID. However, we won't replace the main frame with a
|
|
|
|
// speculative RFH until after it's swapped in, and we'll generally prefer to
|
|
|
|
// return a non-speculative RFH for the same node ID if one exists.
|
|
|
|
const bool is_speculative = (static_cast<content::RenderFrameHostImpl*>(host)
|
|
|
|
->frame_tree_node()
|
|
|
|
->render_manager()
|
|
|
|
->current_frame_host() != host);
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
NotificationStateLock lock_scope(this);
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK(browser_);
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
const auto it = frame_id_map_.find(global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
if (it != frame_id_map_.end()) {
|
|
|
|
auto info = it->second;
|
|
|
|
|
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
// Check that the frame info hasn't changed unexpectedly.
|
2021-08-19 23:07:44 +02:00
|
|
|
DCHECK_EQ(info->global_id_, global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK_EQ(info->is_guest_view_, is_guest_view);
|
|
|
|
DCHECK_EQ(info->is_main_frame_, is_main_frame);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!info->is_guest_view_ && info->is_speculative_ && !is_speculative) {
|
|
|
|
// Upgrade the frame info from speculative to non-speculative.
|
|
|
|
if (info->is_main_frame_) {
|
2021-05-19 02:45:05 +02:00
|
|
|
// Set the main frame object.
|
2021-05-21 03:42:58 +02:00
|
|
|
SetMainFrame(browser_, info->frame_);
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
info->is_speculative_ = false;
|
|
|
|
}
|
2017-10-26 20:17:00 +02:00
|
|
|
return;
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
auto frame_info = new FrameInfo;
|
|
|
|
frame_info->host_ = host;
|
2021-08-19 23:07:44 +02:00
|
|
|
frame_info->global_id_ = global_id;
|
2019-05-24 22:23:43 +02:00
|
|
|
frame_info->is_guest_view_ = is_guest_view;
|
|
|
|
frame_info->is_main_frame_ = is_main_frame;
|
|
|
|
frame_info->is_speculative_ = is_speculative;
|
|
|
|
|
|
|
|
// Guest views don't get their own CefBrowser or CefFrame objects.
|
|
|
|
if (!is_guest_view) {
|
2021-05-21 03:42:58 +02:00
|
|
|
// Create a new frame object.
|
|
|
|
frame_info->frame_ = new CefFrameHostImpl(this, host);
|
|
|
|
MaybeNotifyFrameCreated(frame_info->frame_);
|
|
|
|
if (is_main_frame && !is_speculative) {
|
|
|
|
SetMainFrame(browser_, frame_info->frame_);
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
// Check that the frame info hasn't changed unexpectedly.
|
2021-08-19 23:07:44 +02:00
|
|
|
DCHECK_EQ(frame_util::MakeFrameId(global_id),
|
|
|
|
frame_info->frame_->GetIdentifier());
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK_EQ(frame_info->is_main_frame_, frame_info->frame_->IsMain());
|
|
|
|
#endif
|
|
|
|
}
|
2014-01-02 23:41:11 +01:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
browser_->request_context()->OnRenderFrameCreated(global_id, is_main_frame,
|
|
|
|
is_guest_view);
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Populate the lookup maps.
|
2021-08-19 23:07:44 +02:00
|
|
|
frame_id_map_.insert(std::make_pair(global_id, frame_info));
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// And finally set the ownership.
|
|
|
|
frame_info_set_.insert(base::WrapUnique(frame_info));
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2021-07-25 19:31:39 +02:00
|
|
|
void CefBrowserInfo::FrameHostStateChanged(
|
|
|
|
content::RenderFrameHost* host,
|
|
|
|
content::RenderFrameHost::LifecycleState old_state,
|
|
|
|
content::RenderFrameHost::LifecycleState new_state) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2021-09-15 13:40:08 +02:00
|
|
|
if ((old_state == content::RenderFrameHost::LifecycleState::kPrerendering ||
|
|
|
|
old_state ==
|
|
|
|
content::RenderFrameHost::LifecycleState::kInBackForwardCache) &&
|
|
|
|
new_state == content::RenderFrameHost::LifecycleState::kActive) {
|
|
|
|
if (auto frame = GetFrameForHost(host)) {
|
|
|
|
// Update the associated RFH, which may have changed.
|
|
|
|
frame->MaybeReAttach(this, host);
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
if (frame->IsMain()) {
|
2021-09-15 13:40:08 +02:00
|
|
|
// Update the main frame object.
|
|
|
|
NotificationStateLock lock_scope(this);
|
|
|
|
SetMainFrame(browser_, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update draggable regions.
|
|
|
|
frame->MaybeSendDidStopLoading();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update BackForwardCache state.
|
2021-07-25 19:31:39 +02:00
|
|
|
bool added_to_bfcache =
|
|
|
|
new_state ==
|
|
|
|
content::RenderFrameHost::LifecycleState::kInBackForwardCache;
|
|
|
|
bool removed_from_bfcache =
|
|
|
|
old_state ==
|
|
|
|
content::RenderFrameHost::LifecycleState::kInBackForwardCache;
|
|
|
|
if (!added_to_bfcache && !removed_from_bfcache)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
auto it = frame_id_map_.find(host->GetGlobalId());
|
2021-07-25 19:31:39 +02:00
|
|
|
DCHECK(it != frame_id_map_.end());
|
|
|
|
DCHECK((!it->second->is_in_bfcache_ && added_to_bfcache) ||
|
|
|
|
(it->second->is_in_bfcache_ && removed_from_bfcache));
|
|
|
|
it->second->is_in_bfcache_ = added_to_bfcache;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
NotificationStateLock lock_scope(this);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
const auto global_id = host->GetGlobalId();
|
|
|
|
auto it = frame_id_map_.find(global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK(it != frame_id_map_.end());
|
|
|
|
|
|
|
|
auto frame_info = it->second;
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
browser_->request_context()->OnRenderFrameDeleted(
|
2021-08-19 23:07:44 +02:00
|
|
|
global_id, frame_info->is_main_frame_, frame_info->is_guest_view_);
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Remove from the lookup maps.
|
|
|
|
frame_id_map_.erase(it);
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// And finally delete the frame info.
|
2019-11-06 19:17:18 +01:00
|
|
|
{
|
|
|
|
auto it2 = frame_info_set_.find(frame_info);
|
2021-05-21 03:42:58 +02:00
|
|
|
|
|
|
|
// Explicitly Detach everything but the current main frame.
|
|
|
|
const auto& frame_info = *it2;
|
|
|
|
if (frame_info->frame_ && !frame_info->IsCurrentMainFrame()) {
|
2022-08-16 19:10:43 +02:00
|
|
|
if (frame_info->frame_->Detach(
|
|
|
|
CefFrameHostImpl::DetachReason::RENDER_FRAME_DELETED)) {
|
2021-07-25 19:31:39 +02:00
|
|
|
MaybeNotifyFrameDetached(browser_, frame_info->frame_);
|
2022-08-16 19:10:43 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
|
|
|
|
2019-11-06 19:17:18 +01:00
|
|
|
frame_info_set_.erase(it2);
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetMainFrame() {
|
2021-09-16 10:01:55 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2021-05-21 03:42:58 +02:00
|
|
|
// Early exit if called post-destruction.
|
2021-09-15 20:40:53 +02:00
|
|
|
if (!browser_ || is_closing_)
|
2021-05-21 03:42:58 +02:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
CHECK(main_frame_);
|
2019-05-24 22:23:43 +02:00
|
|
|
return main_frame_;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::CreateTempSubFrame(
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& parent_global_id) {
|
|
|
|
CefRefPtr<CefFrameHostImpl> parent = GetFrameForGlobalId(parent_global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!parent)
|
|
|
|
parent = GetMainFrame();
|
2021-05-21 03:42:58 +02:00
|
|
|
// Intentionally not notifying for temporary frames.
|
|
|
|
return new CefFrameHostImpl(this, parent->GetIdentifier());
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForHost(
|
|
|
|
const content::RenderFrameHost* host,
|
2021-05-19 02:45:05 +02:00
|
|
|
bool* is_guest_view,
|
|
|
|
bool prefer_speculative) const {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = false;
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!host)
|
|
|
|
return nullptr;
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
return GetFrameForGlobalId(
|
|
|
|
const_cast<content::RenderFrameHost*>(host)->GetGlobalId(), is_guest_view,
|
|
|
|
prefer_speculative);
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
2021-05-19 02:45:05 +02:00
|
|
|
bool* is_guest_view,
|
|
|
|
bool prefer_speculative) const {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = false;
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
if (!frame_util::IsValidGlobalId(global_id))
|
2019-05-24 22:23:43 +02:00
|
|
|
return nullptr;
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
const auto it = frame_id_map_.find(global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
if (it != frame_id_map_.end()) {
|
|
|
|
const auto info = it->second;
|
|
|
|
|
|
|
|
if (info->is_guest_view_) {
|
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = true;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-05-19 02:45:05 +02:00
|
|
|
if (info->is_speculative_ && !prefer_speculative) {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (info->is_main_frame_ && main_frame_) {
|
|
|
|
// Always prefer the non-speculative main frame.
|
|
|
|
return main_frame_;
|
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
LOG(WARNING) << "Returning a speculative frame for "
|
|
|
|
<< frame_util::GetFrameDebugString(global_id);
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(info->frame_);
|
|
|
|
return info->frame_;
|
|
|
|
}
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
return nullptr;
|
2015-10-21 20:17:09 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfo::FrameHostList CefBrowserInfo::GetAllFrames() const {
|
2015-10-21 20:17:09 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2019-05-24 22:23:43 +02:00
|
|
|
FrameHostList frames;
|
|
|
|
for (const auto& info : frame_info_set_) {
|
2021-07-25 19:31:39 +02:00
|
|
|
if (info->frame_ && !info->is_speculative_ && !info->is_in_bfcache_) {
|
2019-05-24 22:23:43 +02:00
|
|
|
frames.insert(info->frame_);
|
2021-07-25 19:31:39 +02:00
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
CefBrowserInfo::NavigationLock::NavigationLock() : weak_ptr_factory_(this) {}
|
|
|
|
|
|
|
|
CefBrowserInfo::NavigationLock::~NavigationLock() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (pending_action_) {
|
|
|
|
CEF_POST_TASK(CEF_UIT, std::move(pending_action_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo::NavigationLock>
|
|
|
|
CefBrowserInfo::CreateNavigationLock() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
scoped_refptr<NavigationLock> lock;
|
|
|
|
if (!navigation_lock_) {
|
|
|
|
lock = new NavigationLock();
|
|
|
|
navigation_lock_ = lock->weak_ptr_factory_.GetWeakPtr();
|
|
|
|
} else {
|
|
|
|
lock = navigation_lock_.get();
|
|
|
|
}
|
|
|
|
return lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserInfo::IsNavigationLocked(base::OnceClosure pending_action) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (navigation_lock_) {
|
|
|
|
navigation_lock_->pending_action_ = std::move(pending_action);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
void CefBrowserInfo::MaybeExecuteFrameNotification(
|
|
|
|
FrameNotifyOnceAction pending_action) {
|
|
|
|
CefRefPtr<CefFrameHandler> frame_handler;
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope_(notification_lock_);
|
|
|
|
if (!frame_handler_) {
|
|
|
|
// No notifications will be executed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notification_state_lock_) {
|
|
|
|
// Queue the notification until the lock is released.
|
|
|
|
notification_state_lock_->queue_.push(std::move(pending_action));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_handler = frame_handler_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute immediately if not locked.
|
|
|
|
std::move(pending_action).Run(frame_handler);
|
|
|
|
}
|
|
|
|
|
2021-09-15 13:40:08 +02:00
|
|
|
void CefBrowserInfo::MaybeNotifyDraggableRegionsChanged(
|
|
|
|
CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame,
|
|
|
|
std::vector<CefDraggableRegion> draggable_regions) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(frame->IsMain());
|
|
|
|
|
|
|
|
if (draggable_regions == draggable_regions_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
draggable_regions_ = std::move(draggable_regions);
|
|
|
|
|
|
|
|
if (auto client = browser->GetClient()) {
|
|
|
|
if (auto handler = client->GetDragHandler()) {
|
|
|
|
handler->OnDraggableRegionsChanged(browser.get(), frame,
|
|
|
|
draggable_regions_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Passing in |browser| here because |browser_| may already be cleared.
|
|
|
|
void CefBrowserInfo::SetMainFrame(CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame) {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
DCHECK(browser);
|
|
|
|
DCHECK(!frame || frame->IsMain());
|
|
|
|
|
2021-09-15 13:40:08 +02:00
|
|
|
if (frame && main_frame_ &&
|
|
|
|
frame->GetIdentifier() == main_frame_->GetIdentifier()) {
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> old_frame;
|
|
|
|
if (main_frame_) {
|
|
|
|
old_frame = main_frame_;
|
2022-08-16 19:10:43 +02:00
|
|
|
if (old_frame->Detach(CefFrameHostImpl::DetachReason::NEW_MAIN_FRAME)) {
|
2021-07-25 19:31:39 +02:00
|
|
|
MaybeNotifyFrameDetached(browser, old_frame);
|
2022-08-16 19:10:43 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main_frame_ = frame;
|
|
|
|
|
|
|
|
MaybeNotifyMainFrameChanged(browser, old_frame, main_frame_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfo::MaybeNotifyFrameCreated(
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
// Never notify for temporary objects.
|
|
|
|
DCHECK(!frame->is_temporary());
|
|
|
|
|
|
|
|
MaybeExecuteFrameNotification(base::BindOnce(
|
|
|
|
[](scoped_refptr<CefBrowserInfo> self, CefRefPtr<CefFrameHostImpl> frame,
|
|
|
|
CefRefPtr<CefFrameHandler> handler) {
|
|
|
|
if (auto browser = self->browser()) {
|
|
|
|
handler->OnFrameCreated(browser, frame);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scoped_refptr<CefBrowserInfo>(this), frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passing in |browser| here because |browser_| may already be cleared.
|
|
|
|
void CefBrowserInfo::MaybeNotifyFrameDetached(
|
|
|
|
CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
// Never notify for temporary objects.
|
|
|
|
DCHECK(!frame->is_temporary());
|
|
|
|
|
|
|
|
MaybeExecuteFrameNotification(base::BindOnce(
|
|
|
|
[](CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame,
|
|
|
|
CefRefPtr<CefFrameHandler> handler) {
|
|
|
|
handler->OnFrameDetached(browser, frame);
|
|
|
|
},
|
|
|
|
browser, frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passing in |browser| here because |browser_| may already be cleared.
|
|
|
|
void CefBrowserInfo::MaybeNotifyMainFrameChanged(
|
|
|
|
CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> old_frame,
|
|
|
|
CefRefPtr<CefFrameHostImpl> new_frame) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
// Never notify for temporary objects.
|
|
|
|
DCHECK(!old_frame || !old_frame->is_temporary());
|
|
|
|
DCHECK(!new_frame || !new_frame->is_temporary());
|
|
|
|
|
|
|
|
MaybeExecuteFrameNotification(base::BindOnce(
|
|
|
|
[](CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefFrameHostImpl> old_frame,
|
|
|
|
CefRefPtr<CefFrameHostImpl> new_frame,
|
|
|
|
CefRefPtr<CefFrameHandler> handler) {
|
|
|
|
handler->OnMainFrameChanged(browser, old_frame, new_frame);
|
|
|
|
},
|
|
|
|
browser, old_frame, new_frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfo::RemoveAllFrames(
|
|
|
|
CefRefPtr<CefBrowserHostBase> old_browser) {
|
2019-05-24 22:23:43 +02:00
|
|
|
lock_.AssertAcquired();
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Make sure any callbacks will see the correct state (e.g. like
|
|
|
|
// CefBrowser::GetMainFrame returning nullptr and CefBrowser::IsValid
|
|
|
|
// returning false).
|
|
|
|
DCHECK(!browser_);
|
|
|
|
DCHECK(old_browser);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Clear the lookup maps.
|
|
|
|
frame_id_map_.clear();
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Explicitly Detach everything but the current main frame.
|
2019-05-31 11:50:12 +02:00
|
|
|
for (auto& info : frame_info_set_) {
|
2021-05-21 03:42:58 +02:00
|
|
|
if (info->frame_ && !info->IsCurrentMainFrame()) {
|
2022-08-16 19:10:43 +02:00
|
|
|
if (info->frame_->Detach(
|
|
|
|
CefFrameHostImpl::DetachReason::BROWSER_DESTROYED)) {
|
2021-07-25 19:31:39 +02:00
|
|
|
MaybeNotifyFrameDetached(old_browser, info->frame_);
|
2022-08-16 19:10:43 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
}
|
2019-05-31 11:50:12 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
if (main_frame_)
|
|
|
|
SetMainFrame(old_browser, nullptr);
|
2019-05-31 11:50:12 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// And finally delete the frame info.
|
|
|
|
frame_info_set_.clear();
|
2015-10-21 20:17:09 +02:00
|
|
|
}
|
2021-05-21 03:42:58 +02:00
|
|
|
|
|
|
|
CefBrowserInfo::NotificationStateLock::NotificationStateLock(
|
|
|
|
CefBrowserInfo* browser_info)
|
|
|
|
: browser_info_(browser_info) {
|
2021-09-16 10:01:55 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Take the navigation state lock.
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope_(browser_info_->notification_lock_);
|
|
|
|
CHECK(!browser_info_->notification_state_lock_);
|
|
|
|
browser_info_->notification_state_lock_ = this;
|
|
|
|
// We may need this on destruction, and the original might be cleared.
|
|
|
|
frame_handler_ = browser_info_->frame_handler_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take the browser info state lock.
|
|
|
|
browser_info_lock_scope_.reset(new base::AutoLock(browser_info_->lock_));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserInfo::NotificationStateLock::~NotificationStateLock() {
|
2021-09-16 10:01:55 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2021-05-21 03:42:58 +02:00
|
|
|
// Unlock in reverse order.
|
|
|
|
browser_info_lock_scope_.reset();
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope_(browser_info_->notification_lock_);
|
|
|
|
CHECK_EQ(this, browser_info_->notification_state_lock_);
|
|
|
|
browser_info_->notification_state_lock_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!queue_.empty()) {
|
|
|
|
DCHECK(frame_handler_);
|
|
|
|
|
2021-09-16 10:01:55 +02:00
|
|
|
// Don't navigate while inside callbacks.
|
|
|
|
auto nav_lock = browser_info_->CreateNavigationLock();
|
2021-05-21 03:42:58 +02:00
|
|
|
|
|
|
|
// Empty the queue of pending actions. Any of these actions might result in
|
|
|
|
// the acquisition of a new NotificationStateLock.
|
|
|
|
while (!queue_.empty()) {
|
|
|
|
std::move(queue_.front()).Run(frame_handler_);
|
|
|
|
queue_.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|