2016-07-30 19:35:14 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-07-20 09:30:06 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/osr/osr_web_contents_view.h"
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
|
2017-03-04 02:09:16 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "ui/display/screen.h"
|
2021-06-22 19:17:16 +00:00
|
|
|
#include "ui/display/screen_info.h"
|
2016-12-20 01:23:41 +00:00
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2016-08-04 04:03:24 +00:00
|
|
|
OffScreenWebContentsView::OffScreenWebContentsView(
|
2018-04-18 01:55:30 +00:00
|
|
|
bool transparent,
|
|
|
|
const OnPaintCallback& callback)
|
2021-01-26 18:16:21 +00:00
|
|
|
: transparent_(transparent), callback_(callback) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2016-08-04 06:34:29 +00:00
|
|
|
PlatformCreate();
|
|
|
|
#endif
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
2016-07-29 12:50:27 +00:00
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
OffScreenWebContentsView::~OffScreenWebContentsView() {
|
2018-11-30 05:25:02 +00:00
|
|
|
if (native_window_)
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2016-08-04 06:34:29 +00:00
|
|
|
PlatformDestroy();
|
|
|
|
#endif
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 12:36:22 +00:00
|
|
|
void OffScreenWebContentsView::SetWebContents(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
web_contents_ = web_contents;
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2020-03-14 20:54:14 +00:00
|
|
|
if (GetView())
|
|
|
|
GetView()->InstallTransparency();
|
2016-07-27 12:36:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 05:25:02 +00: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();
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
2018-11-30 05:25:02 +00:00
|
|
|
if (!native_window_)
|
2018-04-18 01:55:30 +00:00
|
|
|
return gfx::NativeView();
|
2018-11-30 05:25:02 +00:00
|
|
|
return native_window_->GetNativeView();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
2018-11-30 05:25:02 +00:00
|
|
|
if (!native_window_)
|
2018-04-18 01:55:30 +00:00
|
|
|
return gfx::NativeView();
|
2018-11-30 05:25:02 +00:00
|
|
|
return native_window_->GetNativeView();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
2018-11-30 05:25:02 +00:00
|
|
|
if (!native_window_)
|
2018-04-18 01:55:30 +00:00
|
|
|
return gfx::NativeWindow();
|
2018-11-30 05:25:02 +00:00
|
|
|
return native_window_->GetNativeWindow();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
2016-08-04 06:34:29 +00:00
|
|
|
#endif
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2020-05-26 20:06:26 +00:00
|
|
|
gfx::Rect OffScreenWebContentsView::GetContainerBounds() const {
|
|
|
|
return GetViewBounds();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::Focus() {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::SetInitialFocus() {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::StoreFocus() {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::RestoreFocus() {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenWebContentsView::FocusThroughTabTraversal(bool reverse) {}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
content::DropData* OffScreenWebContentsView::GetDropData() const {
|
2016-07-20 09:30:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-10-24 15:24:20 +00:00
|
|
|
void OffScreenWebContentsView::TransferDragSecurityInfo(WebContentsView* view) {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
2023-09-29 05:26:41 +00:00
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::Rect OffScreenWebContentsView::GetViewBounds() const {
|
2017-03-04 02:09:16 +00:00
|
|
|
return GetView() ? GetView()->GetViewBounds() : gfx::Rect();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 19:58:00 +00:00
|
|
|
void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
|
|
|
content::RenderWidgetHostViewBase*
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenWebContentsView::CreateViewForWidget(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (render_widget_host->GetView()) {
|
|
|
|
return static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
render_widget_host->GetView());
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
return new OffScreenRenderWidgetHostView(
|
2018-04-18 01:55:30 +00:00
|
|
|
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
|
2018-11-30 05:25:02 +00:00
|
|
|
nullptr, GetSize());
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
content::RenderWidgetHostViewBase*
|
2019-01-30 17:33:32 +00:00
|
|
|
OffScreenWebContentsView::CreateViewForChildWidget(
|
2016-07-30 18:39:17 +00:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* web_contents_impl =
|
2018-04-18 01:55:30 +00:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_);
|
2017-04-14 21:32:33 +00:00
|
|
|
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* view = static_cast<OffScreenRenderWidgetHostView*>(
|
|
|
|
web_contents_impl->GetOuterWebContents()
|
|
|
|
? web_contents_impl->GetOuterWebContents()->GetRenderWidgetHostView()
|
|
|
|
: web_contents_impl->GetRenderWidgetHostView());
|
2017-04-14 21:32:33 +00:00
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
return new OffScreenRenderWidgetHostView(transparent_, painting_,
|
2024-01-30 02:43:28 +00:00
|
|
|
view->frame_rate(), callback_,
|
2018-11-30 05:25:02 +00:00
|
|
|
render_widget_host, view, GetSize());
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
void OffScreenWebContentsView::SetPageTitle(const std::u16string& title) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2020-07-06 18:57:14 +00:00
|
|
|
void OffScreenWebContentsView::RenderViewReady() {
|
|
|
|
if (GetView())
|
|
|
|
GetView()->InstallTransparency();
|
|
|
|
}
|
2018-10-11 13:14:01 +00:00
|
|
|
|
|
|
|
void OffScreenWebContentsView::RenderViewHostChanged(
|
|
|
|
content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2021-11-24 08:45:59 +00:00
|
|
|
void OffScreenWebContentsView::OnCapturerCountChanged() {}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-04-17 21:10:04 +00:00
|
|
|
bool OffScreenWebContentsView::CloseTabAfterEventTrackingIfNeeded() {
|
2016-07-20 09:30:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_MAC)
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2016-07-25 13:55:00 +00:00
|
|
|
void OffScreenWebContentsView::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
2023-10-02 22:01:07 +00:00
|
|
|
const url::Origin& source_origin,
|
2020-10-16 01:30:41 +00:00
|
|
|
blink::DragOperationsMask allowed_ops,
|
2016-07-25 13:55:00 +00:00
|
|
|
const gfx::ImageSkia& image,
|
2022-09-07 07:46:37 +00:00
|
|
|
const gfx::Vector2d& cursor_offset,
|
|
|
|
const gfx::Rect& drag_obj_rect,
|
2020-09-21 08:00:36 +00:00
|
|
|
const blink::mojom::DragEventSourceInfo& event_info,
|
2017-01-24 05:06:48 +00:00
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
2016-08-01 10:06:46 +00:00
|
|
|
if (web_contents_)
|
2020-05-26 20:06:26 +00:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_)
|
|
|
|
->SystemDragEnded(source_rwh);
|
2016-07-25 13:55:00 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 22:01:07 +00:00
|
|
|
void OffScreenWebContentsView::UpdateDragOperation(
|
|
|
|
ui::mojom::DragOperation operation,
|
|
|
|
bool document_is_handling_drag) {}
|
2016-07-25 13:55:00 +00:00
|
|
|
|
2018-01-25 13:46:30 +00:00
|
|
|
void OffScreenWebContentsView::SetPainting(bool painting) {
|
|
|
|
auto* view = GetView();
|
2019-04-17 21:10:04 +00:00
|
|
|
painting_ = painting;
|
2018-01-25 13:46:30 +00:00
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetPainting(painting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenWebContentsView::IsPainting() const {
|
2024-01-30 02:43:28 +00:00
|
|
|
if (auto* view = GetView())
|
|
|
|
return view->is_painting();
|
|
|
|
return painting_;
|
2018-01-25 13:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
|
|
|
auto* view = GetView();
|
2019-04-17 21:10:04 +00:00
|
|
|
frame_rate_ = frame_rate;
|
2018-01-25 13:46:30 +00:00
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetFrameRate(frame_rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int OffScreenWebContentsView::GetFrameRate() const {
|
2024-01-30 02:43:28 +00:00
|
|
|
if (auto* view = GetView())
|
|
|
|
return view->frame_rate();
|
|
|
|
return frame_rate_;
|
2018-01-25 13:46:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const {
|
|
|
|
if (web_contents_) {
|
|
|
|
return static_cast<OffScreenRenderWidgetHostView*>(
|
|
|
|
web_contents_->GetRenderViewHost()->GetWidget()->GetView());
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-07 07:46:37 +00:00
|
|
|
void OffScreenWebContentsView::FullscreenStateChanged(bool is_fullscreen) {}
|
|
|
|
|
2023-03-10 16:07:42 +00:00
|
|
|
void OffScreenWebContentsView::UpdateWindowControlsOverlay(
|
|
|
|
const gfx::Rect& bounding_rect) {}
|
|
|
|
|
2024-01-31 23:04:13 +00:00
|
|
|
content::BackForwardTransitionAnimationManager*
|
|
|
|
OffScreenWebContentsView::GetBackForwardTransitionAnimationManager() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
} // namespace electron
|