2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2016 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.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/root_window_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/base/cef_build.h"
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/cef_app.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/client_handler_std.h"
|
2022-10-28 20:17:18 +02:00
|
|
|
#include "tests/cefclient/browser/client_prefs.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Images that are loaded early and cached.
|
|
|
|
static const char* kDefaultImageCache[] = {"menu_icon", "window_icon"};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
RootWindowViews::RootWindowViews() = default;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
RootWindowViews::~RootWindowViews() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
}
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
void RootWindowViews::SetTitlebarHeight(const std::optional<float>& height) {
|
|
|
|
if (window_) {
|
|
|
|
window_->SetTitlebarHeight(height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::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) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(delegate);
|
2021-06-19 21:54:45 +02:00
|
|
|
DCHECK(!config->with_osr); // Windowless rendering is not supported.
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(!initialized_);
|
|
|
|
|
|
|
|
delegate_ = delegate;
|
2021-06-19 21:54:45 +02:00
|
|
|
config_ = std::move(config);
|
|
|
|
|
|
|
|
CreateClientHandler(config_->url);
|
2016-01-19 21:09:01 +01:00
|
|
|
initialized_ = true;
|
|
|
|
|
2019-11-18 21:02:39 +01:00
|
|
|
// Continue initialization on the UI thread.
|
2022-10-28 20:17:18 +02:00
|
|
|
InitOnUIThread(settings, delegate_->GetRequestContext(this));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
|
|
|
|
bool with_controls,
|
|
|
|
bool with_osr,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(delegate);
|
|
|
|
DCHECK(!with_osr); // Windowless rendering is not supported.
|
|
|
|
DCHECK(!initialized_);
|
|
|
|
|
|
|
|
delegate_ = delegate;
|
2021-06-19 21:54:45 +02:00
|
|
|
config_ = std::make_unique<RootWindowConfig>();
|
|
|
|
config_->with_controls = with_controls;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (popupFeatures.xSet) {
|
2016-01-19 21:09:01 +01:00
|
|
|
initial_bounds_.x = popupFeatures.x;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (popupFeatures.ySet) {
|
2016-01-19 21:09:01 +01:00
|
|
|
initial_bounds_.y = popupFeatures.y;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (popupFeatures.widthSet) {
|
2016-01-19 21:09:01 +01:00
|
|
|
initial_bounds_.width = popupFeatures.width;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (popupFeatures.heightSet) {
|
2016-01-19 21:09:01 +01:00
|
|
|
initial_bounds_.height = popupFeatures.height;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CreateClientHandler(std::string());
|
|
|
|
initialized_ = true;
|
|
|
|
|
|
|
|
// The Window will be created in ViewsWindow::OnPopupBrowserViewCreated().
|
|
|
|
client = client_handler_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::Show(ShowMode mode) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Show, this, mode));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
window_->Show();
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case ShowMinimized:
|
|
|
|
window_->Minimize();
|
|
|
|
break;
|
|
|
|
case ShowMaximized:
|
|
|
|
window_->Maximize();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::Hide() {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Hide, this));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->Hide();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::SetBounds, this, x, y,
|
|
|
|
width, height));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_) {
|
|
|
|
window_->SetBounds(
|
|
|
|
CefRect(x, y, static_cast<int>(width), static_cast<int>(height)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::Close(bool force) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Close, this, force));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->Close(force);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::SetDeviceScaleFactor(float device_scale_factor) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
// Windowless rendering is not supported.
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
float RootWindowViews::GetDeviceScaleFactor() const {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
// Windowless rendering is not supported.
|
|
|
|
NOTREACHED();
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> RootWindowViews::GetBrowser() const {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
return browser_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientWindowHandle RootWindowViews::GetWindowHandle() const {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// ClientWindowHandle is a GtkWidget* on Linux and we don't have one of those.
|
2021-06-17 22:08:01 +02:00
|
|
|
return nullptr;
|
2016-01-19 21:09:01 +01:00
|
|
|
#else
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return browser_->GetHost()->GetWindowHandle();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return kNullWindowHandle;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool RootWindowViews::WithExtension() const {
|
2019-11-18 21:02:39 +01:00
|
|
|
DCHECK(initialized_);
|
2021-06-19 21:54:45 +02:00
|
|
|
return config_->with_extension;
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
bool RootWindowViews::WithControls() {
|
2019-11-18 21:02:39 +01:00
|
|
|
DCHECK(initialized_);
|
2021-06-19 21:54:45 +02:00
|
|
|
return config_->with_controls;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool RootWindowViews::WithExtension() {
|
2019-11-18 21:02:39 +01:00
|
|
|
DCHECK(initialized_);
|
2021-06-19 21:54:45 +02:00
|
|
|
return config_->with_extension;
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnExtensionsChanged(const ExtensionSet& extensions) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnExtensionsChanged,
|
|
|
|
this, extensions));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_) {
|
|
|
|
window_->OnExtensionsChanged(extensions);
|
|
|
|
} else {
|
|
|
|
// Window may not exist yet for popups.
|
|
|
|
pending_extensions_ = extensions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RootWindowViews::InitiallyHidden() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2021-06-19 21:54:45 +02:00
|
|
|
return config_->initially_hidden;
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefWindow> RootWindowViews::GetParentWindow() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2021-06-19 21:54:45 +02:00
|
|
|
return config_->parent_window;
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
CefRect RootWindowViews::GetInitialBounds() {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return initial_bounds_;
|
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
cef_show_state_t RootWindowViews::GetInitialShowState() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return initial_show_state_;
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
scoped_refptr<ImageCache> RootWindowViews::GetImageCache() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return image_cache_;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::OnViewsWindowCreated(CefRefPtr<ViewsWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(!window_);
|
|
|
|
window_ = window;
|
2021-06-19 21:54:45 +02:00
|
|
|
window_->SetAlwaysOnTop(config_->always_on_top);
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
if (!pending_extensions_.empty()) {
|
|
|
|
window_->OnExtensionsChanged(pending_extensions_);
|
|
|
|
pending_extensions_.clear();
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
void RootWindowViews::OnViewsWindowClosing(CefRefPtr<ViewsWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(window_);
|
|
|
|
|
|
|
|
cef_show_state_t show_state;
|
|
|
|
std::optional<CefRect> dip_bounds;
|
|
|
|
if (window_->GetWindowRestorePreferences(show_state, dip_bounds)) {
|
|
|
|
prefs::SaveWindowRestorePreferences(show_state, dip_bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::OnViewsWindowDestroyed(CefRefPtr<ViewsWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2020-01-15 15:28:12 +01:00
|
|
|
window_ = nullptr;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Continue on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&RootWindowViews::NotifyViewsWindowDestroyed, this));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void RootWindowViews::OnViewsWindowActivated(CefRefPtr<ViewsWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Continue on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&RootWindowViews::NotifyViewsWindowActivated, this));
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
ViewsWindow::Delegate* RootWindowViews::GetDelegateForPopup(
|
|
|
|
CefRefPtr<CefClient> client) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
// |handler| was created in RootWindowViews::InitAsPopup().
|
|
|
|
ClientHandlerStd* handler = static_cast<ClientHandlerStd*>(client.get());
|
|
|
|
RootWindowViews* root_window =
|
|
|
|
static_cast<RootWindowViews*>(handler->delegate());
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2022-04-11 22:54:33 +02:00
|
|
|
// May be nullptr when using the default popup behavior.
|
|
|
|
if (root_window) {
|
|
|
|
// Transfer some state to the child RootWindowViews.
|
|
|
|
root_window->image_cache_ = image_cache_;
|
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
return root_window;
|
|
|
|
}
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
void RootWindowViews::CreateExtensionWindow(CefRefPtr<CefExtension> extension,
|
|
|
|
const CefRect& source_bounds,
|
|
|
|
CefRefPtr<CefWindow> parent_window,
|
|
|
|
base::OnceClosure close_callback) {
|
2017-08-04 00:55:19 +02:00
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::CreateExtensionWindow,
|
|
|
|
this, extension, source_bounds,
|
|
|
|
parent_window, std::move(close_callback)));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate_->CreateExtensionWindow(extension, source_bounds, parent_window,
|
2021-06-19 21:54:45 +02:00
|
|
|
std::move(close_callback), false);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::OnTest(int test_id) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::OnTest, this, test_id));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate_->OnTest(this, test_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnExit() {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::OnExit, this));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate_->OnExit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
DCHECK(!browser_);
|
|
|
|
browser_ = browser;
|
2017-08-04 00:55:19 +02:00
|
|
|
delegate_->OnBrowserCreated(this, browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnBrowserClosing(CefRefPtr<CefBrowser> browser) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (browser_) {
|
|
|
|
DCHECK_EQ(browser->GetIdentifier(), browser_->GetIdentifier());
|
2020-01-15 15:28:12 +01:00
|
|
|
browser_ = nullptr;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
client_handler_->DetachDelegate();
|
2020-01-15 15:28:12 +01:00
|
|
|
client_handler_ = nullptr;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
browser_destroyed_ = true;
|
|
|
|
NotifyDestroyedIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnSetAddress(const std::string& url) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&RootWindowViews::OnSetAddress, this, url));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetAddress(url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnSetTitle(const std::string& title) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&RootWindowViews::OnSetTitle, this, title));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetTitle(title);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnSetFavicon(CefRefPtr<CefImage> image) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&RootWindowViews::OnSetFavicon, this, image));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetFavicon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnSetFullscreen(bool fullscreen) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnSetFullscreen, this,
|
|
|
|
fullscreen));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetFullscreen(fullscreen);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void RootWindowViews::OnAutoResize(const CefSize& new_size) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&RootWindowViews::OnAutoResize, this, new_size));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_position = false;
|
|
|
|
CefPoint position;
|
|
|
|
if (position_on_resize_) {
|
|
|
|
// Position the window centered on and immediately below the source.
|
|
|
|
const int x_offset = (initial_bounds_.width - new_size.width) / 2;
|
|
|
|
position.Set(initial_bounds_.x + x_offset,
|
|
|
|
initial_bounds_.y + initial_bounds_.height);
|
|
|
|
has_position = true;
|
|
|
|
|
|
|
|
// Don't change the window position on future resizes.
|
|
|
|
position_on_resize_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_) {
|
|
|
|
window_->SetBrowserSize(new_size, has_position, position);
|
|
|
|
window_->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::OnSetLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&RootWindowViews::OnSetLoadingState, this,
|
|
|
|
isLoading, canGoBack, canGoForward));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_) {
|
2021-08-28 03:55:15 +02:00
|
|
|
window_->SetLoadingState(isLoading, canGoBack, canGoForward);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
// Reset to the default window icon when loading begins.
|
2017-08-04 00:55:19 +02:00
|
|
|
window_->SetFavicon(
|
|
|
|
delegate_->GetImageCache()->GetCachedImage("window_icon"));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::OnSetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnSetDraggableRegions,
|
|
|
|
this, regions));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetDraggableRegions(regions);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void RootWindowViews::OnTakeFocus(bool next) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&RootWindowViews::OnTakeFocus, this, next));
|
2017-02-17 00:19:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2017-02-17 00:19:43 +01:00
|
|
|
window_->TakeFocus(next);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
void RootWindowViews::OnBeforeContextMenu(CefRefPtr<CefMenuModel> model) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2017-02-25 06:03:31 +01:00
|
|
|
window_->OnBeforeContextMenu(model);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::CreateClientHandler(const std::string& url) {
|
|
|
|
DCHECK(!client_handler_);
|
|
|
|
|
2022-03-22 19:31:30 +01:00
|
|
|
client_handler_ = new ClientHandlerStd(this, config_->with_controls, url);
|
2016-01-19 21:09:01 +01:00
|
|
|
client_handler_->set_download_favicon_images(true);
|
|
|
|
}
|
|
|
|
|
2019-11-18 21:02:39 +01:00
|
|
|
void RootWindowViews::InitOnUIThread(
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::InitOnUIThread, this,
|
2022-10-28 20:17:18 +02:00
|
|
|
settings, request_context));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
if (config_->initially_hidden && !config_->source_bounds.IsEmpty()) {
|
|
|
|
// The window will be sized and positioned in OnAutoResize().
|
|
|
|
initial_bounds_ = config_->source_bounds;
|
|
|
|
position_on_resize_ = true;
|
|
|
|
} else if (!config_->bounds.IsEmpty()) {
|
|
|
|
// Initial state was specified via the config object.
|
|
|
|
initial_bounds_ = config_->bounds;
|
|
|
|
initial_show_state_ = config_->show_state;
|
|
|
|
} else {
|
|
|
|
// Initial state may be specified via the command-line or global
|
|
|
|
// preferences.
|
|
|
|
std::optional<CefRect> bounds;
|
|
|
|
if (prefs::LoadWindowRestorePreferences(initial_show_state_, bounds) &&
|
|
|
|
bounds) {
|
|
|
|
initial_bounds_ = *bounds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
image_cache_ = delegate_->GetImageCache();
|
|
|
|
|
|
|
|
// Populate the default image cache.
|
|
|
|
ImageCache::ImageInfoSet image_set;
|
2023-01-02 23:59:03 +01:00
|
|
|
for (size_t i = 0U; i < std::size(kDefaultImageCache); ++i) {
|
2017-08-04 00:55:19 +02:00
|
|
|
image_set.push_back(ImageCache::ImageInfo::Create2x(kDefaultImageCache[i]));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
image_cache_->LoadImages(
|
2021-06-19 21:54:45 +02:00
|
|
|
image_set, base::BindOnce(&RootWindowViews::CreateViewsWindow, this,
|
2022-10-28 20:17:18 +02:00
|
|
|
settings, request_context));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::CreateViewsWindow(
|
|
|
|
const CefBrowserSettings& settings,
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
const ImageCache::ImageSet& images) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(!window_);
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Make sure the default images loaded successfully.
|
2022-09-05 22:31:47 +02:00
|
|
|
DCHECK_EQ(images.size(), std::size(kDefaultImageCache));
|
|
|
|
for (size_t i = 0U; i < std::size(kDefaultImageCache); ++i) {
|
2017-08-04 00:55:19 +02:00
|
|
|
DCHECK(images[i]) << "Default image " << i << " failed to load";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create the ViewsWindow. It will show itself after creation.
|
2022-10-28 20:17:18 +02:00
|
|
|
ViewsWindow::Create(this, client_handler_, config_->url, settings,
|
2016-01-19 21:09:01 +01:00
|
|
|
request_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootWindowViews::NotifyViewsWindowDestroyed() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
window_destroyed_ = true;
|
|
|
|
NotifyDestroyedIfDone();
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void RootWindowViews::NotifyViewsWindowActivated() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
delegate_->OnRootWindowActivated(this);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void RootWindowViews::NotifyDestroyedIfDone() {
|
|
|
|
// Notify once both the window and the browser have been destroyed.
|
2017-08-04 00:55:19 +02:00
|
|
|
if (window_destroyed_ && browser_destroyed_) {
|
2022-06-02 11:49:50 +02:00
|
|
|
// The delegate may be holding the last reference to |this|, so take a
|
|
|
|
// reference here to keep |this| alive until after the method completes.
|
|
|
|
scoped_refptr<RootWindow> self = this;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
delegate_->OnRootWindowDestroyed(this);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!config_->close_callback.is_null()) {
|
2021-06-19 21:54:45 +02:00
|
|
|
std::move(config_->close_callback).Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace client
|