1 // Copyright (c) 2015 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_BROWSER_WINDOW_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_H_ 7 #pragma once 8 9 #include <memory> 10 11 #include "include/cef_browser.h" 12 #include "tests/cefclient/browser/client_handler.h" 13 #include "tests/cefclient/browser/client_types.h" 14 15 namespace client { 16 17 // Represents a native child window hosting a single browser instance. The 18 // methods of this class must be called on the main thread unless otherwise 19 // indicated. 20 class BrowserWindow : public ClientHandler::Delegate { 21 public: 22 // This interface is implemented by the owner of the BrowserWindow. The 23 // methods of this class will be called on the main thread. 24 class Delegate { 25 public: 26 // Called when the browser has been created. 27 virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) = 0; 28 29 // Called when the BrowserWindow is closing. OnBrowserWindowClosing()30 virtual void OnBrowserWindowClosing() {} 31 32 // Called when the BrowserWindow has been destroyed. 33 virtual void OnBrowserWindowDestroyed() = 0; 34 35 // Set the window URL address. 36 virtual void OnSetAddress(const std::string& url) = 0; 37 38 // Set the window title. 39 virtual void OnSetTitle(const std::string& title) = 0; 40 41 // Set fullscreen mode. 42 virtual void OnSetFullscreen(bool fullscreen) = 0; 43 44 // Auto-resize contents. 45 virtual void OnAutoResize(const CefSize& new_size) = 0; 46 47 // Set the loading state. 48 virtual void OnSetLoadingState(bool isLoading, 49 bool canGoBack, 50 bool canGoForward) = 0; 51 52 // Set the draggable regions. 53 virtual void OnSetDraggableRegions( 54 const std::vector<CefDraggableRegion>& regions) = 0; 55 56 protected: ~Delegate()57 virtual ~Delegate() {} 58 }; 59 60 // Create a new browser and native window. 61 virtual void CreateBrowser(ClientWindowHandle parent_handle, 62 const CefRect& rect, 63 const CefBrowserSettings& settings, 64 CefRefPtr<CefDictionaryValue> extra_info, 65 CefRefPtr<CefRequestContext> request_context) = 0; 66 67 // Retrieve the configuration that will be used when creating a popup window. 68 // The popup browser will initially be parented to |temp_handle| which should 69 // be a pre-existing hidden window. The native window will be created later 70 // after the browser has been created. This method will be called on the 71 // browser process UI thread. 72 virtual void GetPopupConfig(CefWindowHandle temp_handle, 73 CefWindowInfo& windowInfo, 74 CefRefPtr<CefClient>& client, 75 CefBrowserSettings& settings) = 0; 76 77 // Show the popup window with correct parent and bounds in parent coordinates. 78 virtual void ShowPopup(ClientWindowHandle parent_handle, 79 int x, 80 int y, 81 size_t width, 82 size_t height) = 0; 83 84 // Show the window. 85 virtual void Show() = 0; 86 87 // Hide the window. 88 virtual void Hide() = 0; 89 90 // Set the window bounds in parent coordinates. 91 virtual void SetBounds(int x, int y, size_t width, size_t height) = 0; 92 93 // Set focus to the window. 94 virtual void SetFocus(bool focus) = 0; 95 96 // Set the device scale factor. Only used in combination with off-screen 97 // rendering. 98 virtual void SetDeviceScaleFactor(float device_scale_factor); 99 100 // Returns the device scale factor. Only used in combination with off-screen 101 // rendering. 102 virtual float GetDeviceScaleFactor() const; 103 104 // Returns the window handle. 105 virtual ClientWindowHandle GetWindowHandle() const = 0; 106 107 // Returns the browser owned by the window. 108 CefRefPtr<CefBrowser> GetBrowser() const; 109 110 // Returns true if the browser is closing. 111 bool IsClosing() const; 112 113 protected: 114 // Allow deletion via std::unique_ptr only. 115 friend std::default_delete<BrowserWindow>; 116 117 // Constructor may be called on any thread. 118 // |delegate| must outlive this object. 119 explicit BrowserWindow(Delegate* delegate); 120 121 // ClientHandler::Delegate methods. 122 void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override; 123 void OnBrowserClosing(CefRefPtr<CefBrowser> browser) override; 124 void OnBrowserClosed(CefRefPtr<CefBrowser> browser) override; 125 void OnSetAddress(const std::string& url) override; 126 void OnSetTitle(const std::string& title) override; 127 void OnSetFullscreen(bool fullscreen) override; 128 void OnAutoResize(const CefSize& new_size) override; 129 void OnSetLoadingState(bool isLoading, 130 bool canGoBack, 131 bool canGoForward) override; 132 void OnSetDraggableRegions( 133 const std::vector<CefDraggableRegion>& regions) override; 134 135 Delegate* delegate_; 136 CefRefPtr<CefBrowser> browser_; 137 CefRefPtr<ClientHandler> client_handler_; 138 bool is_closing_; 139 140 private: 141 DISALLOW_COPY_AND_ASSIGN(BrowserWindow); 142 }; 143 144 } // namespace client 145 146 #endif // CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_H_ 147