2016-07-30 21:35:14 +02:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-07-20 11:30:06 +02:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/osr/osr_web_contents_view.h"
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2019-04-17 23:10:04 +02:00
|
|
|
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
|
2017-03-04 03:09:16 +01:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2020-07-21 22:34:34 -07:00
|
|
|
#include "third_party/blink/public/common/widget/screen_info.h"
|
2017-03-04 03:09:16 +01:00
|
|
|
#include "ui/display/screen.h"
|
2016-12-19 17:23:41 -08:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2016-08-04 13:03:24 +09:00
|
|
|
OffScreenWebContentsView::OffScreenWebContentsView(
|
2018-04-17 21:55:30 -04:00
|
|
|
bool transparent,
|
|
|
|
const OnPaintCallback& callback)
|
2021-01-26 19:16:21 +01:00
|
|
|
: transparent_(transparent), callback_(callback) {
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_MAC)
|
2016-08-04 15:34:29 +09:00
|
|
|
PlatformCreate();
|
|
|
|
#endif
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
2016-07-29 14:50:27 +02:00
|
|
|
|
2016-07-20 11:30:06 +02:00
|
|
|
OffScreenWebContentsView::~OffScreenWebContentsView() {
|
2018-11-29 21:25:02 -08:00
|
|
|
if (native_window_)
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_MAC)
|
2016-08-04 15:34:29 +09:00
|
|
|
PlatformDestroy();
|
|
|
|
#endif
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2016-07-27 14:36:22 +02:00
|
|
|
void OffScreenWebContentsView::SetWebContents(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
web_contents_ = web_contents;
|
2017-04-12 20:54:03 +02:00
|
|
|
|
2020-03-14 13:54:14 -07:00
|
|
|
if (GetView())
|
|
|
|
GetView()->InstallTransparency();
|
2016-07-27 14:36:22 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:25:02 -08:00
|
|
|
void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
|
|
|
|
if (native_window_)
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
|
|
|
|
native_window_ = window;
|
|
|
|
|
|
|
|
if (native_window_)
|
|
|
|
native_window_->AddObserver(this);
|
|
|
|
|
|
|
|
OnWindowResize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::OnWindowResize() {
|
|
|
|
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
|
|
|
if (GetView())
|
|
|
|
GetView()->SetSize(GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::OnWindowClosed() {
|
|
|
|
if (native_window_) {
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
native_window_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size OffScreenWebContentsView::GetSize() {
|
|
|
|
return native_window_ ? native_window_->GetSize() : gfx::Size();
|
|
|
|
}
|
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if !defined(OS_MAC)
|
2016-07-30 20:39:17 +02:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
2018-11-29 21:25:02 -08:00
|
|
|
if (!native_window_)
|
2018-04-17 21:55:30 -04:00
|
|
|
return gfx::NativeView();
|
2018-11-29 21:25:02 -08:00
|
|
|
return native_window_->GetNativeView();
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 20:39:17 +02:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
2018-11-29 21:25:02 -08:00
|
|
|
if (!native_window_)
|
2018-04-17 21:55:30 -04:00
|
|
|
return gfx::NativeView();
|
2018-11-29 21:25:02 -08:00
|
|
|
return native_window_->GetNativeView();
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 20:39:17 +02:00
|
|
|
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
2018-11-29 21:25:02 -08:00
|
|
|
if (!native_window_)
|
2018-04-17 21:55:30 -04:00
|
|
|
return gfx::NativeWindow();
|
2018-11-29 21:25:02 -08:00
|
|
|
return native_window_->GetNativeWindow();
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
2016-08-04 15:34:29 +09:00
|
|
|
#endif
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2020-05-26 13:06:26 -07:00
|
|
|
gfx::Rect OffScreenWebContentsView::GetContainerBounds() const {
|
|
|
|
return GetViewBounds();
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void OffScreenWebContentsView::Focus() {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void OffScreenWebContentsView::SetInitialFocus() {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void OffScreenWebContentsView::StoreFocus() {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void OffScreenWebContentsView::RestoreFocus() {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2018-05-15 03:59:22 +02:00
|
|
|
void OffScreenWebContentsView::FocusThroughTabTraversal(bool reverse) {}
|
|
|
|
|
2016-07-30 20:39:17 +02:00
|
|
|
content::DropData* OffScreenWebContentsView::GetDropData() const {
|
2016-07-20 11:30:06 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-30 20:39:17 +02:00
|
|
|
gfx::Rect OffScreenWebContentsView::GetViewBounds() const {
|
2017-03-04 03:09:16 +01:00
|
|
|
return GetView() ? GetView()->GetViewBounds() : gfx::Rect();
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 15:58:00 -04:00
|
|
|
void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
|
|
|
content::RenderWidgetHostViewBase*
|
2018-04-17 21:55:30 -04:00
|
|
|
OffScreenWebContentsView::CreateViewForWidget(
|
2019-12-10 16:22:35 -08:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2017-03-04 03:09:16 +01:00
|
|
|
if (render_widget_host->GetView()) {
|
|
|
|
return static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
render_widget_host->GetView());
|
|
|
|
}
|
2017-03-05 16:18:57 +01:00
|
|
|
|
2017-03-04 03:09:16 +01:00
|
|
|
return new OffScreenRenderWidgetHostView(
|
2018-04-17 21:55:30 -04:00
|
|
|
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
|
2018-11-29 21:25:02 -08:00
|
|
|
nullptr, GetSize());
|
2017-03-04 03:09:16 +01:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:30:06 +02:00
|
|
|
content::RenderWidgetHostViewBase*
|
2019-01-30 09:33:32 -08:00
|
|
|
OffScreenWebContentsView::CreateViewForChildWidget(
|
2016-07-30 20:39:17 +02:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2020-10-26 11:56:31 -07:00
|
|
|
auto* web_contents_impl =
|
2018-04-17 21:55:30 -04:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_);
|
2017-04-14 23:32:33 +02:00
|
|
|
|
2020-10-26 11:56:31 -07:00
|
|
|
auto* view = static_cast<OffScreenRenderWidgetHostView*>(
|
|
|
|
web_contents_impl->GetOuterWebContents()
|
|
|
|
? web_contents_impl->GetOuterWebContents()->GetRenderWidgetHostView()
|
|
|
|
: web_contents_impl->GetRenderWidgetHostView());
|
2017-04-14 23:32:33 +02:00
|
|
|
|
2019-04-17 23:10:04 +02:00
|
|
|
return new OffScreenRenderWidgetHostView(transparent_, painting_,
|
2018-10-11 06:14:01 -07:00
|
|
|
view->GetFrameRate(), callback_,
|
2018-11-29 21:25:02 -08:00
|
|
|
render_widget_host, view, GetSize());
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2021-03-16 12:18:45 -04:00
|
|
|
void OffScreenWebContentsView::SetPageTitle(const std::u16string& title) {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2020-07-06 11:57:14 -07:00
|
|
|
void OffScreenWebContentsView::RenderViewReady() {
|
|
|
|
if (GetView())
|
|
|
|
GetView()->InstallTransparency();
|
|
|
|
}
|
2018-10-11 06:14:01 -07:00
|
|
|
|
|
|
|
void OffScreenWebContentsView::RenderViewHostChanged(
|
|
|
|
content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) {}
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_MAC)
|
2019-04-17 23:10:04 +02:00
|
|
|
bool OffScreenWebContentsView::CloseTabAfterEventTrackingIfNeeded() {
|
2016-07-20 11:30:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-12 11:33:58 -07:00
|
|
|
#endif // defined(OS_MAC)
|
2016-07-20 11:30:06 +02:00
|
|
|
|
2016-07-25 15:55:00 +02:00
|
|
|
void OffScreenWebContentsView::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
2020-10-15 18:30:41 -07:00
|
|
|
blink::DragOperationsMask allowed_ops,
|
2016-07-25 15:55:00 +02:00
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
2020-09-21 01:00:36 -07:00
|
|
|
const blink::mojom::DragEventSourceInfo& event_info,
|
2017-01-24 14:06:48 +09:00
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
2016-08-01 12:06:46 +02:00
|
|
|
if (web_contents_)
|
2020-05-26 13:06:26 -07:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_)
|
|
|
|
->SystemDragEnded(source_rwh);
|
2016-07-25 15:55:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::UpdateDragCursor(
|
2021-01-12 15:31:23 -08:00
|
|
|
ui::mojom::DragOperation operation) {}
|
2016-07-25 15:55:00 +02:00
|
|
|
|
2018-01-25 14:46:30 +01:00
|
|
|
void OffScreenWebContentsView::SetPainting(bool painting) {
|
|
|
|
auto* view = GetView();
|
2019-04-17 23:10:04 +02:00
|
|
|
painting_ = painting;
|
2018-01-25 14:46:30 +01:00
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetPainting(painting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenWebContentsView::IsPainting() const {
|
|
|
|
auto* view = GetView();
|
|
|
|
if (view != nullptr) {
|
|
|
|
return view->IsPainting();
|
|
|
|
} else {
|
|
|
|
return painting_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
|
|
|
auto* view = GetView();
|
2019-04-17 23:10:04 +02:00
|
|
|
frame_rate_ = frame_rate;
|
2018-01-25 14:46:30 +01:00
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetFrameRate(frame_rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int OffScreenWebContentsView::GetFrameRate() const {
|
|
|
|
auto* view = GetView();
|
|
|
|
if (view != nullptr) {
|
|
|
|
return view->GetFrameRate();
|
|
|
|
} else {
|
|
|
|
return frame_rate_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:09:16 +01:00
|
|
|
OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const {
|
|
|
|
if (web_contents_) {
|
|
|
|
return static_cast<OffScreenRenderWidgetHostView*>(
|
|
|
|
web_contents_->GetRenderViewHost()->GetWidget()->GetView());
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|