2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_info_manager.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
#include "base/command_line.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "base/logging.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/task/sequenced_task_runner.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/browser_platform_delegate.h"
|
|
|
|
#include "cef/libcef/browser/extensions/browser_extensions_util.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/common/cef_switches.h"
|
|
|
|
#include "cef/libcef/common/extensions/extensions_util.h"
|
|
|
|
#include "cef/libcef/common/frame_util.h"
|
|
|
|
#include "cef/libcef/common/values_impl.h"
|
|
|
|
#include "cef/libcef/features/runtime.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "content/public/browser/child_process_host.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2020-07-23 21:46:57 +02:00
|
|
|
#include "content/public/common/url_constants.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
// Timeout delay for new browser info responses.
|
|
|
|
const int64_t kNewBrowserInfoResponseTimeoutMs = 2000;
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void TranslatePopupFeatures(const blink::mojom::WindowFeatures& webKitFeatures,
|
2015-11-17 19:20:13 +01:00
|
|
|
CefPopupFeatures& features) {
|
2022-09-26 21:30:45 +02:00
|
|
|
features.x = static_cast<int>(webKitFeatures.bounds.x());
|
2017-03-03 23:37:23 +01:00
|
|
|
features.xSet = webKitFeatures.has_x;
|
2022-09-26 21:30:45 +02:00
|
|
|
features.y = static_cast<int>(webKitFeatures.bounds.y());
|
2017-03-03 23:37:23 +01:00
|
|
|
features.ySet = webKitFeatures.has_y;
|
2022-09-26 21:30:45 +02:00
|
|
|
features.width = static_cast<int>(webKitFeatures.bounds.width());
|
2017-03-03 23:37:23 +01:00
|
|
|
features.widthSet = webKitFeatures.has_width;
|
2022-09-26 21:30:45 +02:00
|
|
|
features.height = static_cast<int>(webKitFeatures.bounds.height());
|
2017-05-17 11:29:28 +02:00
|
|
|
features.heightSet = webKitFeatures.has_height;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2023-01-03 00:34:43 +01:00
|
|
|
features.isPopup = webKitFeatures.is_popup;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserInfoManager* g_info_manager = nullptr;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
CefBrowserInfoManager::CefBrowserInfoManager() {
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(!g_info_manager);
|
|
|
|
g_info_manager = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserInfoManager::~CefBrowserInfoManager() {
|
|
|
|
DCHECK(browser_info_list_.empty());
|
|
|
|
g_info_manager = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefBrowserInfoManager* CefBrowserInfoManager::GetInstance() {
|
|
|
|
return g_info_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreateBrowserInfo(
|
|
|
|
bool is_popup,
|
2019-03-19 10:42:54 +01:00
|
|
|
bool is_windowless,
|
2024-04-17 18:01:26 +02:00
|
|
|
bool print_preview_enabled,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) {
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
|
|
|
new CefBrowserInfo(++next_browser_id_, is_popup, is_windowless,
|
|
|
|
print_preview_enabled, extra_info);
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreatePopupBrowserInfo(
|
|
|
|
content::WebContents* new_contents,
|
2019-03-19 10:42:54 +01:00
|
|
|
bool is_windowless,
|
2024-04-17 18:01:26 +02:00
|
|
|
bool print_preview_enabled,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) {
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-07-21 19:26:10 +02:00
|
|
|
auto frame_host = new_contents->GetPrimaryMainFrame();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info;
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
browser_info = new CefBrowserInfo(++next_browser_id_, true, is_windowless,
|
|
|
|
print_preview_enabled, extra_info);
|
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
// Continue any pending NewBrowserInfo request.
|
2024-04-17 18:01:26 +02:00
|
|
|
ContinueNewBrowserInfo(frame_host->GetGlobalFrameToken(), browser_info,
|
2024-04-24 23:23:47 +02:00
|
|
|
/*is_excluded=*/false);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserInfoManager::CanCreateWindow(
|
2017-05-31 17:33:30 +02:00
|
|
|
content::RenderFrameHost* opener,
|
2015-11-17 19:20:13 +01:00
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
2016-10-21 21:52:29 +02:00
|
|
|
const std::string& frame_name,
|
2015-11-17 19:20:13 +01:00
|
|
|
WindowOpenDisposition disposition,
|
2017-03-03 23:37:23 +01:00
|
|
|
const blink::mojom::WindowFeatures& features,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-07-23 20:41:56 +02:00
|
|
|
content::OpenURLParams params(target_url, referrer, disposition,
|
|
|
|
ui::PAGE_TRANSITION_LINK,
|
|
|
|
/*is_renderer_initiated=*/true);
|
|
|
|
params.user_gesture = user_gesture;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser;
|
2020-07-23 21:46:57 +02:00
|
|
|
if (!MaybeAllowNavigation(opener, params, browser) || !browser) {
|
2015-11-17 19:20:13 +01:00
|
|
|
// Cancel the popup.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
bool allow = true;
|
2023-02-09 19:15:15 +01:00
|
|
|
bool handled = false;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
CefWindowInfo window_info;
|
2024-04-17 18:01:26 +02:00
|
|
|
CefBrowserCreateParams::InitWindowInfo(&window_info, browser.get());
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
auto pending_popup = std::make_unique<CefBrowserInfoManager::PendingPopup>();
|
2023-02-09 19:15:15 +01:00
|
|
|
pending_popup->step = PendingPopup::CAN_CREATE_WINDOW;
|
2021-08-19 23:07:44 +02:00
|
|
|
pending_popup->opener_global_id = opener->GetGlobalId();
|
2016-10-21 21:52:29 +02:00
|
|
|
pending_popup->target_url = target_url;
|
|
|
|
pending_popup->target_frame_name = frame_name;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Start with the current browser's settings.
|
|
|
|
pending_popup->client = client;
|
|
|
|
pending_popup->settings = browser->settings();
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
// With the Chrome runtime, we want to use default popup Browser creation
|
|
|
|
// for document picture-in-picture.
|
|
|
|
pending_popup->use_default_browser_creation =
|
|
|
|
disposition == WindowOpenDisposition::NEW_PICTURE_IN_PICTURE;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> opener_frame = browser->GetFrameForHost(opener);
|
|
|
|
DCHECK(opener_frame);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
CefPopupFeatures cef_features;
|
|
|
|
TranslatePopupFeatures(features, cef_features);
|
|
|
|
|
|
|
|
// Default to the size from the popup features.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef_features.xSet) {
|
2022-04-08 22:48:56 +02:00
|
|
|
window_info.bounds.x = cef_features.x;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_features.ySet) {
|
2022-04-08 22:48:56 +02:00
|
|
|
window_info.bounds.y = cef_features.y;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_features.widthSet) {
|
2022-04-08 22:48:56 +02:00
|
|
|
window_info.bounds.width = cef_features.width;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (cef_features.heightSet) {
|
2022-04-08 22:48:56 +02:00
|
|
|
window_info.bounds.height = cef_features.height;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
allow = !handler->OnBeforePopup(
|
2019-05-24 22:23:43 +02:00
|
|
|
browser.get(), opener_frame, pending_popup->target_url.spec(),
|
2015-11-17 19:20:13 +01:00
|
|
|
pending_popup->target_frame_name,
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<cef_window_open_disposition_t>(disposition), user_gesture,
|
2022-04-08 22:48:56 +02:00
|
|
|
cef_features, window_info, pending_popup->client,
|
2019-03-19 10:42:54 +01:00
|
|
|
pending_popup->settings, pending_popup->extra_info,
|
|
|
|
no_javascript_access);
|
2023-02-09 19:15:15 +01:00
|
|
|
handled = true;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allow) {
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserCreateParams create_params;
|
2024-04-17 18:01:26 +02:00
|
|
|
create_params.MaybeSetWindowInfo(window_info, /*allow_alloy_style=*/true,
|
|
|
|
/*allow_chrome_style=*/true);
|
2022-04-11 23:29:53 +02:00
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
if (!handled) {
|
2024-04-17 18:01:26 +02:00
|
|
|
// Use default Browser creation with Chrome style if OnBeforePopup was
|
|
|
|
// unhandled.
|
2023-02-09 19:15:15 +01:00
|
|
|
// TODO(chrome): Expose a mechanism for the client to choose default
|
|
|
|
// creation.
|
|
|
|
pending_popup->use_default_browser_creation = true;
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
create_params.popup_with_views_hosted_opener = ShouldCreateViewsHostedPopup(
|
|
|
|
browser, pending_popup->use_default_browser_creation);
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
// Potentially use Alloy style with the Chrome runtime.
|
|
|
|
create_params.popup_with_alloy_style_opener = browser->IsAlloyStyle();
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
create_params.settings = pending_popup->settings;
|
|
|
|
create_params.client = pending_popup->client;
|
2019-03-19 10:42:54 +01:00
|
|
|
create_params.extra_info = pending_popup->extra_info;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
pending_popup->platform_delegate =
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserPlatformDelegate::Create(create_params);
|
2015-11-17 19:20:13 +01:00
|
|
|
CHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Expect runtime style to match.
|
|
|
|
pending_popup->alloy_style = !create_params.IsChromeStyle();
|
|
|
|
CHECK_EQ(pending_popup->alloy_style,
|
|
|
|
pending_popup->platform_delegate->IsAlloyStyle());
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
// Between the calls to CanCreateWindow and GetCustomWebContentsView
|
|
|
|
// RenderViewHostImpl::CreateNewWindow() will call
|
|
|
|
// RenderProcessHostImpl::FilterURL() which, in the case of "javascript:"
|
|
|
|
// URIs, rewrites the URL to "about:blank". We need to apply the same filter
|
|
|
|
// otherwise GetCustomWebContentsView will fail to retrieve the PopupInfo.
|
|
|
|
opener->GetProcess()->FilterURL(false, &pending_popup->target_url);
|
|
|
|
|
|
|
|
PushPendingPopup(std::move(pending_popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return allow;
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:44:11 +01:00
|
|
|
void CefBrowserInfoManager::GetCustomWebContentsView(
|
2015-11-17 19:20:13 +01:00
|
|
|
const GURL& target_url,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_id,
|
2024-06-21 17:26:59 +02:00
|
|
|
raw_ptr<content::WebContentsView>* view,
|
|
|
|
raw_ptr<content::RenderViewHostDelegateView>* delegate_view) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
auto pending_popup = PopPendingPopup(PendingPopup::CAN_CREATE_WINDOW,
|
2024-04-17 18:01:26 +02:00
|
|
|
PendingPopup::CAN_CREATE_WINDOW,
|
2023-02-09 19:15:15 +01:00
|
|
|
opener_global_id, target_url);
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(pending_popup.get());
|
|
|
|
DCHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
|
|
|
if (pending_popup->platform_delegate->IsWindowless()) {
|
|
|
|
pending_popup->platform_delegate->CreateViewForWebContents(view,
|
|
|
|
delegate_view);
|
|
|
|
}
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
pending_popup->step = PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW;
|
2016-01-06 20:20:54 +01:00
|
|
|
PushPendingPopup(std::move(pending_popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::WebContentsCreated(
|
|
|
|
const GURL& target_url,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_id,
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient>& client,
|
2019-03-19 10:42:54 +01:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate,
|
2023-02-09 19:15:15 +01:00
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
|
|
|
content::WebContents* new_contents) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// GET_CUSTOM_WEB_CONTENTS_VIEW is only used with Alloy style.
|
|
|
|
auto pending_popup = PopPendingPopup(
|
|
|
|
PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW,
|
|
|
|
PendingPopup::CAN_CREATE_WINDOW, opener_global_id, target_url);
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(pending_popup.get());
|
|
|
|
DCHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
|
|
|
settings = pending_popup->settings;
|
|
|
|
client = pending_popup->client;
|
2016-01-06 20:20:54 +01:00
|
|
|
platform_delegate = std::move(pending_popup->platform_delegate);
|
2019-03-19 10:42:54 +01:00
|
|
|
extra_info = pending_popup->extra_info;
|
2023-02-09 19:15:15 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// AddWebContents (the next step) is only used with Chrome style.
|
|
|
|
if (!pending_popup->alloy_style) {
|
2023-02-09 19:15:15 +01:00
|
|
|
pending_popup->step = PendingPopup::WEB_CONTENTS_CREATED;
|
|
|
|
pending_popup->new_contents = new_contents;
|
|
|
|
PushPendingPopup(std::move(pending_popup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserInfoManager::AddWebContents(content::WebContents* new_contents) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2023-02-09 19:15:15 +01:00
|
|
|
DCHECK(cef::IsChromeRuntimeEnabled());
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2023-02-09 19:15:15 +01:00
|
|
|
|
|
|
|
// Pending popup information may be missing in cases where
|
|
|
|
// chrome::AddWebContents is called directly from the Chrome UI (profile
|
|
|
|
// settings, etc).
|
|
|
|
auto pending_popup =
|
2024-04-17 18:01:26 +02:00
|
|
|
PopPendingPopup(PendingPopup::WEB_CONTENTS_CREATED,
|
|
|
|
PendingPopup::WEB_CONTENTS_CREATED, new_contents);
|
2023-02-09 19:15:15 +01:00
|
|
|
if (pending_popup) {
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(!pending_popup->alloy_style);
|
2023-02-09 19:15:15 +01:00
|
|
|
return !pending_popup->use_default_browser_creation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed with default handling.
|
|
|
|
return false;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefBrowserInfoManager::OnGetNewBrowserInfo(
|
2024-01-26 03:12:43 +01:00
|
|
|
const content::GlobalRenderFrameHostToken& global_token,
|
2021-05-14 18:58:55 +02:00
|
|
|
cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback) {
|
2024-01-26 03:12:43 +01:00
|
|
|
DCHECK(frame_util::IsValidGlobalToken(global_token));
|
2021-05-14 18:58:55 +02:00
|
|
|
DCHECK(callback);
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
auto callback_runner = base::SequencedTaskRunner::GetCurrentDefault();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
2024-04-24 23:23:47 +02:00
|
|
|
GetBrowserInfoInternal(global_token);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
if (browser_info) {
|
2015-11-17 19:20:13 +01:00
|
|
|
// Send the response immediately.
|
2024-04-24 23:23:47 +02:00
|
|
|
SendNewBrowserInfoResponse(browser_info, /*is_excluded=*/false,
|
|
|
|
std::move(callback), callback_runner);
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that no request for the same route is currently queued.
|
2024-01-26 03:12:43 +01:00
|
|
|
DCHECK(pending_new_browser_info_map_.find(global_token) ==
|
2019-05-24 22:23:43 +02:00
|
|
|
pending_new_browser_info_map_.end());
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
const int timeout_id = ++next_timeout_id_;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Queue the request.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<PendingNewBrowserInfo> pending(new PendingNewBrowserInfo());
|
2024-01-26 03:12:43 +01:00
|
|
|
pending->global_token = global_token;
|
2020-01-23 22:58:01 +01:00
|
|
|
pending->timeout_id = timeout_id;
|
2021-05-14 18:58:55 +02:00
|
|
|
pending->callback = std::move(callback);
|
|
|
|
pending->callback_runner = callback_runner;
|
2019-05-24 22:23:43 +02:00
|
|
|
pending_new_browser_info_map_.insert(
|
2024-01-26 03:12:43 +01:00
|
|
|
std::make_pair(global_token, std::move(pending)));
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
// Register a timeout for the pending response so that the renderer process
|
2023-02-09 19:15:15 +01:00
|
|
|
// doesn't hang forever. With the Chrome runtime, timeouts may occur in cases
|
|
|
|
// where chrome::AddWebContents or WebContents::Create are called directly
|
|
|
|
// from the Chrome UI (profile settings, etc).
|
2020-01-23 22:58:01 +01:00
|
|
|
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
switches::kDisableNewBrowserInfoTimeout)) {
|
|
|
|
CEF_POST_DELAYED_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(&CefBrowserInfoManager::TimeoutNewBrowserInfoResponse,
|
2024-01-26 03:12:43 +01:00
|
|
|
global_token, timeout_id),
|
2020-01-23 22:58:01 +01:00
|
|
|
kNewBrowserInfoResponseTimeoutMs);
|
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
// Check for excluded content (PDF viewer or print preview).
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(
|
|
|
|
&CefBrowserInfoManager::CheckExcludedNewBrowserInfoOnUIThread,
|
|
|
|
global_token));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefBrowserInfoManager::CheckExcludedNewBrowserInfoOnUIThread(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (!g_info_manager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// May return nullptr for PDF renderer process.
|
|
|
|
auto* rfh = content::RenderFrameHost::FromFrameToken(global_token);
|
|
|
|
if (!rfh) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
// PDF viewer and print preview create multiple renderer processes. These
|
|
|
|
// excluded processes are not tracked by CefBrowserInfo.
|
2024-04-17 18:01:26 +02:00
|
|
|
CefBrowserInfo* browser_info;
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_excluded;
|
|
|
|
GetFrameHost(rfh, /*prefer_speculative=*/true, &browser_info, &is_excluded);
|
|
|
|
if (browser_info && is_excluded) {
|
2024-04-17 18:01:26 +02:00
|
|
|
g_info_manager->ContinueNewBrowserInfo(global_token, browser_info,
|
2024-04-24 23:23:47 +02:00
|
|
|
/*is_excluded=*/true);
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::ContinueNewBrowserInfo(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token,
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_excluded) {
|
2024-04-17 18:01:26 +02:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
// Continue any pending NewBrowserInfo request.
|
|
|
|
auto it = pending_new_browser_info_map_.find(global_token);
|
|
|
|
if (it != pending_new_browser_info_map_.end()) {
|
2024-04-24 23:23:47 +02:00
|
|
|
SendNewBrowserInfoResponse(browser_info, is_excluded,
|
2024-04-17 18:01:26 +02:00
|
|
|
std::move(it->second->callback),
|
|
|
|
it->second->callback_runner);
|
|
|
|
pending_new_browser_info_map_.erase(it);
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::RemoveBrowserInfo(
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info) {
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
if (*it == browser_info) {
|
|
|
|
browser_info_list_.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::DestroyAllBrowsers() {
|
|
|
|
BrowserInfoList list;
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
list = browser_info_list_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy any remaining browser windows.
|
|
|
|
if (!list.empty()) {
|
|
|
|
BrowserInfoList::iterator it = list.begin();
|
|
|
|
for (; it != list.end(); ++it) {
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser = (*it)->browser();
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(browser.get());
|
|
|
|
if (browser.get()) {
|
|
|
|
// DestroyBrowser will call RemoveBrowserInfo.
|
|
|
|
browser->DestroyBrowser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 13:24:30 +02:00
|
|
|
#if DCHECK_IS_ON()
|
2015-11-17 19:20:13 +01:00
|
|
|
{
|
|
|
|
// Verify that all browser windows have been destroyed.
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
DCHECK(browser_info_list_.empty());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfo(
|
2024-04-24 23:23:47 +02:00
|
|
|
const content::GlobalRenderFrameHostId& global_id) {
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2024-04-24 23:23:47 +02:00
|
|
|
return GetBrowserInfoInternal(global_id);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfo(
|
2024-04-24 23:23:47 +02:00
|
|
|
const content::GlobalRenderFrameHostToken& global_token) {
|
2024-01-26 03:12:43 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2024-04-24 23:23:47 +02:00
|
|
|
return GetBrowserInfoInternal(global_token);
|
2024-01-26 03:12:43 +01:00
|
|
|
}
|
|
|
|
|
2020-07-23 20:41:56 +02:00
|
|
|
bool CefBrowserInfoManager::MaybeAllowNavigation(
|
|
|
|
content::RenderFrameHost* opener,
|
|
|
|
const content::OpenURLParams& params,
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase>& browser_out) const {
|
2020-07-23 20:41:56 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
auto browser = CefBrowserHostBase::GetBrowserForHost(opener);
|
2020-07-23 21:46:57 +02:00
|
|
|
if (!browser) {
|
|
|
|
// Print preview uses a modal dialog where we don't own the WebContents.
|
|
|
|
// Allow that navigation to proceed.
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-23 20:41:56 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!browser->MaybeAllowNavigation(opener, params)) {
|
2020-07-23 20:41:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_out = browser;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// static
|
|
|
|
bool CefBrowserInfoManager::ShouldCreateViewsHostedPopup(
|
|
|
|
CefRefPtr<CefBrowserHostBase> opener,
|
|
|
|
bool use_default_browser_creation) {
|
|
|
|
// In most cases, Views-hosted browsers should create Views-hosted popups
|
|
|
|
// and native browsers should use default popup handling. With the Chrome
|
|
|
|
// runtime, we should additionally use default handling (a) when using an
|
|
|
|
// external parent and (b) when using default Browser creation.
|
|
|
|
return opener->HasView() &&
|
|
|
|
!opener->platform_delegate()->HasExternalParent() &&
|
|
|
|
!use_default_browser_creation;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserInfoManager::GetFrameHost(
|
|
|
|
content::RenderFrameHost* rfh,
|
|
|
|
bool prefer_speculative,
|
|
|
|
CefBrowserInfo** browser_info,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool* is_excluded) {
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(rfh);
|
|
|
|
|
|
|
|
const bool is_pdf_process = rfh->GetProcess()->IsPdf();
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
const bool is_browser_process_guest =
|
|
|
|
extensions::IsBrowserPluginGuest(web_contents);
|
|
|
|
const bool is_print_preview_dialog =
|
|
|
|
extensions::IsPrintPreviewDialog(web_contents);
|
|
|
|
|
|
|
|
bool excluded =
|
|
|
|
is_pdf_process || is_browser_process_guest || is_print_preview_dialog;
|
|
|
|
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame;
|
|
|
|
|
|
|
|
// A BrowserHost may match an excluded RFH type. Some associations are
|
|
|
|
// registered directly via CefBrowserInfo::MaybeCreateFrame and some are
|
|
|
|
// discovered indirectly via extensions::GetOwnerForGuestContents.
|
|
|
|
auto browser = CefBrowserHostBase::GetBrowserForHost(rfh);
|
2024-04-24 23:23:47 +02:00
|
|
|
if (browser && !excluded) {
|
|
|
|
frame = browser->browser_info()->GetFrameForHost(rfh, prefer_speculative);
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (browser_info) {
|
|
|
|
*browser_info = browser ? browser->browser_info().get() : nullptr;
|
|
|
|
}
|
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
if (is_excluded) {
|
|
|
|
*is_excluded = excluded;
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (VLOG_IS_ON(1)) {
|
|
|
|
const std::string& debug_string =
|
|
|
|
frame_util::GetFrameDebugString(rfh->GetGlobalFrameToken());
|
|
|
|
const bool is_main = rfh->GetParent() == nullptr;
|
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
VLOG(1) << "frame " << debug_string << ", pdf_process=" << is_pdf_process
|
2024-04-17 18:01:26 +02:00
|
|
|
<< ", browser_process_guest=" << is_browser_process_guest
|
|
|
|
<< ", print_preview_dialog=" << is_print_preview_dialog
|
|
|
|
<< ", main=" << is_main << (browser ? "" : ", has no BrowserHost")
|
|
|
|
<< (frame ? "" : ", has no FrameHost");
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2024-04-24 21:38:49 +02:00
|
|
|
// static
|
|
|
|
bool CefBrowserInfoManager::IsExcludedFrameHost(content::RenderFrameHost* rfh) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(rfh);
|
|
|
|
|
|
|
|
const bool is_pdf_process = rfh->GetProcess()->IsPdf();
|
|
|
|
if (is_pdf_process) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
const bool is_browser_process_guest =
|
|
|
|
extensions::IsBrowserPluginGuest(web_contents);
|
|
|
|
if (is_browser_process_guest) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const bool is_print_preview_dialog =
|
|
|
|
extensions::IsPrintPreviewDialog(web_contents);
|
|
|
|
if (is_print_preview_dialog) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfoManager::BrowserInfoList
|
|
|
|
CefBrowserInfoManager::GetBrowserInfoList() {
|
2016-07-20 20:03:38 +02:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2019-05-24 22:23:43 +02:00
|
|
|
BrowserInfoList copy;
|
|
|
|
copy.assign(browser_info_list_.begin(), browser_info_list_.end());
|
|
|
|
return copy;
|
2016-07-20 20:03:38 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserInfoManager::RenderProcessHostDestroyed(
|
|
|
|
content::RenderProcessHost* host) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
host->RemoveObserver(this);
|
|
|
|
|
2016-05-11 18:18:43 +02:00
|
|
|
const int render_process_id = host->GetID();
|
2017-05-09 22:45:57 +02:00
|
|
|
DCHECK_GT(render_process_id, 0);
|
2016-05-11 18:18:43 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Remove all pending requests that reference the destroyed host.
|
2017-05-09 22:45:57 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
PendingNewBrowserInfoMap::iterator it =
|
|
|
|
pending_new_browser_info_map_.begin();
|
|
|
|
while (it != pending_new_browser_info_map_.end()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
const auto& info = it->second;
|
2024-01-26 03:12:43 +01:00
|
|
|
if (info->global_token.child_id == render_process_id) {
|
2021-05-14 18:58:55 +02:00
|
|
|
CancelNewBrowserInfoResponse(info.get());
|
2019-05-24 22:23:43 +02:00
|
|
|
it = pending_new_browser_info_map_.erase(it);
|
2021-05-14 18:58:55 +02:00
|
|
|
} else {
|
2017-05-09 22:45:57 +02:00
|
|
|
++it;
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
2017-05-09 22:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all pending popups that reference the destroyed host as the opener.
|
|
|
|
{
|
|
|
|
PendingPopupList::iterator it = pending_popup_list_.begin();
|
|
|
|
while (it != pending_popup_list_.end()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
PendingPopup* popup = it->get();
|
2021-08-19 23:07:44 +02:00
|
|
|
if (popup->opener_global_id.child_id == render_process_id) {
|
2017-05-09 22:45:57 +02:00
|
|
|
it = pending_popup_list_.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:45:57 +02:00
|
|
|
void CefBrowserInfoManager::PushPendingPopup(
|
|
|
|
std::unique_ptr<PendingPopup> popup) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-01-06 20:20:54 +01:00
|
|
|
pending_popup_list_.push_back(std::move(popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserInfoManager::PendingPopup>
|
2021-08-19 23:07:44 +02:00
|
|
|
CefBrowserInfoManager::PopPendingPopup(
|
2024-04-17 18:01:26 +02:00
|
|
|
PendingPopup::Step previous_step_alloy,
|
|
|
|
PendingPopup::Step previous_step_chrome,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_id,
|
|
|
|
const GURL& target_url) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2021-08-19 23:07:44 +02:00
|
|
|
DCHECK(frame_util::IsValidGlobalId(opener_global_id));
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK_LE(previous_step_alloy, PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW);
|
|
|
|
DCHECK_LE(previous_step_chrome, PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
PendingPopupList::iterator it = pending_popup_list_.begin();
|
|
|
|
for (; it != pending_popup_list_.end(); ++it) {
|
2017-07-27 01:19:27 +02:00
|
|
|
PendingPopup* popup = it->get();
|
2024-04-17 18:01:26 +02:00
|
|
|
const auto previous_step =
|
|
|
|
popup->alloy_style ? previous_step_alloy : previous_step_chrome;
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
if (popup->step == previous_step &&
|
|
|
|
popup->opener_global_id == opener_global_id &&
|
2015-11-17 19:20:13 +01:00
|
|
|
popup->target_url == target_url) {
|
2017-07-27 01:19:27 +02:00
|
|
|
// Transfer ownership of the pointer.
|
|
|
|
it->release();
|
|
|
|
pending_popup_list_.erase(it);
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(popup);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
std::unique_ptr<CefBrowserInfoManager::PendingPopup>
|
2024-04-17 18:01:26 +02:00
|
|
|
CefBrowserInfoManager::PopPendingPopup(PendingPopup::Step previous_step_alloy,
|
|
|
|
PendingPopup::Step previous_step_chrome,
|
2023-02-09 19:15:15 +01:00
|
|
|
content::WebContents* new_contents) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK_GE(previous_step_alloy, PendingPopup::WEB_CONTENTS_CREATED);
|
|
|
|
DCHECK_GE(previous_step_chrome, PendingPopup::WEB_CONTENTS_CREATED);
|
2023-02-09 19:15:15 +01:00
|
|
|
|
|
|
|
PendingPopupList::iterator it = pending_popup_list_.begin();
|
|
|
|
for (; it != pending_popup_list_.end(); ++it) {
|
|
|
|
PendingPopup* popup = it->get();
|
2024-04-17 18:01:26 +02:00
|
|
|
const auto previous_step =
|
|
|
|
popup->alloy_style ? previous_step_alloy : previous_step_chrome;
|
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
if (popup->step == previous_step && popup->new_contents == new_contents) {
|
|
|
|
// Transfer ownership of the pointer.
|
|
|
|
it->release();
|
|
|
|
pending_popup_list_.erase(it);
|
|
|
|
return base::WrapUnique(popup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfoInternal(
|
2024-04-24 23:23:47 +02:00
|
|
|
const content::GlobalRenderFrameHostId& global_id) {
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_lock_.AssertAcquired();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame_util::IsValidGlobalId(global_id)) {
|
2017-10-26 20:17:00 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
for (const auto& browser_info : browser_info_list_) {
|
2024-04-24 23:23:47 +02:00
|
|
|
auto frame = browser_info->GetFrameForGlobalId(global_id);
|
|
|
|
if (frame) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfoInternal(
|
2024-04-24 23:23:47 +02:00
|
|
|
const content::GlobalRenderFrameHostToken& global_token) {
|
2024-01-26 03:12:43 +01:00
|
|
|
browser_info_lock_.AssertAcquired();
|
|
|
|
|
|
|
|
if (!frame_util::IsValidGlobalToken(global_token)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& browser_info : browser_info_list_) {
|
2024-04-24 23:23:47 +02:00
|
|
|
auto frame = browser_info->GetFrameForGlobalToken(global_token);
|
|
|
|
if (frame) {
|
2024-01-26 03:12:43 +01:00
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// static
|
|
|
|
void CefBrowserInfoManager::SendNewBrowserInfoResponse(
|
2017-07-27 01:19:27 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_excluded,
|
2021-05-14 18:58:55 +02:00
|
|
|
cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback,
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> callback_runner) {
|
|
|
|
if (!callback_runner->RunsTasksInCurrentSequence()) {
|
|
|
|
callback_runner->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(&CefBrowserInfoManager::SendNewBrowserInfoResponse,
|
2024-04-24 23:23:47 +02:00
|
|
|
browser_info, is_excluded, std::move(callback),
|
2021-08-19 23:07:44 +02:00
|
|
|
callback_runner));
|
2016-05-11 18:18:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
auto params = cef::mojom::NewBrowserInfo::New();
|
2024-04-24 23:23:47 +02:00
|
|
|
params->is_excluded = is_excluded;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
if (browser_info) {
|
2021-05-14 18:58:55 +02:00
|
|
|
params->browser_id = browser_info->browser_id();
|
|
|
|
params->is_windowless = browser_info->is_windowless();
|
|
|
|
params->is_popup = browser_info->is_popup();
|
2024-04-17 18:01:26 +02:00
|
|
|
params->print_preview_enabled = browser_info->print_preview_enabled();
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
auto extra_info = browser_info->extra_info();
|
|
|
|
if (extra_info) {
|
|
|
|
auto extra_info_impl =
|
|
|
|
static_cast<CefDictionaryValueImpl*>(extra_info.get());
|
2023-01-30 22:42:40 +01:00
|
|
|
auto extra_info_value = extra_info_impl->CopyValue();
|
|
|
|
params->extra_info = std::move(extra_info_value.GetDict());
|
2020-01-23 22:58:01 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The new browser info response has timed out.
|
2021-05-14 18:58:55 +02:00
|
|
|
params->browser_id = -1;
|
2019-03-19 10:42:54 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
std::move(callback).Run(std::move(params));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefBrowserInfoManager::CancelNewBrowserInfoResponse(
|
|
|
|
PendingNewBrowserInfo* pending_info) {
|
2024-04-24 23:23:47 +02:00
|
|
|
SendNewBrowserInfoResponse(/*browser_info=*/nullptr, /*is_excluded=*/false,
|
2021-05-14 18:58:55 +02:00
|
|
|
std::move(pending_info->callback),
|
|
|
|
pending_info->callback_runner);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2020-01-23 22:58:01 +01:00
|
|
|
|
|
|
|
// static
|
2021-08-19 23:07:44 +02:00
|
|
|
void CefBrowserInfoManager::TimeoutNewBrowserInfoResponse(
|
2024-01-26 03:12:43 +01:00
|
|
|
const content::GlobalRenderFrameHostToken& global_token,
|
2021-08-19 23:07:44 +02:00
|
|
|
int timeout_id) {
|
2021-11-29 20:58:09 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!g_info_manager) {
|
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
|
|
|
|
|
|
|
base::AutoLock lock_scope(g_info_manager->browser_info_lock_);
|
|
|
|
|
|
|
|
// Continue the NewBrowserInfo request if it's still pending.
|
2024-01-26 03:12:43 +01:00
|
|
|
auto it = g_info_manager->pending_new_browser_info_map_.find(global_token);
|
2020-01-23 22:58:01 +01:00
|
|
|
if (it != g_info_manager->pending_new_browser_info_map_.end()) {
|
|
|
|
const auto& pending_info = it->second;
|
|
|
|
// Don't accidentally timeout a new request for the same frame.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (pending_info->timeout_id != timeout_id) {
|
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
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Cases where we expect to time out are:
|
|
|
|
// - With the Chrome runtime when chrome::AddWebContents or
|
|
|
|
// WebContents::Create are called directly from the Chrome UI (profile
|
|
|
|
// settings, etc). A RFH will exist without a matching CefBrowserHost.
|
|
|
|
// - When the PDF renderer is loaded in the print preview dialog. There will
|
|
|
|
// be no RFH in this case.
|
|
|
|
// Any additional cases should be debugged and, if possible,
|
|
|
|
// extensions::GetOwnerForGuestContents should be improved to find the
|
|
|
|
// associated CefBrowserHost.
|
|
|
|
const bool has_rfh =
|
|
|
|
!!content::RenderFrameHost::FromFrameToken(global_token);
|
2021-11-29 20:58:09 +01:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
LOG(ERROR) << "Timeout of new browser info response for frame "
|
2024-04-17 18:01:26 +02:00
|
|
|
<< frame_util::GetFrameDebugString(global_token)
|
|
|
|
<< " (has_rfh=" << has_rfh << ")";
|
2020-01-23 22:58:01 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
CancelNewBrowserInfoResponse(pending_info.get());
|
2020-01-23 22:58:01 +01:00
|
|
|
g_info_manager->pending_new_browser_info_map_.erase(it);
|
|
|
|
}
|
|
|
|
}
|