• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 The Chromium Embedded Framework Authors.
2 // Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libcef/browser/osr/web_contents_view_osr.h"
7 
8 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
9 #include "libcef/browser/osr/render_widget_host_view_osr.h"
10 #include "libcef/common/drag_data_impl.h"
11 
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
13 #include "content/browser/browser_plugin/browser_plugin_guest.h"
14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/public/browser/render_widget_host.h"
16 
CefWebContentsViewOSR(SkColor background_color,bool use_shared_texture,bool use_external_begin_frame)17 CefWebContentsViewOSR::CefWebContentsViewOSR(SkColor background_color,
18                                              bool use_shared_texture,
19                                              bool use_external_begin_frame)
20     : background_color_(background_color),
21       use_shared_texture_(use_shared_texture),
22       use_external_begin_frame_(use_external_begin_frame),
23       web_contents_(nullptr) {}
24 
~CefWebContentsViewOSR()25 CefWebContentsViewOSR::~CefWebContentsViewOSR() {}
26 
WebContentsCreated(content::WebContents * web_contents)27 void CefWebContentsViewOSR::WebContentsCreated(
28     content::WebContents* web_contents) {
29   DCHECK(!web_contents_);
30   web_contents_ = web_contents;
31 
32   RenderViewCreated();
33 }
34 
RenderViewCreated()35 void CefWebContentsViewOSR::RenderViewCreated() {
36   if (web_contents_) {
37     auto host = web_contents_->GetRenderViewHost();
38     CefRenderWidgetHostViewOSR* view =
39         static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
40     if (view)
41       view->InstallTransparency();
42   }
43 }
44 
GetNativeView() const45 gfx::NativeView CefWebContentsViewOSR::GetNativeView() const {
46   return gfx::NativeView();
47 }
48 
GetContentNativeView() const49 gfx::NativeView CefWebContentsViewOSR::GetContentNativeView() const {
50   return gfx::NativeView();
51 }
52 
GetTopLevelNativeWindow() const53 gfx::NativeWindow CefWebContentsViewOSR::GetTopLevelNativeWindow() const {
54   return gfx::NativeWindow();
55 }
56 
GetContainerBounds() const57 gfx::Rect CefWebContentsViewOSR::GetContainerBounds() const {
58   return GetViewBounds();
59 }
60 
Focus()61 void CefWebContentsViewOSR::Focus() {}
62 
SetInitialFocus()63 void CefWebContentsViewOSR::SetInitialFocus() {}
64 
StoreFocus()65 void CefWebContentsViewOSR::StoreFocus() {}
66 
RestoreFocus()67 void CefWebContentsViewOSR::RestoreFocus() {}
68 
FocusThroughTabTraversal(bool reverse)69 void CefWebContentsViewOSR::FocusThroughTabTraversal(bool reverse) {}
70 
GotFocus(content::RenderWidgetHostImpl * render_widget_host)71 void CefWebContentsViewOSR::GotFocus(
72     content::RenderWidgetHostImpl* render_widget_host) {
73   if (web_contents_) {
74     content::WebContentsImpl* web_contents_impl =
75         static_cast<content::WebContentsImpl*>(web_contents_);
76     if (web_contents_impl)
77       web_contents_impl->NotifyWebContentsFocused(render_widget_host);
78   }
79 }
80 
LostFocus(content::RenderWidgetHostImpl * render_widget_host)81 void CefWebContentsViewOSR::LostFocus(
82     content::RenderWidgetHostImpl* render_widget_host) {
83   if (web_contents_) {
84     content::WebContentsImpl* web_contents_impl =
85         static_cast<content::WebContentsImpl*>(web_contents_);
86     if (web_contents_impl)
87       web_contents_impl->NotifyWebContentsLostFocus(render_widget_host);
88   }
89 }
90 
TakeFocus(bool reverse)91 void CefWebContentsViewOSR::TakeFocus(bool reverse) {
92   if (web_contents_->GetDelegate())
93     web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse);
94 }
95 
GetDropData() const96 content::DropData* CefWebContentsViewOSR::GetDropData() const {
97   return nullptr;
98 }
99 
GetViewBounds() const100 gfx::Rect CefWebContentsViewOSR::GetViewBounds() const {
101   CefRenderWidgetHostViewOSR* view = GetView();
102   return view ? view->GetViewBounds() : gfx::Rect();
103 }
104 
CreateView(gfx::NativeView context)105 void CefWebContentsViewOSR::CreateView(gfx::NativeView context) {}
106 
CreateViewForWidget(content::RenderWidgetHost * render_widget_host)107 content::RenderWidgetHostViewBase* CefWebContentsViewOSR::CreateViewForWidget(
108     content::RenderWidgetHost* render_widget_host) {
109   if (render_widget_host->GetView()) {
110     return static_cast<content::RenderWidgetHostViewBase*>(
111         render_widget_host->GetView());
112   }
113 
114   return new CefRenderWidgetHostViewOSR(background_color_, use_shared_texture_,
115                                         use_external_begin_frame_,
116                                         render_widget_host, nullptr);
117 }
118 
119 // Called for popup and fullscreen widgets.
120 content::RenderWidgetHostViewBase*
CreateViewForChildWidget(content::RenderWidgetHost * render_widget_host)121 CefWebContentsViewOSR::CreateViewForChildWidget(
122     content::RenderWidgetHost* render_widget_host) {
123   CefRenderWidgetHostViewOSR* view = GetView();
124   CHECK(view);
125 
126   return new CefRenderWidgetHostViewOSR(background_color_, use_shared_texture_,
127                                         use_external_begin_frame_,
128                                         render_widget_host, view);
129 }
130 
SetPageTitle(const std::u16string & title)131 void CefWebContentsViewOSR::SetPageTitle(const std::u16string& title) {}
132 
RenderViewReady()133 void CefWebContentsViewOSR::RenderViewReady() {
134   RenderViewCreated();
135 }
136 
RenderViewHostChanged(content::RenderViewHost * old_host,content::RenderViewHost * new_host)137 void CefWebContentsViewOSR::RenderViewHostChanged(
138     content::RenderViewHost* old_host,
139     content::RenderViewHost* new_host) {}
140 
SetOverscrollControllerEnabled(bool enabled)141 void CefWebContentsViewOSR::SetOverscrollControllerEnabled(bool enabled) {}
142 
OnCapturerCountChanged()143 void CefWebContentsViewOSR::OnCapturerCountChanged() {}
144 
145 #if BUILDFLAG(IS_MAC)
CloseTabAfterEventTrackingIfNeeded()146 bool CefWebContentsViewOSR::CloseTabAfterEventTrackingIfNeeded() {
147   return false;
148 }
149 #endif  // BUILDFLAG(IS_MAC)
150 
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)151 void CefWebContentsViewOSR::StartDragging(
152     const content::DropData& drop_data,
153     blink::DragOperationsMask allowed_ops,
154     const gfx::ImageSkia& image,
155     const gfx::Vector2d& image_offset,
156     const blink::mojom::DragEventSourceInfo& event_info,
157     content::RenderWidgetHostImpl* source_rwh) {
158   CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser();
159   if (browser.get()) {
160     browser->StartDragging(drop_data, allowed_ops, image, image_offset,
161                            event_info, source_rwh);
162   } else if (web_contents_) {
163     static_cast<content::WebContentsImpl*>(web_contents_)
164         ->SystemDragEnded(source_rwh);
165   }
166 }
167 
UpdateDragCursor(ui::mojom::DragOperation operation)168 void CefWebContentsViewOSR::UpdateDragCursor(
169     ui::mojom::DragOperation operation) {
170   CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser();
171   if (browser.get())
172     browser->UpdateDragCursor(operation);
173 }
174 
GetView() const175 CefRenderWidgetHostViewOSR* CefWebContentsViewOSR::GetView() const {
176   if (web_contents_) {
177     return static_cast<CefRenderWidgetHostViewOSR*>(
178         web_contents_->GetRenderViewHost()->GetWidget()->GetView());
179   }
180   return nullptr;
181 }
182 
GetBrowser() const183 AlloyBrowserHostImpl* CefWebContentsViewOSR::GetBrowser() const {
184   CefRenderWidgetHostViewOSR* view = GetView();
185   if (view)
186     return view->browser_impl().get();
187   return nullptr;
188 }
189