2015-01-27 01:03:25 +01:00
|
|
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_
|
|
|
|
#pragma once
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
#include <memory>
|
2017-08-04 00:55:19 +02:00
|
|
|
#include <set>
|
2015-01-27 01:03:25 +01:00
|
|
|
#include <string>
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "include/base/cef_callback_forward.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
#include "include/base/cef_ref_counted.h"
|
|
|
|
#include "include/cef_browser.h"
|
2023-11-29 02:33:44 +01:00
|
|
|
#include "include/cef_command_line.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "include/views/cef_window.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/client_types.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "tests/cefclient/browser/image_cache.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
enum class WindowType {
|
|
|
|
NORMAL,
|
|
|
|
|
|
|
|
// The window is a modal dialog.
|
|
|
|
DIALOG,
|
2023-11-14 18:16:43 +01:00
|
|
|
|
|
|
|
// The window is a DevTools popup.
|
|
|
|
DEVTOOLS,
|
2023-06-14 10:20:02 +02:00
|
|
|
};
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Used to configure how a RootWindow is created.
|
|
|
|
struct RootWindowConfig {
|
2023-12-05 00:45:54 +01:00
|
|
|
// |command_line| will be non-nullptr when used for new window creation via
|
|
|
|
// OnAlreadyRunningAppRelaunch. Otherwise, the global command-line will be
|
|
|
|
// used.
|
2024-01-20 03:22:56 +01:00
|
|
|
explicit RootWindowConfig(CefRefPtr<CefCommandLine> command_line = nullptr);
|
2023-11-29 02:33:44 +01:00
|
|
|
|
|
|
|
// Associated command-line.
|
|
|
|
CefRefPtr<CefCommandLine> command_line;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// If true the Views framework will be used.
|
|
|
|
bool use_views;
|
|
|
|
|
2024-06-26 02:12:37 +02:00
|
|
|
// If true Alloy style will be used. Alloy style is optional. Windowless
|
2024-04-17 18:01:26 +02:00
|
|
|
// rendering requires Alloy style.
|
|
|
|
bool use_alloy_style;
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
// Configure the window type.
|
|
|
|
WindowType window_type = WindowType::NORMAL;
|
|
|
|
|
2018-02-28 05:47:36 +01:00
|
|
|
// If true the window will always display above other windows.
|
2022-10-28 20:17:18 +02:00
|
|
|
bool always_on_top = false;
|
2018-02-28 05:47:36 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// If true the window will show controls.
|
2022-10-28 20:17:18 +02:00
|
|
|
bool with_controls = true;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// If true the window will use windowless (off-screen) rendering.
|
2022-10-28 20:17:18 +02:00
|
|
|
bool with_osr = false;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// If true the window will be created initially hidden.
|
2022-10-28 20:17:18 +02:00
|
|
|
bool initially_hidden = false;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// Requested window position. If |bounds| and |source_bounds| are empty the
|
|
|
|
// default window size and location will be used.
|
|
|
|
CefRect bounds;
|
|
|
|
|
|
|
|
// Position of the UI element that triggered the window creation. If |bounds|
|
|
|
|
// is empty and |source_bounds| is non-empty the new window will be positioned
|
|
|
|
// relative to |source_bounds|. This is currently only implemented for Views-
|
2023-11-29 02:33:44 +01:00
|
|
|
// hosted windows when |initially_hidden| is also true.
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRect source_bounds;
|
|
|
|
|
2022-11-07 21:21:44 +01:00
|
|
|
// Requested window show state. Only used when |bounds| is non-empty and
|
|
|
|
// |initially_hidden| is false.
|
2022-10-28 20:17:18 +02:00
|
|
|
cef_show_state_t show_state = CEF_SHOW_STATE_NORMAL;
|
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
// Parent window. Only used for Views-hosted windows.
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefWindow> parent_window;
|
|
|
|
|
|
|
|
// Callback to be executed when the window is closed. Will be executed on the
|
2023-11-29 02:33:44 +01:00
|
|
|
// main thread. This is currently only implemented for Views-hosted windows.
|
2021-06-19 21:54:45 +02:00
|
|
|
base::OnceClosure close_callback;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// Initial URL to load.
|
|
|
|
std::string url;
|
|
|
|
};
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Represents a top-level native window in the browser process. While references
|
|
|
|
// to this object are thread-safe the methods must be called on the main thread
|
|
|
|
// unless otherwise indicated.
|
2017-05-17 11:29:28 +02:00
|
|
|
class RootWindow
|
|
|
|
: public base::RefCountedThreadSafe<RootWindow, DeleteOnMainThread> {
|
2015-01-27 01:03:25 +01:00
|
|
|
public:
|
|
|
|
// This interface is implemented by the owner of the RootWindow. The methods
|
|
|
|
// of this class will be called on the main thread.
|
|
|
|
class Delegate {
|
|
|
|
public:
|
2024-02-08 22:29:17 +01:00
|
|
|
// Called to synchronously retrieve the CefRequestContext for browser. Only
|
2024-06-26 02:12:37 +02:00
|
|
|
// called for non-popup browsers. Must be called on the main thread. This
|
|
|
|
// method is only safe when using the global request context.
|
2024-02-08 22:29:17 +01:00
|
|
|
// TODO: Delete this method and use the async version instead.
|
|
|
|
virtual CefRefPtr<CefRequestContext> GetRequestContext() = 0;
|
|
|
|
|
|
|
|
using RequestContextCallback =
|
|
|
|
base::OnceCallback<void(CefRefPtr<CefRequestContext>)>;
|
|
|
|
|
|
|
|
// Called to asynchronously retrieve the CefRequestContext for browser. Only
|
|
|
|
// called for non-popup browsers. Save to call on any thread. |callback|
|
|
|
|
// will be executed on the UI thread after the request context is
|
|
|
|
// initialized.
|
|
|
|
virtual void GetRequestContext(RequestContextCallback callback) = 0;
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Returns the ImageCache.
|
|
|
|
virtual scoped_refptr<ImageCache> GetImageCache() = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Called to execute a test. See resource.h for |test_id| values.
|
|
|
|
virtual void OnTest(RootWindow* root_window, int test_id) = 0;
|
|
|
|
|
|
|
|
// Called to exit the application.
|
|
|
|
virtual void OnExit(RootWindow* root_window) = 0;
|
|
|
|
|
|
|
|
// Called when the RootWindow has been destroyed.
|
|
|
|
virtual void OnRootWindowDestroyed(RootWindow* root_window) = 0;
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Called when the RootWindow is activated (becomes the foreground window).
|
|
|
|
virtual void OnRootWindowActivated(RootWindow* root_window) = 0;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
protected:
|
2024-01-20 03:22:56 +01:00
|
|
|
virtual ~Delegate() = default;
|
2015-01-27 01:03:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create a new RootWindow object. This method may be called on any thread.
|
|
|
|
// Use RootWindowManager::CreateRootWindow() or CreateRootWindowAsPopup()
|
2016-01-19 21:09:01 +01:00
|
|
|
// instead of calling this method directly. |use_views| will be true if the
|
2024-04-17 18:01:26 +02:00
|
|
|
// Views framework should be used. |use_alloy_style| will be true if Alloy
|
|
|
|
// style should be used.
|
|
|
|
static scoped_refptr<RootWindow> Create(bool use_views, bool use_alloy_style);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
// Returns the RootWindow associated with the specified |browser_id|. Must be
|
|
|
|
// called on the main thread.
|
|
|
|
static scoped_refptr<RootWindow> GetForBrowser(int browser_id);
|
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
// Returns true if the RootWindow is Views-hosted.
|
|
|
|
virtual bool IsViewsHosted() const { return false; }
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Returns true if the RootWindow is Alloy style, otherwise Chrome style.
|
|
|
|
bool IsAlloyStyle() const { return use_alloy_style_; }
|
|
|
|
|
2015-02-03 00:18:16 +01:00
|
|
|
// Initialize as a normal window. This will create and show a native window
|
|
|
|
// hosting a single browser instance. This method may be called on any thread.
|
2021-06-17 22:08:01 +02:00
|
|
|
// |delegate| must be non-nullptr and outlive this object.
|
2015-01-27 01:03:25 +01:00
|
|
|
// Use RootWindowManager::CreateRootWindow() instead of calling this method
|
|
|
|
// directly.
|
|
|
|
virtual void Init(RootWindow::Delegate* delegate,
|
2021-06-19 21:54:45 +02:00
|
|
|
std::unique_ptr<RootWindowConfig> config,
|
2017-08-04 00:55:19 +02:00
|
|
|
const CefBrowserSettings& settings) = 0;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2015-02-03 00:18:16 +01:00
|
|
|
// Initialize as a popup window. This is used to attach a new native window to
|
|
|
|
// a single browser instance that will be created later. The native window
|
|
|
|
// will be created and shown once the browser is available. This method may be
|
2021-06-17 22:08:01 +02:00
|
|
|
// called on any thread. |delegate| must be non-nullptr and outlive this
|
|
|
|
// object. Use RootWindowManager::CreateRootWindowAsPopup() instead of calling
|
|
|
|
// this method directly. Called on the UI thread.
|
2015-01-27 01:03:25 +01:00
|
|
|
virtual void InitAsPopup(RootWindow::Delegate* delegate,
|
|
|
|
bool with_controls,
|
|
|
|
bool with_osr,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) = 0;
|
|
|
|
|
|
|
|
enum ShowMode {
|
|
|
|
ShowNormal,
|
|
|
|
ShowMinimized,
|
|
|
|
ShowMaximized,
|
2019-02-07 22:36:31 +01:00
|
|
|
ShowNoActivate,
|
2015-01-27 01:03:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Show the window.
|
|
|
|
virtual void Show(ShowMode mode) = 0;
|
|
|
|
|
|
|
|
// Hide the window.
|
|
|
|
virtual void Hide() = 0;
|
|
|
|
|
|
|
|
// Set the window bounds in screen coordinates.
|
|
|
|
virtual void SetBounds(int x, int y, size_t width, size_t height) = 0;
|
|
|
|
|
|
|
|
// Close the window. If |force| is true onunload handlers will not be
|
|
|
|
// executed.
|
|
|
|
virtual void Close(bool force) = 0;
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Set the device scale factor. Only used in combination with off-screen
|
|
|
|
// rendering.
|
|
|
|
virtual void SetDeviceScaleFactor(float device_scale_factor) = 0;
|
|
|
|
|
|
|
|
// Returns the device scale factor. Only used in combination with off-screen
|
|
|
|
// rendering.
|
|
|
|
virtual float GetDeviceScaleFactor() const = 0;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Returns the browser that this window contains, if any.
|
|
|
|
virtual CefRefPtr<CefBrowser> GetBrowser() const = 0;
|
|
|
|
|
2015-02-03 00:18:16 +01:00
|
|
|
// Returns the native handle for this window, if any.
|
2015-01-29 21:53:53 +01:00
|
|
|
virtual ClientWindowHandle GetWindowHandle() const = 0;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Returns true if this window is using windowless rendering (osr).
|
|
|
|
virtual bool WithWindowlessRendering() const = 0;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
protected:
|
|
|
|
// Allow deletion via scoped_refptr only.
|
|
|
|
friend struct DeleteOnMainThread;
|
|
|
|
friend class base::RefCountedThreadSafe<RootWindow, DeleteOnMainThread>;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
explicit RootWindow(bool use_alloy_style);
|
2017-08-04 00:55:19 +02:00
|
|
|
virtual ~RootWindow();
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
Delegate* delegate_ = nullptr;
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const bool use_alloy_style_;
|
2015-01-27 01:03:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace client
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_
|