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.
|
|
|
|
|
2016-08-03 02:01:35 +00:00
|
|
|
#include "atom/browser/osr/osr_web_contents_view.h"
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2017-04-11 12:19:34 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
2017-04-14 21:32:33 +00:00
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
2017-03-04 02:09:16 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2018-07-20 16:08:18 +00:00
|
|
|
#include "third_party/blink/public/platform/web_screen_info.h"
|
2017-03-04 02:09:16 +00:00
|
|
|
#include "ui/display/screen.h"
|
2016-12-20 01:23:41 +00:00
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2016-08-04 04:03:24 +00:00
|
|
|
OffScreenWebContentsView::OffScreenWebContentsView(
|
2018-04-18 01:55:30 +00:00
|
|
|
bool transparent,
|
|
|
|
const OnPaintCallback& callback)
|
2018-05-21 22:18:38 +00:00
|
|
|
: transparent_(transparent), callback_(callback) {
|
2016-08-04 06:34:29 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
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() {
|
2016-08-04 06:34:29 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
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
|
|
|
|
2017-04-12 02:11:49 +00:00
|
|
|
RenderViewCreated(web_contents_->GetRenderViewHost());
|
2016-07-27 12:36:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-04 06:34:29 +00:00
|
|
|
#if !defined(OS_MACOSX)
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!web_contents_)
|
|
|
|
return gfx::NativeView();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2018-05-16 19:12:45 +00:00
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!relay)
|
|
|
|
return gfx::NativeView();
|
2017-03-04 02:09:16 +00:00
|
|
|
return relay->window->GetNativeView();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!web_contents_)
|
|
|
|
return gfx::NativeView();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2018-05-16 19:12:45 +00:00
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!relay)
|
|
|
|
return gfx::NativeView();
|
2017-03-04 02:09:16 +00:00
|
|
|
return relay->window->GetNativeView();
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!web_contents_)
|
|
|
|
return gfx::NativeWindow();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2018-05-16 19:12:45 +00:00
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!relay)
|
|
|
|
return gfx::NativeWindow();
|
2017-03-04 02:09:16 +00:00
|
|
|
return relay->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
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
void OffScreenWebContentsView::GetContainerBounds(gfx::Rect* out) const {
|
2016-07-20 09:30:06 +00:00
|
|
|
*out = GetViewBounds();
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::SizeContents(const gfx::Size& size) {}
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size,
|
2018-04-18 01:55:30 +00:00
|
|
|
gfx::NativeView context) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
|
|
|
content::RenderWidgetHostViewBase*
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenWebContentsView::CreateViewForWidget(
|
|
|
|
content::RenderWidgetHost* render_widget_host,
|
|
|
|
bool is_guest_view_hack) {
|
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
|
|
|
|
2018-05-04 06:45:12 +00:00
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
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,
|
|
|
|
nullptr, relay->window.get());
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
content::RenderWidgetHostViewBase*
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenWebContentsView::CreateViewForPopupWidget(
|
2016-07-30 18:39:17 +00:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2018-05-04 06:45:12 +00:00
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
2017-04-14 21:32:33 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
content::WebContentsImpl* web_contents_impl =
|
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_);
|
2017-04-14 21:32:33 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenRenderWidgetHostView* 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
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
return new OffScreenRenderWidgetHostView(
|
2018-04-18 01:55:30 +00:00
|
|
|
transparent_, true, view->GetFrameRate(), callback_, render_widget_host,
|
|
|
|
view, relay->window.get());
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
void OffScreenWebContentsView::RenderViewCreated(
|
|
|
|
content::RenderViewHost* host) {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (GetView())
|
|
|
|
GetView()->InstallTransparency();
|
2017-04-09 21:02:02 +00:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2017-04-11 12:19:34 +00:00
|
|
|
host->Send(new AtomViewMsg_Offscreen(host->GetRoutingID()));
|
2017-04-09 21:02:02 +00:00
|
|
|
#endif
|
2016-07-20 09:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 18:39:17 +00:00
|
|
|
void OffScreenWebContentsView::RenderViewSwappedIn(
|
2018-04-18 01:55:30 +00:00
|
|
|
content::RenderViewHost* 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
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::SetAllowOtherViews(bool allow) {}
|
2016-07-20 09:30:06 +00:00
|
|
|
|
|
|
|
bool OffScreenWebContentsView::GetAllowOtherViews() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenWebContentsView::IsEventTracking() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenWebContentsView::CloseTabAfterEventTracking() {}
|
2016-07-20 09:30:06 +00:00
|
|
|
#endif // defined(OS_MACOSX)
|
|
|
|
|
2016-07-25 13:55:00 +00:00
|
|
|
void OffScreenWebContentsView::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
|
|
|
blink::WebDragOperationsMask allowed_ops,
|
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
2017-01-24 05:06:48 +00:00
|
|
|
const content::DragEventSourceInfo& event_info,
|
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
2016-08-01 10:06:46 +00:00
|
|
|
if (web_contents_)
|
2017-01-24 05:06:48 +00:00
|
|
|
web_contents_->SystemDragEnded(source_rwh);
|
2016-07-25 13:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenWebContentsView::UpdateDragCursor(
|
2018-04-18 01:55:30 +00:00
|
|
|
blink::WebDragOperation operation) {}
|
2016-07-25 13:55:00 +00:00
|
|
|
|
2018-01-25 13:46:30 +00:00
|
|
|
void OffScreenWebContentsView::SetPainting(bool painting) {
|
|
|
|
auto* view = GetView();
|
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetPainting(painting);
|
|
|
|
} else {
|
|
|
|
painting_ = 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();
|
|
|
|
if (view != nullptr) {
|
|
|
|
view->SetFrameRate(frame_rate);
|
|
|
|
} else {
|
|
|
|
frame_rate_ = frame_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int OffScreenWebContentsView::GetFrameRate() const {
|
|
|
|
auto* view = GetView();
|
|
|
|
if (view != nullptr) {
|
|
|
|
return view->GetFrameRate();
|
|
|
|
} else {
|
|
|
|
return frame_rate_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-20 09:30:06 +00:00
|
|
|
} // namespace atom
|