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 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REMOTE_FRAME_OWNER_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REMOTE_FRAME_OWNER_H_
7 
8 #include "third_party/blink/public/common/frame/frame_owner_element_type.h"
9 #include "third_party/blink/public/common/frame/frame_policy.h"
10 #include "third_party/blink/public/mojom/scroll/scrollbar_mode.mojom-blink.h"
11 #include "third_party/blink/public/web/web_frame_owner_properties.h"
12 #include "third_party/blink/renderer/core/core_export.h"
13 #include "third_party/blink/renderer/core/frame/frame_owner.h"
14 #include "third_party/blink/renderer/core/scroll/scroll_types.h"
15 #include "third_party/blink/renderer/platform/wtf/casting.h"
16 
17 namespace blink {
18 
19 // Helper class to bridge communication for a frame with a remote parent.
20 // Currently, it serves two purposes:
21 // 1. Allows the local frame's loader to retrieve sandbox flags associated with
22 //    its owner element in another process.
23 // 2. Trigger a load event on its owner element once it finishes a load.
24 class CORE_EXPORT RemoteFrameOwner final
25     : public GarbageCollected<RemoteFrameOwner>,
26       public FrameOwner {
27   USING_GARBAGE_COLLECTED_MIXIN(RemoteFrameOwner);
28 
29  public:
30   RemoteFrameOwner(const FramePolicy&,
31                    const WebFrameOwnerProperties&,
32                    FrameOwnerElementType frame_owner_element_type);
33 
34   // FrameOwner overrides:
ContentFrame()35   Frame* ContentFrame() const override { return frame_.Get(); }
36   void SetContentFrame(Frame&) override;
37   void ClearContentFrame() override;
GetFramePolicy()38   const FramePolicy& GetFramePolicy() const override { return frame_policy_; }
39   void AddResourceTiming(const ResourceTimingInfo&) override;
40   void DispatchLoad() override;
CanRenderFallbackContent()41   bool CanRenderFallbackContent() const override {
42     return frame_owner_element_type_ == FrameOwnerElementType::kObject;
43   }
44   void RenderFallbackContent(Frame*) override;
45   void IntrinsicSizingInfoChanged() override;
46   void SetNeedsOcclusionTracking(bool) override;
47 
BrowsingContextContainerName()48   AtomicString BrowsingContextContainerName() const override {
49     return browsing_context_container_name_;
50   }
ScrollbarMode()51   mojom::blink::ScrollbarMode ScrollbarMode() const override {
52     return scrollbar_;
53   }
MarginWidth()54   int MarginWidth() const override { return margin_width_; }
MarginHeight()55   int MarginHeight() const override { return margin_height_; }
AllowFullscreen()56   bool AllowFullscreen() const override { return allow_fullscreen_; }
AllowPaymentRequest()57   bool AllowPaymentRequest() const override { return allow_payment_request_; }
IsDisplayNone()58   bool IsDisplayNone() const override { return is_display_none_; }
RequiredCsp()59   AtomicString RequiredCsp() const override { return required_csp_; }
60   bool ShouldLazyLoadChildren() const final;
61 
SetFramePolicy(const FramePolicy & frame_policy)62   void SetFramePolicy(const FramePolicy& frame_policy) {
63     frame_policy_ = frame_policy;
64   }
SetBrowsingContextContainerName(const WebString & name)65   void SetBrowsingContextContainerName(const WebString& name) {
66     browsing_context_container_name_ = name;
67   }
68   void SetScrollbarMode(mojom::blink::ScrollbarMode);
SetMarginWidth(int margin_width)69   void SetMarginWidth(int margin_width) { margin_width_ = margin_width; }
SetMarginHeight(int margin_height)70   void SetMarginHeight(int margin_height) { margin_height_ = margin_height; }
SetAllowFullscreen(bool allow_fullscreen)71   void SetAllowFullscreen(bool allow_fullscreen) {
72     allow_fullscreen_ = allow_fullscreen;
73   }
SetAllowPaymentRequest(bool allow_payment_request)74   void SetAllowPaymentRequest(bool allow_payment_request) {
75     allow_payment_request_ = allow_payment_request;
76   }
SetIsDisplayNone(bool is_display_none)77   void SetIsDisplayNone(bool is_display_none) {
78     is_display_none_ = is_display_none;
79   }
SetRequiredCsp(const WebString & required_csp)80   void SetRequiredCsp(const WebString& required_csp) {
81     required_csp_ = required_csp;
82   }
83 
84   void Trace(Visitor*) override;
85 
86  private:
87   // Intentionally private to prevent redundant checks when the type is
88   // already HTMLFrameOwnerElement.
IsLocal()89   bool IsLocal() const override { return false; }
IsRemote()90   bool IsRemote() const override { return true; }
91 
92   Member<Frame> frame_;
93   FramePolicy frame_policy_;
94   AtomicString browsing_context_container_name_;
95   mojom::blink::ScrollbarMode scrollbar_;
96   int margin_width_;
97   int margin_height_;
98   bool allow_fullscreen_;
99   bool allow_payment_request_;
100   bool is_display_none_;
101   bool needs_occlusion_tracking_;
102   WebString required_csp_;
103   const FrameOwnerElementType frame_owner_element_type_;
104 };
105 
106 template <>
107 struct DowncastTraits<RemoteFrameOwner> {
108   static bool AllowFrom(const FrameOwner& owner) { return owner.IsRemote(); }
109 };
110 
111 }  // namespace blink
112 
113 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REMOTE_FRAME_OWNER_H_
114