1 // Copyright 2017 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "libcef/browser/extensions/browser_platform_delegate_background.h"
6
7 #include <utility>
8
9 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
10 #include "libcef/browser/thread_util.h"
11 #include "libcef/features/runtime_checks.h"
12
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/render_widget_host.h"
15
CefBrowserPlatformDelegateBackground(std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)16 CefBrowserPlatformDelegateBackground::CefBrowserPlatformDelegateBackground(
17 std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
18 : native_delegate_(std::move(native_delegate)) {
19 REQUIRE_ALLOY_RUNTIME();
20 native_delegate_->set_windowless_handler(this);
21 }
22
CreateHostWindow()23 bool CefBrowserPlatformDelegateBackground::CreateHostWindow() {
24 // Nothing to do here.
25 return true;
26 }
27
CloseHostWindow()28 void CefBrowserPlatformDelegateBackground::CloseHostWindow() {
29 // No host window, so continue browser destruction now. Do it asynchronously
30 // so the call stack has a chance to unwind.
31 CEF_POST_TASK(CEF_UIT,
32 base::Bind(&AlloyBrowserHostImpl::WindowDestroyed,
33 static_cast<AlloyBrowserHostImpl*>(browser_)));
34 }
35
GetHostWindowHandle() const36 CefWindowHandle CefBrowserPlatformDelegateBackground::GetHostWindowHandle()
37 const {
38 return kNullWindowHandle;
39 }
40
GetBackgroundColor() const41 SkColor CefBrowserPlatformDelegateBackground::GetBackgroundColor() const {
42 return native_delegate_->GetBackgroundColor();
43 }
44
WasResized()45 void CefBrowserPlatformDelegateBackground::WasResized() {
46 // Nothing to do here.
47 }
48
SendKeyEvent(const CefKeyEvent & event)49 void CefBrowserPlatformDelegateBackground::SendKeyEvent(
50 const CefKeyEvent& event) {
51 // Nothing to do here.
52 }
53
SendMouseClickEvent(const CefMouseEvent & event,CefBrowserHost::MouseButtonType type,bool mouseUp,int clickCount)54 void CefBrowserPlatformDelegateBackground::SendMouseClickEvent(
55 const CefMouseEvent& event,
56 CefBrowserHost::MouseButtonType type,
57 bool mouseUp,
58 int clickCount) {
59 // Nothing to do here.
60 }
61
SendMouseMoveEvent(const CefMouseEvent & event,bool mouseLeave)62 void CefBrowserPlatformDelegateBackground::SendMouseMoveEvent(
63 const CefMouseEvent& event,
64 bool mouseLeave) {
65 // Nothing to do here.
66 }
67
SendMouseWheelEvent(const CefMouseEvent & event,int deltaX,int deltaY)68 void CefBrowserPlatformDelegateBackground::SendMouseWheelEvent(
69 const CefMouseEvent& event,
70 int deltaX,
71 int deltaY) {
72 // Nothing to do here.
73 }
74
SendTouchEvent(const CefTouchEvent & event)75 void CefBrowserPlatformDelegateBackground::SendTouchEvent(
76 const CefTouchEvent& event) {
77 // Nothing to do here.
78 }
79
SendFocusEvent(bool setFocus)80 void CefBrowserPlatformDelegateBackground::SendFocusEvent(bool setFocus) {
81 // Nothing to do here.
82 }
83
GetScreenPoint(const gfx::Point & view_pt) const84 gfx::Point CefBrowserPlatformDelegateBackground::GetScreenPoint(
85 const gfx::Point& view_pt) const {
86 // Nothing to do here.
87 return view_pt;
88 }
89
ViewText(const std::string & text)90 void CefBrowserPlatformDelegateBackground::ViewText(const std::string& text) {
91 native_delegate_->ViewText(text);
92 }
93
HandleKeyboardEvent(const content::NativeWebKeyboardEvent & event)94 bool CefBrowserPlatformDelegateBackground::HandleKeyboardEvent(
95 const content::NativeWebKeyboardEvent& event) {
96 // Nothing to do here.
97 return false;
98 }
99
GetEventHandle(const content::NativeWebKeyboardEvent & event) const100 CefEventHandle CefBrowserPlatformDelegateBackground::GetEventHandle(
101 const content::NativeWebKeyboardEvent& event) const {
102 return native_delegate_->GetEventHandle(event);
103 }
104
105 std::unique_ptr<CefFileDialogRunner>
CreateFileDialogRunner()106 CefBrowserPlatformDelegateBackground::CreateFileDialogRunner() {
107 return native_delegate_->CreateFileDialogRunner();
108 }
109
110 std::unique_ptr<CefJavaScriptDialogRunner>
CreateJavaScriptDialogRunner()111 CefBrowserPlatformDelegateBackground::CreateJavaScriptDialogRunner() {
112 return native_delegate_->CreateJavaScriptDialogRunner();
113 }
114
115 std::unique_ptr<CefMenuRunner>
CreateMenuRunner()116 CefBrowserPlatformDelegateBackground::CreateMenuRunner() {
117 // No default menu implementation for background browsers.
118 return nullptr;
119 }
120
GetParentWindowHandle() const121 CefWindowHandle CefBrowserPlatformDelegateBackground::GetParentWindowHandle()
122 const {
123 return GetHostWindowHandle();
124 }
125
GetParentScreenPoint(const gfx::Point & view) const126 gfx::Point CefBrowserPlatformDelegateBackground::GetParentScreenPoint(
127 const gfx::Point& view) const {
128 return GetScreenPoint(view);
129 }
130