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