OLD | NEW |
(Empty) | |
| 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 "web/RemoteFrameOwner.h" |
| 6 |
| 7 #include "core/frame/LocalFrame.h" |
| 8 #include "public/web/WebFrameClient.h" |
| 9 #include "web/WebLocalFrameImpl.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 RemoteFrameOwner::RemoteFrameOwner(SandboxFlags flags, const WebFrameOwnerProper
ties& frameOwnerProperties) |
| 14 : m_sandboxFlags(flags) |
| 15 , m_scrolling(static_cast<ScrollbarMode>(frameOwnerProperties.scrollingMode)
) |
| 16 , m_marginWidth(frameOwnerProperties.marginWidth) |
| 17 , m_marginHeight(frameOwnerProperties.marginHeight) |
| 18 { |
| 19 } |
| 20 |
| 21 DEFINE_TRACE(RemoteFrameOwner) |
| 22 { |
| 23 visitor->trace(m_frame); |
| 24 FrameOwner::trace(visitor); |
| 25 } |
| 26 |
| 27 void RemoteFrameOwner::setScrollingMode(WebFrameOwnerProperties::ScrollingMode m
ode) |
| 28 { |
| 29 m_scrolling = static_cast<ScrollbarMode>(mode); |
| 30 } |
| 31 |
| 32 void RemoteFrameOwner::setContentFrame(Frame& frame) |
| 33 { |
| 34 #if !ENABLE(OILPAN) |
| 35 // Ownership of RemoteFrameOwner is complicated without Oilpan. Normally, a |
| 36 // frame owner like HTMLFrameOwnerElement is kept alive by the DOM tree in |
| 37 // its parent frame: the content frame of the frame owner only has a raw |
| 38 // pointer back to its owner. |
| 39 // |
| 40 // However, a parent frame that is remote has no DOM tree, and thus, nothing |
| 41 // to keep the remote frame owner alive. Instead, we manually ref() and |
| 42 // deref() in setContentFrame() and clearContentFrame() to ensure that the |
| 43 // remote frame owner remains live while associated with a frame. |
| 44 // |
| 45 // In an ideal world, Frame::m_owner would be a RefPtr, which would remove |
| 46 // the need for this manual ref() / deref() pair. However, it's non-trivial |
| 47 // to make that change, since HTMLFrameOwnerElement (which has FrameOwner |
| 48 // has a base class) is already refcounted via a different base class. |
| 49 // |
| 50 // The other tricky part is WebFrame::swap(): during swap(), there is a |
| 51 // period of time when a frame owner won't have an associated content frame. |
| 52 // To prevent the refcount from going to zero, WebFrame::swap() must keep a |
| 53 // stack reference to the frame owner if it is a remote frame owner. |
| 54 ref(); |
| 55 #endif |
| 56 m_frame = &frame; |
| 57 } |
| 58 |
| 59 void RemoteFrameOwner::clearContentFrame() |
| 60 { |
| 61 ASSERT(m_frame->owner() == this); |
| 62 m_frame = nullptr; |
| 63 #if !ENABLE(OILPAN) |
| 64 // Balance the ref() in setContentFrame(). |
| 65 deref(); |
| 66 #endif |
| 67 } |
| 68 |
| 69 void RemoteFrameOwner::dispatchLoad() |
| 70 { |
| 71 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrame(*m_f
rame)); |
| 72 webFrame->client()->dispatchLoad(); |
| 73 } |
| 74 |
| 75 } // namespace blink |
OLD | NEW |