• 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 <string>
10 
11 #include "include/base/cef_scoped_ptr.h"
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             const 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                              const base::Closure& 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   bool with_controls_;
108   bool always_on_top_;
109   bool with_extension_;
110   bool initially_hidden_;
111   CefRefPtr<CefWindow> parent_window_;
112   bool is_popup_;
113   CefRect initial_bounds_;
114   base::Closure close_callback_;
115   bool position_on_resize_;
116   CefRefPtr<ClientHandler> client_handler_;
117 
118   bool initialized_;
119   bool window_destroyed_;
120   bool browser_destroyed_;
121 
122   CefRefPtr<CefBrowser> browser_;
123 
124   // Only accessed on the browser process UI thread.
125   CefRefPtr<ViewsWindow> window_;
126   ExtensionSet pending_extensions_;
127   scoped_refptr<ImageCache> image_cache_;
128 
129   DISALLOW_COPY_AND_ASSIGN(RootWindowViews);
130 };
131 
132 }  // namespace client
133 
134 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_VIEWS_H_
135