1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_CHILD_FRAME_H_
#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_CHILD_FRAME_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/input/touch_action.h"
#include "components/input/child_frame_input_helper.h"
#include "components/input/event_with_latency_info.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/frame_timing_details_map.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/host/host_frame_sink_client.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/common/content_export.h"
#include "content/public/browser/touch_selection_controller_client_manager.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom.h"
#include "third_party/blink/public/common/widget/visual_properties.h"
#include "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/viewport_intersection_state.mojom-forward.h"
#include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h"
#include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom-forward.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#if BUILDFLAG(IS_MAC)
#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
#endif // BUILDFLAG(IS_MAC)
namespace content {
class CrossProcessFrameConnector;
class RenderWidgetHost;
class RenderWidgetHostViewChildFrameTest;
class TouchSelectionControllerClientChildFrame;
// RenderWidgetHostViewChildFrame implements the view for a RenderWidgetHost
// associated with content being rendered in a separate process from
// content that is embedding it. This is not a platform-specific class; rather,
// the embedding renderer process implements the platform containing the
// widget, and the top-level frame's RenderWidgetHostView will ultimately
// manage all native widget interaction.
//
// See comments in render_widget_host_view.h about this class and its members.
class CONTENT_EXPORT RenderWidgetHostViewChildFrame
: public RenderWidgetHostViewBase,
public TouchSelectionControllerClientManager::Observer,
public RenderFrameMetadataProvider::Observer,
public viz::HostFrameSinkClient {
public:
// TODO(crbug.com/40170974): Pass multi-screen info from the parent.
static RenderWidgetHostViewChildFrame* Create(
RenderWidgetHost* widget,
const display::ScreenInfos& parent_screen_infos);
RenderWidgetHostViewChildFrame(const RenderWidgetHostViewChildFrame&) =
delete;
RenderWidgetHostViewChildFrame& operator=(
const RenderWidgetHostViewChildFrame&) = delete;
void SetFrameConnector(CrossProcessFrameConnector* frame_connector);
// TouchSelectionControllerClientManager::Observer implementation.
void OnManagerWillDestroy(
TouchSelectionControllerClientManager* manager) override;
// RenderWidgetHostView implementation.
void InitAsChild(gfx::NativeView parent_view) override;
void SetSize(const gfx::Size& size) override;
void SetBounds(const gfx::Rect& rect) override;
void Focus() override;
bool HasFocus() override;
bool IsSurfaceAvailableForCopy() override;
void CopyFromSurface(
const gfx::Rect& src_rect,
const gfx::Size& output_size,
base::OnceCallback<void(const SkBitmap&)> callback) override;
void EnsureSurfaceSynchronizedForWebTest() override;
void Hide() override;
bool IsShowing() override;
void WasUnOccluded() override;
void WasOccluded() override;
gfx::Rect GetViewBounds() override;
gfx::Size GetVisibleViewportSize() override;
gfx::Size GetVisibleViewportSizeDevicePx() override;
void SetInsets(const gfx::Insets& insets) override;
gfx::NativeView GetNativeView() override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
bool IsPointerLocked() override;
void TakeFallbackContentFrom(RenderWidgetHostView* view) override;
// RenderWidgetHostViewBase implementation.
#if BUILDFLAG(IS_ANDROID)
bool IsTouchSequencePotentiallyActiveOnViz() override;
void RequestInputBackForDragAndDrop(
blink::mojom::DragDataPtr drag_data,
const url::Origin& source_origin,
blink::DragOperationsMask drag_operations_mask,
SkBitmap bitmap,
gfx::Vector2d cursor_offset_in_dip,
gfx::Rect drag_obj_rect_in_dip,
blink::mojom::DragEventSourceInfoPtr event_info) override;
#endif
RenderWidgetHostViewBase* GetRootView() override;
uint32_t GetCaptureSequenceNumber() const override;
gfx::Size GetCompositorViewportPixelSize() override;
void InitAsPopup(RenderWidgetHostView* parent_host_view,
const gfx::Rect& bounds,
const gfx::Rect& anchor_rect) override;
void UpdateCursor(const ui::Cursor& cursor) override;
void UpdateScreenInfo() override;
void SendInitialPropertiesIfNeeded() override;
void SetIsLoading(bool is_loading) override;
void RenderProcessGone() override;
void ShowWithVisibility(PageVisibilityState page_visibility) override;
void Destroy() override;
void UpdateTooltipUnderCursor(const std::u16string& tooltip_text) override;
void UpdateTooltipFromKeyboard(const std::u16string& tooltip_text,
const gfx::Rect& bounds) override;
void ClearKeyboardTriggeredTooltip() override;
void GestureEventAck(const blink::WebGestureEvent& event,
blink::mojom::InputEventResultSource ack_source,
blink::mojom::InputEventResultState ack_result) override;
// Since the URL of content rendered by this class is not displayed in
// the URL bar, this method does not need an implementation.
void ResetFallbackToFirstNavigationSurface() override {}
void TransformPointToRootSurface(gfx::PointF* point) override;
gfx::Rect GetBoundsInRootWindow() override;
void DidStopFlinging() override;
blink::mojom::PointerLockResult LockPointer(
bool request_unadjusted_movement) override;
blink::mojom::PointerLockResult ChangePointerLock(
bool request_unadjusted_movement) override;
void UnlockPointer() override;
const viz::FrameSinkId& GetFrameSinkId() const override;
const viz::LocalSurfaceId& GetLocalSurfaceId() const override;
void NotifyHitTestRegionUpdated(const viz::AggregatedHitTestRegion&) override;
bool ScreenRectIsUnstableFor(const blink::WebInputEvent& event) override;
bool ScreenRectIsUnstableForIOv2For(
const blink::WebInputEvent& event) override;
void PreProcessTouchEvent(const blink::WebTouchEvent& event) override;
viz::FrameSinkId GetRootFrameSinkId() override;
viz::SurfaceId GetCurrentSurfaceId() const override;
bool HasSize() const override;
double GetCSSZoomFactor() const override;
gfx::PointF TransformPointToRootCoordSpaceF(
const gfx::PointF& point) const override;
bool TransformPointToCoordSpaceForView(
const gfx::PointF& point,
input::RenderWidgetHostViewInput* target_view,
gfx::PointF* transformed_point) override;
void DidNavigate() override;
gfx::PointF TransformRootPointToViewCoordSpace(
const gfx::PointF& point) override;
TouchSelectionControllerClientManager*
GetTouchSelectionControllerClientManager() override;
void UpdateIntrinsicSizingInfo(
blink::mojom::IntrinsicSizingInfoPtr sizing_info) override;
std::unique_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget()
override;
bool IsRenderWidgetHostViewChildFrame() const override;
void InvalidateLocalSurfaceIdAndAllocationGroup() override;
#if BUILDFLAG(IS_MAC)
// RenderWidgetHostView implementation.
void SetActive(bool active) override;
void ShowDefinitionForSelection() override;
void SpeakSelection() override;
void SetWindowFrameInScreen(const gfx::Rect& rect) override;
void ShowSharePicker(
const std::string& title,
const std::string& text,
const std::string& url,
const std::vector<std::string>& file_paths,
blink::mojom::ShareService::ShareCallback callback) override;
uint64_t GetNSViewId() const override;
#endif // BUILDFLAG(IS_MAC)
blink::mojom::InputEventResultState FilterInputEvent(
const blink::WebInputEvent& input_event) override;
void EnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) override;
void DisableAutoResize(const gfx::Size& new_size) override;
viz::ScopedSurfaceIdAllocator DidUpdateVisualProperties(
const cc::RenderFrameMetadata& metadata) override;
// RenderFrameMetadataProvider::Observer implementation.
void OnRenderFrameMetadataChangedBeforeActivation(
const cc::RenderFrameMetadata& metadata) override {}
void OnRenderFrameMetadataChangedAfterActivation(
base::TimeTicks activation_time) override;
void OnRenderFrameSubmission() override {}
void OnLocalSurfaceIdChanged(
const cc::RenderFrameMetadata& metadata) override {}
// viz::HostFrameSinkClient implementation.
void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
void OnFrameTokenChanged(uint32_t frame_token,
base::TimeTicks activation_time) override;
CrossProcessFrameConnector* FrameConnectorForTesting() const {
return frame_connector_;
}
RenderWidgetHostViewBase* GetParentViewInput() override;
void RegisterFrameSinkId();
void UnregisterFrameSinkId();
void UpdateViewportIntersection(
const blink::mojom::ViewportIntersectionState& intersection_state,
const std::optional<blink::VisualProperties>& visual_properties);
// TODO(sunxd): Rename SetIsInert to UpdateIsInert.
void SetIsInert();
void UpdateInheritedEffectiveTouchAction();
void UpdateRenderThrottlingStatus();
ui::TextInputType GetTextInputType() const;
// Retrieves the UTF-16 code unit range containing accessible text in the
// view. Returns false if the information cannot be retrieved right now.
bool GetTextRange(gfx::Range* range) const;
RenderWidgetHostViewBase* GetRootRenderWidgetHostView() const;
protected:
friend class RenderWidgetHostView;
friend class RenderWidgetHostViewChildFrameTest;
FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewChildFrameTest,
ForwardsBeginFrameAcks);
RenderWidgetHostViewChildFrame(
RenderWidgetHost* widget,
const display::ScreenInfos& parent_screen_infos);
void Init();
// Sets |parent_frame_sink_id_| and registers frame sink hierarchy. If the
// parent was already set then it also unregisters hierarchy.
void SetParentFrameSinkId(const viz::FrameSinkId& parent_frame_sink_id);
// Clears current compositor surface, if one is in use.
void ClearCompositorSurfaceIfNecessary();
void ProcessFrameSwappedCallbacks();
// RenderWidgetHostViewBase:
void UpdateFrameSinkIdRegistration() override;
void UpdateBackgroundColor() override;
std::optional<DisplayFeature> GetDisplayFeature() override;
void DisableDisplayFeatureOverrideForEmulation() override;
void OverrideDisplayFeatureForEmulation(
const DisplayFeature* display_feature) override;
void NotifyHostAndDelegateOnWasShown(
blink::mojom::RecordContentToVisibleTimeRequestPtr) final;
void RequestSuccessfulPresentationTimeFromHostOrDelegate(
blink::mojom::RecordContentToVisibleTimeRequestPtr) final;
void CancelSuccessfulPresentationTimeRequestForHostAndDelegate() final;
void StopFlingingIfNecessary(
const blink::WebGestureEvent& event,
blink::mojom::InputEventResultState ack_result) override;
// The ID for FrameSink associated with this view.
viz::FrameSinkId frame_sink_id_;
// Surface-related state.
viz::SurfaceInfo last_activated_surface_info_;
gfx::Rect last_screen_rect_;
// frame_connector_ provides a platform abstraction. Messages
// sent through it are routed to the embedding renderer process.
raw_ptr<CrossProcessFrameConnector> frame_connector_;
base::WeakPtr<RenderWidgetHostViewChildFrame> AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
ui::Compositor* GetCompositor() override;
void SetInputHelperForTesting(
std::unique_ptr<input::ChildFrameInputHelper> input_helper) {
input_helper_ = std::move(input_helper);
}
protected:
~RenderWidgetHostViewChildFrame() override;
private:
FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest,
HiddenOOPIFWillNotGenerateCompositorFrames);
FRIEND_TEST_ALL_PREFIXES(
SitePerProcessBrowserTest,
HiddenOOPIFWillNotGenerateCompositorFramesAfterNavigation);
FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest,
SubframeVisibleAfterRenderViewBecomesSwappedOut);
FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostInputEventRouterTest,
FilteredGestureDoesntInterruptBubbling);
friend class RenderWidgetHostViewChildFrameTest;
virtual void FirstSurfaceActivation(const viz::SurfaceInfo& surface_info);
void DetachFromTouchSelectionClientManagerIfNecessary();
// Returns false if the view cannot be shown. This is the case where the frame
// associated with this view or a cross process ancestor frame has been hidden
// using CSS.
bool CanBecomeVisible();
void OnDidUpdateVisualPropertiesComplete(
const cc::RenderFrameMetadata& metadata);
void ForwardTouchpadZoomEventIfNecessary(
const blink::WebGestureEvent& event,
blink::mojom::InputEventResultState ack_result) override;
// TODO(crbug.com/375388841): Remove these once Aura also uses
// TouchSelectionControllerInputObserver. These are not needed on Android
// since it uses TouchSelectionControllerInputObserver.
#if !BUILDFLAG(IS_ANDROID)
// Performs gesture ack handling needed for swipe-to-move-cursor gestures.
void HandleSwipeToMoveCursorGestureAck(const blink::WebGestureEvent& event);
// Whether a swipe-to-move-cursor gesture is activated.
bool swipe_to_move_cursor_activated_ = false;
#endif
std::vector<base::OnceClosure> frame_swapped_callbacks_;
std::unique_ptr<input::ChildFrameInputHelper> input_helper_;
// The surface client ID of the parent RenderWidgetHostView. 0 if none.
viz::FrameSinkId parent_frame_sink_id_;
gfx::Insets insets_;
std::unique_ptr<TouchSelectionControllerClientChildFrame>
selection_controller_client_;
// If a new RWHVCF is created for a cross-origin navigation, the parent
// will typically not notice and will not transmit a full complement of
// properties.
bool initial_properties_sent_ = false;
base::WeakPtrFactory<RenderWidgetHostViewChildFrame> weak_factory_{this};
};
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_CHILD_FRAME_H_
|