• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_VIEWS_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_VIEWS_H_
7 #pragma once
8 
9 #include <memory>
10 #include <string>
11 
12 #include "tests/cefclient/browser/client_handler.h"
13 #include "tests/cefclient/browser/root_window.h"
14 #include "tests/cefclient/browser/views_window.h"
15 
16 namespace client {
17 
18 // Views framework implementation of a top-level window in the browser process.
19 // The methods of this class must be called on the main thread unless otherwise
20 // indicated.
21 class RootWindowViews : public RootWindow,
22                         public ClientHandler::Delegate,
23                         public ViewsWindow::Delegate {
24  public:
25   // Constructor may be called on any thread.
26   RootWindowViews();
27   ~RootWindowViews();
28 
29   // RootWindow methods:
30   void Init(RootWindow::Delegate* delegate,
31             std::unique_ptr<RootWindowConfig> config,
32             const CefBrowserSettings& settings) override;
33   void InitAsPopup(RootWindow::Delegate* delegate,
34                    bool with_controls,
35                    bool with_osr,
36                    const CefPopupFeatures& popupFeatures,
37                    CefWindowInfo& windowInfo,
38                    CefRefPtr<CefClient>& client,
39                    CefBrowserSettings& settings) override;
40   void Show(ShowMode mode) override;
41   void Hide() override;
42   void SetBounds(int x, int y, size_t width, size_t height) override;
43   void Close(bool force) override;
44   void SetDeviceScaleFactor(float device_scale_factor) override;
45   float GetDeviceScaleFactor() const override;
46   CefRefPtr<CefBrowser> GetBrowser() const override;
47   ClientWindowHandle GetWindowHandle() const override;
WithWindowlessRendering()48   bool WithWindowlessRendering() const override { return false; }
49   bool WithExtension() const override;
50   void OnExtensionsChanged(const ExtensionSet& extensions) override;
51 
52   // ViewsWindow::Delegate methods:
53   bool WithControls() override;
54   bool WithExtension() override;
55   bool InitiallyHidden() override;
56   CefRefPtr<CefWindow> GetParentWindow() override;
57   CefRect GetWindowBounds() override;
58   scoped_refptr<ImageCache> GetImageCache() override;
59   void OnViewsWindowCreated(CefRefPtr<ViewsWindow> window) override;
60   void OnViewsWindowDestroyed(CefRefPtr<ViewsWindow> window) override;
61   void OnViewsWindowActivated(CefRefPtr<ViewsWindow> window) override;
62   ViewsWindow::Delegate* GetDelegateForPopup(
63       CefRefPtr<CefClient> client) override;
64   void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
65                              const CefRect& source_bounds,
66                              CefRefPtr<CefWindow> parent_window,
67                              base::OnceClosure close_callback) override;
68   void OnTest(int test_id) override;
69   void OnExit() override;
70 
71  protected:
72   // ClientHandler::Delegate methods:
73   void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override;
74   void OnBrowserClosing(CefRefPtr<CefBrowser> browser) override;
75   void OnBrowserClosed(CefRefPtr<CefBrowser> browser) override;
76   void OnSetAddress(const std::string& url) override;
77   void OnSetTitle(const std::string& title) override;
78   void OnSetFavicon(CefRefPtr<CefImage> image) override;
79   void OnSetFullscreen(bool fullscreen) override;
80   void OnAutoResize(const CefSize& new_size) override;
81   void OnSetLoadingState(bool isLoading,
82                          bool canGoBack,
83                          bool canGoForward) override;
84   void OnSetDraggableRegions(
85       const std::vector<CefDraggableRegion>& regions) override;
86   void OnTakeFocus(bool next) override;
87   void OnBeforeContextMenu(CefRefPtr<CefMenuModel> model) override;
88 
89  private:
90   void CreateClientHandler(const std::string& url);
91 
92   void InitOnUIThread(const CefBrowserSettings& settings,
93                       const std::string& startup_url,
94                       CefRefPtr<CefRequestContext> request_context);
95   void CreateViewsWindow(const CefBrowserSettings& settings,
96                          const std::string& startup_url,
97                          CefRefPtr<CefRequestContext> request_context,
98                          const ImageCache::ImageSet& images);
99 
100   void NotifyViewsWindowDestroyed();
101   void NotifyViewsWindowActivated();
102   void NotifyDestroyedIfDone();
103 
104   // After initialization all members are only accessed on the main thread
105   // unless otherwise indicated.
106   // Members set during initialization.
107   std::unique_ptr<RootWindowConfig> config_;
108   bool is_popup_ = false;
109   CefRect initial_bounds_;
110   bool position_on_resize_ = false;
111   CefRefPtr<ClientHandler> client_handler_;
112 
113   bool initialized_ = false;
114   bool window_destroyed_ = false;
115   bool browser_destroyed_ = false;
116 
117   CefRefPtr<CefBrowser> browser_;
118 
119   // Only accessed on the browser process UI thread.
120   CefRefPtr<ViewsWindow> window_;
121   ExtensionSet pending_extensions_;
122   scoped_refptr<ImageCache> image_cache_;
123 
124   DISALLOW_COPY_AND_ASSIGN(RootWindowViews);
125 };
126 
127 }  // namespace client
128 
129 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_VIEWS_H_
130