2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 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.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_platform_delegate.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "libcef/browser/context.h"
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
#include "build/build_config.h"
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "libcef/browser/browser_host_base.h"
|
|
|
|
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/extensions/browser_platform_delegate_background.h"
|
2020-07-04 04:51:17 +02:00
|
|
|
#include "libcef/features/runtime_checks.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_win.h"
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr_win.h"
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_mac.h"
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr_mac.h"
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_linux.h"
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr_linux.h"
|
|
|
|
#else
|
|
|
|
#error A delegate implementation is not available for your platform.
|
|
|
|
#endif
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
#include "libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "libcef/browser/views/browser_platform_delegate_views.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
namespace {
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> CreateNativeDelegate(
|
2017-04-20 21:28:17 +02:00
|
|
|
const CefWindowInfo& window_info,
|
2020-07-04 20:21:34 +02:00
|
|
|
SkColor background_color) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateNativeWin>(
|
2020-07-04 20:21:34 +02:00
|
|
|
window_info, background_color);
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateNativeMac>(
|
2017-04-20 21:28:17 +02:00
|
|
|
window_info, background_color);
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateNativeLinux>(
|
2020-07-04 20:21:34 +02:00
|
|
|
window_info, background_color);
|
2015-11-17 19:20:13 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateOsr> CreateOSRDelegate(
|
2020-07-04 20:21:34 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
|
|
|
|
bool use_shared_texture,
|
|
|
|
bool use_external_begin_frame) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateOsrWin>(
|
2020-07-04 20:21:34 +02:00
|
|
|
std::move(native_delegate), use_shared_texture, use_external_begin_frame);
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateOsrMac>(
|
2017-04-20 21:28:17 +02:00
|
|
|
std::move(native_delegate));
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateOsrLinux>(
|
2020-07-04 20:21:34 +02:00
|
|
|
std::move(native_delegate), use_external_begin_frame);
|
2015-11-17 19:20:13 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// static
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
|
2020-09-25 03:40:47 +02:00
|
|
|
const CefBrowserCreateParams& create_params) {
|
2017-04-20 21:28:17 +02:00
|
|
|
const bool is_windowless =
|
|
|
|
create_params.window_info &&
|
|
|
|
create_params.window_info->windowless_rendering_enabled &&
|
2017-05-17 11:29:28 +02:00
|
|
|
create_params.client && create_params.client->GetRenderHandler().get();
|
2017-04-20 21:28:17 +02:00
|
|
|
const SkColor background_color = CefContext::Get()->GetBackgroundColor(
|
|
|
|
&create_params.settings, is_windowless ? STATE_ENABLED : STATE_DISABLED);
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
if (cef::IsChromeRuntimeEnabled()) {
|
|
|
|
// CefWindowInfo is not used in this case.
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
|
|
|
CreateNativeDelegate(CefWindowInfo(), background_color);
|
2021-02-18 02:58:25 +01:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2021-04-02 22:53:17 +02:00
|
|
|
if (create_params.browser_view ||
|
|
|
|
create_params.popup_with_views_hosted_opener) {
|
2021-02-18 02:58:25 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateChromeViews>(
|
|
|
|
std::move(native_delegate),
|
|
|
|
static_cast<CefBrowserViewImpl*>(create_params.browser_view.get()));
|
|
|
|
}
|
|
|
|
#endif
|
2020-09-25 03:40:47 +02:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateChrome>(
|
|
|
|
std::move(native_delegate));
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (create_params.window_info) {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
2020-07-04 20:21:34 +02:00
|
|
|
CreateNativeDelegate(*create_params.window_info.get(),
|
|
|
|
background_color);
|
|
|
|
if (is_windowless) {
|
|
|
|
REQUIRE_ALLOY_RUNTIME();
|
|
|
|
|
|
|
|
const bool use_shared_texture =
|
|
|
|
create_params.window_info &&
|
|
|
|
create_params.window_info->shared_texture_enabled;
|
|
|
|
|
|
|
|
const bool use_external_begin_frame =
|
|
|
|
create_params.window_info &&
|
|
|
|
create_params.window_info->external_begin_frame_enabled;
|
|
|
|
|
|
|
|
return CreateOSRDelegate(std::move(native_delegate), use_shared_texture,
|
|
|
|
use_external_begin_frame);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return std::move(native_delegate);
|
2017-08-04 00:55:19 +02:00
|
|
|
} else if (create_params.extension_host_type ==
|
2021-04-21 00:52:34 +02:00
|
|
|
extensions::mojom::ViewType::kExtensionBackgroundPage) {
|
2017-08-04 00:55:19 +02:00
|
|
|
// Creating a background extension host without a window.
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
2020-07-04 20:21:34 +02:00
|
|
|
CreateNativeDelegate(CefWindowInfo(), background_color);
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateBackground>(
|
2017-08-04 00:55:19 +02:00
|
|
|
std::move(native_delegate));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2021-02-18 02:58:25 +01:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2016-01-19 21:09:01 +01:00
|
|
|
else {
|
|
|
|
// CefWindowInfo is not used in this case.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
2020-07-04 20:21:34 +02:00
|
|
|
CreateNativeDelegate(CefWindowInfo(), background_color);
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefBrowserPlatformDelegateViews>(
|
2016-01-19 21:09:01 +01:00
|
|
|
std::move(native_delegate),
|
2017-04-20 21:28:17 +02:00
|
|
|
static_cast<CefBrowserViewImpl*>(create_params.browser_view.get()));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2021-02-18 02:58:25 +01:00
|
|
|
#endif // defined(TOOLKIT_VIEWS)
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
return nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|