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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-10-08 20:17:18 +02:00
|
|
|
#include <optional>
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/callback_forward.h"
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-01-21 19:32:46 +01:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_client.h"
|
|
|
|
#include "cef/include/views/cef_browser_view.h"
|
|
|
|
#include "cef/include/views/cef_browser_view_delegate.h"
|
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/views/browser_view_view.h"
|
|
|
|
#include "cef/libcef/browser/views/view_impl.h"
|
2017-02-17 00:19:43 +01:00
|
|
|
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
class CefBrowserHostBase;
|
2024-03-29 17:48:33 +01:00
|
|
|
class CefWidget;
|
2023-09-25 21:40:17 +02:00
|
|
|
class CefWindowImpl;
|
2023-09-07 19:28:27 +02:00
|
|
|
class ChromeBrowserView;
|
2024-03-29 17:48:33 +01:00
|
|
|
class Profile;
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
class CefBrowserViewImpl
|
|
|
|
: public CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>,
|
|
|
|
public CefBrowserViewView::Delegate {
|
2016-01-19 21:09:01 +01:00
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
using ParentClass =
|
|
|
|
CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>;
|
|
|
|
|
|
|
|
CefBrowserViewImpl(const CefBrowserViewImpl&) = delete;
|
|
|
|
CefBrowserViewImpl& operator=(const CefBrowserViewImpl&) = delete;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-10-12 20:52:17 +02:00
|
|
|
~CefBrowserViewImpl() override;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create a new CefBrowserView instance. |delegate| may be nullptr.
|
2022-04-08 22:48:56 +02:00
|
|
|
// |window_info| will only be used when creating a Chrome child window.
|
2016-01-19 21:09:01 +01:00
|
|
|
static CefRefPtr<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);
|
|
|
|
|
|
|
|
// Create a new CefBrowserView instance for a popup. |delegate| may be
|
|
|
|
// nullptr.
|
|
|
|
static CefRefPtr<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
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// Called from CefBrowserPlatformDelegate[Chrome]Views.
|
2016-01-19 21:09:01 +01:00
|
|
|
void WebContentsCreated(content::WebContents* web_contents);
|
2024-03-29 17:48:33 +01:00
|
|
|
void WebContentsDestroyed(content::WebContents* web_contents);
|
2020-09-25 03:40:47 +02:00
|
|
|
void BrowserCreated(CefBrowserHostBase* browser,
|
2019-07-17 20:47:27 +02:00
|
|
|
base::RepeatingClosure on_bounds_changed);
|
2020-09-25 03:40:47 +02:00
|
|
|
void BrowserDestroyed(CefBrowserHostBase* browser);
|
2024-11-05 20:58:45 +01:00
|
|
|
void RequestFocusSync();
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Called to handle accelerators when the event is unhandled by the web
|
|
|
|
// content and the browser client.
|
2024-06-14 19:01:45 +02:00
|
|
|
bool HandleKeyboardEvent(const input::NativeWebKeyboardEvent& event);
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// CefBrowserView methods:
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() override;
|
2021-04-11 22:10:11 +02:00
|
|
|
CefRefPtr<CefView> GetChromeToolbar() override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void SetPreferAccelerators(bool prefer_accelerators) override;
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t GetRuntimeStyle() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefView methods:
|
|
|
|
CefRefPtr<CefBrowserView> AsBrowserView() override { return this; }
|
2021-01-21 19:32:46 +01:00
|
|
|
void RequestFocus() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void SetBackgroundColor(cef_color_t color) override;
|
|
|
|
|
|
|
|
// CefViewAdapter methods:
|
|
|
|
void Detach() override;
|
|
|
|
std::string GetDebugType() override { return "BrowserView"; }
|
2023-01-30 22:42:40 +01:00
|
|
|
void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefBrowserViewView::Delegate methods:
|
2024-03-29 17:48:33 +01:00
|
|
|
void AddedToWidget() override;
|
|
|
|
void RemovedFromWidget() override;
|
2019-07-17 20:47:27 +02:00
|
|
|
void OnBoundsChanged() override;
|
2023-08-31 19:16:46 +02:00
|
|
|
bool OnGestureEvent(ui::GestureEvent* event) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// Return the WebView representation of this object.
|
|
|
|
views::WebView* web_view() const;
|
2024-11-05 20:58:45 +01:00
|
|
|
views::View* content_view() const override { return web_view(); }
|
2021-02-18 02:58:25 +01:00
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
// Return the CEF specialization of BrowserView.
|
|
|
|
ChromeBrowserView* chrome_browser_view() const;
|
|
|
|
|
2023-09-25 21:40:17 +02:00
|
|
|
// Return the CefWindowImpl hosting this object.
|
2024-01-12 00:32:08 +01:00
|
|
|
CefWindowImpl* cef_window_impl() const;
|
2023-09-25 21:40:17 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsAlloyStyle() const { return is_alloy_style_; }
|
|
|
|
bool IsChromeStyle() const { return !is_alloy_style_; }
|
|
|
|
|
2024-10-12 20:52:17 +02:00
|
|
|
base::WeakPtr<CefBrowserViewImpl> GetWeakPtr() {
|
|
|
|
return weak_ptr_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
|
|
|
// Create a new implementation object.
|
|
|
|
// Always call Initialize() after creation.
|
|
|
|
// |delegate| may be nullptr.
|
2024-04-17 18:01:26 +02:00
|
|
|
CefBrowserViewImpl(CefRefPtr<CefBrowserViewDelegate> delegate,
|
2024-10-08 20:17:18 +02:00
|
|
|
bool is_devtools_popup,
|
|
|
|
std::optional<cef_runtime_style_t> opener_runtime_style);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void 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);
|
|
|
|
|
|
|
|
void SetDefaults(const CefBrowserSettings& settings);
|
|
|
|
|
|
|
|
// CefViewImpl methods:
|
2021-02-18 02:58:25 +01:00
|
|
|
views::View* CreateRootView() override;
|
2016-07-21 23:21:32 +02:00
|
|
|
void InitializeRootView() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Logic extracted from UnhandledKeyboardEventHandler::HandleKeyboardEvent for
|
|
|
|
// the handling of accelerators. Returns true if the event was handled by the
|
|
|
|
// accelerator.
|
2024-06-14 19:01:45 +02:00
|
|
|
bool HandleAccelerator(const input::NativeWebKeyboardEvent& event,
|
2017-02-17 00:19:43 +01:00
|
|
|
views::FocusManager* focus_manager);
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void DisassociateFromWidget();
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// True if the browser is Alloy style, otherwise Chrome style.
|
|
|
|
const bool is_alloy_style_;
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
std::unique_ptr<CefBrowserCreateParams> pending_browser_create_params_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
|
|
|
|
bool ignore_next_char_event_ = false;
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
base::RepeatingClosure on_bounds_changed_;
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefWidget> cef_widget_ = nullptr;
|
|
|
|
raw_ptr<Profile> profile_ = nullptr;
|
2024-03-29 17:48:33 +01:00
|
|
|
|
2021-01-21 19:32:46 +01:00
|
|
|
base::WeakPtrFactory<CefBrowserViewImpl> weak_ptr_factory_;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefBrowserViewImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
|