2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 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/views/browser_view_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
2024-03-19 22:11:42 +01:00
|
|
|
#include <optional>
|
2024-01-20 23:48:57 +01:00
|
|
|
|
2024-07-02 20:16:55 +02:00
|
|
|
#include "cef/libcef/browser/browser_event_util.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/chrome/views/chrome_browser_view.h"
|
|
|
|
#include "cef/libcef/browser/context.h"
|
|
|
|
#include "cef/libcef/browser/request_context_impl.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/browser/views/widget.h"
|
|
|
|
#include "cef/libcef/browser/views/window_impl.h"
|
2024-03-29 17:48:33 +01:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2024-06-14 19:01:45 +02:00
|
|
|
#include "components/input/native_web_keyboard_event.h"
|
2017-02-17 00:19:43 +01:00
|
|
|
#include "ui/content_accelerators/accelerator_util.h"
|
|
|
|
|
2023-08-31 19:16:46 +02:00
|
|
|
namespace {
|
|
|
|
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<cef_gesture_command_t> GetGestureCommand(
|
2023-08-31 19:16:46 +02:00
|
|
|
ui::GestureEvent* event) {
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2024-07-29 19:09:20 +02:00
|
|
|
if (event->details().type() == ui::EventType::kGestureSwipe) {
|
2023-08-31 19:16:46 +02:00
|
|
|
if (event->details().swipe_left()) {
|
|
|
|
return CEF_GESTURE_COMMAND_BACK;
|
|
|
|
} else if (event->details().swipe_right()) {
|
|
|
|
return CEF_GESTURE_COMMAND_FORWARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2024-03-19 22:11:42 +01:00
|
|
|
return std::nullopt;
|
2023-08-31 19:16:46 +02:00
|
|
|
}
|
|
|
|
|
2024-10-08 20:17:18 +02:00
|
|
|
bool ComputeAlloyStyle(
|
|
|
|
CefBrowserViewDelegate* cef_delegate,
|
|
|
|
bool is_devtools_popup,
|
|
|
|
std::optional<cef_runtime_style_t> opener_runtime_style) {
|
|
|
|
if (is_devtools_popup) {
|
|
|
|
// Alloy style is not supported with Chrome DevTools popups.
|
|
|
|
if (cef_delegate &&
|
|
|
|
cef_delegate->GetBrowserRuntimeStyle() == CEF_RUNTIME_STYLE_ALLOY) {
|
|
|
|
LOG(ERROR) << "GetBrowserRuntimeStyle() requested Alloy style; only "
|
|
|
|
"Chrome style is supported for DevTools popups";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opener_runtime_style) {
|
|
|
|
// Popup style must match the opener style.
|
|
|
|
const bool opener_alloy_style =
|
|
|
|
*opener_runtime_style == CEF_RUNTIME_STYLE_ALLOY;
|
|
|
|
if (cef_delegate) {
|
|
|
|
const auto requested_style = cef_delegate->GetBrowserRuntimeStyle();
|
|
|
|
if (requested_style != CEF_RUNTIME_STYLE_DEFAULT &&
|
|
|
|
requested_style != (opener_alloy_style ? CEF_RUNTIME_STYLE_ALLOY
|
|
|
|
: CEF_RUNTIME_STYLE_CHROME)) {
|
|
|
|
LOG(ERROR)
|
|
|
|
<< "GetBrowserRuntimeStyle() for popups must match opener style";
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
2024-10-08 20:17:18 +02:00
|
|
|
return opener_alloy_style;
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
|
2024-10-08 20:17:18 +02:00
|
|
|
// Chrome style is the default unless Alloy is specifically requested.
|
|
|
|
return cef_delegate &&
|
|
|
|
cef_delegate->GetBrowserRuntimeStyle() == CEF_RUNTIME_STYLE_ALLOY;
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 19:16:46 +02:00
|
|
|
} // namespace
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
|
|
|
CefRefPtr<CefClient> client,
|
2017-05-17 11:29:28 +02:00
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
2022-04-08 22:48:56 +02:00
|
|
|
return CefBrowserViewImpl::Create(CefWindowInfo(), client, url, settings,
|
|
|
|
extra_info, request_context, delegate);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserView> CefBrowserView::GetForBrowser(
|
|
|
|
CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
auto browser_impl = CefBrowserHostBase::FromBrowser(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_impl && browser_impl->is_views_hosted()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return browser_impl->GetBrowserView();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::Create(
|
2022-04-08 22:48:56 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
if (!request_context) {
|
|
|
|
request_context = CefRequestContext::GetGlobalContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that the browser context is valid. Do this here instead of risking
|
|
|
|
// potential browser creation failure when this view is added to the window.
|
|
|
|
auto request_context_impl =
|
|
|
|
static_cast<CefRequestContextImpl*>(request_context.get());
|
|
|
|
if (!request_context_impl->VerifyBrowserContext()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserViewImpl> browser_view =
|
2024-10-08 20:17:18 +02:00
|
|
|
new CefBrowserViewImpl(delegate, /*is_devtools_popup=*/false,
|
|
|
|
/*opener_runtime_style=*/std::nullopt);
|
2022-04-08 22:48:56 +02:00
|
|
|
browser_view->SetPendingBrowserCreateParams(
|
|
|
|
window_info, client, url, settings, extra_info, request_context);
|
2016-01-19 21:09:01 +01:00
|
|
|
browser_view->Initialize();
|
|
|
|
browser_view->SetDefaults(settings);
|
|
|
|
return browser_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::CreateForPopup(
|
|
|
|
const CefBrowserSettings& settings,
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate,
|
2024-10-08 20:17:18 +02:00
|
|
|
bool is_devtools,
|
|
|
|
cef_runtime_style_t opener_runtime_style) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserViewImpl> browser_view =
|
2024-10-08 20:17:18 +02:00
|
|
|
new CefBrowserViewImpl(delegate, is_devtools, opener_runtime_style);
|
2016-01-19 21:09:01 +01:00
|
|
|
browser_view->Initialize();
|
|
|
|
browser_view->SetDefaults(settings);
|
|
|
|
return browser_view;
|
|
|
|
}
|
|
|
|
|
2024-10-12 20:52:17 +02:00
|
|
|
CefBrowserViewImpl::~CefBrowserViewImpl() {
|
|
|
|
// We want no further callbacks to this object.
|
|
|
|
weak_ptr_factory_.InvalidateWeakPtrs();
|
|
|
|
|
|
|
|
// |browser_| may exist here if the BrowserView was removed from the Views
|
|
|
|
// hierarchy prior to tear-down and the last BrowserView reference was
|
|
|
|
// released. In that case DisassociateFromWidget() will be called when the
|
|
|
|
// BrowserView is removed from the Window but Detach() will not be called
|
|
|
|
// because the BrowserView was not destroyed via the Views hierarchy
|
|
|
|
// tear-down.
|
|
|
|
DCHECK(!cef_widget_);
|
|
|
|
if (browser_ && !browser_->WillBeDestroyed()) {
|
|
|
|
// With Alloy style |browser_| will disappear when WindowDestroyed()
|
|
|
|
// indirectly calls BrowserDestroyed() so keep a reference.
|
|
|
|
CefRefPtr<CefBrowserHostBase> browser = browser_;
|
|
|
|
|
|
|
|
// Force the browser to be destroyed.
|
|
|
|
browser->WindowDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefBrowserViewImpl::WebContentsCreated(
|
|
|
|
content::WebContents* web_contents) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_view()) {
|
2021-02-18 02:58:25 +01:00
|
|
|
web_view()->SetWebContents(web_contents);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void CefBrowserViewImpl::WebContentsDestroyed(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
// This will always be called before BrowserDestroyed().
|
|
|
|
DisassociateFromWidget();
|
|
|
|
|
|
|
|
if (web_view()) {
|
|
|
|
web_view()->SetWebContents(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
void CefBrowserViewImpl::BrowserCreated(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase* browser,
|
2019-07-17 20:47:27 +02:00
|
|
|
base::RepeatingClosure on_bounds_changed) {
|
2016-01-19 21:09:01 +01:00
|
|
|
browser_ = browser;
|
2019-07-17 20:47:27 +02:00
|
|
|
on_bounds_changed_ = on_bounds_changed;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
void CefBrowserViewImpl::BrowserDestroyed(CefBrowserHostBase* browser) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK_EQ(browser, browser_);
|
|
|
|
browser_ = nullptr;
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// If this BrowserView belonged to a Widget then we expect to have received a
|
|
|
|
// call to DisassociateFromWidget().
|
|
|
|
DCHECK(!cef_widget_);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2024-11-05 20:58:45 +01:00
|
|
|
void CefBrowserViewImpl::RequestFocusSync() {
|
|
|
|
// With Chrome style the root_view() type (ChromeBrowserView) does not accept
|
|
|
|
// focus, so always give focus to the WebView directly.
|
|
|
|
if (web_view()) {
|
|
|
|
if (auto widget = web_view()->GetWidget(); widget->IsMinimized()) {
|
|
|
|
// Don't activate a minimized Widget, or it will be shown.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activate the Widget and indirectly call WebContents::Focus().
|
|
|
|
web_view()->RequestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
bool CefBrowserViewImpl::HandleKeyboardEvent(
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!root_view()) {
|
2018-11-03 02:15:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
views::FocusManager* focus_manager = root_view()->GetFocusManager();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!focus_manager) {
|
2018-11-03 02:15:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (HandleAccelerator(event, focus_manager)) {
|
2018-11-03 02:15:09 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
// Give the CefWindowDelegate a chance to handle the event.
|
2024-01-12 00:32:08 +01:00
|
|
|
if (auto* window_impl = cef_window_impl()) {
|
2017-02-17 00:19:43 +01:00
|
|
|
CefKeyEvent cef_event;
|
2024-07-02 20:16:55 +02:00
|
|
|
if (GetCefKeyEvent(event, cef_event) &&
|
2017-02-17 00:19:43 +01:00
|
|
|
window_impl->OnKeyEvent(cef_event)) {
|
2018-11-03 02:15:09 +01:00
|
|
|
return true;
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed with default native handling.
|
2018-11-03 02:15:09 +01:00
|
|
|
return unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
|
|
|
|
focus_manager);
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefBrowser> CefBrowserViewImpl::GetBrowser() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
return browser_;
|
|
|
|
}
|
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
CefRefPtr<CefView> CefBrowserViewImpl::GetChromeToolbar() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!is_alloy_style_) {
|
2023-09-07 19:28:27 +02:00
|
|
|
return chrome_browser_view()->cef_toolbar();
|
2021-04-11 22:10:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void CefBrowserViewImpl::SetPreferAccelerators(bool prefer_accelerators) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_view()) {
|
2021-02-18 02:58:25 +01:00
|
|
|
web_view()->set_allow_accelerators(prefer_accelerators);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t CefBrowserViewImpl::GetRuntimeStyle() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(CEF_RUNTIME_STYLE_DEFAULT);
|
|
|
|
return IsAlloyStyle() ? CEF_RUNTIME_STYLE_ALLOY : CEF_RUNTIME_STYLE_CHROME;
|
|
|
|
}
|
|
|
|
|
2021-01-21 19:32:46 +01:00
|
|
|
void CefBrowserViewImpl::RequestFocus() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
// Always execute asynchronously to work around issue #3040.
|
2024-11-05 20:58:45 +01:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserViewImpl::RequestFocusSync,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2021-01-21 19:32:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefBrowserViewImpl::SetBackgroundColor(cef_color_t color) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
ParentClass::SetBackgroundColor(color);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_view()) {
|
2021-02-18 02:58:25 +01:00
|
|
|
web_view()->SetResizeBackgroundColor(color);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserViewImpl::Detach() {
|
|
|
|
ParentClass::Detach();
|
|
|
|
|
|
|
|
// root_view() will be nullptr now.
|
|
|
|
DCHECK(!root_view());
|
|
|
|
|
|
|
|
if (browser_) {
|
2024-06-26 02:12:37 +02:00
|
|
|
// With Alloy style |browser_| will disappear when WindowDestroyed()
|
2021-02-18 02:58:25 +01:00
|
|
|
// indirectly calls BrowserDestroyed() so keep a reference.
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser = browser_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Force the browser to be destroyed.
|
2021-02-18 02:58:25 +01:00
|
|
|
browser->WindowDestroyed();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
void CefBrowserViewImpl::GetDebugInfo(base::Value::Dict* info,
|
2016-01-19 21:09:01 +01:00
|
|
|
bool include_children) {
|
|
|
|
ParentClass::GetDebugInfo(info, include_children);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2023-01-30 22:42:40 +01:00
|
|
|
info->Set("url", browser_->GetMainFrame()->GetURL().ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
void CefBrowserViewImpl::AddedToWidget() {
|
|
|
|
DCHECK(!cef_widget_);
|
|
|
|
|
|
|
|
views::Widget* widget = root_view()->GetWidget();
|
|
|
|
DCHECK(widget);
|
|
|
|
CefWidget* cef_widget = CefWidget::GetForWidget(widget);
|
|
|
|
DCHECK(cef_widget);
|
|
|
|
|
2024-10-07 19:50:16 +02:00
|
|
|
if (!browser_ && !is_alloy_style_) {
|
|
|
|
if (cef_widget->IsAlloyStyle()) {
|
2024-04-17 18:01:26 +02:00
|
|
|
LOG(ERROR) << "Cannot add Chrome style BrowserView to Alloy style Window";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cef_widget->IsChromeStyle() && cef_widget->GetThemeProfile()) {
|
|
|
|
LOG(ERROR) << "Cannot add multiple Chrome style BrowserViews";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!browser_ && pending_browser_create_params_) {
|
|
|
|
// Top-level browsers will be created when this view is added to the views
|
|
|
|
// hierarchy.
|
|
|
|
pending_browser_create_params_->browser_view = this;
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
CefBrowserHostBase::Create(*pending_browser_create_params_);
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(browser_);
|
|
|
|
|
|
|
|
pending_browser_create_params_.reset(nullptr);
|
|
|
|
}
|
2024-03-29 17:48:33 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_widget_ = cef_widget;
|
2024-03-29 17:48:33 +01:00
|
|
|
profile_ = Profile::FromBrowserContext(browser_->GetBrowserContext());
|
|
|
|
DCHECK(profile_);
|
|
|
|
|
|
|
|
// May call Widget::ThemeChanged().
|
|
|
|
cef_widget_->AddAssociatedProfile(profile_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserViewImpl::RemovedFromWidget() {
|
2024-06-26 02:12:37 +02:00
|
|
|
// With Chrome style this may be called after BrowserDestroyed(), in which
|
2024-03-29 17:48:33 +01:00
|
|
|
// case the following call will be a no-op.
|
|
|
|
DisassociateFromWidget();
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
void CefBrowserViewImpl::OnBoundsChanged() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!on_bounds_changed_.is_null()) {
|
2019-07-17 20:47:27 +02:00
|
|
|
on_bounds_changed_.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-17 20:47:27 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 19:16:46 +02:00
|
|
|
bool CefBrowserViewImpl::OnGestureEvent(ui::GestureEvent* event) {
|
|
|
|
if (auto command = GetGestureCommand(event)) {
|
|
|
|
if (delegate() && delegate()->OnGestureCommand(this, *command)) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-05-26 11:05:33 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (is_alloy_style_ && browser_) {
|
2024-06-26 02:12:37 +02:00
|
|
|
// Default handling for Alloy style.
|
2023-08-31 19:16:46 +02:00
|
|
|
switch (*command) {
|
|
|
|
case CEF_GESTURE_COMMAND_BACK:
|
|
|
|
browser_->GoBack();
|
|
|
|
break;
|
|
|
|
case CEF_GESTURE_COMMAND_FORWARD:
|
|
|
|
browser_->GoForward();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2023-05-26 11:05:33 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-31 19:16:46 +02:00
|
|
|
|
|
|
|
return false;
|
2023-05-26 11:05:33 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserViewImpl::CefBrowserViewImpl(
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserViewDelegate> delegate,
|
2024-10-08 20:17:18 +02:00
|
|
|
bool is_devtools_popup,
|
|
|
|
std::optional<cef_runtime_style_t> opener_runtime_style)
|
2024-04-17 18:01:26 +02:00
|
|
|
: ParentClass(delegate),
|
2024-10-08 20:17:18 +02:00
|
|
|
is_alloy_style_(ComputeAlloyStyle(delegate.get(),
|
|
|
|
is_devtools_popup,
|
|
|
|
opener_runtime_style)),
|
2024-04-17 18:01:26 +02:00
|
|
|
weak_ptr_factory_(this) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void CefBrowserViewImpl::SetPendingBrowserCreateParams(
|
2022-04-08 22:48:56 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
DCHECK(!pending_browser_create_params_);
|
2024-01-20 23:48:57 +01:00
|
|
|
pending_browser_create_params_ = std::make_unique<CefBrowserCreateParams>();
|
2024-04-17 18:01:26 +02:00
|
|
|
pending_browser_create_params_->MaybeSetWindowInfo(
|
|
|
|
window_info, /*allow_alloy_style=*/true, /*allow_chrome_style=*/true);
|
2016-01-19 21:09:01 +01:00
|
|
|
pending_browser_create_params_->client = client;
|
2021-04-15 01:28:22 +02:00
|
|
|
pending_browser_create_params_->url = url;
|
2016-01-19 21:09:01 +01:00
|
|
|
pending_browser_create_params_->settings = settings;
|
2019-03-19 10:42:54 +01:00
|
|
|
pending_browser_create_params_->extra_info = extra_info;
|
2016-01-19 21:09:01 +01:00
|
|
|
pending_browser_create_params_->request_context = request_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserViewImpl::SetDefaults(const CefBrowserSettings& settings) {
|
2017-04-20 21:28:17 +02:00
|
|
|
SetBackgroundColor(
|
|
|
|
CefContext::Get()->GetBackgroundColor(&settings, STATE_DISABLED));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
views::View* CefBrowserViewImpl::CreateRootView() {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!is_alloy_style_) {
|
2023-09-07 19:28:27 +02:00
|
|
|
return new ChromeBrowserView(this);
|
2021-02-18 02:58:25 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
return new CefBrowserViewView(delegate(), this);
|
|
|
|
}
|
2016-07-21 23:21:32 +02:00
|
|
|
|
|
|
|
void CefBrowserViewImpl::InitializeRootView() {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!is_alloy_style_) {
|
2023-09-07 19:28:27 +02:00
|
|
|
chrome_browser_view()->Initialize();
|
2021-02-18 02:58:25 +01:00
|
|
|
} else {
|
|
|
|
static_cast<CefBrowserViewView*>(root_view())->Initialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
views::WebView* CefBrowserViewImpl::web_view() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!root_view()) {
|
2022-04-08 22:48:56 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-04-08 22:48:56 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!is_alloy_style_) {
|
2023-09-07 19:28:27 +02:00
|
|
|
return chrome_browser_view()->contents_web_view();
|
2021-02-18 02:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<CefBrowserViewView*>(root_view());
|
2016-07-21 23:21:32 +02:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
ChromeBrowserView* CefBrowserViewImpl::chrome_browser_view() const {
|
2024-04-17 18:01:26 +02:00
|
|
|
CHECK(!is_alloy_style_);
|
2023-09-07 19:28:27 +02:00
|
|
|
return static_cast<ChromeBrowserView*>(root_view());
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
CefWindowImpl* CefBrowserViewImpl::cef_window_impl() const {
|
|
|
|
// Same implementation as GetWindow().
|
|
|
|
if (!root_view()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-09-25 21:40:17 +02:00
|
|
|
CefRefPtr<CefWindow> window =
|
|
|
|
view_util::GetWindowFor(root_view()->GetWidget());
|
|
|
|
return static_cast<CefWindowImpl*>(window.get());
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
bool CefBrowserViewImpl::HandleAccelerator(
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event,
|
2017-02-17 00:19:43 +01:00
|
|
|
views::FocusManager* focus_manager) {
|
|
|
|
// Previous calls to TranslateMessage can generate Char events as well as
|
|
|
|
// RawKeyDown events, even if the latter triggered an accelerator. In these
|
|
|
|
// cases, we discard the Char events.
|
2020-06-09 19:48:00 +02:00
|
|
|
if (event.GetType() == blink::WebInputEvent::Type::kChar &&
|
2017-04-20 21:28:17 +02:00
|
|
|
ignore_next_char_event_) {
|
2017-02-17 00:19:43 +01:00
|
|
|
ignore_next_char_event_ = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's necessary to reset this flag, because a RawKeyDown event may not
|
|
|
|
// always generate a Char event.
|
|
|
|
ignore_next_char_event_ = false;
|
|
|
|
|
2020-06-09 19:48:00 +02:00
|
|
|
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown) {
|
2017-02-17 00:19:43 +01:00
|
|
|
ui::Accelerator accelerator =
|
|
|
|
ui::GetAcceleratorFromNativeWebKeyboardEvent(event);
|
|
|
|
|
|
|
|
// This is tricky: we want to set ignore_next_char_event_ if
|
|
|
|
// ProcessAccelerator returns true. But ProcessAccelerator might delete
|
|
|
|
// |this| if the accelerator is a "close tab" one. So we speculatively
|
|
|
|
// set the flag and fix it if no event was handled.
|
|
|
|
ignore_next_char_event_ = true;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (focus_manager->ProcessAccelerator(accelerator)) {
|
2017-02-17 00:19:43 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
// ProcessAccelerator didn't handle the accelerator, so we know both
|
|
|
|
// that |this| is still valid, and that we didn't want to set the flag.
|
|
|
|
ignore_next_char_event_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-21 19:32:46 +01:00
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void CefBrowserViewImpl::DisassociateFromWidget() {
|
|
|
|
if (!cef_widget_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// May call Widget::ThemeChanged().
|
|
|
|
cef_widget_->RemoveAssociatedProfile(profile_);
|
|
|
|
cef_widget_ = nullptr;
|
|
|
|
profile_ = nullptr;
|
|
|
|
}
|