2021-02-18 02:58:25 +01:00
|
|
|
// Copyright 2021 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_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
#include "libcef/browser/views/color_provider_tracker.h"
|
|
|
|
#include "libcef/browser/views/widget.h"
|
|
|
|
|
2024-04-15 03:34:45 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2021-02-18 02:58:25 +01:00
|
|
|
#include "chrome/browser/ui/browser.h"
|
|
|
|
#include "chrome/browser/ui/views/frame/browser_frame.h"
|
|
|
|
|
|
|
|
// An overview of the Chrome Browser object model is provided below. Object
|
|
|
|
// creation normally begins with a call to Browser::Create(CreateParams) which
|
|
|
|
// then creates the necessary Browser view, window and frame objects. CEF has
|
|
|
|
// modified the default object creation model are described below to better
|
|
|
|
// integrate with the existing CEF Views APIs.
|
|
|
|
//
|
|
|
|
// OVERVIEW
|
|
|
|
//
|
|
|
|
// Browser and BrowserWindow are the primary Chrome objects. Browser provides
|
|
|
|
// the concrete state and mutation methods while BrowserWindow is an interface
|
|
|
|
// implemented by the platform-specific "view" of the Browser window.
|
|
|
|
//
|
|
|
|
// Browser:
|
|
|
|
// - Creates a BrowserView (aka BrowserWindow) and BrowserFrame (aka Widget) via
|
|
|
|
// a call to BrowserWindow::CreateBrowserWindow() in the Browser constructor.
|
|
|
|
// - An existing BrowserWindow can alternately be specified via the
|
|
|
|
// Browser::CreateParams::window parameter.
|
|
|
|
// - Owned by the BrowserView after creation.
|
|
|
|
//
|
|
|
|
// The Chrome Views implementation uses BrowserView to represent the browser
|
|
|
|
// client area and BrowserFrame (plus helpers) to represent the non-client
|
|
|
|
// window frame.
|
|
|
|
//
|
|
|
|
// BrowserView:
|
|
|
|
// - Extends BrowserWindow, views::ClientView, views::WidgetDelegate.
|
|
|
|
// - Owns the Browser.
|
|
|
|
// - References the BrowserFrame.
|
|
|
|
// - Passed to Widget::Init() via Widget::InitParams::delegate to receive
|
|
|
|
// WidgetDelegate callbacks.
|
|
|
|
// - Extended by CEF as ChromeBrowserView.
|
|
|
|
// BrowserFrame:
|
|
|
|
// - Extends Widget (aka views::internal::NativeWidgetDelegate).
|
|
|
|
// - References the BrowserView.
|
|
|
|
// - Creates/owns a DesktopBrowserFrameAura (aka NativeBrowserFrame) via
|
|
|
|
// BrowserFrame::InitBrowserFrame().
|
|
|
|
// - Extended by CEF as ChromeBrowserFrame.
|
|
|
|
//
|
|
|
|
// Chrome custom window/frame handling is implemented using platform-specific
|
|
|
|
// objects.
|
|
|
|
//
|
|
|
|
// DesktopBrowserFrameAura:
|
|
|
|
// - Extends NativeBrowserFrame, DesktopNativeWidgetAura.
|
|
|
|
// - Acts as a helper for BrowserFrame.
|
|
|
|
// - Creates/references a BrowserDesktopWindowTreeHostWin via
|
|
|
|
// DesktopBrowserFrameAura::InitNativeWidget().
|
|
|
|
// BrowserDesktopWindowTreeHostWin (for Windows):
|
|
|
|
// - Extends DesktopWindowTreeHost.
|
|
|
|
// - References DesktopBrowserFrameAura, BrowserView, BrowserFrame.
|
|
|
|
// - Passed to Widget::Init() via Widget::InitParams::desktop_window_tree_host.
|
|
|
|
//
|
|
|
|
// CEF MODIFICATIONS
|
|
|
|
//
|
|
|
|
// The CEF Views integration uses an alternative approach of creating the
|
|
|
|
// ChromeBrowserFrame in CefWindowView::CreateWidget() and the
|
|
|
|
// ChromeBrowserView in CefBrowserViewImpl::CreateRootView().
|
|
|
|
// The object associations described above are then configured via
|
|
|
|
// ChromeBrowserView::AddedToWidget() and ChromeBrowserHostImpl::Create()
|
|
|
|
// after the BrowserView is added to the Widget. The Chromium code has been
|
|
|
|
// patched to allow later initialization of the Browser, BrowserFrame and
|
|
|
|
// BrowserView members to support this model.
|
|
|
|
//
|
|
|
|
// CEF does not use Chrome's NativeBrowserFrame (aka DesktopBrowserFrameAura),
|
|
|
|
// BrowserNonClientFrameView or BrowserRootView objects (all normally created by
|
|
|
|
// BrowserFrame during Widget initialization). Consequently
|
|
|
|
// |BrowserFrame::native_browser_frame_| and |BrowserFrame::browser_frame_view_|
|
|
|
|
// (sometimes retrieved via BrowserFrame::GetFrameView) will be nullptr and the
|
|
|
|
// Chromium code has been patched to add the necessary null checks.
|
|
|
|
//
|
|
|
|
// CEF does not pass ChromeBrowserView as the WidgetDelegate when the Widget is
|
|
|
|
// initialized in CefWindowView::CreateWidget(). Some of the WidgetDelegate
|
|
|
|
// callbacks may need to be routed from CefWindowView to ChromeBrowserView in
|
|
|
|
// the future.
|
|
|
|
//
|
|
|
|
// See the chrome_runtime_views.patch file for the complete set of related
|
|
|
|
// modifications.
|
|
|
|
|
|
|
|
class BrowserView;
|
2024-03-29 17:48:33 +01:00
|
|
|
class CefWindowView;
|
2021-02-18 02:58:25 +01:00
|
|
|
|
|
|
|
// Widget for a Views-hosted Chrome browser. Created in
|
|
|
|
// CefWindowView::CreateWidget() when the Chrome runtime is enabled.
|
2024-03-29 17:48:33 +01:00
|
|
|
class ChromeBrowserFrame : public BrowserFrame,
|
|
|
|
public CefWidget,
|
|
|
|
public CefColorProviderTracker::Observer {
|
2021-02-18 02:58:25 +01:00
|
|
|
public:
|
2024-03-29 17:48:33 +01:00
|
|
|
explicit ChromeBrowserFrame(CefWindowView* window_view);
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
ChromeBrowserFrame(const ChromeBrowserFrame&) = delete;
|
|
|
|
ChromeBrowserFrame& operator=(const ChromeBrowserFrame&) = delete;
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// Called from ChromeBrowserView::InitBrowser after |browser| creation.
|
2021-02-18 02:58:25 +01:00
|
|
|
void Init(BrowserView* browser_view, std::unique_ptr<Browser> browser);
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// CefWidget methods:
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsAlloyStyle() const override { return false; }
|
2024-03-29 17:48:33 +01:00
|
|
|
views::Widget* GetWidget() override { return this; }
|
|
|
|
const views::Widget* GetWidget() const override { return this; }
|
|
|
|
void Initialized() override;
|
|
|
|
bool IsInitialized() const override { return initialized_; }
|
|
|
|
void AddAssociatedProfile(Profile* profile) override;
|
|
|
|
void RemoveAssociatedProfile(Profile* profile) override;
|
|
|
|
Profile* GetThemeProfile() const override;
|
|
|
|
bool ToggleFullscreenMode() override;
|
|
|
|
|
|
|
|
// BrowserFrame methods:
|
|
|
|
void UserChangedTheme(BrowserThemeChangeType theme_change_type) override;
|
2023-09-25 21:40:17 +02:00
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
// views::Widget methods:
|
|
|
|
views::internal::RootView* CreateRootView() override;
|
|
|
|
std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView()
|
|
|
|
override;
|
2023-11-14 18:16:43 +01:00
|
|
|
void Activate() override;
|
2021-02-18 02:58:25 +01:00
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// NativeWidgetDelegate methods:
|
|
|
|
void OnNativeWidgetDestroyed() override;
|
|
|
|
|
|
|
|
// ui::NativeThemeObserver methods:
|
|
|
|
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
|
|
|
|
2023-09-25 21:40:17 +02:00
|
|
|
BrowserView* browser_view() const { return browser_view_; }
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
private:
|
2024-03-29 17:48:33 +01:00
|
|
|
// CefColorProviderTracker::Observer methods:
|
|
|
|
void OnColorProviderCacheResetMissed() override;
|
|
|
|
|
2024-04-15 03:34:45 +02:00
|
|
|
void NotifyThemeColorsChanged(bool chrome_theme);
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
CefWindowView* window_view_;
|
2023-09-25 21:40:17 +02:00
|
|
|
BrowserView* browser_view_ = nullptr;
|
2024-03-29 17:48:33 +01:00
|
|
|
|
|
|
|
bool initialized_ = false;
|
|
|
|
bool native_theme_change_ = false;
|
|
|
|
|
|
|
|
CefColorProviderTracker color_provider_tracker_{this};
|
2024-04-15 03:34:45 +02:00
|
|
|
|
|
|
|
base::WeakPtrFactory<ChromeBrowserFrame> weak_ptr_factory_{this};
|
2021-02-18 02:58:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
|