Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / frame / RemoteFrame.cpp
blob48626ba5afbbb55922db9a5ba2d475277050deae
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/frame/RemoteFrame.h"
8 #include "bindings/core/v8/WindowProxy.h"
9 #include "bindings/core/v8/WindowProxyManager.h"
10 #include "core/dom/RemoteSecurityContext.h"
11 #include "core/frame/RemoteDOMWindow.h"
12 #include "core/frame/RemoteFrameClient.h"
13 #include "core/frame/RemoteFrameView.h"
14 #include "core/html/HTMLFrameOwnerElement.h"
15 #include "core/layout/LayoutPart.h"
16 #include "core/loader/FrameLoadRequest.h"
17 #include "core/paint/DeprecatedPaintLayer.h"
18 #include "platform/PluginScriptForbiddenScope.h"
19 #include "platform/UserGestureIndicator.h"
20 #include "platform/graphics/GraphicsLayer.h"
21 #include "platform/weborigin/SecurityPolicy.h"
22 #include "public/platform/WebLayer.h"
24 namespace blink {
26 inline RemoteFrame::RemoteFrame(RemoteFrameClient* client, FrameHost* host, FrameOwner* owner)
27 : Frame(client, host, owner)
28 , m_securityContext(RemoteSecurityContext::create())
29 , m_domWindow(RemoteDOMWindow::create(*this))
30 , m_windowProxyManager(WindowProxyManager::create(*this))
31 , m_remotePlatformLayer(nullptr)
35 PassRefPtrWillBeRawPtr<RemoteFrame> RemoteFrame::create(RemoteFrameClient* client, FrameHost* host, FrameOwner* owner)
37 return adoptRefWillBeNoop(new RemoteFrame(client, host, owner));
40 RemoteFrame::~RemoteFrame()
44 DEFINE_TRACE(RemoteFrame)
46 visitor->trace(m_view);
47 visitor->trace(m_securityContext);
48 visitor->trace(m_domWindow);
49 visitor->trace(m_windowProxyManager);
50 Frame::trace(visitor);
53 DOMWindow* RemoteFrame::domWindow() const
55 return m_domWindow.get();
58 WindowProxy* RemoteFrame::windowProxy(DOMWrapperWorld& world)
60 WindowProxy* windowProxy = m_windowProxyManager->windowProxy(world);
61 ASSERT(windowProxy);
62 windowProxy->initializeIfNeeded();
63 return windowProxy;
66 void RemoteFrame::navigate(Document& originDocument, const KURL& url, bool replaceCurrentItem, UserGestureStatus userGestureStatus)
68 // The process where this frame actually lives won't have sufficient information to determine
69 // correct referrer, since it won't have access to the originDocument. Set it now.
70 ResourceRequest request(url);
71 request.setHTTPReferrer(SecurityPolicy::generateReferrer(originDocument.referrerPolicy(), url, originDocument.outgoingReferrer()));
72 request.setHasUserGesture(userGestureStatus == UserGestureStatus::Active);
73 remoteFrameClient()->navigate(request, replaceCurrentItem);
76 void RemoteFrame::navigate(const FrameLoadRequest& passedRequest)
78 UserGestureStatus gesture = UserGestureIndicator::processingUserGesture() ? UserGestureStatus::Active : UserGestureStatus::None;
79 navigate(*passedRequest.originDocument(), passedRequest.resourceRequest().url(), passedRequest.replacesCurrentItem(), gesture);
82 void RemoteFrame::reload(FrameLoadType frameLoadType, ClientRedirectPolicy clientRedirectPolicy)
84 remoteFrameClient()->reload(frameLoadType, clientRedirectPolicy);
87 void RemoteFrame::detach(FrameDetachType type)
89 PluginScriptForbiddenScope forbidPluginDestructorScripting;
90 // Frame::detach() requires the caller to keep a reference to this, since
91 // otherwise it may clear the last reference to this, causing it to be
92 // deleted, which can cause a use-after-free.
93 RefPtrWillBeRawPtr<RemoteFrame> protect(this);
94 detachChildren();
95 if (!client())
96 return;
97 client()->willBeDetached();
98 m_windowProxyManager->clearForClose();
99 setView(nullptr);
100 Frame::detach(type);
103 bool RemoteFrame::prepareForCommit()
105 detachChildren();
106 return !!host();
109 RemoteSecurityContext* RemoteFrame::securityContext() const
111 return m_securityContext.get();
114 void RemoteFrame::disconnectOwnerElement()
116 // The RemotePlatformLayer needs to be cleared in disconnectOwnerElement()
117 // because it must happen on WebFrame::swap() and Frame::detach().
118 if (m_remotePlatformLayer)
119 setRemotePlatformLayer(nullptr);
121 Frame::disconnectOwnerElement();
124 bool RemoteFrame::shouldClose()
126 // TODO(nasko): Implement running the beforeunload handler in the actual
127 // LocalFrame running in a different process and getting back a real result.
128 return true;
131 void RemoteFrame::forwardInputEvent(Event* event)
133 remoteFrameClient()->forwardInputEvent(event);
136 void RemoteFrame::frameRectsChanged(const IntRect& frameRect)
138 remoteFrameClient()->frameRectsChanged(frameRect);
141 void RemoteFrame::setView(PassRefPtrWillBeRawPtr<RemoteFrameView> view)
143 // Oilpan: as RemoteFrameView performs no finalization actions,
144 // no explicit dispose() of it needed here. (cf. FrameView::dispose().)
145 m_view = view;
148 void RemoteFrame::createView()
150 setView(nullptr);
151 if (!tree().parent() || !tree().parent()->isLocalFrame()) {
152 // FIXME: This is not the right place to clear the previous frame's
153 // widget. We do it here because the LocalFrame cleanup after a swap is
154 // still work in progress.
155 if (ownerLayoutObject()) {
156 HTMLFrameOwnerElement* owner = deprecatedLocalOwner();
157 ASSERT(owner);
158 owner->setWidget(nullptr);
161 return;
164 RefPtrWillBeRawPtr<RemoteFrameView> view = RemoteFrameView::create(this);
165 setView(view);
167 if (ownerLayoutObject()) {
168 HTMLFrameOwnerElement* owner = deprecatedLocalOwner();
169 ASSERT(owner);
170 owner->setWidget(view);
174 RemoteFrameClient* RemoteFrame::remoteFrameClient() const
176 return static_cast<RemoteFrameClient*>(client());
179 void RemoteFrame::setRemotePlatformLayer(WebLayer* layer)
181 if (m_remotePlatformLayer)
182 GraphicsLayer::unregisterContentsLayer(m_remotePlatformLayer);
183 m_remotePlatformLayer = layer;
184 if (m_remotePlatformLayer)
185 GraphicsLayer::registerContentsLayer(layer);
187 ASSERT(owner());
188 toHTMLFrameOwnerElement(owner())->setNeedsCompositingUpdate();
191 } // namespace blink