Commit 099e6ff1 authored by danakj's avatar danakj Committed by Commit Bot

Introduce LocalFrame::GetWidgetForLocalRoot()

For LocalFrames that are in a Page owned by a WebView, each LocalFrame
has a WebLocalFrameImpl which has a WebFrameWidget. This is always
present except very early during initialization which most code can
ignore.

For LocalFrames in non-ordinary Pages, which live without a WebView
(such as WebPagePopupImpl, devtools agent, unit tests) the LocalFrame
has an EmptyLocalFrameClient instead of WebLocalFrameImpl and thus
there are no WebFrameWidgets.

Currently parts of core/ can not get to the WebFrameWidget because
WebLocalFrameImpl is banned due to the layering mess being unresolved.
It is also difficult to find the path there as going from LocalFrame
requires:

WebLocalFrameImpl::FromFrame(local_frame)->LocalRootFrameWidget()

Since the conversion to WebLocalFrameImpl isn't a member of LocalFrame
it's very hard to find and remember this path!

We introduce here a well-lit road from LocalFrame to its WebFrameWidget
and use it throughout ChromeClientImpl.

While updating ChromeClientImpl we note that it was early-outting on
WebViewImpl::does_composite() due to a null WebWidgetClient which it
is no longer using, as it defers to the WebFrameWidget. Since
ChromeClient means we have a WebView, we also know that WebFrameWidget
does exist, and it is a better place to early out. So these are moved.

This change will allow my display-mode CL for 1060336 to find the
WebFrameWidget from code in core/css/ without changing blink layering
more dramatically. And it is a long time coming to make this path
clearer.

R=dtapuska@chromium.org

Bug: 1060336, 844547, 1058633
Change-Id: Iabb71ebf0c5ebaf7daea924425c9d3a3a2c23d54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101847Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751064}
parent 43bcd3e4
......@@ -200,17 +200,7 @@ class PagePopupChromeClient final : public EmptyChromeClient {
}
void SetTouchAction(LocalFrame* frame, TouchAction touch_action) override {
DCHECK(frame);
WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(frame);
// TODO(https://crbug.com/844547): check if we are setting touch action on
// pop up window or not.
if (!web_frame)
return;
WebFrameWidget* widget = web_frame->LocalRoot()->FrameWidget();
if (!widget)
return;
if (WebWidgetClient* client = To<WebFrameWidgetBase>(widget)->Client())
client->SetTouchAction(static_cast<WebTouchAction>(touch_action));
// Touch action is not used in the compositor for WebPagePopup.
}
void AttachRootLayer(scoped_refptr<cc::Layer> layer,
......
......@@ -1315,6 +1315,15 @@ LocalFrameClient* LocalFrame::Client() const {
return static_cast<LocalFrameClient*>(Frame::Client());
}
FrameWidget* LocalFrame::GetWidgetForLocalRoot() {
WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(this);
if (!web_frame)
return nullptr;
// This WebFrameWidgetBase upcasts to a FrameWidget which is the interface
// exposed to Blink core.
return web_frame->LocalRootFrameWidget();
}
WebContentSettingsClient* LocalFrame::GetContentSettingsClient() {
return Client() ? Client()->GetContentSettingsClient() : nullptr;
}
......
......@@ -89,6 +89,7 @@ class FrameConsole;
class FrameOverlay;
// class FrameScheduler;
class FrameSelection;
class FrameWidget;
class InputMethodController;
class InspectorTraceEvents;
class CoreProbeSink;
......@@ -304,6 +305,13 @@ class CORE_EXPORT LocalFrame final : public Frame,
LocalFrameClient* Client() const;
// Returns the widget for this frame, or from the nearest ancestor which is a
// local root. It is never null for frames in ordinary Pages (which means the
// Page is inside a WebView), except very early in initialization. For frames
// in a non-ordinary Page (without a WebView, such as in unit tests, popups,
// devtools), it will always be null.
FrameWidget* GetWidgetForLocalRoot();
WebContentSettingsClient* GetContentSettingsClient();
PluginData* GetPluginData() const;
......
......@@ -387,19 +387,27 @@ bool WebFrameWidgetBase::ShouldRecordMainFrameMetrics() {
}
void WebFrameWidgetBase::SetNeedsRecalculateRasterScales() {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->SetNeedsRecalculateRasterScales();
}
void WebFrameWidgetBase::SetBackgroundColor(SkColor color) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->set_background_color(color);
}
void WebFrameWidgetBase::SetOverscrollBehavior(
const cc::OverscrollBehavior& overscroll_behavior) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->SetOverscrollBehavior(overscroll_behavior);
}
void WebFrameWidgetBase::RegisterSelection(cc::LayerSelection selection) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->RegisterSelection(selection);
}
......@@ -413,10 +421,14 @@ void WebFrameWidgetBase::StartPageScaleAnimation(
}
void WebFrameWidgetBase::RequestBeginMainFrameNotExpected(bool request) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->RequestBeginMainFrameNotExpected(request);
}
int WebFrameWidgetBase::GetLayerTreeId() {
if (!View()->does_composite())
return 0;
return widget_base_.LayerTreeHost()->GetId();
}
......@@ -438,11 +450,15 @@ cc::EventListenerProperties WebFrameWidgetBase::EventListenerProperties(
}
void WebFrameWidgetBase::StartDeferringCommits(base::TimeDelta timeout) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->StartDeferringCommits(timeout);
}
void WebFrameWidgetBase::StopDeferringCommits(
cc::PaintHoldingCommitTrigger triggger) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->StopDeferringCommits(triggger);
}
......@@ -763,9 +779,18 @@ class ReportTimeSwapPromise : public cc::SwapPromise {
DISALLOW_COPY_AND_ASSIGN(ReportTimeSwapPromise);
};
void WebFrameWidgetBase::NotifySwapAndPresentationTimeInBlink(
WebReportTimeCallback swap_time_callback,
WebReportTimeCallback presentation_time_callback) {
NotifySwapAndPresentationTime(std::move(swap_time_callback),
std::move(presentation_time_callback));
}
void WebFrameWidgetBase::NotifySwapAndPresentationTime(
WebReportTimeCallback swap_time_callback,
WebReportTimeCallback presentation_time_callback) {
if (!View()->does_composite())
return;
widget_base_.LayerTreeHost()->QueueSwapPromise(
std::make_unique<ReportTimeSwapPromise>(
std::move(swap_time_callback), std::move(presentation_time_callback),
......
......@@ -22,15 +22,11 @@
#include "third_party/blink/renderer/platform/graphics/paint/paint_image.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/widget/frame_widget.h"
#include "third_party/blink/renderer/platform/widget/widget_base.h"
#include "third_party/blink/renderer/platform/widget/widget_base_client.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace cc {
class AnimationHost;
class Layer;
}
namespace gfx {
class Point;
class PointF;
......@@ -51,7 +47,8 @@ class CORE_EXPORT WebFrameWidgetBase
: public GarbageCollected<WebFrameWidgetBase>,
public WebFrameWidget,
public WidgetBaseClient,
public mojom::blink::FrameWidget {
public mojom::blink::FrameWidget,
public FrameWidget {
public:
WebFrameWidgetBase(
WebWidgetClient&,
......@@ -65,7 +62,8 @@ class CORE_EXPORT WebFrameWidgetBase
widget);
~WebFrameWidgetBase() override;
WebWidgetClient* Client() const { return client_; }
// Returns the WebFrame that this widget is attached to. It will be a local
// root since only local roots have a widget attached.
WebLocalFrameImpl* LocalRootImpl() const { return local_root_; }
// Returns the bounding box of the block type node touched by the WebPoint.
......@@ -90,13 +88,27 @@ class CORE_EXPORT WebFrameWidgetBase
base::WeakPtr<PaintWorkletPaintDispatcher> EnsureCompositorPaintDispatcher(
scoped_refptr<base::SingleThreadTaskRunner>* paint_task_runner);
// Sets the root layer. The |layer| can be null when detaching the root layer.
virtual void SetRootLayer(scoped_refptr<cc::Layer> layer) = 0;
cc::AnimationHost* AnimationHost() const;
virtual HitTestResult CoreHitTestResultAt(const gfx::Point&) = 0;
// FrameWidget implementation.
WebWidgetClient* Client() const final { return client_; }
cc::AnimationHost* AnimationHost() const final;
void SetOverscrollBehavior(
const cc::OverscrollBehavior& overscroll_behavior) final;
void RequestAnimationAfterDelay(const base::TimeDelta&) final;
void RegisterSelection(cc::LayerSelection selection) final;
void RequestDecode(const cc::PaintImage&,
base::OnceCallback<void(bool)>) final;
void NotifySwapAndPresentationTimeInBlink(
WebReportTimeCallback swap_callback,
WebReportTimeCallback presentation_callback) final;
void RequestBeginMainFrameNotExpected(bool request) final;
int GetLayerTreeId() final;
void SetEventListenerProperties(cc::EventListenerClass,
cc::EventListenerProperties) final;
cc::EventListenerProperties EventListenerProperties(
cc::EventListenerClass) const final;
// WebFrameWidget implementation.
void Close() override;
WebLocalFrame* LocalRoot() const override;
......@@ -156,9 +168,6 @@ class CORE_EXPORT WebFrameWidgetBase
// mojom::blink::FrameWidget methods.
void DragSourceSystemDragEnded() override;
// Image decode functionality.
void RequestDecode(const PaintImage&, base::OnceCallback<void(bool)>);
// Called when the FrameView for this Widget's local root is created.
virtual void DidCreateLocalRootView() {}
......@@ -168,8 +177,6 @@ class CORE_EXPORT WebFrameWidgetBase
// focused frame has a different local root.
LocalFrame* FocusedLocalFrameInWidget() const;
void RequestAnimationAfterDelay(const base::TimeDelta&);
virtual void Trace(Visitor*);
// For when the embedder itself change scales on the page (e.g. devtools)
......@@ -181,14 +188,6 @@ class CORE_EXPORT WebFrameWidgetBase
// paint into another widget which has a background color of its own.
void SetBackgroundColor(SkColor color);
// Set the browser's behavior when overscroll happens, e.g. whether to glow
// or navigate.
void SetOverscrollBehavior(const cc::OverscrollBehavior& overscroll_behavior);
// Used to update the active selection bounds. Pass a default-constructed
// LayerSelection to clear it.
void RegisterSelection(cc::LayerSelection selection);
// Starts an animation of the page scale to a target scale factor and scroll
// offset.
// If use_anchor is true, destination is a point on the screen that will
......@@ -199,27 +198,9 @@ class CORE_EXPORT WebFrameWidgetBase
float new_page_scale,
base::TimeDelta duration);
// Enable or disable BeginMainFrameNotExpected signals from the compositor,
// which are consumed by the blink scheduler.
void RequestBeginMainFrameNotExpected(bool request);
// A stable numeric Id for the local root's compositor. For tracing/debugging
// purposes.
int GetLayerTreeId();
// Called to update if scroll events should be sent.
void SetHaveScrollEventHandlers(bool);
// Set or get what event handlers exist in the document contained in the
// WebWidget in order to inform the compositor thread if it is able to handle
// an input event, or it needs to pass it to the main thread to be handled.
// The class is the type of input event, and for each class there is a
// properties defining if the compositor thread can handle the event.
void SetEventListenerProperties(cc::EventListenerClass,
cc::EventListenerProperties);
cc::EventListenerProperties EventListenerProperties(
cc::EventListenerClass) const;
// Start deferring commits to the compositor, allowing document lifecycle
// updates without committing the layer tree. Commits are deferred
// until at most the given |timeout| has passed. If multiple calls are made
......
......@@ -136,11 +136,12 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
bool ForSubframe() const override { return true; }
void IntrinsicSizingInfoChanged(const IntrinsicSizingInfo&) override;
void DidCreateLocalRootView() override;
void SetRootLayer(scoped_refptr<cc::Layer>) override;
HitTestResult CoreHitTestResultAt(const gfx::Point&) override;
void ZoomToFindInPageRect(const WebRect& rect_in_root_frame) override;
// FrameWidget overrides:
void SetRootLayer(scoped_refptr<cc::Layer>) override;
// WidgetBaseClient overrides:
void BeginMainFrame(base::TimeTicks last_frame_time) override;
......
......@@ -98,10 +98,12 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
// WebFrameWidgetBase overrides:
bool ForSubframe() const override { return false; }
void SetRootLayer(scoped_refptr<cc::Layer>) override;
HitTestResult CoreHitTestResultAt(const gfx::Point&) override;
void ZoomToFindInPageRect(const WebRect& rect_in_root_frame) override;
// FrameWidget overrides:
void SetRootLayer(scoped_refptr<cc::Layer>) override;
// WidgetBaseClient overrides:
void BeginMainFrame(base::TimeTicks last_frame_time) override;
......
......@@ -86,39 +86,33 @@ enum class GlobalObjectReusePolicy;
class CORE_EXPORT EmptyChromeClient : public ChromeClient {
public:
~EmptyChromeClient() override = default;
void ChromeDestroyed() override {}
// ChromeClient implementation.
WebViewImpl* GetWebView() const override { return nullptr; }
void ChromeDestroyed() override {}
void SetWindowRect(const IntRect&, LocalFrame&) override {}
IntRect RootWindowRect(LocalFrame&) override { return IntRect(); }
void Focus(LocalFrame*) override {}
bool CanTakeFocus(mojom::blink::FocusType) override { return false; }
void TakeFocus(mojom::blink::FocusType) override {}
void Show(NavigationPolicy) override {}
void DidOverscroll(const gfx::Vector2dF&,
const gfx::Vector2dF&,
const gfx::PointF&,
const gfx::Vector2dF&) override {}
void SetOverscrollBehavior(LocalFrame& frame,
const cc::OverscrollBehavior&) override {}
void BeginLifecycleUpdates(LocalFrame& main_frame) override {}
void StartDeferringCommits(LocalFrame& main_frame,
base::TimeDelta timeout) override {}
void StopDeferringCommits(LocalFrame& main_frame,
cc::PaintHoldingCommitTrigger) override {}
void StartDragging(LocalFrame*,
const WebDragData&,
WebDragOperationsMask,
const SkBitmap& drag_image,
const gfx::Point& drag_image_offset) override {}
bool AcceptsLoadDrops() const override { return true; }
bool ShouldReportDetailedMessageForSource(LocalFrame&,
const String&) override {
return false;
......@@ -130,14 +124,11 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
unsigned,
const String&,
const String&) override {}
bool CanOpenBeforeUnloadConfirmPanel() override { return false; }
bool OpenBeforeUnloadConfirmPanelDelegate(LocalFrame*, bool) override {
return true;
}
void CloseWindowSoon() override {}
Page* CreateWindowDelegate(LocalFrame*,
const FrameLoadRequest&,
const AtomicString&,
......@@ -147,7 +138,6 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
const SessionStorageNamespaceId&) override {
return nullptr;
}
bool OpenJavaScriptAlertDelegate(LocalFrame*, const String&) override {
return false;
}
......@@ -160,7 +150,6 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
String&) override {
return false;
}
bool HasOpenedPopup() const override { return false; }
PopupMenu* OpenPopupMenu(LocalFrame&, HTMLSelectElement&) override;
PagePopup* OpenPagePopup(PagePopupClient*) override { return nullptr; }
......@@ -172,7 +161,6 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
void InvalidateRect(const IntRect&) override {}
void ScheduleAnimation(const LocalFrameView*,
base::TimeDelta = base::TimeDelta()) override {}
IntRect ViewportToScreen(const IntRect& r,
const LocalFrameView*) const override {
return r;
......@@ -184,13 +172,9 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
return WebScreenInfo();
}
void ContentsSizeChanged(LocalFrame*, const IntSize&) const override {}
void ShowMouseOverURL(const HitTestResult&) override {}
void SetToolTip(LocalFrame&, const String&, TextDirection) override {}
void PrintDelegate(LocalFrame*) override {}
ColorChooser* OpenColorChooser(LocalFrame*,
ColorChooserClient*,
const Color&) override;
......@@ -199,18 +183,14 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
DateTimeChooserClient*,
const DateTimeChooserParameters&) override;
void OpenTextDataListChooser(HTMLInputElement&) override;
void OpenFileChooser(LocalFrame*, scoped_refptr<FileChooser>) override;
void SetCursor(const ui::Cursor&, LocalFrame* local_root) override {}
void SetCursorOverridden(bool) override {}
ui::Cursor LastSetCursorForTesting() const override {
return PointerCursor();
}
void AttachRootLayer(scoped_refptr<cc::Layer>,
LocalFrame* local_root) override;
void SetEventListenerProperties(LocalFrame*,
cc::EventListenerClass,
cc::EventListenerProperties) override {}
......@@ -224,32 +204,23 @@ class CORE_EXPORT EmptyChromeClient : public ChromeClient {
void SetNeedsUnbufferedInputForDebugger(LocalFrame*, bool) override {}
void RequestUnbufferedInputEvents(LocalFrame*) override {}
void SetTouchAction(LocalFrame*, TouchAction) override {}
void DidAssociateFormControlsAfterLoad(LocalFrame*) override {}
String AcceptLanguages() override;
void RegisterPopupOpeningObserver(PopupOpeningObserver*) override {}
void UnregisterPopupOpeningObserver(PopupOpeningObserver*) override {}
void NotifyPopupOpeningObservers() const override {}
void FallbackCursorModeLockCursor(LocalFrame* frame,
bool left,
bool right,
bool up,
bool down) override {}
void FallbackCursorModeSetCursorVisibility(LocalFrame* frame,
bool visible) override {}
void RequestBeginMainFrameNotExpected(LocalFrame& frame,
bool request) override {}
int GetLayerTreeId(LocalFrame& frame) override { return 0; }
void SetCursorForPlugin(const ui::Cursor&, LocalFrame*) override {}
void InstallSupplements(LocalFrame&) override {}
void MainFrameScrollOffsetChanged(LocalFrame& main_frame) const override {}
};
......
......@@ -116,6 +116,8 @@ class CORE_EXPORT ChromeClient : public GarbageCollected<ChromeClient> {
public:
virtual ~ChromeClient() = default;
virtual WebViewImpl* GetWebView() const = 0;
// Converts the scalar value from window coordinates to viewport scale.
virtual float WindowToViewportScalar(LocalFrame*,
const float value) const = 0;
......@@ -263,8 +265,6 @@ class CORE_EXPORT ChromeClient : public GarbageCollected<ChromeClient> {
String& result);
virtual bool TabsToLinks() = 0;
virtual WebViewImpl* GetWebView() const = 0;
virtual WebScreenInfo GetScreenInfo(LocalFrame& frame) const = 0;
virtual void SetCursor(const ui::Cursor&, LocalFrame* local_root) = 0;
......
......@@ -63,9 +63,8 @@ class CORE_EXPORT ChromeClientImpl final : public ChromeClient {
~ChromeClientImpl() override;
void Trace(Visitor* visitor) override;
WebViewImpl* GetWebView() const override;
// ChromeClient methods:
WebViewImpl* GetWebView() const override;
void ChromeDestroyed() override;
void SetWindowRect(const IntRect&, LocalFrame&) override;
IntRect RootWindowRect(LocalFrame&) override;
......
......@@ -1442,6 +1442,8 @@ jumbo_component("platform") {
"webrtc/webrtc_video_frame_adapter.h",
"webrtc/webrtc_video_utils.cc",
"webrtc/webrtc_video_utils.h",
"widget/frame_widget.cc",
"widget/frame_widget.h",
"widget/widget_base.cc",
"widget/widget_base.h",
"widget/widget_base_client.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/widget/frame_widget.h"
namespace blink {
FrameWidget::~FrameWidget() = default;
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
#include "third_party/blink/public/web/web_swap_result.h"
#include "third_party/blink/public/web/web_widget_client.h"
#include "third_party/blink/renderer/platform/platform_export.h"
namespace cc {
class AnimationHost;
class Layer;
class PaintImage;
} // namespace cc
namespace blink {
// In interface exposed within Blink from local root frames that provides
// local-root specific things related to compositing and input.
class PLATFORM_EXPORT FrameWidget {
public:
virtual ~FrameWidget();
// Returns the WebWidgetClient, which is implemented outside of blink.
virtual WebWidgetClient* Client() const = 0;
// Returns the compositors's AnimationHost for the widget.
virtual cc::AnimationHost* AnimationHost() const = 0;
// Set the browser's behavior when overscroll happens, e.g. whether to glow
// or navigate.
virtual void SetOverscrollBehavior(
const cc::OverscrollBehavior& overscroll_behavior) = 0;
// Posts a task with the given delay, then calls ScheduleAnimation() on the
// Client().
virtual void RequestAnimationAfterDelay(const base::TimeDelta&) = 0;
// Sets the root layer. The |layer| can be null when detaching the root layer.
virtual void SetRootLayer(scoped_refptr<cc::Layer> layer) = 0;
// Used to update the active selection bounds. Pass a default-constructed
// LayerSelection to clear it.
virtual void RegisterSelection(cc::LayerSelection selection) = 0;
// Image decode functionality.
virtual void RequestDecode(const cc::PaintImage&,
base::OnceCallback<void(bool)>) = 0;
// Forwards to WebFrameWidget::NotifySwapAndPresentationTime().
// The |callback| will be fired when the corresponding renderer frame is
// submitted (still called "swapped") to the display compositor (either with
// DidSwap or DidNotSwap).
virtual void NotifySwapAndPresentationTimeInBlink(
WebReportTimeCallback swap_callback,
WebReportTimeCallback presentation_callback) = 0;
// Enable or disable BeginMainFrameNotExpected signals from the compositor,
// which are consumed by the blink scheduler.
virtual void RequestBeginMainFrameNotExpected(bool request) = 0;
// A stable numeric Id for the local root's compositor. For tracing/debugging
// purposes.
virtual int GetLayerTreeId() = 0;
// Set or get what event handlers exist in the document contained in the
// WebWidget in order to inform the compositor thread if it is able to handle
// an input event, or it needs to pass it to the main thread to be handled.
// The class is the type of input event, and for each class there is a
// properties defining if the compositor thread can handle the event.
virtual void SetEventListenerProperties(cc::EventListenerClass,
cc::EventListenerProperties) = 0;
virtual cc::EventListenerProperties EventListenerProperties(
cc::EventListenerClass) const = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment