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"
|
2024-07-29 12:42:57 -05:00
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "shell/browser/native_window.h"
|
2017-03-04 03:09:16 +01:00
|
|
|
#include "ui/display/screen.h"
|
2021-06-22 12:17:16 -07:00
|
|
|
#include "ui/display/screen_info.h"
|
2016-12-19 17:23:41 -08:00
|
|
|
|
2016-07-20 11:30:06 +02:00
|
|
|
namespace electron {
|
|
|
|
|
2016-08-04 13:03:24 +09:00
|
|
|
OffScreenWebContentsView::OffScreenWebContentsView(
|
2018-04-17 21:55:30 -04:00
|
|
|
bool transparent,
|
2024-08-23 08:23:13 +08:00
|
|
|
bool offscreen_use_shared_texture,
|
2018-04-17 21:55:30 -04:00
|
|
|
const OnPaintCallback& callback)
|
2024-08-23 08:23:13 +08:00
|
|
|
: transparent_(transparent),
|
|
|
|
offscreen_use_shared_texture_(offscreen_use_shared_texture),
|
|
|
|
callback_(callback) {
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_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);
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_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
|
|
|
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
|
|
|
view->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
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
|
|
|
view->SetSize(GetSize());
|
2018-11-29 21:25:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if !BUILDFLAG(IS_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_)
|
2024-11-30 16:47:30 -06:00
|
|
|
return {};
|
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_)
|
2024-11-30 16:47:30 -06:00
|
|
|
return {};
|
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_)
|
2024-11-30 16:47:30 -06:00
|
|
|
return {};
|
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
|
|
|
}
|
|
|
|
|
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 {
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
|
|
|
return view->GetViewBounds();
|
|
|
|
return {};
|
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) {
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* rwhv = render_widget_host->GetView())
|
|
|
|
return static_cast<content::RenderWidgetHostViewBase*>(rwhv);
|
2017-03-05 16:18:57 +01:00
|
|
|
|
2017-03-04 03:09:16 +01:00
|
|
|
return new OffScreenRenderWidgetHostView(
|
2024-08-23 08:23:13 +08:00
|
|
|
transparent_, offscreen_use_shared_texture_, painting_, GetFrameRate(),
|
|
|
|
callback_, render_widget_host, 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
|
|
|
|
2024-08-23 08:23:13 +08:00
|
|
|
return new OffScreenRenderWidgetHostView(
|
|
|
|
transparent_, offscreen_use_shared_texture_, painting_,
|
|
|
|
view->frame_rate(), callback_, render_widget_host, view, GetSize());
|
2016-07-20 11:30:06 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 11:57:14 -07:00
|
|
|
void OffScreenWebContentsView::RenderViewReady() {
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
|
|
|
view->InstallTransparency();
|
2020-07-06 11:57:14 -07:00
|
|
|
}
|
2018-10-11 06:14:01 -07:00
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-04-17 23:10:04 +02:00
|
|
|
bool OffScreenWebContentsView::CloseTabAfterEventTrackingIfNeeded() {
|
2016-07-20 11:30:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-09 18:58:52 -08:00
|
|
|
#endif // BUILDFLAG(IS_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,
|
2023-10-02 18:01:07 -04:00
|
|
|
const url::Origin& source_origin,
|
2020-10-15 18:30:41 -07:00
|
|
|
blink::DragOperationsMask allowed_ops,
|
2016-07-25 15:55:00 +02:00
|
|
|
const gfx::ImageSkia& image,
|
2022-09-07 09:46:37 +02:00
|
|
|
const gfx::Vector2d& cursor_offset,
|
|
|
|
const gfx::Rect& drag_obj_rect,
|
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
|
|
|
}
|
|
|
|
|
2018-01-25 14:46:30 +01:00
|
|
|
void OffScreenWebContentsView::SetPainting(bool painting) {
|
2019-04-17 23:10:04 +02:00
|
|
|
painting_ = painting;
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
2018-01-25 14:46:30 +01:00
|
|
|
view->SetPainting(painting);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenWebContentsView::IsPainting() const {
|
2024-01-29 20:43:28 -06:00
|
|
|
if (auto* view = GetView())
|
|
|
|
return view->is_painting();
|
|
|
|
return painting_;
|
2018-01-25 14:46:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
2019-04-17 23:10:04 +02:00
|
|
|
frame_rate_ = frame_rate;
|
2024-08-06 11:25:59 -05:00
|
|
|
if (auto* view = GetView())
|
2018-01-25 14:46:30 +01:00
|
|
|
view->SetFrameRate(frame_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
int OffScreenWebContentsView::GetFrameRate() const {
|
2024-01-29 20:43:28 -06:00
|
|
|
if (auto* view = GetView())
|
|
|
|
return view->frame_rate();
|
|
|
|
return frame_rate_;
|
2018-01-25 14:46:30 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-31 17:04:13 -06:00
|
|
|
content::BackForwardTransitionAnimationManager*
|
|
|
|
OffScreenWebContentsView::GetBackForwardTransitionAnimationManager() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-20 11:30:06 +02:00
|
|
|
} // namespace electron
|