2020-07-04 20:21:34 +02: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/alloy/browser_platform_delegate_alloy.h"
|
2020-07-04 20:21:34 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
#include "base/logging.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
|
|
|
#include "cef/libcef/browser/extensions/extension_background_host.h"
|
|
|
|
#include "cef/libcef/browser/extensions/extension_system.h"
|
|
|
|
#include "cef/libcef/browser/extensions/extension_view_host.h"
|
|
|
|
#include "cef/libcef/browser/extensions/extension_web_contents_observer.h"
|
|
|
|
#include "cef/libcef/common/extensions/extensions_util.h"
|
|
|
|
#include "cef/libcef/common/net/url_util.h"
|
2024-04-30 03:09:17 +02:00
|
|
|
#include "cef/libcef/features/features.h"
|
2024-04-27 03:21:18 +02:00
|
|
|
#include "chrome/browser/task_manager/web_contents_tags.h"
|
|
|
|
#include "chrome/browser/ui/tab_helpers.h"
|
2022-02-17 19:17:29 +01:00
|
|
|
#include "components/find_in_page/find_tab_helper.h"
|
|
|
|
#include "components/find_in_page/find_types.h"
|
2024-04-27 20:25:51 +02:00
|
|
|
#include "components/performance_manager/embedder/performance_manager_registry.h"
|
2020-07-04 20:21:34 +02:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "extensions/browser/process_manager.h"
|
2022-02-18 17:33:40 +01:00
|
|
|
#include "pdf/pdf_features.h"
|
2020-07-04 20:21:34 +02:00
|
|
|
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/dialogs/alloy_javascript_dialog_manager_delegate.h"
|
|
|
|
#include "cef/libcef/features/runtime_checks.h"
|
2024-04-30 03:09:17 +02:00
|
|
|
#include "chrome/browser/printing/printing_init.h"
|
|
|
|
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
|
|
|
#include "components/javascript_dialogs/tab_modal_dialog_manager.h"
|
|
|
|
#include "components/permissions/permission_request_manager.h"
|
|
|
|
#include "components/zoom/zoom_controller.h"
|
|
|
|
#include "extensions/browser/extension_registry.h"
|
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
|
2024-04-27 03:21:18 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kAttachedHelpersUserDataKey[] = "CefAttachedHelpers";
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
const extensions::Extension* GetExtensionForUrl(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url) {
|
|
|
|
auto* registry = extensions::ExtensionRegistry::Get(browser_context);
|
|
|
|
if (!registry) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::string extension_id = url.host();
|
|
|
|
return registry->enabled_extensions().GetByID(extension_id);
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
|
2024-04-27 03:21:18 +02:00
|
|
|
} // namespace
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
CefBrowserPlatformDelegateAlloy::CefBrowserPlatformDelegateAlloy()
|
|
|
|
: weak_ptr_factory_(this) {}
|
|
|
|
|
|
|
|
content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserCreateParams& create_params,
|
2020-07-04 20:21:34 +02:00
|
|
|
bool& own_web_contents) {
|
2020-09-25 03:40:47 +02:00
|
|
|
DCHECK(primary_);
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
if (!create_params.request_context) {
|
|
|
|
// Using the global request context.
|
2023-11-14 18:16:43 +01:00
|
|
|
create_params.request_context = CefRequestContext::GetGlobalContext();
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
auto* browser_context =
|
|
|
|
CefRequestContextImpl::GetBrowserContext(create_params.request_context);
|
|
|
|
CHECK(browser_context);
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
scoped_refptr<content::SiteInstance> site_instance;
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2021-04-15 01:28:22 +02:00
|
|
|
if (extensions::ExtensionsEnabled() && !create_params.url.empty()) {
|
|
|
|
GURL gurl = url_util::MakeGURL(create_params.url, /*fixup=*/true);
|
2020-07-04 20:21:34 +02:00
|
|
|
if (!create_params.extension) {
|
|
|
|
// We might be loading an extension app view where the extension URL is
|
|
|
|
// provided by the client.
|
2024-04-30 03:09:17 +02:00
|
|
|
create_params.extension = GetExtensionForUrl(browser_context, gurl);
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
if (create_params.extension) {
|
2021-04-21 00:52:34 +02:00
|
|
|
if (create_params.extension_host_type ==
|
|
|
|
extensions::mojom::ViewType::kInvalid) {
|
2023-11-21 20:17:55 +01:00
|
|
|
// Default to popup behavior.
|
2020-07-04 20:21:34 +02:00
|
|
|
create_params.extension_host_type =
|
2023-11-21 20:17:55 +01:00
|
|
|
extensions::mojom::ViewType::kExtensionPopup;
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extension resources will fail to load if we don't use a SiteInstance
|
|
|
|
// associated with the extension.
|
2024-01-26 03:12:43 +01:00
|
|
|
// (AlloyContentBrowserClient::SiteInstanceGotProcessAndSite won't find
|
|
|
|
// the extension to register with InfoMap, and AllowExtensionResourceLoad
|
|
|
|
// in ExtensionProtocolHandler::MaybeCreateJob will return false resulting
|
|
|
|
// in ERR_BLOCKED_BY_CLIENT).
|
2020-07-04 20:21:34 +02:00
|
|
|
site_instance = extensions::ProcessManager::Get(browser_context)
|
2021-04-15 01:28:22 +02:00
|
|
|
->GetSiteInstanceForURL(gurl);
|
2020-07-04 20:21:34 +02:00
|
|
|
DCHECK(site_instance);
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
content::WebContents::CreateParams wc_create_params(browser_context,
|
|
|
|
site_instance);
|
|
|
|
|
|
|
|
if (IsWindowless()) {
|
|
|
|
// Create the OSR view for the WebContents.
|
|
|
|
CreateViewForWebContents(&wc_create_params.view,
|
|
|
|
&wc_create_params.delegate_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto web_contents = content::WebContents::Create(wc_create_params);
|
|
|
|
CHECK(web_contents);
|
|
|
|
|
|
|
|
own_web_contents = true;
|
|
|
|
return web_contents.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::WebContentsCreated(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
bool owned) {
|
|
|
|
CefBrowserPlatformDelegate::WebContentsCreated(web_contents, owned);
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
if (primary_) {
|
2024-04-27 03:21:18 +02:00
|
|
|
AttachHelpers(web_contents);
|
2022-04-08 22:48:56 +02:00
|
|
|
|
|
|
|
if (owned) {
|
|
|
|
SetOwnedWebContents(web_contents);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DCHECK(!owned);
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::AddNewContents(
|
|
|
|
content::WebContents* source,
|
|
|
|
std::unique_ptr<content::WebContents> new_contents,
|
|
|
|
const GURL& target_url,
|
|
|
|
WindowOpenDisposition disposition,
|
2022-09-26 21:30:45 +02:00
|
|
|
const blink::mojom::WindowFeatures& window_features,
|
2020-07-04 20:21:34 +02:00
|
|
|
bool user_gesture,
|
|
|
|
bool* was_blocked) {
|
2020-09-25 03:40:47 +02:00
|
|
|
DCHECK(primary_);
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> owner =
|
|
|
|
AlloyBrowserHostImpl::GetBrowserForContents(new_contents.get());
|
2020-07-04 20:21:34 +02:00
|
|
|
if (owner) {
|
|
|
|
// Taking ownership of |new_contents|.
|
|
|
|
static_cast<CefBrowserPlatformDelegateAlloy*>(
|
|
|
|
owner->platform_delegate_.get())
|
|
|
|
->SetOwnedWebContents(new_contents.release());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
if (extension_host_) {
|
|
|
|
extension_host_->AddNewContents(source, std::move(new_contents), target_url,
|
2022-09-26 21:30:45 +02:00
|
|
|
disposition, window_features, user_gesture,
|
2020-07-04 20:21:34 +02:00
|
|
|
was_blocked);
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2021-07-23 18:40:13 +02:00
|
|
|
bool CefBrowserPlatformDelegateAlloy::
|
|
|
|
ShouldAllowRendererInitiatedCrossProcessNavigation(
|
|
|
|
bool is_main_frame_navigation) {
|
2020-07-04 20:21:34 +02:00
|
|
|
if (extension_host_) {
|
2021-07-23 18:40:13 +02:00
|
|
|
return extension_host_->ShouldAllowRendererInitiatedCrossProcessNavigation(
|
|
|
|
is_main_frame_navigation);
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::RenderViewReady() {
|
|
|
|
ConfigureAutoResize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::BrowserCreated(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase* browser) {
|
2020-07-04 20:21:34 +02:00
|
|
|
CefBrowserPlatformDelegate::BrowserCreated(browser);
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Only register WebContents delegate/observers if we're the primary delegate.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!primary_) {
|
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
|
|
|
|
|
|
|
DCHECK(!web_contents_->GetDelegate());
|
2024-04-17 18:01:26 +02:00
|
|
|
web_contents_->SetDelegate(
|
|
|
|
AlloyBrowserHostImpl::FromBaseChecked(browser).get());
|
2020-07-04 20:21:34 +02:00
|
|
|
|
2024-04-27 03:21:18 +02:00
|
|
|
AttachHelpers(web_contents_);
|
2022-06-02 11:49:50 +02:00
|
|
|
|
|
|
|
// Used for print preview and JavaScript dialogs.
|
2024-01-20 23:48:57 +01:00
|
|
|
web_contents_dialog_helper_ =
|
|
|
|
std::make_unique<AlloyWebContentsDialogHelper>(web_contents_, this);
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
|
|
|
|
const extensions::Extension* extension,
|
|
|
|
const GURL& url,
|
2021-04-21 00:52:34 +02:00
|
|
|
extensions::mojom::ViewType host_type) {
|
2020-09-25 03:40:47 +02:00
|
|
|
REQUIRE_ALLOY_RUNTIME();
|
|
|
|
DCHECK(primary_);
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
// Should get WebContentsCreated and BrowserCreated calls first.
|
|
|
|
DCHECK(web_contents_);
|
|
|
|
DCHECK(browser_);
|
|
|
|
DCHECK(!extension_host_);
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
auto alloy_browser = AlloyBrowserHostImpl::FromBaseChecked(browser_.get());
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2023-11-21 20:17:55 +01:00
|
|
|
if (host_type == extensions::mojom::ViewType::kExtensionPopup) {
|
2020-07-04 20:21:34 +02:00
|
|
|
// Create an extension host that we own.
|
|
|
|
extension_host_ = new extensions::CefExtensionViewHost(
|
2024-04-17 18:01:26 +02:00
|
|
|
alloy_browser.get(), extension, web_contents_, url, host_type);
|
2020-07-04 20:21:34 +02:00
|
|
|
// Trigger load of the extension URL.
|
2021-03-04 23:36:57 +01:00
|
|
|
extension_host_->CreateRendererSoon();
|
2021-04-21 00:52:34 +02:00
|
|
|
} else if (host_type ==
|
|
|
|
extensions::mojom::ViewType::kExtensionBackgroundPage) {
|
2020-07-04 20:21:34 +02:00
|
|
|
is_background_host_ = true;
|
2020-09-25 03:40:47 +02:00
|
|
|
alloy_browser->is_background_host_ = true;
|
2020-07-04 20:21:34 +02:00
|
|
|
// Create an extension host that will be owned by ProcessManager.
|
|
|
|
extension_host_ = new extensions::CefExtensionBackgroundHost(
|
2024-04-17 18:01:26 +02:00
|
|
|
alloy_browser.get(),
|
2020-07-04 20:21:34 +02:00
|
|
|
base::BindOnce(&CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()),
|
|
|
|
extension, web_contents_, url, host_type);
|
|
|
|
// Load will be triggered by ProcessManager::CreateBackgroundHost.
|
|
|
|
} else {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << " Unsupported extension host type: " << host_type;
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extensions::ExtensionHost* CefBrowserPlatformDelegateAlloy::GetExtensionHost()
|
|
|
|
const {
|
|
|
|
return extension_host_;
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::BrowserDestroyed(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase* browser) {
|
|
|
|
if (primary_) {
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-09-25 03:40:47 +02:00
|
|
|
DestroyExtensionHost();
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2020-09-25 03:40:47 +02:00
|
|
|
owned_web_contents_.reset();
|
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
|
|
|
}
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
web_modal::WebContentsModalDialogHost*
|
|
|
|
CefBrowserPlatformDelegateAlloy::GetWebContentsModalDialogHost() const {
|
|
|
|
return web_contents_dialog_helper_.get();
|
|
|
|
}
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
void CefBrowserPlatformDelegateAlloy::SendCaptureLostEvent() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents_) {
|
2020-07-08 19:23:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-08 19:23:29 +02:00
|
|
|
content::RenderViewHost* host = web_contents_->GetRenderViewHost();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!host) {
|
2020-07-08 19:23:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-08 19:23:29 +02:00
|
|
|
|
|
|
|
content::RenderWidgetHostImpl* widget =
|
|
|
|
content::RenderWidgetHostImpl::From(host->GetWidget());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2020-07-04 20:21:34 +02:00
|
|
|
widget->LostCapture();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
|
2020-07-04 20:21:34 +02:00
|
|
|
void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
|
2023-01-06 19:33:32 +01:00
|
|
|
if (!browser_) {
|
2020-07-08 19:23:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-08 19:23:29 +02:00
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
// Dismiss any existing popups.
|
2023-01-06 19:33:32 +01:00
|
|
|
auto frame = browser_->GetMainFrame();
|
|
|
|
if (frame && frame->IsValid()) {
|
|
|
|
static_cast<CefFrameHostImpl*>(frame.get())->NotifyMoveOrResizeStarted();
|
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
bool CefBrowserPlatformDelegateAlloy::PreHandleGestureEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const blink::WebGestureEvent& event) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (extension_host_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return extension_host_->PreHandleGestureEvent(source, event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateAlloy::IsNeverComposited(
|
|
|
|
content::WebContents* web_contents) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (extension_host_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return extension_host_->IsNeverComposited(web_contents);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::SetAutoResizeEnabled(
|
|
|
|
bool enabled,
|
|
|
|
const CefSize& min_size,
|
|
|
|
const CefSize& max_size) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (enabled == auto_resize_enabled_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
|
|
|
|
auto_resize_enabled_ = enabled;
|
|
|
|
if (enabled) {
|
|
|
|
auto_resize_min_ = gfx::Size(min_size.width, min_size.height);
|
|
|
|
auto_resize_max_ = gfx::Size(max_size.width, max_size.height);
|
|
|
|
} else {
|
|
|
|
auto_resize_min_ = auto_resize_max_ = gfx::Size();
|
|
|
|
}
|
|
|
|
ConfigureAutoResize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::ConfigureAutoResize() {
|
|
|
|
if (!web_contents_ || !web_contents_->GetRenderWidgetHostView()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto_resize_enabled_) {
|
|
|
|
web_contents_->GetRenderWidgetHostView()->EnableAutoResize(
|
|
|
|
auto_resize_min_, auto_resize_max_);
|
|
|
|
} else {
|
|
|
|
web_contents_->GetRenderWidgetHostView()->DisableAutoResize(gfx::Size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 19:17:29 +01:00
|
|
|
void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
|
2020-07-04 20:21:34 +02:00
|
|
|
bool forward,
|
|
|
|
bool matchCase,
|
|
|
|
bool findNext) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
|
2022-02-17 19:17:29 +01:00
|
|
|
find_in_page::FindTabHelper::FromWebContents(web_contents_)
|
|
|
|
->StartFinding(searchText.ToString16(), forward, matchCase, findNext,
|
|
|
|
/*run_synchronously_for_testing=*/false);
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::StopFinding(bool clearSelection) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
|
2022-02-17 19:17:29 +01:00
|
|
|
last_search_result_ = find_in_page::FindNotificationDetails();
|
|
|
|
find_in_page::FindTabHelper::FromWebContents(web_contents_)
|
|
|
|
->StopFinding(clearSelection ? find_in_page::SelectionAction::kClear
|
|
|
|
: find_in_page::SelectionAction::kKeep);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateAlloy::HandleFindReply(
|
|
|
|
int request_id,
|
|
|
|
int number_of_matches,
|
|
|
|
const gfx::Rect& selection_rect,
|
|
|
|
int active_match_ordinal,
|
|
|
|
bool final_update) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!web_contents_) {
|
2022-02-17 19:17:29 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-02-17 19:17:29 +01:00
|
|
|
|
|
|
|
auto find_in_page =
|
|
|
|
find_in_page::FindTabHelper::FromWebContents(web_contents_);
|
|
|
|
|
|
|
|
find_in_page->HandleFindReply(request_id, number_of_matches, selection_rect,
|
|
|
|
active_match_ordinal, final_update);
|
|
|
|
if (!(find_in_page->find_result() == last_search_result_)) {
|
|
|
|
last_search_result_ = find_in_page->find_result();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-07-04 20:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
base::RepeatingClosure
|
|
|
|
CefBrowserPlatformDelegateAlloy::GetBoundsChangedCallback() {
|
|
|
|
if (web_contents_dialog_helper_) {
|
|
|
|
return web_contents_dialog_helper_->GetBoundsChangedCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
return base::RepeatingClosure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
|
|
|
|
content::WebContents* owned_contents) {
|
2020-09-25 03:40:47 +02:00
|
|
|
DCHECK(primary_);
|
|
|
|
|
2020-07-04 20:21:34 +02:00
|
|
|
// Should not currently own a WebContents.
|
|
|
|
CHECK(!owned_web_contents_);
|
|
|
|
owned_web_contents_.reset(owned_contents);
|
|
|
|
}
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2020-07-04 20:21:34 +02:00
|
|
|
void CefBrowserPlatformDelegateAlloy::DestroyExtensionHost() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!extension_host_) {
|
2020-07-04 20:21:34 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-04 20:21:34 +02:00
|
|
|
if (extension_host_->extension_host_type() ==
|
2021-04-21 00:52:34 +02:00
|
|
|
extensions::mojom::ViewType::kExtensionBackgroundPage) {
|
2020-07-04 20:21:34 +02:00
|
|
|
DCHECK(is_background_host_);
|
|
|
|
// Close notification for background pages arrives via CloseContents.
|
|
|
|
// The extension host will be deleted by
|
|
|
|
// ProcessManager::CloseBackgroundHost and OnExtensionHostDeleted will be
|
|
|
|
// called to notify us.
|
|
|
|
extension_host_->Close();
|
|
|
|
} else {
|
|
|
|
DCHECK(!is_background_host_);
|
|
|
|
// We own the extension host and must delete it.
|
|
|
|
delete extension_host_;
|
|
|
|
extension_host_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted() {
|
|
|
|
DCHECK(is_background_host_);
|
|
|
|
DCHECK(extension_host_);
|
|
|
|
extension_host_ = nullptr;
|
|
|
|
}
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2024-04-27 03:21:18 +02:00
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateAlloy::AttachHelpers(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
// If already attached, nothing to be done.
|
|
|
|
base::SupportsUserData::Data* attached_tag =
|
|
|
|
web_contents->GetUserData(&kAttachedHelpersUserDataKey);
|
|
|
|
if (attached_tag) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark as attached.
|
|
|
|
web_contents->SetUserData(&kAttachedHelpersUserDataKey,
|
|
|
|
std::make_unique<base::SupportsUserData::Data>());
|
|
|
|
|
2024-04-30 03:09:17 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2024-04-27 03:21:18 +02:00
|
|
|
// Create all the helpers.
|
|
|
|
if (cef::IsAlloyRuntimeEnabled()) {
|
|
|
|
find_in_page::FindTabHelper::CreateForWebContents(web_contents);
|
|
|
|
permissions::PermissionRequestManager::CreateForWebContents(web_contents);
|
|
|
|
PrefsTabHelper::CreateForWebContents(web_contents);
|
|
|
|
printing::InitializePrintingForWebContents(web_contents);
|
|
|
|
zoom::ZoomController::CreateForWebContents(web_contents);
|
|
|
|
|
|
|
|
javascript_dialogs::TabModalDialogManager::CreateForWebContents(
|
|
|
|
web_contents, CreateAlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
|
|
|
web_contents));
|
2024-04-30 03:09:17 +02:00
|
|
|
} else
|
|
|
|
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
{
|
2024-04-27 20:25:51 +02:00
|
|
|
if (IsWindowless()) {
|
|
|
|
// Logic from ChromeContentBrowserClientCef::GetWebContentsViewDelegate
|
|
|
|
// which is not called for windowless browsers. Needs to be done before
|
|
|
|
// calling AttachTabHelpers.
|
|
|
|
if (auto* registry =
|
|
|
|
performance_manager::PerformanceManagerRegistry::GetInstance()) {
|
|
|
|
registry->MaybeCreatePageNodeForWebContents(web_contents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 03:21:18 +02:00
|
|
|
// Adopt the WebContents now, so all observers are in place, as the network
|
|
|
|
// requests for its initial navigation will start immediately
|
|
|
|
TabHelpers::AttachTabHelpers(web_contents);
|
|
|
|
|
|
|
|
// Make the tab show up in the task manager.
|
|
|
|
task_manager::WebContentsTags::CreateForTabContents(web_contents);
|
|
|
|
}
|
|
|
|
}
|