• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
6 #define CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
7 #pragma once
8 
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/views/frame/browser_frame.h"
11 
12 // An overview of the Chrome Browser object model is provided below. Object
13 // creation normally begins with a call to Browser::Create(CreateParams) which
14 // then creates the necessary Browser view, window and frame objects. CEF has
15 // modified the default object creation model are described below to better
16 // integrate with the existing CEF Views APIs.
17 //
18 // OVERVIEW
19 //
20 // Browser and BrowserWindow are the primary Chrome objects. Browser provides
21 // the concrete state and mutation methods while BrowserWindow is an interface
22 // implemented by the platform-specific "view" of the Browser window.
23 //
24 // Browser:
25 // - Creates a BrowserView (aka BrowserWindow) and BrowserFrame (aka Widget) via
26 //   a call to BrowserWindow::CreateBrowserWindow() in the Browser constructor.
27 //   - An existing BrowserWindow can alternately be specified via the
28 //     Browser::CreateParams::window parameter.
29 // - Owned by the BrowserView after creation.
30 //
31 // The Chrome Views implementation uses BrowserView to represent the browser
32 // client area and BrowserFrame (plus helpers) to represent the non-client
33 // window frame.
34 //
35 // BrowserView:
36 // - Extends BrowserWindow, views::ClientView, views::WidgetDelegate.
37 // - Owns the Browser.
38 // - References the BrowserFrame.
39 // - Passed to Widget::Init() via Widget::InitParams::delegate to receive
40 //   WidgetDelegate callbacks.
41 // - Extended by CEF as ChromeBrowserView.
42 // BrowserFrame:
43 // - Extends Widget (aka views::internal::NativeWidgetDelegate).
44 // - References the BrowserView.
45 // - Creates/owns a DesktopBrowserFrameAura (aka NativeBrowserFrame) via
46 //   BrowserFrame::InitBrowserFrame().
47 // - Extended by CEF as ChromeBrowserFrame.
48 //
49 // Chrome custom window/frame handling is implemented using platform-specific
50 // objects.
51 //
52 // DesktopBrowserFrameAura:
53 // - Extends NativeBrowserFrame, DesktopNativeWidgetAura.
54 // - Acts as a helper for BrowserFrame.
55 // - Creates/references a BrowserDesktopWindowTreeHostWin via
56 //   DesktopBrowserFrameAura::InitNativeWidget().
57 // BrowserDesktopWindowTreeHostWin (for Windows):
58 // - Extends DesktopWindowTreeHost.
59 // - References DesktopBrowserFrameAura, BrowserView, BrowserFrame.
60 // - Passed to Widget::Init() via Widget::InitParams::desktop_window_tree_host.
61 //
62 // CEF MODIFICATIONS
63 //
64 // The CEF Views integration uses an alternative approach of creating the
65 // ChromeBrowserFrame in CefWindowView::CreateWidget() and the
66 // ChromeBrowserView in CefBrowserViewImpl::CreateRootView().
67 // The object associations described above are then configured via
68 // ChromeBrowserView::AddedToWidget() and ChromeBrowserHostImpl::Create()
69 // after the BrowserView is added to the Widget. The Chromium code has been
70 // patched to allow later initialization of the Browser, BrowserFrame and
71 // BrowserView members to support this model.
72 //
73 // CEF does not use Chrome's NativeBrowserFrame (aka DesktopBrowserFrameAura),
74 // BrowserNonClientFrameView or BrowserRootView objects (all normally created by
75 // BrowserFrame during Widget initialization). Consequently
76 // |BrowserFrame::native_browser_frame_| and |BrowserFrame::browser_frame_view_|
77 // (sometimes retrieved via BrowserFrame::GetFrameView) will be nullptr and the
78 // Chromium code has been patched to add the necessary null checks.
79 //
80 // CEF does not pass ChromeBrowserView as the WidgetDelegate when the Widget is
81 // initialized in CefWindowView::CreateWidget(). Some of the WidgetDelegate
82 // callbacks may need to be routed from CefWindowView to ChromeBrowserView in
83 // the future.
84 //
85 // See the chrome_runtime_views.patch file for the complete set of related
86 // modifications.
87 
88 class BrowserView;
89 
90 // Widget for a Views-hosted Chrome browser. Created in
91 // CefWindowView::CreateWidget() when the Chrome runtime is enabled.
92 class ChromeBrowserFrame : public BrowserFrame {
93  public:
ChromeBrowserFrame()94   ChromeBrowserFrame() {}
95   ChromeBrowserFrame(const ChromeBrowserFrame&) = delete;
96   ChromeBrowserFrame& operator=(const ChromeBrowserFrame&) = delete;
97 
98   void Init(BrowserView* browser_view, std::unique_ptr<Browser> browser);
99 
100   // views::Widget methods:
101   views::internal::RootView* CreateRootView() override;
102   std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView()
103       override;
104 
105  private:
106   Browser* browser_ = nullptr;
107 };
108 
109 #endif  // CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
110