1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4
5 #include "third_party/blink/renderer/core/frame/remote_frame_owner.h"
6
7 #include "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom-blink.h"
8 #include "third_party/blink/public/web/web_local_frame_client.h"
9 #include "third_party/blink/renderer/core/frame/local_dom_window.h"
10 #include "third_party/blink/renderer/core/frame/local_frame.h"
11 #include "third_party/blink/renderer/core/frame/local_frame_client.h"
12 #include "third_party/blink/renderer/core/frame/web_frame_widget_base.h"
13 #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
14 #include "third_party/blink/renderer/core/frame/web_remote_frame_impl.h"
15 #include "third_party/blink/renderer/core/layout/intrinsic_sizing_info.h"
16 #include "third_party/blink/renderer/core/timing/performance.h"
17
18 namespace blink {
19
RemoteFrameOwner(const FramePolicy & frame_policy,const WebFrameOwnerProperties & frame_owner_properties,mojom::blink::FrameOwnerElementType frame_owner_element_type)20 RemoteFrameOwner::RemoteFrameOwner(
21 const FramePolicy& frame_policy,
22 const WebFrameOwnerProperties& frame_owner_properties,
23 mojom::blink::FrameOwnerElementType frame_owner_element_type)
24 : frame_policy_(frame_policy),
25 browsing_context_container_name_(
26 static_cast<String>(frame_owner_properties.name)),
27 scrollbar_(frame_owner_properties.scrollbar_mode),
28 margin_width_(frame_owner_properties.margin_width),
29 margin_height_(frame_owner_properties.margin_height),
30 allow_fullscreen_(frame_owner_properties.allow_fullscreen),
31 allow_payment_request_(frame_owner_properties.allow_payment_request),
32 is_display_none_(frame_owner_properties.is_display_none),
33 color_scheme_(frame_owner_properties.color_scheme),
34 needs_occlusion_tracking_(false),
35 required_csp_(frame_owner_properties.required_csp),
36 frame_owner_element_type_(frame_owner_element_type) {}
37
Trace(Visitor * visitor) const38 void RemoteFrameOwner::Trace(Visitor* visitor) const {
39 visitor->Trace(frame_);
40 FrameOwner::Trace(visitor);
41 }
42
SetScrollbarMode(mojom::blink::ScrollbarMode mode)43 void RemoteFrameOwner::SetScrollbarMode(mojom::blink::ScrollbarMode mode) {
44 scrollbar_ = mode;
45 }
46
SetContentFrame(Frame & frame)47 void RemoteFrameOwner::SetContentFrame(Frame& frame) {
48 frame_ = &frame;
49 }
50
ClearContentFrame()51 void RemoteFrameOwner::ClearContentFrame() {
52 DCHECK_EQ(frame_->Owner(), this);
53 frame_ = nullptr;
54 }
55
AddResourceTiming(const ResourceTimingInfo & info)56 void RemoteFrameOwner::AddResourceTiming(const ResourceTimingInfo& info) {
57 LocalFrame* frame = To<LocalFrame>(frame_.Get());
58 mojom::blink::ResourceTimingInfoPtr resource_timing =
59 Performance::GenerateResourceTiming(
60 *frame->Tree().Parent()->GetSecurityContext()->GetSecurityOrigin(),
61 info, *frame->DomWindow());
62 frame->GetLocalFrameHostRemote().ForwardResourceTimingToParent(
63 std::move(resource_timing));
64 }
65
DispatchLoad()66 void RemoteFrameOwner::DispatchLoad() {
67 auto& local_frame_host = To<LocalFrame>(*frame_).GetLocalFrameHostRemote();
68 local_frame_host.DispatchLoad();
69 }
70
RenderFallbackContent(Frame * failed_frame)71 void RemoteFrameOwner::RenderFallbackContent(Frame* failed_frame) {
72 if (frame_owner_element_type_ != mojom::blink::FrameOwnerElementType::kObject)
73 return;
74 DCHECK(failed_frame->IsLocalFrame());
75 LocalFrame* local_frame = To<LocalFrame>(failed_frame);
76 DCHECK(local_frame->IsProvisional() || ContentFrame() == local_frame);
77 local_frame->GetLocalFrameHostRemote().RenderFallbackContentInParentProcess();
78 }
79
IntrinsicSizingInfoChanged()80 void RemoteFrameOwner::IntrinsicSizingInfoChanged() {
81 LocalFrame& local_frame = To<LocalFrame>(*frame_);
82 IntrinsicSizingInfo intrinsic_sizing_info;
83 bool result =
84 local_frame.View()->GetIntrinsicSizingInfo(intrinsic_sizing_info);
85 // By virtue of having been invoked, GetIntrinsicSizingInfo() should always
86 // succeed here.
87 DCHECK(result);
88
89 auto sizing_info = mojom::blink::IntrinsicSizingInfo::New(
90 gfx::SizeF(intrinsic_sizing_info.size),
91 gfx::SizeF(intrinsic_sizing_info.aspect_ratio),
92 intrinsic_sizing_info.has_width, intrinsic_sizing_info.has_height);
93 WebLocalFrameImpl::FromFrame(local_frame)
94 ->FrameWidgetImpl()
95 ->IntrinsicSizingInfoChanged(std::move(sizing_info));
96 }
97
SetNeedsOcclusionTracking(bool needs_tracking)98 void RemoteFrameOwner::SetNeedsOcclusionTracking(bool needs_tracking) {
99 if (needs_tracking == needs_occlusion_tracking_)
100 return;
101 needs_occlusion_tracking_ = needs_tracking;
102 LocalFrame* local_frame = To<LocalFrame>(frame_.Get());
103 local_frame->GetLocalFrameHostRemote().SetNeedsOcclusionTracking(
104 needs_tracking);
105 }
106
ShouldLazyLoadChildren() const107 bool RemoteFrameOwner::ShouldLazyLoadChildren() const {
108 // Don't use lazy load for children inside an OOPIF, since there's a good
109 // chance that the parent FrameOwner was previously deferred by lazy load
110 // and then loaded in for whatever reason.
111 return false;
112 }
113
114 } // namespace blink
115