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"
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_win.h"
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr_win.h"
|
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
#include "libcef/browser/native/browser_platform_delegate_native_mac.h"
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr_mac.h"
|
|
|
|
#elif defined(OS_LINUX)
|
|
|
|
#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
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
#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,
|
|
|
|
SkColor background_color) {
|
2015-11-17 19:20:13 +01:00
|
|
|
#if defined(OS_WIN)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateNativeWin>(
|
|
|
|
window_info, background_color);
|
2015-11-17 19:20:13 +01:00
|
|
|
#elif defined(OS_MACOSX)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateNativeMac>(
|
|
|
|
window_info, background_color);
|
2015-11-17 19:20:13 +01:00
|
|
|
#elif defined(OS_LINUX)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateNativeLinux>(
|
|
|
|
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(
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate) {
|
2015-11-17 19:20:13 +01:00
|
|
|
#if defined(OS_WIN)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateOsrWin>(
|
|
|
|
std::move(native_delegate));
|
2015-11-17 19:20:13 +01:00
|
|
|
#elif defined(OS_MACOSX)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateOsrMac>(
|
|
|
|
std::move(native_delegate));
|
2015-11-17 19:20:13 +01:00
|
|
|
#elif defined(OS_LINUX)
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<CefBrowserPlatformDelegateOsrLinux>(
|
|
|
|
std::move(native_delegate));
|
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(
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserHostImpl::CreateParams& 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 &&
|
|
|
|
create_params.client &&
|
|
|
|
create_params.client->GetRenderHandler().get();
|
|
|
|
const SkColor background_color = CefContext::Get()->GetBackgroundColor(
|
|
|
|
&create_params.settings, is_windowless ? STATE_ENABLED : STATE_DISABLED);
|
|
|
|
|
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 =
|
2017-04-20 21:28:17 +02:00
|
|
|
CreateNativeDelegate(*create_params.window_info.get(),
|
|
|
|
background_color);
|
|
|
|
if (is_windowless)
|
2016-01-19 21:09:01 +01:00
|
|
|
return CreateOSRDelegate(std::move(native_delegate));
|
|
|
|
return std::move(native_delegate);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
else {
|
|
|
|
// CefWindowInfo is not used in this case.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
2017-04-20 21:28:17 +02:00
|
|
|
CreateNativeDelegate(CefWindowInfo(), background_color);
|
|
|
|
return base::MakeUnique<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
|
|
|
}
|
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
return nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|