fix: move NativeWindow tracking to OSR WCV (#15585)

* fix: move NativeWindow tracking to OSR WCV

* fix oops
This commit is contained in:
Andy Dill 2018-11-29 21:25:02 -08:00 committed by Shelley Vohr
parent 78b88a70bb
commit 8cca1c987b
7 changed files with 71 additions and 81 deletions

View file

@ -53,7 +53,7 @@ class WebViewGuestDelegate;
class FrameSubscriber; class FrameSubscriber;
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
class OffScreenWebContentsView; class OffScreenRenderWidgetHostView;
#endif #endif
namespace api { namespace api {
@ -457,9 +457,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
uint32_t GetNextRequestId() { return ++request_id_; } uint32_t GetNextRequestId() { return ++request_id_; }
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
OffScreenWebContentsView* GetOffScreenWebContentsView() const; OffScreenWebContentsView* GetOffScreenWebContentsView() const override;
OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView() OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView() const;
const override;
#endif #endif
// Called when we receive a CursorChange message from chromium. // Called when we receive a CursorChange message from chromium.

View file

@ -40,7 +40,7 @@
#include "storage/browser/fileapi/isolated_context.h" #include "storage/browser/fileapi/isolated_context.h"
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
#include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/osr/osr_web_contents_view.h"
#endif #endif
#if BUILDFLAG(ENABLE_PRINTING) #if BUILDFLAG(ENABLE_PRINTING)
@ -215,9 +215,9 @@ void CommonWebContentsDelegate::SetOwnerWindow(
NativeWindowRelay::kNativeWindowRelayUserDataKey); NativeWindowRelay::kNativeWindowRelayUserDataKey);
} }
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
auto* osr_rwhv = GetOffScreenRenderWidgetHostView(); auto* osr_wcv = GetOffScreenWebContentsView();
if (osr_rwhv) if (osr_wcv)
osr_rwhv->SetNativeWindow(owner_window); osr_wcv->SetNativeWindow(owner_window);
#endif #endif
} }
@ -256,8 +256,8 @@ content::WebContents* CommonWebContentsDelegate::GetDevToolsWebContents()
} }
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
OffScreenRenderWidgetHostView* OffScreenWebContentsView*
CommonWebContentsDelegate::GetOffScreenRenderWidgetHostView() const { CommonWebContentsDelegate::GetOffScreenWebContentsView() const {
return nullptr; return nullptr;
} }
#endif #endif

View file

@ -33,7 +33,7 @@ class NativeWindow;
class WebDialogHelper; class WebDialogHelper;
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
class OffScreenRenderWidgetHostView; class OffScreenWebContentsView;
#endif #endif
class CommonWebContentsDelegate : public content::WebContentsDelegate, class CommonWebContentsDelegate : public content::WebContentsDelegate,
@ -70,8 +70,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate,
protected: protected:
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
virtual OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView() virtual OffScreenWebContentsView* GetOffScreenWebContentsView() const;
const;
#endif #endif
// content::WebContentsDelegate: // content::WebContentsDelegate:

View file

@ -257,15 +257,14 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
const OnPaintCallback& callback, const OnPaintCallback& callback,
content::RenderWidgetHost* host, content::RenderWidgetHost* host,
OffScreenRenderWidgetHostView* parent_host_view, OffScreenRenderWidgetHostView* parent_host_view,
NativeWindow* native_window) gfx::Size initial_size)
: content::RenderWidgetHostViewBase(host), : content::RenderWidgetHostViewBase(host),
render_widget_host_(content::RenderWidgetHostImpl::From(host)), render_widget_host_(content::RenderWidgetHostImpl::From(host)),
parent_host_view_(parent_host_view), parent_host_view_(parent_host_view),
native_window_(native_window),
transparent_(transparent), transparent_(transparent),
callback_(callback), callback_(callback),
frame_rate_(frame_rate), frame_rate_(frame_rate),
size_(native_window ? native_window->GetSize() : gfx::Size()), size_(initial_size),
painting_(painting), painting_(painting),
is_showing_(!render_widget_host_->is_hidden()), is_showing_(!render_widget_host_->is_hidden()),
cursor_manager_(new content::CursorManager(this)), cursor_manager_(new content::CursorManager(this)),
@ -312,18 +311,12 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
#endif #endif
GetCompositor()->SetDelegate(this); GetCompositor()->SetDelegate(this);
if (native_window_)
native_window_->AddObserver(this);
ResizeRootLayer(false); ResizeRootLayer(false);
render_widget_host_->SetView(this); render_widget_host_->SetView(this);
InstallTransparency(); InstallTransparency();
} }
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
if (native_window_)
native_window_->RemoveObserver(this);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
if (is_showing_) if (is_showing_)
browser_compositor_->SetRenderWidgetHostIsHidden(true); browser_compositor_->SetRenderWidgetHostIsHidden(true);
@ -354,19 +347,6 @@ OffScreenRenderWidgetHostView::CreateBrowserAccessibilityManager(
return nullptr; return nullptr;
} }
void OffScreenRenderWidgetHostView::OnWindowResize() {
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
auto size = native_window_ ? native_window_->GetSize() : gfx::Size();
SetSize(size);
}
void OffScreenRenderWidgetHostView::OnWindowClosed() {
if (native_window_) {
native_window_->RemoveObserver(this);
native_window_ = nullptr;
}
}
void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() { void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() {
const base::TimeTicks frame_time = base::TimeTicks::Now(); const base::TimeTicks frame_time = base::TimeTicks::Now();
const base::TimeDelta vsync_period = const base::TimeDelta vsync_period =
@ -757,7 +737,7 @@ OffScreenRenderWidgetHostView::CreateViewForWidget(
return new OffScreenRenderWidgetHostView( return new OffScreenRenderWidgetHostView(
transparent_, true, embedder_host_view->GetFrameRate(), callback_, transparent_, true, embedder_host_view->GetFrameRate(), callback_,
render_widget_host, embedder_host_view, native_window_); render_widget_host, embedder_host_view, size());
} }
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
@ -1259,18 +1239,6 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
} }
} }
void OffScreenRenderWidgetHostView::SetNativeWindow(NativeWindow* window) {
if (native_window_)
native_window_->RemoveObserver(this);
native_window_ = window;
if (native_window_)
native_window_->AddObserver(this);
OnWindowResize();
}
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) { void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
SetupFrameRate(false); SetupFrameRate(false);

View file

@ -14,8 +14,6 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_observer.h"
#include "atom/browser/osr/osr_output_device.h" #include "atom/browser/osr/osr_output_device.h"
#include "atom/browser/osr/osr_view_proxy.h" #include "atom/browser/osr/osr_view_proxy.h"
#include "base/process/kill.h" #include "base/process/kill.h"
@ -75,7 +73,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
public content::DelegatedFrameHostClient, public content::DelegatedFrameHostClient,
#endif #endif
public NativeWindowObserver,
public OffscreenViewProxyObserver { public OffscreenViewProxyObserver {
public: public:
OffScreenRenderWidgetHostView(bool transparent, OffScreenRenderWidgetHostView(bool transparent,
@ -84,7 +81,7 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
const OnPaintCallback& callback, const OnPaintCallback& callback,
content::RenderWidgetHost* render_widget_host, content::RenderWidgetHost* render_widget_host,
OffScreenRenderWidgetHostView* parent_host_view, OffScreenRenderWidgetHostView* parent_host_view,
NativeWindow* native_window); gfx::Size initial_size);
~OffScreenRenderWidgetHostView() override; ~OffScreenRenderWidgetHostView() override;
content::BrowserAccessibilityManager* CreateBrowserAccessibilityManager( content::BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
@ -205,10 +202,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
bool InstallTransparency(); bool InstallTransparency();
// NativeWindowObserver:
void OnWindowResize() override;
void OnWindowClosed() override;
void OnBeginFrameTimerTick(); void OnBeginFrameTimerTick();
void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period); void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);
@ -268,8 +261,7 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
content::RenderWidgetHostImpl* render_widget_host() const { content::RenderWidgetHostImpl* render_widget_host() const {
return render_widget_host_; return render_widget_host_;
} }
void SetNativeWindow(NativeWindow* window);
NativeWindow* window() const { return native_window_; }
gfx::Size size() const { return size_; } gfx::Size size() const { return size_; }
void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) { void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) {
@ -306,7 +298,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
std::set<OffScreenRenderWidgetHostView*> guest_host_views_; std::set<OffScreenRenderWidgetHostView*> guest_host_views_;
std::set<OffscreenViewProxy*> proxy_views_; std::set<OffscreenViewProxy*> proxy_views_;
NativeWindow* native_window_;
OffScreenOutputDevice* software_output_device_ = nullptr; OffScreenOutputDevice* software_output_device_ = nullptr;
const bool transparent_; const bool transparent_;

View file

@ -15,13 +15,16 @@ namespace atom {
OffScreenWebContentsView::OffScreenWebContentsView( OffScreenWebContentsView::OffScreenWebContentsView(
bool transparent, bool transparent,
const OnPaintCallback& callback) const OnPaintCallback& callback)
: transparent_(transparent), callback_(callback) { : native_window_(nullptr), transparent_(transparent), callback_(callback) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
PlatformCreate(); PlatformCreate();
#endif #endif
} }
OffScreenWebContentsView::~OffScreenWebContentsView() { OffScreenWebContentsView::~OffScreenWebContentsView() {
if (native_window_)
native_window_->RemoveObserver(this);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
PlatformDestroy(); PlatformDestroy();
#endif #endif
@ -34,35 +37,52 @@ void OffScreenWebContentsView::SetWebContents(
RenderViewCreated(web_contents_->GetRenderViewHost()); RenderViewCreated(web_contents_->GetRenderViewHost());
} }
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();
}
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
gfx::NativeView OffScreenWebContentsView::GetNativeView() const { gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
if (!web_contents_) if (!native_window_)
return gfx::NativeView(); return gfx::NativeView();
return native_window_->GetNativeView();
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
return gfx::NativeView();
return relay->GetNativeWindow()->GetNativeView();
} }
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const { gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
if (!web_contents_) if (!native_window_)
return gfx::NativeView(); return gfx::NativeView();
return native_window_->GetNativeView();
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
return gfx::NativeView();
return relay->GetNativeWindow()->GetNativeView();
} }
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const { gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
if (!web_contents_) if (!native_window_)
return gfx::NativeWindow(); return gfx::NativeWindow();
return native_window_->GetNativeWindow();
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
return gfx::NativeWindow();
return relay->GetNativeWindow()->GetNativeWindow();
} }
#endif #endif
@ -104,7 +124,7 @@ OffScreenWebContentsView::CreateViewForWidget(
return new OffScreenRenderWidgetHostView( return new OffScreenRenderWidgetHostView(
transparent_, painting_, GetFrameRate(), callback_, render_widget_host, transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
nullptr, nullptr); nullptr, GetSize());
} }
content::RenderWidgetHostViewBase* content::RenderWidgetHostViewBase*
@ -122,7 +142,7 @@ OffScreenWebContentsView::CreateViewForPopupWidget(
return new OffScreenRenderWidgetHostView(transparent_, true, return new OffScreenRenderWidgetHostView(transparent_, true,
view->GetFrameRate(), callback_, view->GetFrameRate(), callback_,
render_widget_host, view, nullptr); render_widget_host, view, GetSize());
} }
void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {} void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {}

View file

@ -5,6 +5,9 @@
#ifndef ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_ #ifndef ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
#define ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_ #define ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_observer.h"
#include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/osr/osr_render_widget_host_view.h"
#include "content/browser/renderer_host/render_view_host_delegate_view.h" #include "content/browser/renderer_host/render_view_host_delegate_view.h"
#include "content/browser/web_contents/web_contents_view.h" #include "content/browser/web_contents/web_contents_view.h"
@ -21,12 +24,20 @@ class OffScreenView;
namespace atom { namespace atom {
class OffScreenWebContentsView : public content::WebContentsView, class OffScreenWebContentsView : public content::WebContentsView,
public content::RenderViewHostDelegateView { public content::RenderViewHostDelegateView,
public NativeWindowObserver {
public: public:
OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback); OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback);
~OffScreenWebContentsView() override; ~OffScreenWebContentsView() override;
void SetWebContents(content::WebContents*); void SetWebContents(content::WebContents*);
void SetNativeWindow(NativeWindow* window);
// NativeWindowObserver:
void OnWindowResize() override;
void OnWindowClosed() override;
gfx::Size GetSize();
// content::WebContentsView: // content::WebContentsView:
gfx::NativeView GetNativeView() const override; gfx::NativeView GetNativeView() const override;
@ -84,6 +95,8 @@ class OffScreenWebContentsView : public content::WebContentsView,
OffScreenRenderWidgetHostView* GetView() const; OffScreenRenderWidgetHostView* GetView() const;
NativeWindow* native_window_;
const bool transparent_; const bool transparent_;
bool painting_ = true; bool painting_ = true;
int frame_rate_ = 60; int frame_rate_ = 60;