diff --git content/browser/renderer_host/render_widget_host_view_aura.cc content/browser/renderer_host/render_widget_host_view_aura.cc index e6235611a2ae6..61cc0e5f23c85 100644 --- content/browser/renderer_host/render_widget_host_view_aura.cc +++ content/browser/renderer_host/render_widget_host_view_aura.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "base/auto_reset.h" @@ -52,6 +53,7 @@ #include "content/public/browser/content_browser_client.h" #include "content/public/browser/device_service.h" #include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" #include "content/public/common/page_visibility_state.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/common/input/web_input_event.h" @@ -753,6 +755,9 @@ gfx::Rect RenderWidgetHostViewAura::GetViewBounds() { void RenderWidgetHostViewAura::UpdateBackgroundColor() { CHECK(GetBackgroundColor()); + if (!window_) { + return; + } SkColor color = *GetBackgroundColor(); window_->layer()->SetColor(color); } @@ -1102,6 +1107,12 @@ void RenderWidgetHostViewAura::TransformPointToRootSurface(gfx::PointF* point) { } gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() { + if (!root_window_bounds_callback_.is_null()) { + if (auto bounds = root_window_bounds_callback_.Run()) { + return *bounds; + } + } + aura::Window* top_level = window_->GetToplevelWindow(); gfx::Rect bounds(top_level->GetBoundsInScreen()); @@ -2664,6 +2675,16 @@ void RenderWidgetHostViewAura::CreateAuraWindow(aura::client::WindowType type) { window_->layer()->SetColor(GetBackgroundColor() ? *GetBackgroundColor() : SK_ColorWHITE); UpdateFrameSinkIdRegistration(); + + // Do this after |window_| is created to avoid crashes on Win10. + // See https://crbug.com/761389. + auto* web_contents = + WebContents::FromRenderViewHost(RenderViewHost::From(host())); + if (web_contents) { + // TODO(mostynb): actually use prefs. Landing this as a separate CL + // first to rebaseline some unreliable layout tests. + std::ignore = web_contents->GetOrCreateWebPreferences(); + } } void RenderWidgetHostViewAura::UpdateFrameSinkIdRegistration() { diff --git content/browser/renderer_host/render_widget_host_view_aura.h content/browser/renderer_host/render_widget_host_view_aura.h index 33d9c06d52f0e..85a37269f20b7 100644 --- content/browser/renderer_host/render_widget_host_view_aura.h +++ content/browser/renderer_host/render_widget_host_view_aura.h @@ -451,6 +451,12 @@ class CONTENT_EXPORT RenderWidgetHostViewAura } #endif // BUILDFLAG(IS_WIN) + using RootWindowBoundsCallback = + base::RepeatingCallback()>; + void SetRootWindowBoundsCallback(const RootWindowBoundsCallback& callback) { + root_window_bounds_callback_ = callback; + } + protected: ~RenderWidgetHostViewAura() override; @@ -874,6 +880,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura std::optional display_observer_; + RootWindowBoundsCallback root_window_bounds_callback_; + base::WeakPtrFactory weak_ptr_factory_{this}; };