1 // Copyright 2015 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/browser_platform_delegate.h"
6
7 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
8
9 #include "base/logging.h"
10
11 CefBrowserPlatformDelegate::CefBrowserPlatformDelegate() = default;
12
~CefBrowserPlatformDelegate()13 CefBrowserPlatformDelegate::~CefBrowserPlatformDelegate() {
14 DCHECK(!browser_);
15 }
16
CreateWebContents(CefBrowserCreateParams & create_params,bool & own_web_contents)17 content::WebContents* CefBrowserPlatformDelegate::CreateWebContents(
18 CefBrowserCreateParams& create_params,
19 bool& own_web_contents) {
20 NOTREACHED();
21 return nullptr;
22 }
23
CreateViewForWebContents(content::WebContentsView ** view,content::RenderViewHostDelegateView ** delegate_view)24 void CefBrowserPlatformDelegate::CreateViewForWebContents(
25 content::WebContentsView** view,
26 content::RenderViewHostDelegateView** delegate_view) {
27 NOTREACHED();
28 }
29
WebContentsCreated(content::WebContents * web_contents,bool owned)30 void CefBrowserPlatformDelegate::WebContentsCreated(
31 content::WebContents* web_contents,
32 bool owned) {
33 // We should not have a browser at this point.
34 DCHECK(!browser_);
35
36 DCHECK(!web_contents_);
37 web_contents_ = web_contents;
38 }
39
AddNewContents(content::WebContents * source,std::unique_ptr<content::WebContents> new_contents,const GURL & target_url,WindowOpenDisposition disposition,const gfx::Rect & initial_rect,bool user_gesture,bool * was_blocked)40 void CefBrowserPlatformDelegate::AddNewContents(
41 content::WebContents* source,
42 std::unique_ptr<content::WebContents> new_contents,
43 const GURL& target_url,
44 WindowOpenDisposition disposition,
45 const gfx::Rect& initial_rect,
46 bool user_gesture,
47 bool* was_blocked) {
48 NOTREACHED();
49 }
50
WebContentsDestroyed(content::WebContents * web_contents)51 void CefBrowserPlatformDelegate::WebContentsDestroyed(
52 content::WebContents* web_contents) {
53 DCHECK(web_contents_ && web_contents_ == web_contents);
54 web_contents_ = nullptr;
55 }
56
57 bool CefBrowserPlatformDelegate::
ShouldAllowRendererInitiatedCrossProcessNavigation(bool is_main_frame_navigation)58 ShouldAllowRendererInitiatedCrossProcessNavigation(
59 bool is_main_frame_navigation) {
60 return true;
61 }
62
RenderViewCreated(content::RenderViewHost * render_view_host)63 void CefBrowserPlatformDelegate::RenderViewCreated(
64 content::RenderViewHost* render_view_host) {}
65
RenderViewReady()66 void CefBrowserPlatformDelegate::RenderViewReady() {}
67
BrowserCreated(CefBrowserHostBase * browser)68 void CefBrowserPlatformDelegate::BrowserCreated(CefBrowserHostBase* browser) {
69 // We should have an associated WebContents at this point.
70 DCHECK(web_contents_);
71
72 DCHECK(!browser_);
73 DCHECK(browser);
74 browser_ = browser;
75 }
76
CreateExtensionHost(const extensions::Extension * extension,const GURL & url,extensions::mojom::ViewType host_type)77 void CefBrowserPlatformDelegate::CreateExtensionHost(
78 const extensions::Extension* extension,
79 const GURL& url,
80 extensions::mojom::ViewType host_type) {
81 NOTREACHED();
82 }
83
GetExtensionHost() const84 extensions::ExtensionHost* CefBrowserPlatformDelegate::GetExtensionHost()
85 const {
86 NOTREACHED();
87 return nullptr;
88 }
89
NotifyBrowserCreated()90 void CefBrowserPlatformDelegate::NotifyBrowserCreated() {}
91
NotifyBrowserDestroyed()92 void CefBrowserPlatformDelegate::NotifyBrowserDestroyed() {}
93
BrowserDestroyed(CefBrowserHostBase * browser)94 void CefBrowserPlatformDelegate::BrowserDestroyed(CefBrowserHostBase* browser) {
95 // WebContentsDestroyed should already be called.
96 DCHECK(!web_contents_);
97
98 DCHECK(browser_ && browser_ == browser);
99 browser_ = nullptr;
100 }
101
CreateHostWindow()102 bool CefBrowserPlatformDelegate::CreateHostWindow() {
103 NOTREACHED();
104 return true;
105 }
106
CloseHostWindow()107 void CefBrowserPlatformDelegate::CloseHostWindow() {
108 NOTREACHED();
109 }
110
GetHostWindowHandle() const111 CefWindowHandle CefBrowserPlatformDelegate::GetHostWindowHandle() const {
112 NOTREACHED();
113 return kNullWindowHandle;
114 }
115
116 #if defined(TOOLKIT_VIEWS)
GetWindowWidget() const117 views::Widget* CefBrowserPlatformDelegate::GetWindowWidget() const {
118 NOTREACHED();
119 return nullptr;
120 }
121
GetBrowserView() const122 CefRefPtr<CefBrowserView> CefBrowserPlatformDelegate::GetBrowserView() const {
123 NOTREACHED();
124 return nullptr;
125 }
126 #endif // defined(TOOLKIT_VIEWS)
127
PopupWebContentsCreated(const CefBrowserSettings & settings,CefRefPtr<CefClient> client,content::WebContents * new_web_contents,CefBrowserPlatformDelegate * new_platform_delegate,bool is_devtools)128 void CefBrowserPlatformDelegate::PopupWebContentsCreated(
129 const CefBrowserSettings& settings,
130 CefRefPtr<CefClient> client,
131 content::WebContents* new_web_contents,
132 CefBrowserPlatformDelegate* new_platform_delegate,
133 bool is_devtools) {}
134
PopupBrowserCreated(CefBrowserHostBase * new_browser,bool is_devtools)135 void CefBrowserPlatformDelegate::PopupBrowserCreated(
136 CefBrowserHostBase* new_browser,
137 bool is_devtools) {}
138
GetBackgroundColor() const139 SkColor CefBrowserPlatformDelegate::GetBackgroundColor() const {
140 NOTREACHED();
141 return SkColor();
142 }
143
WasResized()144 void CefBrowserPlatformDelegate::WasResized() {
145 NOTREACHED();
146 }
147
SendKeyEvent(const CefKeyEvent & event)148 void CefBrowserPlatformDelegate::SendKeyEvent(const CefKeyEvent& event) {
149 NOTIMPLEMENTED();
150 }
151
SendMouseClickEvent(const CefMouseEvent & event,CefBrowserHost::MouseButtonType type,bool mouseUp,int clickCount)152 void CefBrowserPlatformDelegate::SendMouseClickEvent(
153 const CefMouseEvent& event,
154 CefBrowserHost::MouseButtonType type,
155 bool mouseUp,
156 int clickCount) {
157 NOTIMPLEMENTED();
158 }
159
SendMouseMoveEvent(const CefMouseEvent & event,bool mouseLeave)160 void CefBrowserPlatformDelegate::SendMouseMoveEvent(const CefMouseEvent& event,
161 bool mouseLeave) {
162 NOTIMPLEMENTED();
163 }
164
SendMouseWheelEvent(const CefMouseEvent & event,int deltaX,int deltaY)165 void CefBrowserPlatformDelegate::SendMouseWheelEvent(const CefMouseEvent& event,
166 int deltaX,
167 int deltaY) {
168 NOTIMPLEMENTED();
169 }
170
SendTouchEvent(const CefTouchEvent & event)171 void CefBrowserPlatformDelegate::SendTouchEvent(const CefTouchEvent& event) {
172 NOTIMPLEMENTED();
173 }
174
SetFocus(bool setFocus)175 void CefBrowserPlatformDelegate::SetFocus(bool setFocus) {
176 NOTIMPLEMENTED();
177 }
178
SendCaptureLostEvent()179 void CefBrowserPlatformDelegate::SendCaptureLostEvent() {
180 NOTIMPLEMENTED();
181 }
182
183 #if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
NotifyMoveOrResizeStarted()184 void CefBrowserPlatformDelegate::NotifyMoveOrResizeStarted() {}
185
SizeTo(int width,int height)186 void CefBrowserPlatformDelegate::SizeTo(int width, int height) {}
187 #endif
188
GetScreenPoint(const gfx::Point & view) const189 gfx::Point CefBrowserPlatformDelegate::GetScreenPoint(
190 const gfx::Point& view) const {
191 NOTREACHED();
192 return gfx::Point();
193 }
194
ViewText(const std::string & text)195 void CefBrowserPlatformDelegate::ViewText(const std::string& text) {
196 NOTIMPLEMENTED();
197 }
198
HandleKeyboardEvent(const content::NativeWebKeyboardEvent & event)199 bool CefBrowserPlatformDelegate::HandleKeyboardEvent(
200 const content::NativeWebKeyboardEvent& event) {
201 NOTREACHED();
202 return false;
203 }
204
PreHandleGestureEvent(content::WebContents * source,const blink::WebGestureEvent & event)205 bool CefBrowserPlatformDelegate::PreHandleGestureEvent(
206 content::WebContents* source,
207 const blink::WebGestureEvent& event) {
208 return false;
209 }
210
IsNeverComposited(content::WebContents * web_contents)211 bool CefBrowserPlatformDelegate::IsNeverComposited(
212 content::WebContents* web_contents) {
213 return false;
214 }
215
GetEventHandle(const content::NativeWebKeyboardEvent & event) const216 CefEventHandle CefBrowserPlatformDelegate::GetEventHandle(
217 const content::NativeWebKeyboardEvent& event) const {
218 NOTREACHED();
219 return kNullEventHandle;
220 }
221
222 std::unique_ptr<CefFileDialogRunner>
CreateFileDialogRunner()223 CefBrowserPlatformDelegate::CreateFileDialogRunner() {
224 NOTIMPLEMENTED();
225 return nullptr;
226 }
227
228 std::unique_ptr<CefJavaScriptDialogRunner>
CreateJavaScriptDialogRunner()229 CefBrowserPlatformDelegate::CreateJavaScriptDialogRunner() {
230 NOTIMPLEMENTED();
231 return nullptr;
232 }
233
CreateMenuRunner()234 std::unique_ptr<CefMenuRunner> CefBrowserPlatformDelegate::CreateMenuRunner() {
235 NOTIMPLEMENTED();
236 return nullptr;
237 }
238
IsWindowless() const239 bool CefBrowserPlatformDelegate::IsWindowless() const {
240 return false;
241 }
242
IsViewsHosted() const243 bool CefBrowserPlatformDelegate::IsViewsHosted() const {
244 return false;
245 }
246
WasHidden(bool hidden)247 void CefBrowserPlatformDelegate::WasHidden(bool hidden) {
248 NOTREACHED();
249 }
250
NotifyScreenInfoChanged()251 void CefBrowserPlatformDelegate::NotifyScreenInfoChanged() {
252 NOTREACHED();
253 }
254
Invalidate(cef_paint_element_type_t type)255 void CefBrowserPlatformDelegate::Invalidate(cef_paint_element_type_t type) {
256 NOTREACHED();
257 }
258
SendExternalBeginFrame()259 void CefBrowserPlatformDelegate::SendExternalBeginFrame() {
260 NOTREACHED();
261 }
262
SetWindowlessFrameRate(int frame_rate)263 void CefBrowserPlatformDelegate::SetWindowlessFrameRate(int frame_rate) {
264 NOTREACHED();
265 }
266
ImeSetComposition(const CefString & text,const std::vector<CefCompositionUnderline> & underlines,const CefRange & replacement_range,const CefRange & selection_range)267 void CefBrowserPlatformDelegate::ImeSetComposition(
268 const CefString& text,
269 const std::vector<CefCompositionUnderline>& underlines,
270 const CefRange& replacement_range,
271 const CefRange& selection_range) {
272 NOTREACHED();
273 }
274
ImeCommitText(const CefString & text,const CefRange & replacement_range,int relative_cursor_pos)275 void CefBrowserPlatformDelegate::ImeCommitText(
276 const CefString& text,
277 const CefRange& replacement_range,
278 int relative_cursor_pos) {
279 NOTREACHED();
280 }
281
ImeFinishComposingText(bool keep_selection)282 void CefBrowserPlatformDelegate::ImeFinishComposingText(bool keep_selection) {
283 NOTREACHED();
284 }
285
ImeCancelComposition()286 void CefBrowserPlatformDelegate::ImeCancelComposition() {
287 NOTREACHED();
288 }
289
DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,const CefMouseEvent & event,cef_drag_operations_mask_t allowed_ops)290 void CefBrowserPlatformDelegate::DragTargetDragEnter(
291 CefRefPtr<CefDragData> drag_data,
292 const CefMouseEvent& event,
293 cef_drag_operations_mask_t allowed_ops) {
294 NOTREACHED();
295 }
296
DragTargetDragOver(const CefMouseEvent & event,cef_drag_operations_mask_t allowed_ops)297 void CefBrowserPlatformDelegate::DragTargetDragOver(
298 const CefMouseEvent& event,
299 cef_drag_operations_mask_t allowed_ops) {
300 NOTREACHED();
301 }
302
DragTargetDragLeave()303 void CefBrowserPlatformDelegate::DragTargetDragLeave() {
304 NOTREACHED();
305 }
306
DragTargetDrop(const CefMouseEvent & event)307 void CefBrowserPlatformDelegate::DragTargetDrop(const CefMouseEvent& event) {
308 NOTREACHED();
309 }
310
StartDragging(const content::DropData & drop_data,blink::DragOperationsMask allowed_ops,const gfx::ImageSkia & image,const gfx::Vector2d & image_offset,const blink::mojom::DragEventSourceInfo & event_info,content::RenderWidgetHostImpl * source_rwh)311 void CefBrowserPlatformDelegate::StartDragging(
312 const content::DropData& drop_data,
313 blink::DragOperationsMask allowed_ops,
314 const gfx::ImageSkia& image,
315 const gfx::Vector2d& image_offset,
316 const blink::mojom::DragEventSourceInfo& event_info,
317 content::RenderWidgetHostImpl* source_rwh) {
318 NOTREACHED();
319 }
320
UpdateDragCursor(ui::mojom::DragOperation operation)321 void CefBrowserPlatformDelegate::UpdateDragCursor(
322 ui::mojom::DragOperation operation) {
323 NOTREACHED();
324 }
325
DragSourceEndedAt(int x,int y,cef_drag_operations_mask_t op)326 void CefBrowserPlatformDelegate::DragSourceEndedAt(
327 int x,
328 int y,
329 cef_drag_operations_mask_t op) {
330 NOTREACHED();
331 }
332
DragSourceSystemDragEnded()333 void CefBrowserPlatformDelegate::DragSourceSystemDragEnded() {
334 NOTREACHED();
335 }
336
AccessibilityEventReceived(const content::AXEventNotificationDetails & eventData)337 void CefBrowserPlatformDelegate::AccessibilityEventReceived(
338 const content::AXEventNotificationDetails& eventData) {
339 NOTREACHED();
340 }
341
AccessibilityLocationChangesReceived(const std::vector<content::AXLocationChangeNotificationDetails> & locData)342 void CefBrowserPlatformDelegate::AccessibilityLocationChangesReceived(
343 const std::vector<content::AXLocationChangeNotificationDetails>& locData) {
344 NOTREACHED();
345 }
346
GetDialogPosition(const gfx::Size & size)347 gfx::Point CefBrowserPlatformDelegate::GetDialogPosition(
348 const gfx::Size& size) {
349 NOTREACHED();
350 return gfx::Point();
351 }
352
GetMaximumDialogSize()353 gfx::Size CefBrowserPlatformDelegate::GetMaximumDialogSize() {
354 NOTREACHED();
355 return gfx::Size();
356 }
357
SetAutoResizeEnabled(bool enabled,const CefSize & min_size,const CefSize & max_size)358 void CefBrowserPlatformDelegate::SetAutoResizeEnabled(bool enabled,
359 const CefSize& min_size,
360 const CefSize& max_size) {
361 NOTIMPLEMENTED();
362 }
363
SetAccessibilityState(cef_state_t accessibility_state)364 void CefBrowserPlatformDelegate::SetAccessibilityState(
365 cef_state_t accessibility_state) {
366 NOTIMPLEMENTED();
367 }
368
IsPrintPreviewSupported() const369 bool CefBrowserPlatformDelegate::IsPrintPreviewSupported() const {
370 return true;
371 }
372
Print()373 void CefBrowserPlatformDelegate::Print() {
374 NOTIMPLEMENTED();
375 }
376
PrintToPDF(const CefString & path,const CefPdfPrintSettings & settings,CefRefPtr<CefPdfPrintCallback> callback)377 void CefBrowserPlatformDelegate::PrintToPDF(
378 const CefString& path,
379 const CefPdfPrintSettings& settings,
380 CefRefPtr<CefPdfPrintCallback> callback) {
381 NOTIMPLEMENTED();
382 }
383
Find(const CefString & searchText,bool forward,bool matchCase,bool findNext)384 void CefBrowserPlatformDelegate::Find(const CefString& searchText,
385 bool forward,
386 bool matchCase,
387 bool findNext) {
388 NOTIMPLEMENTED();
389 }
390
StopFinding(bool clearSelection)391 void CefBrowserPlatformDelegate::StopFinding(bool clearSelection) {
392 NOTIMPLEMENTED();
393 }
394
395 // static
TranslateWebEventModifiers(uint32 cef_modifiers)396 int CefBrowserPlatformDelegate::TranslateWebEventModifiers(
397 uint32 cef_modifiers) {
398 int result = 0;
399 // Set modifiers based on key state.
400 if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
401 result |= blink::WebInputEvent::kCapsLockOn;
402 if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
403 result |= blink::WebInputEvent::kShiftKey;
404 if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
405 result |= blink::WebInputEvent::kControlKey;
406 if (cef_modifiers & EVENTFLAG_ALT_DOWN)
407 result |= blink::WebInputEvent::kAltKey;
408 if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
409 result |= blink::WebInputEvent::kLeftButtonDown;
410 if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
411 result |= blink::WebInputEvent::kMiddleButtonDown;
412 if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
413 result |= blink::WebInputEvent::kRightButtonDown;
414 if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
415 result |= blink::WebInputEvent::kMetaKey;
416 if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
417 result |= blink::WebInputEvent::kNumLockOn;
418 if (cef_modifiers & EVENTFLAG_IS_KEY_PAD)
419 result |= blink::WebInputEvent::kIsKeyPad;
420 if (cef_modifiers & EVENTFLAG_IS_LEFT)
421 result |= blink::WebInputEvent::kIsLeft;
422 if (cef_modifiers & EVENTFLAG_IS_RIGHT)
423 result |= blink::WebInputEvent::kIsRight;
424 if (cef_modifiers & EVENTFLAG_ALTGR_DOWN)
425 result |= blink::WebInputEvent::kAltGrKey;
426 if (cef_modifiers & EVENTFLAG_IS_REPEAT)
427 result |= blink::WebInputEvent::kIsAutoRepeat;
428 return result;
429 }
430