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.
6 #include "web/RemoteFrameClientImpl.h"
8 #include "core/events/KeyboardEvent.h"
9 #include "core/events/MouseEvent.h"
10 #include "core/events/WheelEvent.h"
11 #include "core/frame/RemoteFrame.h"
12 #include "core/frame/RemoteFrameView.h"
13 #include "core/layout/LayoutPart.h"
14 #include "platform/exported/WrappedResourceRequest.h"
15 #include "platform/weborigin/SecurityOrigin.h"
16 #include "platform/weborigin/SecurityPolicy.h"
17 #include "public/web/WebRemoteFrameClient.h"
18 #include "web/WebInputEventConversion.h"
19 #include "web/WebLocalFrameImpl.h"
20 #include "web/WebRemoteFrameImpl.h"
24 RemoteFrameClientImpl::RemoteFrameClientImpl(WebRemoteFrameImpl
* webFrame
)
25 : m_webFrame(webFrame
)
29 PassOwnPtrWillBeRawPtr
<RemoteFrameClientImpl
> RemoteFrameClientImpl::create(WebRemoteFrameImpl
* webFrame
)
31 return adoptPtrWillBeNoop(new RemoteFrameClientImpl(webFrame
));
34 DEFINE_TRACE(RemoteFrameClientImpl
)
36 visitor
->trace(m_webFrame
);
37 RemoteFrameClient::trace(visitor
);
40 bool RemoteFrameClientImpl::inShadowTree() const
42 return m_webFrame
->inShadowTree();
45 void RemoteFrameClientImpl::willBeDetached()
49 void RemoteFrameClientImpl::detached(FrameDetachType type
)
51 // Alert the client that the frame is being detached.
52 RefPtrWillBeRawPtr
<WebRemoteFrameImpl
> protector(m_webFrame
.get());
54 WebRemoteFrameClient
* client
= m_webFrame
->client();
58 client
->frameDetached(static_cast<WebRemoteFrameClient::DetachType
>(type
));
59 // Clear our reference to RemoteFrame at the very end, in case the client
61 m_webFrame
->setCoreFrame(nullptr);
64 Frame
* RemoteFrameClientImpl::opener() const
66 return toCoreFrame(m_webFrame
->opener());
69 void RemoteFrameClientImpl::setOpener(Frame
* opener
)
71 WebFrame
* openerFrame
= WebFrame::fromFrame(opener
);
72 if (m_webFrame
->client() && m_webFrame
->opener() != openerFrame
)
73 m_webFrame
->client()->didChangeOpener(openerFrame
);
74 m_webFrame
->setOpener(openerFrame
);
77 Frame
* RemoteFrameClientImpl::parent() const
79 return toCoreFrame(m_webFrame
->parent());
82 Frame
* RemoteFrameClientImpl::top() const
84 return toCoreFrame(m_webFrame
->top());
87 Frame
* RemoteFrameClientImpl::previousSibling() const
89 return toCoreFrame(m_webFrame
->previousSibling());
92 Frame
* RemoteFrameClientImpl::nextSibling() const
94 return toCoreFrame(m_webFrame
->nextSibling());
97 Frame
* RemoteFrameClientImpl::firstChild() const
99 return toCoreFrame(m_webFrame
->firstChild());
102 Frame
* RemoteFrameClientImpl::lastChild() const
104 return toCoreFrame(m_webFrame
->lastChild());
107 bool RemoteFrameClientImpl::willCheckAndDispatchMessageEvent(
108 SecurityOrigin
* target
, MessageEvent
* event
, LocalFrame
* sourceFrame
) const
110 if (m_webFrame
->client())
111 m_webFrame
->client()->postMessageEvent(WebLocalFrameImpl::fromFrame(sourceFrame
), m_webFrame
, WebSecurityOrigin(target
), WebDOMMessageEvent(event
));
115 void RemoteFrameClientImpl::navigate(const ResourceRequest
& request
, bool shouldReplaceCurrentEntry
)
117 if (m_webFrame
->client())
118 m_webFrame
->client()->navigate(WrappedResourceRequest(request
), shouldReplaceCurrentEntry
);
121 void RemoteFrameClientImpl::reload(FrameLoadType loadType
, ClientRedirectPolicy clientRedirectPolicy
)
123 if (m_webFrame
->client())
124 m_webFrame
->client()->reload(loadType
== FrameLoadTypeReloadFromOrigin
, clientRedirectPolicy
== ClientRedirect
);
127 unsigned RemoteFrameClientImpl::backForwardLength()
129 // TODO(creis,japhet): This method should return the real value for the
130 // session history length. For now, return static value for the initial
131 // navigation and the subsequent one moving the frame out-of-process.
132 // See https://crbug.com/501116.
136 // FIXME: Remove this code once we have input routing in the browser
137 // process. See http://crbug.com/339659.
138 void RemoteFrameClientImpl::forwardInputEvent(Event
* event
)
140 // It is possible for a platform event to cause the remote iframe element
141 // to be hidden, which destroys the layout object (for instance, a mouse
142 // event that moves between elements will trigger a mouseout on the old
143 // element, which might hide the new element). In that case we do not
144 // forward. This is divergent behavior from local frames, where the
145 // content of the frame can receive events even after the frame is hidden.
146 // We might need to revisit this after browser hit testing is fully
147 // implemented, since this code path will need to be removed or refactored
149 // See https://crbug.com/520705.
150 if (!toCoreFrame(m_webFrame
)->ownerLayoutObject())
153 // This is only called when we have out-of-process iframes, which
154 // need to forward input events across processes.
155 // FIXME: Add a check for out-of-process iframes enabled.
156 OwnPtr
<WebInputEvent
> webEvent
;
157 if (event
->isKeyboardEvent())
158 webEvent
= adoptPtr(new WebKeyboardEventBuilder(*static_cast<KeyboardEvent
*>(event
)));
159 else if (event
->isMouseEvent())
160 webEvent
= adoptPtr(new WebMouseEventBuilder(m_webFrame
->frame()->view(), toCoreFrame(m_webFrame
)->ownerLayoutObject(), *static_cast<MouseEvent
*>(event
)));
161 else if (event
->isWheelEvent())
162 webEvent
= adoptPtr(new WebMouseWheelEventBuilder(m_webFrame
->frame()->view(), toCoreFrame(m_webFrame
)->ownerLayoutObject(), *static_cast<WheelEvent
*>(event
)));
164 // Other or internal Blink events should not be forwarded.
165 if (!webEvent
|| webEvent
->type
== WebInputEvent::Undefined
)
168 m_webFrame
->client()->forwardInputEvent(webEvent
.get());
171 void RemoteFrameClientImpl::frameRectsChanged(const IntRect
& frameRect
)
173 m_webFrame
->client()->frameRectsChanged(frameRect
);