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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2012-06-11 21:48:55 +02:00
|
|
|
#include <utility>
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-03-07 02:20:24 +01:00
|
|
|
#include "base/command_line.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/bind.h"
|
|
|
|
#include "base/functional/callback_helpers.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/browser_platform_delegate_alloy.h"
|
|
|
|
#include "cef/libcef/browser/audio_capturer.h"
|
|
|
|
#include "cef/libcef/browser/browser_context.h"
|
|
|
|
#include "cef/libcef/browser/browser_info.h"
|
|
|
|
#include "cef/libcef/browser/browser_info_manager.h"
|
|
|
|
#include "cef/libcef/browser/browser_platform_delegate.h"
|
|
|
|
#include "cef/libcef/browser/context.h"
|
|
|
|
#include "cef/libcef/browser/extensions/browser_extensions_util.h"
|
|
|
|
#include "cef/libcef/browser/hang_monitor.h"
|
|
|
|
#include "cef/libcef/browser/media_access_query.h"
|
|
|
|
#include "cef/libcef/browser/osr/osr_util.h"
|
|
|
|
#include "cef/libcef/browser/request_context_impl.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/common/cef_switches.h"
|
|
|
|
#include "cef/libcef/common/drag_data_impl.h"
|
|
|
|
#include "cef/libcef/common/frame_util.h"
|
|
|
|
#include "cef/libcef/common/net/url_util.h"
|
|
|
|
#include "cef/libcef/common/request_impl.h"
|
|
|
|
#include "cef/libcef/common/values_impl.h"
|
|
|
|
#include "cef/libcef/features/runtime.h"
|
2022-04-15 21:55:23 +02:00
|
|
|
#include "chrome/browser/file_select_helper.h"
|
2019-10-15 13:11:59 +02:00
|
|
|
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
|
2024-06-14 19:01:45 +02:00
|
|
|
#include "components/input/native_web_keyboard_event.h"
|
2023-10-05 01:46:45 +02:00
|
|
|
#include "components/zoom/page_zoom.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/browser/gpu/compositor_util.h"
|
2017-04-28 22:39:37 +02:00
|
|
|
#include "content/public/browser/desktop_media_id.h"
|
2018-10-24 22:37:39 +02:00
|
|
|
#include "content/public/browser/file_select_listener.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "content/public/browser/keyboard_event_processing_result.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/navigation_controller.h"
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "content/public/browser/navigation_handle.h"
|
2014-01-02 23:41:11 +01:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "content/public/browser/render_widget_host.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2022-04-08 22:48:56 +02:00
|
|
|
#include "content/public/common/url_constants.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "extensions/common/constants.h"
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "net/base/net_errors.h"
|
2017-01-23 18:36:54 +01:00
|
|
|
#include "ui/events/base_event_utils.h"
|
2014-10-19 03:47:27 +02:00
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
#include "extensions/common/extension.h"
|
|
|
|
#endif
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
using content::KeyboardEventProcessingResult;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
|
|
|
|
2021-10-19 00:17:16 +02:00
|
|
|
static constexpr base::TimeDelta kRecentlyAudibleTimeout = base::Seconds(2);
|
2020-05-01 20:18:18 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl static methods.
|
2013-11-08 17:06:06 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserCreateParams& create_params) {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate =
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserPlatformDelegate::Create(create_params);
|
|
|
|
CHECK(platform_delegate);
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Expect runtime style to match.
|
|
|
|
CHECK(platform_delegate->IsAlloyStyle());
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2016-01-19 21:09:01 +01:00
|
|
|
const bool is_devtools_popup = !!create_params.devtools_opener;
|
2024-04-30 03:09:17 +02:00
|
|
|
#else
|
|
|
|
const bool is_devtools_popup = false;
|
|
|
|
#endif
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> info =
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserInfoManager::GetInstance()->CreateBrowserInfo(
|
2019-03-19 10:42:54 +01:00
|
|
|
is_devtools_popup, platform_delegate->IsWindowless(),
|
2024-04-17 18:01:26 +02:00
|
|
|
platform_delegate->IsPrintPreviewSupported(),
|
2019-03-19 10:42:54 +01:00
|
|
|
create_params.extra_info);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
bool own_web_contents = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
// This call may modify |create_params|.
|
|
|
|
auto web_contents =
|
|
|
|
platform_delegate->CreateWebContents(create_params, own_web_contents);
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
auto request_context_impl =
|
|
|
|
static_cast<CefRequestContextImpl*>(create_params.request_context.get());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-03 22:13:27 +02:00
|
|
|
CefRefPtr<CefExtension> cef_extension;
|
|
|
|
if (create_params.extension) {
|
|
|
|
auto cef_browser_context = request_context_impl->GetBrowserContext();
|
|
|
|
cef_extension =
|
|
|
|
cef_browser_context->GetExtension(create_params.extension->id());
|
|
|
|
CHECK(cef_extension);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-03 22:13:27 +02:00
|
|
|
auto platform_delegate_ptr = platform_delegate.get();
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
|
2020-07-03 22:13:27 +02:00
|
|
|
create_params.settings, create_params.client, web_contents,
|
2024-04-30 03:09:17 +02:00
|
|
|
own_web_contents, info,
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
FromBaseChecked(create_params.devtools_opener),
|
|
|
|
#else
|
|
|
|
/*opener=*/nullptr,
|
|
|
|
#endif
|
|
|
|
is_devtools_popup, request_context_impl, std::move(platform_delegate)
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
cef_extension
|
|
|
|
#endif
|
|
|
|
);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser) {
|
2017-08-04 00:55:19 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
GURL url = url_util::MakeGURL(create_params.url, /*fixup=*/true);
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2017-08-04 00:55:19 +02:00
|
|
|
if (create_params.extension) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_ptr->CreateExtensionHost(
|
2021-04-15 01:28:22 +02:00
|
|
|
create_params.extension, url, create_params.extension_host_type);
|
2024-04-30 03:09:17 +02:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (!url.is_empty()) {
|
2021-04-15 01:28:22 +02:00
|
|
|
content::OpenURLParams params(url, content::Referrer(),
|
2020-09-25 03:40:47 +02:00
|
|
|
WindowOpenDisposition::CURRENT_TAB,
|
|
|
|
CefFrameHostImpl::kPageTransitionExplicit,
|
|
|
|
/*is_renderer_initiated=*/false);
|
|
|
|
browser->LoadMainFrameURL(params);
|
2013-08-27 20:19:21 +02:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return browser.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
2012-04-03 03:34:16 +02:00
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
2012-04-04 20:18:09 +02:00
|
|
|
content::WebContents* web_contents,
|
2018-05-18 12:45:18 +02:00
|
|
|
bool own_web_contents,
|
2012-12-30 12:17:49 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> opener,
|
2016-01-19 21:09:01 +01:00
|
|
|
bool is_devtools_popup,
|
2019-03-24 00:40:32 +01:00
|
|
|
CefRefPtr<CefRequestContextImpl> request_context,
|
2024-04-30 03:09:17 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
CefRefPtr<CefExtension> extension
|
|
|
|
#endif
|
|
|
|
) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(web_contents);
|
|
|
|
DCHECK(browser_info);
|
|
|
|
DCHECK(request_context);
|
|
|
|
DCHECK(platform_delegate);
|
2012-12-30 12:17:49 +01:00
|
|
|
|
|
|
|
// If |opener| is non-NULL it must be a popup window.
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(!opener.get() || browser_info->is_popup());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (opener) {
|
2017-05-09 22:45:57 +02:00
|
|
|
if (!opener->platform_delegate_) {
|
|
|
|
// The opener window is being destroyed. Cancel the popup.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (own_web_contents) {
|
2020-07-03 22:13:27 +02:00
|
|
|
delete web_contents;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-09 22:45:57 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Give the opener browser's platform delegate an opportunity to modify the
|
|
|
|
// new browser's platform delegate.
|
|
|
|
opener->platform_delegate_->PopupWebContentsCreated(
|
|
|
|
settings, client, web_contents, platform_delegate.get(),
|
|
|
|
is_devtools_popup);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
// Take ownership of |web_contents| if |own_web_contents| is true.
|
|
|
|
platform_delegate->WebContentsCreated(web_contents, own_web_contents);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = new AlloyBrowserHostImpl(
|
2017-05-17 11:29:28 +02:00
|
|
|
settings, client, web_contents, browser_info, opener, request_context,
|
2024-04-30 03:09:17 +02:00
|
|
|
std::move(platform_delegate)
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
extension
|
|
|
|
#endif
|
|
|
|
);
|
2020-09-18 00:24:08 +02:00
|
|
|
browser->InitializeBrowser();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser->CreateHostWindow()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-12-02 21:07:03 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Notify that the browser has been created. These must be delivered in the
|
|
|
|
// expected order.
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
if (opener && opener->platform_delegate_) {
|
|
|
|
// 1. Notify the opener browser's platform delegate. With Views this will
|
|
|
|
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
|
|
|
|
// Do this first for consistency with the Chrome runtime.
|
2024-04-17 18:01:26 +02:00
|
|
|
opener->platform_delegate_->PopupBrowserCreated(
|
|
|
|
browser->platform_delegate(), browser.get(), is_devtools_popup);
|
2022-04-08 22:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Notify the browser's LifeSpanHandler. This must always be the first
|
2020-10-08 21:54:42 +02:00
|
|
|
// notification for the browser. Block navigation to avoid issues with focus
|
|
|
|
// changes being sent to an unbound interface.
|
|
|
|
{
|
|
|
|
auto navigation_lock = browser_info->CreateNavigationLock();
|
|
|
|
browser->OnAfterCreated();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
// 3. Notify the platform delegate. With Views this will result in a call to
|
2016-01-19 21:09:01 +01:00
|
|
|
// CefBrowserViewDelegate::OnBrowserCreated().
|
|
|
|
browser->platform_delegate_->NotifyBrowserCreated();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::FromBaseChecked(
|
|
|
|
CefRefPtr<CefBrowserHostBase> host_base) {
|
|
|
|
if (!host_base) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
CHECK(host_base->IsAlloyStyle());
|
|
|
|
return static_cast<AlloyBrowserHostImpl*>(host_base.get());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// static
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::GetBrowserForHost(
|
2012-04-03 03:34:16 +02:00
|
|
|
const content::RenderViewHost* host) {
|
2024-04-17 18:01:26 +02:00
|
|
|
return FromBaseChecked(CefBrowserHostBase::GetBrowserForHost(host));
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::GetBrowserForHost(
|
2014-01-02 23:41:11 +01:00
|
|
|
const content::RenderFrameHost* host) {
|
2024-04-17 18:01:26 +02:00
|
|
|
return FromBaseChecked(CefBrowserHostBase::GetBrowserForHost(host));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::GetBrowserForContents(
|
2015-07-16 23:40:01 +02:00
|
|
|
const content::WebContents* contents) {
|
2024-04-17 18:01:26 +02:00
|
|
|
return FromBaseChecked(CefBrowserHostBase::GetBrowserForContents(contents));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2021-08-19 23:07:44 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::GetBrowserForGlobalId(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id) {
|
2024-04-17 18:01:26 +02:00
|
|
|
return FromBaseChecked(CefBrowserHostBase::GetBrowserForGlobalId(global_id));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl methods.
|
2012-04-03 03:34:16 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
AlloyBrowserHostImpl::~AlloyBrowserHostImpl() = default;
|
2013-11-08 17:06:06 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::CloseBrowser(bool force_close) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
2013-03-19 23:59:33 +01:00
|
|
|
// Exit early if a close attempt is already pending and this method is
|
|
|
|
// called again from somewhere other than WindowDestroyed().
|
2014-07-01 00:30:29 +02:00
|
|
|
if (destruction_state_ >= DESTRUCTION_STATE_PENDING &&
|
|
|
|
(IsWindowless() || !window_destroyed_)) {
|
2013-03-19 23:59:33 +01:00
|
|
|
if (force_close && destruction_state_ == DESTRUCTION_STATE_PENDING) {
|
|
|
|
// Upgrade the destruction state.
|
|
|
|
destruction_state_ = DESTRUCTION_STATE_ACCEPTED;
|
2012-11-21 01:40:15 +01:00
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destruction_state_ < DESTRUCTION_STATE_ACCEPTED) {
|
2017-05-17 11:29:28 +02:00
|
|
|
destruction_state_ = (force_close ? DESTRUCTION_STATE_ACCEPTED
|
|
|
|
: DESTRUCTION_STATE_PENDING);
|
2013-03-19 23:59:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
content::WebContents* contents = web_contents();
|
2020-08-29 00:39:23 +02:00
|
|
|
if (contents && contents->NeedToFireBeforeUnloadOrUnloadEvents()) {
|
2013-03-19 23:59:33 +01:00
|
|
|
// Will result in a call to BeforeUnloadFired() and, if the close isn't
|
|
|
|
// canceled, CloseContents().
|
2018-10-02 14:14:11 +02:00
|
|
|
contents->DispatchBeforeUnload(false /* auto_cancel */);
|
2012-11-21 01:40:15 +01:00
|
|
|
} else {
|
2013-03-19 23:59:33 +01:00
|
|
|
CloseContents(contents);
|
2012-11-21 01:40:15 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::CloseBrowser,
|
2018-06-19 00:08:20 +02:00
|
|
|
this, force_close));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::TryCloseBrowser() {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "called on invalid thread";
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protect against multiple requests to close while the close is pending.
|
|
|
|
if (destruction_state_ <= DESTRUCTION_STATE_PENDING) {
|
|
|
|
if (destruction_state_ == DESTRUCTION_STATE_NONE) {
|
|
|
|
// Request that the browser close.
|
|
|
|
CloseBrowser(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel the close.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow the close.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefWindowHandle AlloyBrowserHostImpl::GetWindowHandle() {
|
2021-02-18 02:58:25 +01:00
|
|
|
if (is_views_hosted_ && CEF_CURRENTLY_ON_UIT()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
// Always return the most up-to-date window handle for a views-hosted
|
|
|
|
// browser since it may change if the view is re-parented.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return platform_delegate_->GetHostWindowHandle();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
return host_window_handle_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefWindowHandle AlloyBrowserHostImpl::GetOpenerWindowHandle() {
|
2012-04-03 03:34:16 +02:00
|
|
|
return opener_;
|
|
|
|
}
|
|
|
|
|
2022-02-17 19:17:29 +01:00
|
|
|
void AlloyBrowserHostImpl::Find(const CefString& searchText,
|
2020-09-22 21:54:02 +02:00
|
|
|
bool forward,
|
|
|
|
bool matchCase,
|
|
|
|
bool findNext) {
|
2020-07-03 22:13:27 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2013-10-24 00:44:12 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2022-02-17 19:17:29 +01:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::Find, this, searchText,
|
|
|
|
forward, matchCase, findNext));
|
2020-07-03 22:13:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (platform_delegate_) {
|
2022-02-17 19:17:29 +01:00
|
|
|
platform_delegate_->Find(searchText, forward, matchCase, findNext);
|
2013-10-24 00:44:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::StopFinding(bool clearSelection) {
|
2020-07-03 22:13:27 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::StopFinding,
|
2018-06-19 00:08:20 +02:00
|
|
|
this, clearSelection));
|
2020-07-03 22:13:27 +02:00
|
|
|
return;
|
2013-10-24 00:44:12 +02:00
|
|
|
}
|
2020-07-03 22:13:27 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->StopFinding(clearSelection);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-10-24 00:44:12 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SetAutoResizeEnabled(bool enabled,
|
|
|
|
const CefSize& min_size,
|
|
|
|
const CefSize& max_size) {
|
2017-08-04 00:55:19 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::SetAutoResizeEnabled,
|
|
|
|
this, enabled, min_size, max_size));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->SetAutoResizeEnabled(enabled, min_size, max_size);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<CefExtension> AlloyBrowserHostImpl::GetExtension() {
|
2017-08-04 00:55:19 +02:00
|
|
|
return extension_;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsBackgroundHost() {
|
2017-08-04 00:55:19 +02:00
|
|
|
return is_background_host_;
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
bool AlloyBrowserHostImpl::CanExecuteChromeCommand(int command_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyBrowserHostImpl::ExecuteChromeCommand(
|
|
|
|
int command_id,
|
|
|
|
cef_window_open_disposition_t disposition) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsWindowRenderingDisabled() {
|
2014-07-01 00:30:29 +02:00
|
|
|
return IsWindowless();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::WasResized() {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::WasResized, this));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->WasResized();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::WasHidden(bool hidden) {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2018-06-19 00:08:20 +02:00
|
|
|
base::BindOnce(&CefBrowserHost::WasHidden, this, hidden));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->WasHidden(hidden);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::NotifyScreenInfoChanged() {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::NotifyScreenInfoChanged, this));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->NotifyScreenInfoChanged();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::Invalidate(PaintElementType type) {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::Invalidate, this, type));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->Invalidate(type);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SendExternalBeginFrame() {
|
2018-07-03 02:46:03 +02:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2018-07-03 02:46:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_UIT,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::SendExternalBeginFrame, this));
|
2018-07-03 02:46:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->SendExternalBeginFrame();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-07-03 02:46:03 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SendTouchEvent(const CefTouchEvent& event) {
|
2020-07-03 22:13:27 +02:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2020-07-03 22:13:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SendTouchEvent,
|
|
|
|
this, event));
|
2015-06-05 00:33:24 +02:00
|
|
|
return;
|
2020-07-03 22:13:27 +02:00
|
|
|
}
|
2015-06-05 00:33:24 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->SendTouchEvent(event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-21 01:40:15 +01:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SendCaptureLostEvent() {
|
2012-11-21 01:40:15 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::SendCaptureLostEvent, this));
|
2012-11-21 01:40:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->SendCaptureLostEvent();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-21 01:40:15 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
int AlloyBrowserHostImpl::GetWindowlessFrameRate() {
|
2015-05-13 17:43:50 +02:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "called on invalid thread";
|
2015-05-13 17:43:50 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
return osr_util::ClampFrameRate(settings_.windowless_frame_rate);
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SetWindowlessFrameRate(int frame_rate) {
|
2015-05-13 17:43:50 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::SetWindowlessFrameRate,
|
2018-06-19 00:08:20 +02:00
|
|
|
this, frame_rate));
|
2015-05-13 17:43:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings_.windowless_frame_rate = frame_rate;
|
2016-08-15 11:30:17 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2016-08-15 11:30:17 +02:00
|
|
|
platform_delegate_->SetWindowlessFrameRate(frame_rate);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl public methods.
|
2012-04-03 03:34:16 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsWindowless() const {
|
2016-02-29 21:23:44 +01:00
|
|
|
return is_windowless_;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsVisible() const {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (IsWindowless() && platform_delegate_) {
|
|
|
|
return !platform_delegate_->IsHidden();
|
|
|
|
}
|
|
|
|
return CefBrowserHostBase::IsVisible();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsPictureInPictureSupported() const {
|
2019-10-15 13:11:59 +02:00
|
|
|
// Not currently supported with OSR.
|
|
|
|
return !IsWindowless();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::WindowDestroyed() {
|
2013-03-19 23:59:33 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(!window_destroyed_);
|
|
|
|
window_destroyed_ = true;
|
|
|
|
CloseBrowser(true);
|
2012-11-21 01:40:15 +01:00
|
|
|
}
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
bool AlloyBrowserHostImpl::WillBeDestroyed() const {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
return destruction_state_ >= DESTRUCTION_STATE_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DestroyBrowser() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
destruction_state_ = DESTRUCTION_STATE_COMPLETED;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Destroy any platform constructs first.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (javascript_dialog_manager_.get()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
javascript_dialog_manager_->Destroy();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (menu_manager_.get()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
menu_manager_->Destroy();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2024-05-13 23:36:09 +02:00
|
|
|
// Disassociate the platform delegate from this browser. This will trigger
|
|
|
|
// WebContents destruction in most cases.
|
2015-11-17 19:20:13 +01:00
|
|
|
platform_delegate_->BrowserDestroyed(this);
|
|
|
|
|
|
|
|
// Delete objects created by the platform delegate that may be referenced by
|
|
|
|
// the WebContents.
|
2020-01-15 14:36:24 +01:00
|
|
|
file_dialog_manager_.reset(nullptr);
|
|
|
|
javascript_dialog_manager_.reset(nullptr);
|
|
|
|
menu_manager_.reset(nullptr);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-05-01 20:18:18 +02:00
|
|
|
// Delete the audio capturer
|
2022-01-25 22:15:23 +01:00
|
|
|
if (recently_audible_timer_) {
|
|
|
|
recently_audible_timer_->Stop();
|
|
|
|
recently_audible_timer_.reset();
|
|
|
|
}
|
2020-05-01 20:18:18 +02:00
|
|
|
audio_capturer_.reset(nullptr);
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
CefBrowserHostBase::DestroyBrowser();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::CancelContextMenu() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (menu_manager_) {
|
2015-11-17 19:20:13 +01:00
|
|
|
menu_manager_->CancelContextMenu();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
bool AlloyBrowserHostImpl::MaybeAllowNavigation(
|
|
|
|
content::RenderFrameHost* opener,
|
|
|
|
const content::OpenURLParams& params) {
|
2024-04-24 23:23:47 +02:00
|
|
|
const bool is_guest_view = extensions::IsBrowserPluginGuest(
|
|
|
|
content::WebContents::FromRenderFrameHost(opener));
|
2021-11-23 21:28:12 +01:00
|
|
|
if (is_guest_view && !params.is_pdf &&
|
|
|
|
!params.url.SchemeIs(extensions::kExtensionScheme) &&
|
2020-09-25 03:40:47 +02:00
|
|
|
!params.url.SchemeIs(content::kChromeUIScheme)) {
|
|
|
|
// The PDF viewer will load the PDF extension in the guest view, and print
|
2021-11-23 21:28:12 +01:00
|
|
|
// preview will load chrome://print in the guest view. The PDF renderer
|
|
|
|
// used with PdfUnseasoned will set |params.is_pdf| when loading the PDF
|
|
|
|
// stream (see PdfNavigationThrottle::WillStartRequest). All other
|
|
|
|
// navigations are passed to the owner browser.
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(
|
|
|
|
base::IgnoreResult(&AlloyBrowserHostImpl::OpenURLFromTab),
|
2024-04-23 22:06:00 +02:00
|
|
|
this, nullptr, params, base::NullCallback()));
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
return false;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-09-22 21:54:02 +02:00
|
|
|
extensions::ExtensionHost* AlloyBrowserHostImpl::GetExtensionHost() const {
|
2020-07-03 22:13:27 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(platform_delegate_);
|
2020-07-04 20:21:34 +02:00
|
|
|
return platform_delegate_->GetExtensionHost();
|
2020-07-03 22:13:27 +02:00
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2020-07-03 22:13:27 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
|
2020-09-25 03:40:47 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::OnSetFocus,
|
|
|
|
this, source));
|
2020-09-25 03:40:47 +02:00
|
|
|
return;
|
2012-09-10 21:47:58 +02:00
|
|
|
}
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (contents_delegate_->OnSetFocus(source)) {
|
2020-09-25 03:40:47 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2021-09-27 09:50:07 +02:00
|
|
|
platform_delegate_->SetFocus(true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 18:51:51 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::EnterFullscreenModeForTab(
|
2020-07-08 19:23:29 +02:00
|
|
|
content::RenderFrameHost* requesting_frame,
|
2019-11-12 17:11:44 +01:00
|
|
|
const blink::mojom::FullscreenOptions& options) {
|
2020-09-18 00:24:08 +02:00
|
|
|
contents_delegate_->EnterFullscreenModeForTab(requesting_frame, options);
|
|
|
|
WasResized();
|
2015-06-05 00:33:24 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ExitFullscreenModeForTab(
|
2015-06-05 00:33:24 +02:00
|
|
|
content::WebContents* web_contents) {
|
2020-09-18 00:24:08 +02:00
|
|
|
contents_delegate_->ExitFullscreenModeForTab(web_contents);
|
|
|
|
WasResized();
|
2015-06-05 00:33:24 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsFullscreenForTabOrPending(
|
2019-09-04 17:13:32 +02:00
|
|
|
const content::WebContents* web_contents) {
|
2015-06-05 00:33:24 +02:00
|
|
|
return is_fullscreen_;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
blink::mojom::DisplayMode AlloyBrowserHostImpl::GetDisplayMode(
|
2019-09-04 17:13:32 +02:00
|
|
|
const content::WebContents* web_contents) {
|
2019-11-12 17:11:44 +01:00
|
|
|
return is_fullscreen_ ? blink::mojom::DisplayMode::kFullscreen
|
|
|
|
: blink::mojom::DisplayMode::kBrowser;
|
2015-06-05 00:33:24 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::FindReply(content::WebContents* web_contents,
|
|
|
|
int request_id,
|
|
|
|
int number_of_matches,
|
|
|
|
const gfx::Rect& selection_rect,
|
|
|
|
int active_match_ordinal,
|
|
|
|
bool final_update) {
|
2022-02-17 19:17:29 +01:00
|
|
|
auto alloy_delegate =
|
|
|
|
static_cast<CefBrowserPlatformDelegateAlloy*>(platform_delegate());
|
|
|
|
if (alloy_delegate->HandleFindReply(request_id, number_of_matches,
|
|
|
|
selection_rect, active_match_ordinal,
|
|
|
|
final_update)) {
|
|
|
|
if (client_) {
|
|
|
|
if (auto handler = client_->GetFindHandler()) {
|
|
|
|
const auto& details = alloy_delegate->last_search_result();
|
|
|
|
CefRect rect(details.selection_rect().x(), details.selection_rect().y(),
|
|
|
|
details.selection_rect().width(),
|
|
|
|
details.selection_rect().height());
|
|
|
|
handler->OnFindResult(
|
|
|
|
this, details.request_id(), details.number_of_matches(), rect,
|
|
|
|
details.active_match_ordinal(), details.final_update());
|
|
|
|
}
|
2015-01-12 22:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ImeSetComposition(
|
2016-10-28 18:11:24 +02:00
|
|
|
const CefString& text,
|
|
|
|
const std::vector<CefCompositionUnderline>& underlines,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
const CefRange& selection_range) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2016-10-28 18:11:24 +02:00
|
|
|
return;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::ImeSetComposition, this, text,
|
2018-06-19 00:08:20 +02:00
|
|
|
underlines, replacement_range, selection_range));
|
2016-10-28 18:11:24 +02:00
|
|
|
return;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->ImeSetComposition(text, underlines, replacement_range,
|
|
|
|
selection_range);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ImeCommitText(const CefString& text,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
int relative_cursor_pos) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2016-10-28 18:11:24 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::ImeCommitText, this,
|
|
|
|
text, replacement_range, relative_cursor_pos));
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->ImeCommitText(text, replacement_range,
|
|
|
|
relative_cursor_pos);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ImeFinishComposingText(bool keep_selection) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2016-10-28 18:11:24 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::ImeFinishComposingText,
|
2018-06-19 00:08:20 +02:00
|
|
|
this, keep_selection));
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->ImeFinishComposingText(keep_selection);
|
|
|
|
}
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ImeCancelComposition() {
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2016-10-28 18:11:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::ImeCancelComposition, this));
|
2016-10-28 18:11:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->ImeCancelComposition();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragTargetDragEnter(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDragData> drag_data,
|
2014-07-01 00:30:29 +02:00
|
|
|
const CefMouseEvent& event,
|
|
|
|
CefBrowserHost::DragOperationsMask allowed_ops) {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2016-02-29 21:23:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::DragTargetDragEnter,
|
|
|
|
this, drag_data, event, allowed_ops));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!drag_data.get()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->DragTargetDragEnter(drag_data, event, allowed_ops);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragTargetDragOver(
|
2017-05-17 11:29:28 +02:00
|
|
|
const CefMouseEvent& event,
|
2014-07-01 00:30:29 +02:00
|
|
|
CefBrowserHost::DragOperationsMask allowed_ops) {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2016-02-29 21:23:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::DragTargetDragOver, this,
|
|
|
|
event, allowed_ops));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:13:27 +02:00
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->DragTargetDragOver(event, allowed_ops);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragTargetDragLeave() {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::DragTargetDragLeave, this));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->DragTargetDragLeave();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::DragTargetDrop,
|
2018-06-19 00:08:20 +02:00
|
|
|
this, event));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->DragTargetDrop(event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragSourceSystemDragEnded() {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::DragSourceSystemDragEnded, this));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->DragSourceSystemDragEnded();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DragSourceEndedAt(
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
CefBrowserHost::DragOperationsMask op) {
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!IsWindowless()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Window rendering is not disabled";
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:23:44 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::DragSourceEndedAt, this,
|
|
|
|
x, y, op));
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->DragSourceEndedAt(x, y, op);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::SetAudioMuted(bool mute) {
|
2019-02-26 17:44:17 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SetAudioMuted,
|
|
|
|
this, mute));
|
2019-02-26 17:44:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents()) {
|
2019-02-26 17:44:17 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-26 17:44:17 +01:00
|
|
|
web_contents()->SetAudioMuted(mute);
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsAudioMuted() {
|
2019-02-26 17:44:17 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "called on invalid thread";
|
2019-02-26 17:44:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents()) {
|
2019-02-26 17:44:17 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-26 17:44:17 +01:00
|
|
|
return web_contents()->IsAudioMuted();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// content::WebContentsDelegate methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
content::WebContents* AlloyBrowserHostImpl::OpenURLFromTab(
|
2012-04-03 03:34:16 +02:00
|
|
|
content::WebContents* source,
|
2024-04-23 22:06:00 +02:00
|
|
|
const content::OpenURLParams& params,
|
|
|
|
base::OnceCallback<void(content::NavigationHandle&)>
|
|
|
|
navigation_handle_callback) {
|
|
|
|
auto target_contents = contents_delegate_->OpenURLFromTabEx(
|
|
|
|
source, params, navigation_handle_callback);
|
2020-09-25 03:40:47 +02:00
|
|
|
if (target_contents) {
|
2015-03-09 21:22:31 +01:00
|
|
|
// Start a navigation in the current browser that will result in the
|
|
|
|
// creation of a new render process.
|
2020-09-25 03:40:47 +02:00
|
|
|
LoadMainFrameURL(params);
|
|
|
|
return target_contents;
|
2015-03-09 21:22:31 +01:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Cancel the navigation.
|
2015-03-09 21:22:31 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2021-07-23 18:40:13 +02:00
|
|
|
bool AlloyBrowserHostImpl::ShouldAllowRendererInitiatedCrossProcessNavigation(
|
2017-08-04 00:55:19 +02:00
|
|
|
bool is_main_frame_navigation) {
|
2021-07-23 18:40:13 +02:00
|
|
|
return platform_delegate_->ShouldAllowRendererInitiatedCrossProcessNavigation(
|
|
|
|
is_main_frame_navigation);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::AddNewContents(
|
2018-05-18 12:45:18 +02:00
|
|
|
content::WebContents* source,
|
|
|
|
std::unique_ptr<content::WebContents> new_contents,
|
2020-06-09 19:48:00 +02:00
|
|
|
const GURL& target_url,
|
2018-05-18 12:45:18 +02:00
|
|
|
WindowOpenDisposition disposition,
|
2022-09-26 21:30:45 +02:00
|
|
|
const blink::mojom::WindowFeatures& window_features,
|
2018-05-18 12:45:18 +02:00
|
|
|
bool user_gesture,
|
|
|
|
bool* was_blocked) {
|
2020-07-03 22:13:27 +02:00
|
|
|
platform_delegate_->AddNewContents(source, std::move(new_contents),
|
2022-09-26 21:30:45 +02:00
|
|
|
target_url, disposition, window_features,
|
2020-07-03 22:13:27 +02:00
|
|
|
user_gesture, was_blocked);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::LoadingStateChanged(content::WebContents* source,
|
2021-12-16 23:35:54 +01:00
|
|
|
bool should_show_loading_ui) {
|
|
|
|
contents_delegate_->LoadingStateChanged(source, should_show_loading_ui);
|
2018-04-10 19:52:15 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::CloseContents(content::WebContents* source) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destruction_state_ == DESTRUCTION_STATE_COMPLETED) {
|
2013-03-19 23:59:33 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
|
|
|
|
bool close_browser = true;
|
|
|
|
|
|
|
|
// If this method is called in response to something other than
|
|
|
|
// WindowDestroyed() ask the user if the browser should close.
|
2014-07-01 00:30:29 +02:00
|
|
|
if (client_.get() && (IsWindowless() || !window_destroyed_)) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
|
2013-03-19 23:59:33 +01:00
|
|
|
if (handler.get()) {
|
|
|
|
close_browser = !handler->DoClose(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (close_browser) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destruction_state_ != DESTRUCTION_STATE_ACCEPTED) {
|
2013-03-19 23:59:33 +01:00
|
|
|
destruction_state_ = DESTRUCTION_STATE_ACCEPTED;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsWindowless() && !window_destroyed_) {
|
2013-03-19 23:59:33 +01:00
|
|
|
// A window exists so try to close it using the platform method. Will
|
|
|
|
// result in a call to WindowDestroyed() if/when the window is destroyed
|
|
|
|
// via the platform window destruction mechanism.
|
2015-11-17 19:20:13 +01:00
|
|
|
platform_delegate_->CloseHostWindow();
|
2013-03-19 23:59:33 +01:00
|
|
|
} else {
|
2013-10-29 23:19:51 +01:00
|
|
|
// Keep a reference to the browser while it's in the process of being
|
|
|
|
// destroyed.
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser(this);
|
2013-10-29 23:19:51 +01:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
if (source) {
|
|
|
|
// Try to fast shutdown the associated process.
|
2022-07-21 19:26:10 +02:00
|
|
|
source->GetPrimaryMainFrame()->GetProcess()->FastShutdownIfPossible(
|
|
|
|
1, false);
|
2021-03-04 23:36:57 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// No window exists. Destroy the browser immediately. Don't call other
|
|
|
|
// browser methods after calling DestroyBrowser().
|
2013-03-19 23:59:33 +01:00
|
|
|
DestroyBrowser();
|
|
|
|
}
|
|
|
|
} else if (destruction_state_ != DESTRUCTION_STATE_NONE) {
|
|
|
|
destruction_state_ = DESTRUCTION_STATE_NONE;
|
|
|
|
}
|
2012-06-25 20:05:00 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::UpdateTargetURL(content::WebContents* source,
|
|
|
|
const GURL& url) {
|
2020-09-18 00:24:08 +02:00
|
|
|
contents_delegate_->UpdateTargetURL(source, url);
|
2012-09-07 23:01:27 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::DidAddMessageToConsole(
|
2016-11-23 21:54:29 +01:00
|
|
|
content::WebContents* source,
|
2019-07-16 19:59:21 +02:00
|
|
|
blink::mojom::ConsoleMessageLevel level,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& message,
|
2016-11-23 21:54:29 +01:00
|
|
|
int32_t line_no,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& source_id) {
|
2020-09-18 00:24:08 +02:00
|
|
|
return contents_delegate_->DidAddMessageToConsole(source, level, message,
|
|
|
|
line_no, source_id);
|
2012-09-07 23:01:27 +02:00
|
|
|
}
|
|
|
|
|
2023-10-05 01:46:45 +02:00
|
|
|
void AlloyBrowserHostImpl::ContentsZoomChange(bool zoom_in) {
|
|
|
|
zoom::PageZoom::Zoom(
|
|
|
|
web_contents(), zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::BeforeUnloadFired(content::WebContents* source,
|
|
|
|
bool proceed,
|
|
|
|
bool* proceed_to_fire_unload) {
|
2013-03-19 23:59:33 +01:00
|
|
|
if (destruction_state_ == DESTRUCTION_STATE_ACCEPTED || proceed) {
|
|
|
|
*proceed_to_fire_unload = true;
|
|
|
|
} else if (!proceed) {
|
|
|
|
*proceed_to_fire_unload = false;
|
|
|
|
destruction_state_ = DESTRUCTION_STATE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::TakeFocus(content::WebContents* source,
|
|
|
|
bool reverse) {
|
2012-06-11 17:52:49 +02:00
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client_->GetFocusHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (handler.get()) {
|
2012-06-11 17:52:49 +02:00
|
|
|
handler->OnTakeFocus(this, !reverse);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-22 22:40:28 +01:00
|
|
|
void AlloyBrowserHostImpl::CanDownload(
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& request_method,
|
|
|
|
base::OnceCallback<void(bool)> callback) {
|
|
|
|
contents_delegate_->CanDownload(url, request_method, std::move(callback));
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
KeyboardEventProcessingResult AlloyBrowserHostImpl::PreHandleKeyboardEvent(
|
2012-08-29 00:26:35 +02:00
|
|
|
content::WebContents* source,
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) {
|
2020-09-25 03:40:47 +02:00
|
|
|
return contents_delegate_->PreHandleKeyboardEvent(source, event);
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::HandleKeyboardEvent(
|
2012-08-29 00:26:35 +02:00
|
|
|
content::WebContents* source,
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) {
|
2012-06-07 19:38:12 +02:00
|
|
|
// Check to see if event should be ignored.
|
2023-09-15 21:51:43 +02:00
|
|
|
if (event.skip_if_unhandled) {
|
2018-11-03 02:15:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-07 19:38:12 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (contents_delegate_->HandleKeyboardEvent(source, event)) {
|
2020-09-25 03:40:47 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-08-15 11:30:17 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2020-09-25 03:40:47 +02:00
|
|
|
return platform_delegate_->HandleKeyboardEvent(event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-09-25 03:40:47 +02:00
|
|
|
return false;
|
2012-06-07 19:38:12 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::PreHandleGestureEvent(
|
2017-08-04 00:55:19 +02:00
|
|
|
content::WebContents* source,
|
|
|
|
const blink::WebGestureEvent& event) {
|
2020-07-03 22:13:27 +02:00
|
|
|
return platform_delegate_->PreHandleGestureEvent(source, event);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::CanDragEnter(content::WebContents* source,
|
|
|
|
const content::DropData& data,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::DragOperationsMask mask) {
|
2020-05-13 20:30:44 +02:00
|
|
|
CefRefPtr<CefDragHandler> handler;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (client_) {
|
2020-05-13 20:30:44 +02:00
|
|
|
handler = client_->GetDragHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-05-13 20:30:44 +02:00
|
|
|
if (handler) {
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefDragDataImpl> drag_data(new CefDragDataImpl(data));
|
|
|
|
drag_data->SetReadOnly(true);
|
|
|
|
if (handler->OnDragEnter(
|
2017-05-17 11:29:28 +02:00
|
|
|
this, drag_data.get(),
|
|
|
|
static_cast<CefDragHandler::DragOperationsMask>(mask))) {
|
2013-06-24 17:45:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::GetCustomWebContentsView(
|
2014-07-01 00:30:29 +02:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
const GURL& target_url,
|
2017-03-15 23:04:16 +01:00
|
|
|
int opener_render_process_id,
|
|
|
|
int opener_render_frame_id,
|
2024-06-21 17:26:59 +02:00
|
|
|
raw_ptr<content::WebContentsView>* view,
|
|
|
|
raw_ptr<content::RenderViewHostDelegateView>* delegate_view) {
|
2017-02-10 23:44:11 +01:00
|
|
|
CefBrowserInfoManager::GetInstance()->GetCustomWebContentsView(
|
2021-08-19 23:07:44 +02:00
|
|
|
target_url,
|
|
|
|
frame_util::MakeGlobalId(opener_render_process_id,
|
|
|
|
opener_render_frame_id),
|
|
|
|
view, delegate_view);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::WebContentsCreated(
|
2012-04-03 03:34:16 +02:00
|
|
|
content::WebContents* source_contents,
|
2016-10-21 21:52:29 +02:00
|
|
|
int opener_render_process_id,
|
2014-04-04 18:50:38 +02:00
|
|
|
int opener_render_frame_id,
|
2015-07-24 02:06:56 +02:00
|
|
|
const std::string& frame_name,
|
2012-04-03 03:34:16 +02:00
|
|
|
const GURL& target_url,
|
2017-07-27 01:19:27 +02:00
|
|
|
content::WebContents* new_contents) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserSettings settings;
|
|
|
|
CefRefPtr<CefClient> client;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate;
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info;
|
2013-02-09 23:38:24 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserInfoManager::GetInstance()->WebContentsCreated(
|
2021-08-19 23:07:44 +02:00
|
|
|
target_url,
|
|
|
|
frame_util::MakeGlobalId(opener_render_process_id,
|
|
|
|
opener_render_frame_id),
|
2023-02-09 19:15:15 +01:00
|
|
|
settings, client, platform_delegate, extra_info, new_contents);
|
2014-01-02 23:41:11 +01:00
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> info =
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserInfoManager::GetInstance()->CreatePopupBrowserInfo(
|
2024-04-17 18:01:26 +02:00
|
|
|
new_contents, platform_delegate->IsWindowless(),
|
|
|
|
platform_delegate->IsPrintPreviewSupported(), extra_info);
|
2020-07-03 22:13:27 +02:00
|
|
|
CHECK(info.get());
|
|
|
|
CHECK(info->is_popup());
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> opener =
|
|
|
|
GetBrowserForContents(source_contents);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!opener) {
|
2017-05-09 22:45:57 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
// Popups must share the same RequestContext as the parent.
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context = opener->request_context();
|
2020-07-03 22:13:27 +02:00
|
|
|
CHECK(request_context);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2018-05-18 12:45:18 +02:00
|
|
|
// We don't officially own |new_contents| until AddNewContents() is called.
|
|
|
|
// However, we need to install observers/delegates here.
|
2024-04-30 03:09:17 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
|
|
|
|
settings, client, new_contents, /*own_web_contents=*/false, info, opener,
|
|
|
|
/*is_devtools_popup=*/false, request_context, std::move(platform_delegate)
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
/*extension=*/nullptr
|
|
|
|
#endif
|
|
|
|
);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
void AlloyBrowserHostImpl::RendererUnresponsive(
|
|
|
|
content::WebContents* source,
|
|
|
|
content::RenderWidgetHost* render_widget_host,
|
|
|
|
base::RepeatingClosure hang_monitor_restarter) {
|
|
|
|
hang_monitor::RendererUnresponsive(this, render_widget_host,
|
|
|
|
hang_monitor_restarter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyBrowserHostImpl::RendererResponsive(
|
|
|
|
content::WebContents* source,
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
|
|
|
hang_monitor::RendererResponsive(this, render_widget_host);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
content::JavaScriptDialogManager*
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl::GetJavaScriptDialogManager(content::WebContents* source) {
|
2024-06-04 18:19:14 +02:00
|
|
|
return CefBrowserHostBase::GetJavaScriptDialogManager();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::RunFileChooser(
|
2016-06-21 00:59:23 +02:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2020-08-29 00:39:23 +02:00
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
2018-10-02 14:14:11 +02:00
|
|
|
const blink::mojom::FileChooserParams& params) {
|
2022-04-15 21:55:23 +02:00
|
|
|
// This will eventually call into CefFileDialogManager.
|
|
|
|
FileSelectHelper::RunFileChooser(render_frame_host, std::move(listener),
|
|
|
|
params);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:03:31 +02:00
|
|
|
bool AlloyBrowserHostImpl::ShowContextMenu(
|
2015-07-16 23:40:01 +02:00
|
|
|
const content::ContextMenuParams& params) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-08-15 11:30:17 +02:00
|
|
|
if (!menu_manager_.get() && platform_delegate_) {
|
2024-01-20 23:48:57 +01:00
|
|
|
menu_manager_ = std::make_unique<CefMenuManager>(
|
|
|
|
this, platform_delegate_->CreateMenuRunner());
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
return menu_manager_->CreateContextMenu(params);
|
2013-02-09 23:38:24 +01:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::UpdatePreferredSize(content::WebContents* source,
|
|
|
|
const gfx::Size& pref_size) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2016-08-15 11:30:17 +02:00
|
|
|
platform_delegate_->SizeTo(pref_size.width(), pref_size.height());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ResizeDueToAutoResize(content::WebContents* source,
|
|
|
|
const gfx::Size& new_size) {
|
2017-08-04 00:55:19 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (client_) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client_->GetDisplayHandler();
|
|
|
|
if (handler && handler->OnAutoResize(
|
|
|
|
this, CefSize(new_size.width(), new_size.height()))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdatePreferredSize(source, new_size);
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::RequestMediaAccessPermission(
|
2012-06-22 00:50:34 +02:00
|
|
|
content::WebContents* web_contents,
|
2013-01-15 20:12:28 +01:00
|
|
|
const content::MediaStreamRequest& request,
|
2018-06-19 00:08:20 +02:00
|
|
|
content::MediaResponseCallback callback) {
|
2022-07-08 09:40:35 +02:00
|
|
|
auto returned_callback = media_access_query::RequestMediaAccessPermission(
|
|
|
|
this, request, std::move(callback), /*default_disallow=*/true);
|
|
|
|
// Callback should not be returned.
|
|
|
|
DCHECK(returned_callback.is_null());
|
2012-06-22 00:50:34 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::CheckMediaAccessPermission(
|
2018-04-19 17:44:42 +02:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2023-12-06 21:16:15 +01:00
|
|
|
const url::Origin& security_origin,
|
2019-09-04 17:13:32 +02:00
|
|
|
blink::mojom::MediaStreamType type) {
|
2022-06-30 09:31:18 +02:00
|
|
|
return media_access_query::CheckMediaAccessPermission(this, render_frame_host,
|
|
|
|
security_origin, type);
|
2015-03-25 22:22:47 +01:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsNeverComposited(
|
|
|
|
content::WebContents* web_contents) {
|
2020-07-03 22:13:27 +02:00
|
|
|
return platform_delegate_->IsNeverComposited(web_contents);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
content::PictureInPictureResult AlloyBrowserHostImpl::EnterPictureInPicture(
|
2022-02-21 23:23:40 +01:00
|
|
|
content::WebContents* web_contents) {
|
2019-10-15 13:11:59 +02:00
|
|
|
if (!IsPictureInPictureSupported()) {
|
|
|
|
return content::PictureInPictureResult::kNotSupported;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
return PictureInPictureWindowManager::GetInstance()
|
|
|
|
->EnterVideoPictureInPicture(web_contents);
|
2019-10-15 13:11:59 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::ExitPictureInPicture() {
|
2019-10-15 13:11:59 +02:00
|
|
|
DCHECK(IsPictureInPictureSupported());
|
|
|
|
PictureInPictureWindowManager::GetInstance()->ExitPictureInPicture();
|
|
|
|
}
|
|
|
|
|
2024-06-14 19:01:45 +02:00
|
|
|
bool AlloyBrowserHostImpl::IsBackForwardCacheSupported(
|
|
|
|
content::WebContents& web_contents) {
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
return true;
|
|
|
|
#else
|
2024-04-17 18:01:26 +02:00
|
|
|
// Disabled with Alloy bootstrap due to issue #3237.
|
|
|
|
return cef::IsChromeRuntimeEnabled();
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2021-09-15 19:38:44 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported(
|
2022-02-21 23:23:40 +01:00
|
|
|
content::WebContents& web_contents) {
|
2023-01-30 18:43:54 +01:00
|
|
|
return content::PreloadingEligibility::kEligible;
|
2021-09-15 19:38:44 +02:00
|
|
|
}
|
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
void AlloyBrowserHostImpl::DraggableRegionsChanged(
|
|
|
|
const std::vector<blink::mojom::DraggableRegionPtr>& regions,
|
|
|
|
content::WebContents* contents) {
|
|
|
|
contents_delegate_->DraggableRegionsChanged(regions, contents);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// content::WebContentsObserver methods.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::DidFinishNavigation(
|
2017-03-03 23:37:23 +01:00
|
|
|
content::NavigationHandle* navigation_handle) {
|
2017-12-21 20:57:42 +01:00
|
|
|
if (web_contents()) {
|
2024-04-17 18:01:26 +02:00
|
|
|
auto cef_browser_context = CefBrowserContext::FromBrowserContext(
|
|
|
|
web_contents()->GetBrowserContext());
|
2020-07-01 02:57:00 +02:00
|
|
|
if (cef_browser_context) {
|
|
|
|
cef_browser_context->AddVisitedURLs(
|
2024-04-17 18:01:26 +02:00
|
|
|
navigation_handle->GetURL(), navigation_handle->GetRedirectChain(),
|
|
|
|
navigation_handle->GetPageTransition());
|
2017-12-21 20:57:42 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::OnAudioStateChanged(bool audible) {
|
2020-05-01 20:18:18 +02:00
|
|
|
if (audible) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (recently_audible_timer_) {
|
2022-01-25 22:15:23 +01:00
|
|
|
recently_audible_timer_->Stop();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-01-25 22:15:23 +01:00
|
|
|
|
2020-05-01 20:18:18 +02:00
|
|
|
StartAudioCapturer();
|
|
|
|
} else if (audio_capturer_) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!recently_audible_timer_) {
|
2022-01-25 22:15:23 +01:00
|
|
|
recently_audible_timer_ = std::make_unique<base::OneShotTimer>();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-01-25 22:15:23 +01:00
|
|
|
|
2020-05-01 20:18:18 +02:00
|
|
|
// If you have a media playing that has a short quiet moment, web_contents
|
|
|
|
// will immediately switch to non-audible state. We don't want to stop
|
|
|
|
// audio stream so quickly, let's give the stream some time to resume
|
|
|
|
// playing.
|
2022-01-25 22:15:23 +01:00
|
|
|
recently_audible_timer_->Start(
|
2020-05-01 20:18:18 +02:00
|
|
|
FROM_HERE, kRecentlyAudibleTimeout,
|
2020-09-22 21:54:02 +02:00
|
|
|
base::BindOnce(&AlloyBrowserHostImpl::OnRecentlyAudibleTimerFired,
|
|
|
|
this));
|
2020-05-01 20:18:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::OnRecentlyAudibleTimerFired() {
|
2020-05-01 20:18:18 +02:00
|
|
|
audio_capturer_.reset();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::AccessibilityEventReceived(
|
2024-05-23 03:52:35 +02:00
|
|
|
const ui::AXUpdatesAndEvents& details) {
|
2017-05-12 20:28:25 +02:00
|
|
|
// Only needed in windowless mode.
|
|
|
|
if (IsWindowless()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents() || !platform_delegate_) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2024-05-23 03:52:35 +02:00
|
|
|
platform_delegate_->AccessibilityEventReceived(details);
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::AccessibilityLocationChangesReceived(
|
2024-05-23 03:52:35 +02:00
|
|
|
const std::vector<ui::AXLocationChanges>& details) {
|
2017-05-12 20:28:25 +02:00
|
|
|
// Only needed in windowless mode.
|
|
|
|
if (IsWindowless()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents() || !platform_delegate_) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2024-05-23 03:52:35 +02:00
|
|
|
platform_delegate_->AccessibilityLocationChangesReceived(details);
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::WebContentsDestroyed() {
|
2024-05-13 23:36:09 +02:00
|
|
|
// In case we're notified before the CefBrowserContentsDelegate,
|
|
|
|
// reset it first for consistent state in DestroyWebContents.
|
|
|
|
if (GetWebContents()) {
|
|
|
|
contents_delegate_->WebContentsDestroyed();
|
|
|
|
}
|
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
auto wc = web_contents();
|
|
|
|
content::WebContentsObserver::Observe(nullptr);
|
2024-05-13 23:36:09 +02:00
|
|
|
DestroyWebContents(wc);
|
|
|
|
|
|
|
|
if (destruction_state_ < DESTRUCTION_STATE_COMPLETED) {
|
|
|
|
// We were not called via DestroyBrowser. This can occur when (for example)
|
|
|
|
// a pending popup WebContents is destroyed during parent WebContents
|
|
|
|
// destruction. Try to close the associated browser now.
|
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::CloseBrowser,
|
|
|
|
this, /*force_close=*/true));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 04:51:17 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::StartAudioCapturer() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!client_.get() || audio_capturer_) {
|
2020-05-01 20:18:18 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-05-01 20:18:18 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefAudioHandler> audio_handler = client_->GetAudioHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!audio_handler.get()) {
|
2020-05-01 20:18:18 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-05-01 20:18:18 +02:00
|
|
|
|
|
|
|
CefAudioParameters params;
|
|
|
|
params.channel_layout = CEF_CHANNEL_LAYOUT_STEREO;
|
|
|
|
params.sample_rate = media::AudioParameters::kAudioCDSampleRate;
|
|
|
|
params.frames_per_buffer = 1024;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!audio_handler->GetAudioParameters(this, params)) {
|
2020-05-01 20:18:18 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-05-01 20:18:18 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
audio_capturer_ =
|
|
|
|
std::make_unique<CefAudioCapturer>(params, this, audio_handler);
|
2020-05-01 20:18:18 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl private methods.
|
2012-04-03 03:34:16 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl::AlloyBrowserHostImpl(
|
2012-12-30 12:17:49 +01:00
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> opener,
|
2019-03-24 00:40:32 +01:00
|
|
|
CefRefPtr<CefRequestContextImpl> request_context,
|
2024-04-30 03:09:17 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
CefRefPtr<CefExtension> extension
|
|
|
|
#endif
|
|
|
|
)
|
2020-09-25 03:40:47 +02:00
|
|
|
: CefBrowserHostBase(settings,
|
|
|
|
client,
|
|
|
|
std::move(platform_delegate),
|
|
|
|
browser_info,
|
|
|
|
request_context),
|
2020-09-18 00:24:08 +02:00
|
|
|
content::WebContentsObserver(web_contents),
|
2015-11-17 19:20:13 +01:00
|
|
|
opener_(kNullWindowHandle),
|
2024-04-30 03:09:17 +02:00
|
|
|
is_windowless_(platform_delegate_->IsWindowless())
|
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
,
|
|
|
|
extension_(extension)
|
|
|
|
#endif
|
|
|
|
{
|
2020-09-18 00:24:08 +02:00
|
|
|
contents_delegate_->ObserveWebContents(web_contents);
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
if (opener.get() && !is_views_hosted_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
// GetOpenerWindowHandle() only returns a value for non-views-hosted
|
|
|
|
// popup browsers.
|
2015-11-17 19:20:13 +01:00
|
|
|
opener_ = opener->GetWindowHandle();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Associate the platform delegate with this browser.
|
2015-11-17 19:20:13 +01:00
|
|
|
platform_delegate_->BrowserCreated(this);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
// Make sure RenderFrameCreated is called at least one time.
|
2022-07-21 19:26:10 +02:00
|
|
|
RenderFrameCreated(web_contents->GetPrimaryMainFrame());
|
2018-05-18 12:45:18 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
bool AlloyBrowserHostImpl::CreateHostWindow() {
|
2016-01-19 21:09:01 +01:00
|
|
|
// |host_window_handle_| will not change after initial host creation for
|
|
|
|
// non-views-hosted browsers.
|
|
|
|
bool success = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!IsWindowless()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
success = platform_delegate_->CreateHostWindow();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (success && !is_views_hosted_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return success;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
gfx::Point AlloyBrowserHostImpl::GetScreenPoint(const gfx::Point& view,
|
|
|
|
bool want_dip_coords) const {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2022-05-13 13:38:41 +02:00
|
|
|
return platform_delegate_->GetScreenPoint(view, want_dip_coords);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
return gfx::Point();
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
void AlloyBrowserHostImpl::StartDragging(
|
2016-11-23 21:54:29 +01:00
|
|
|
const content::DropData& drop_data,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::DragOperationsMask allowed_ops,
|
2016-11-23 21:54:29 +01:00
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
2020-10-08 21:54:42 +02:00
|
|
|
const blink::mojom::DragEventSourceInfo& event_info,
|
2016-11-23 21:54:29 +01:00
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
|
|
|
if (platform_delegate_) {
|
|
|
|
platform_delegate_->StartDragging(drop_data, allowed_ops, image,
|
|
|
|
image_offset, event_info, source_rwh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:08:48 +02:00
|
|
|
void AlloyBrowserHostImpl::UpdateDragOperation(
|
|
|
|
ui::mojom::DragOperation operation,
|
|
|
|
bool document_is_handling_drag) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (platform_delegate_) {
|
2023-10-19 20:08:48 +02:00
|
|
|
platform_delegate_->UpdateDragOperation(operation,
|
|
|
|
document_is_handling_drag);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
}
|