• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_VIEWS_BROWSER_VIEW_IMPL_H_
6 #define CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
7 #pragma once
8 
9 #include "include/cef_client.h"
10 #include "include/views/cef_browser_view.h"
11 #include "include/views/cef_browser_view_delegate.h"
12 #include "libcef/browser/browser_host_base.h"
13 #include "libcef/browser/views/browser_view_view.h"
14 #include "libcef/browser/views/view_impl.h"
15 
16 #include "base/callback_forward.h"
17 #include "base/memory/weak_ptr.h"
18 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
19 
20 class CefBrowserHostBase;
21 
22 class CefBrowserViewImpl
23     : public CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>,
24       public CefBrowserViewView::Delegate {
25  public:
26   using ParentClass =
27       CefViewImpl<views::View, CefBrowserView, CefBrowserViewDelegate>;
28 
29   CefBrowserViewImpl(const CefBrowserViewImpl&) = delete;
30   CefBrowserViewImpl& operator=(const CefBrowserViewImpl&) = delete;
31 
32   // Create a new CefBrowserView instance. |delegate| may be nullptr.
33   static CefRefPtr<CefBrowserViewImpl> Create(
34       CefRefPtr<CefClient> client,
35       const CefString& url,
36       const CefBrowserSettings& settings,
37       CefRefPtr<CefDictionaryValue> extra_info,
38       CefRefPtr<CefRequestContext> request_context,
39       CefRefPtr<CefBrowserViewDelegate> delegate);
40 
41   // Create a new CefBrowserView instance for a popup. |delegate| may be
42   // nullptr.
43   static CefRefPtr<CefBrowserViewImpl> CreateForPopup(
44       const CefBrowserSettings& settings,
45       CefRefPtr<CefBrowserViewDelegate> delegate);
46 
47   // Called from CefBrowserPlatformDelegateViews.
48   void WebContentsCreated(content::WebContents* web_contents);
49   void BrowserCreated(CefBrowserHostBase* browser,
50                       base::RepeatingClosure on_bounds_changed);
51   void BrowserDestroyed(CefBrowserHostBase* browser);
52 
53   // Called to handle accelerators when the event is unhandled by the web
54   // content and the browser client.
55   bool HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event);
56 
57   // CefBrowserView methods:
58   CefRefPtr<CefBrowser> GetBrowser() override;
59   CefRefPtr<CefView> GetChromeToolbar() override;
60   void SetPreferAccelerators(bool prefer_accelerators) override;
61 
62   // CefView methods:
AsBrowserView()63   CefRefPtr<CefBrowserView> AsBrowserView() override { return this; }
64   void RequestFocus() override;
65   void SetBackgroundColor(cef_color_t color) override;
66 
67   // CefViewAdapter methods:
68   void Detach() override;
GetDebugType()69   std::string GetDebugType() override { return "BrowserView"; }
70   void GetDebugInfo(base::DictionaryValue* info,
71                     bool include_children) override;
72 
73   // CefBrowserViewView::Delegate methods:
74   void OnBrowserViewAdded() override;
75   void OnBoundsChanged() override;
76 
77   // Return the WebView representation of this object.
78   views::WebView* web_view() const;
79 
80  private:
81   // Create a new implementation object.
82   // Always call Initialize() after creation.
83   // |delegate| may be nullptr.
84   explicit CefBrowserViewImpl(CefRefPtr<CefBrowserViewDelegate> delegate);
85 
86   void SetPendingBrowserCreateParams(
87       CefRefPtr<CefClient> client,
88       const CefString& url,
89       const CefBrowserSettings& settings,
90       CefRefPtr<CefDictionaryValue> extra_info,
91       CefRefPtr<CefRequestContext> request_context);
92 
93   void SetDefaults(const CefBrowserSettings& settings);
94 
95   // CefViewImpl methods:
96   views::View* CreateRootView() override;
97   void InitializeRootView() override;
98 
99   // Logic extracted from UnhandledKeyboardEventHandler::HandleKeyboardEvent for
100   // the handling of accelerators. Returns true if the event was handled by the
101   // accelerator.
102   bool HandleAccelerator(const content::NativeWebKeyboardEvent& event,
103                          views::FocusManager* focus_manager);
104 
105   void RequestFocusInternal();
106 
107   std::unique_ptr<CefBrowserCreateParams> pending_browser_create_params_;
108 
109   CefRefPtr<CefBrowserHostBase> browser_;
110 
111   views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
112   bool ignore_next_char_event_ = false;
113 
114   base::RepeatingClosure on_bounds_changed_;
115 
116   base::WeakPtrFactory<CefBrowserViewImpl> weak_ptr_factory_;
117 
118   IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefBrowserViewImpl);
119 };
120 
121 #endif  // CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_
122