OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "public/web/WebFrame.h" | 6 #include "public/web/WebFrame.h" |
7 | 7 |
8 #include "bindings/core/v8/WindowProxyManager.h" | 8 #include "bindings/core/v8/WindowProxyManager.h" |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "core/frame/RemoteFrame.h" | 12 #include "core/frame/RemoteFrame.h" |
13 #include "core/html/HTMLFrameElementBase.h" | 13 #include "core/html/HTMLFrameElementBase.h" |
14 #include "core/html/HTMLFrameOwnerElement.h" | 14 #include "core/html/HTMLFrameOwnerElement.h" |
15 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
16 #include "platform/UserGestureIndicator.h" | 16 #include "platform/UserGestureIndicator.h" |
17 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
18 #include "public/web/WebElement.h" | 18 #include "public/web/WebElement.h" |
19 #include "public/web/WebFrameOwnerProperties.h" | 19 #include "public/web/WebFrameOwnerProperties.h" |
20 #include "public/web/WebSandboxFlags.h" | 20 #include "public/web/WebSandboxFlags.h" |
21 #include "web/OpenedFrameTracker.h" | 21 #include "web/OpenedFrameTracker.h" |
22 #include "web/RemoteBridgeFrameOwner.h" | 22 #include "web/RemoteBridgeFrameOwner.h" |
23 #include "web/WebLocalFrameImpl.h" | 23 #include "web/WebLocalFrameImpl.h" |
24 #include "web/WebRemoteFrameImpl.h" | 24 #include "web/WebRemoteFrameImpl.h" |
25 #include <algorithm> | 25 #include <algorithm> |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 Frame* toCoreFrame(const WebFrame* frame) | |
30 { | |
31 if (!frame) | |
32 return 0; | |
33 | |
34 return frame->isWebLocalFrame() | |
35 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) | |
36 : toWebRemoteFrameImpl(frame)->frame(); | |
37 } | |
38 | |
39 bool WebFrame::swap(WebFrame* frame) | 29 bool WebFrame::swap(WebFrame* frame) |
40 { | 30 { |
41 using std::swap; | 31 using std::swap; |
42 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this); | 32 RefPtrWillBeRawPtr<Frame> oldFrame = toImplBase()->frame(); |
43 #if !ENABLE(OILPAN) | 33 #if !ENABLE(OILPAN) |
44 RefPtrWillBeRawPtr<WebLocalFrameImpl> protectWebLocalFrame = isWebLocalFrame () ? toWebLocalFrameImpl(this) : nullptr; | 34 RefPtr<WebFrameImplBase> protectThis = toImplBase(); |
45 RefPtrWillBeRawPtr<WebRemoteFrameImpl> protectWebRemoteFrame = isWebRemoteFr ame() ? toWebRemoteFrameImpl(this) : nullptr; | |
46 #endif | 35 #endif |
47 | 36 |
48 // Unload the current Document in this frame: this calls unload handlers, | 37 // Unload the current Document in this frame: this calls unload handlers, |
49 // detaches child frames, etc. Since this runs script, make sure this frame | 38 // detaches child frames, etc. Since this runs script, make sure this frame |
50 // wasn't detached before continuing with the swap. | 39 // wasn't detached before continuing with the swap. |
51 // FIXME: There is no unit test for this condition, so one needs to be | 40 // FIXME: There is no unit test for this condition, so one needs to be |
52 // written. | 41 // written. |
53 if (!oldFrame->prepareForCommit()) | 42 if (!oldFrame->prepareForCommit()) |
54 return false; | 43 return false; |
55 | 44 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); | 95 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); |
107 ownerElement->setContentFrame(localFrame); | 96 ownerElement->setContentFrame(localFrame); |
108 ownerElement->setWidget(localFrame.view()); | 97 ownerElement->setWidget(localFrame.view()); |
109 } else { | 98 } else { |
110 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); | 99 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); |
111 } | 100 } |
112 } else { | 101 } else { |
113 localFrame.page()->setMainFrame(&localFrame); | 102 localFrame.page()->setMainFrame(&localFrame); |
114 } | 103 } |
115 } else { | 104 } else { |
116 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, name); | 105 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, name, null Atom); |
117 } | 106 } |
118 | 107 |
119 toCoreFrame(frame)->windowProxyManager()->setGlobals(globals); | 108 frame->toImplBase()->frame()->windowProxyManager()->setGlobals(globals); |
120 | 109 |
121 m_parent = nullptr; | 110 m_parent = nullptr; |
122 | 111 |
123 return true; | 112 return true; |
124 } | 113 } |
125 | 114 |
126 void WebFrame::detach() | 115 void WebFrame::detach() |
127 { | 116 { |
128 toCoreFrame(this)->detach(FrameDetachType::Remove); | 117 toImplBase()->frame()->detach(FrameDetachType::Remove); |
129 } | 118 } |
130 | 119 |
131 WebSecurityOrigin WebFrame::securityOrigin() const | 120 WebSecurityOrigin WebFrame::securityOrigin() const |
132 { | 121 { |
133 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n()); | 122 return WebSecurityOrigin(toImplBase()->frame()->securityContext()->securityO rigin()); |
134 } | 123 } |
135 | 124 |
136 | 125 |
137 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags) | 126 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags) |
138 { | 127 { |
139 // At the moment, this is only used to replicate sandbox flags | 128 // At the moment, this is only used to replicate sandbox flags |
140 // for frames with a remote owner. | 129 // for frames with a remote owner. |
141 FrameOwner* owner = toCoreFrame(this)->owner(); | 130 FrameOwner* owner = toImplBase()->frame()->owner(); |
142 ASSERT(owner); | 131 ASSERT(owner); |
143 toRemoteBridgeFrameOwner(owner)->setSandboxFlags(static_cast<SandboxFlags>(f lags)); | 132 toRemoteBridgeFrameOwner(owner)->setSandboxFlags(static_cast<SandboxFlags>(f lags)); |
144 } | 133 } |
145 | 134 |
146 WebFrame* WebFrame::opener() const | 135 WebFrame* WebFrame::opener() const |
147 { | 136 { |
148 return m_opener; | 137 return m_opener; |
149 } | 138 } |
150 | 139 |
151 void WebFrame::setOpener(WebFrame* opener) | 140 void WebFrame::setOpener(WebFrame* opener) |
(...skipping 21 matching lines...) Expand all Loading... | |
173 newChild->m_previousSibling = previousSibling; | 162 newChild->m_previousSibling = previousSibling; |
174 } | 163 } |
175 | 164 |
176 if (next) { | 165 if (next) { |
177 newChild->m_nextSibling = next; | 166 newChild->m_nextSibling = next; |
178 next->m_previousSibling = newChild; | 167 next->m_previousSibling = newChild; |
179 } else { | 168 } else { |
180 m_lastChild = newChild; | 169 m_lastChild = newChild; |
181 } | 170 } |
182 | 171 |
183 toCoreFrame(this)->tree().invalidateScopedChildCount(); | 172 toImplBase()->frame()->tree().invalidateScopedChildCount(); |
184 toCoreFrame(this)->host()->incrementSubframeCount(); | 173 toImplBase()->frame()->host()->incrementSubframeCount(); |
185 } | 174 } |
186 | 175 |
187 void WebFrame::appendChild(WebFrame* child) | 176 void WebFrame::appendChild(WebFrame* child) |
188 { | 177 { |
189 // TODO(dcheng): Original code asserts that the frames have the same Page. | 178 // TODO(dcheng): Original code asserts that the frames have the same Page. |
190 // We should add an equivalent check... figure out what. | 179 // We should add an equivalent check... figure out what. |
191 insertAfter(child, m_lastChild); | 180 insertAfter(child, m_lastChild); |
192 } | 181 } |
193 | 182 |
194 void WebFrame::removeChild(WebFrame* child) | 183 void WebFrame::removeChild(WebFrame* child) |
195 { | 184 { |
196 child->m_parent = 0; | 185 child->m_parent = 0; |
197 | 186 |
198 if (m_firstChild == child) | 187 if (m_firstChild == child) |
199 m_firstChild = child->m_nextSibling; | 188 m_firstChild = child->m_nextSibling; |
200 else | 189 else |
201 child->m_previousSibling->m_nextSibling = child->m_nextSibling; | 190 child->m_previousSibling->m_nextSibling = child->m_nextSibling; |
202 | 191 |
203 if (m_lastChild == child) | 192 if (m_lastChild == child) |
204 m_lastChild = child->m_previousSibling; | 193 m_lastChild = child->m_previousSibling; |
205 else | 194 else |
206 child->m_nextSibling->m_previousSibling = child->m_previousSibling; | 195 child->m_nextSibling->m_previousSibling = child->m_previousSibling; |
207 | 196 |
208 child->m_previousSibling = child->m_nextSibling = 0; | 197 child->m_previousSibling = child->m_nextSibling = 0; |
209 | 198 |
210 toCoreFrame(this)->tree().invalidateScopedChildCount(); | 199 toImplBase()->frame()->tree().invalidateScopedChildCount(); |
211 toCoreFrame(this)->host()->decrementSubframeCount(); | 200 toImplBase()->frame()->host()->decrementSubframeCount(); |
212 } | 201 } |
213 | 202 |
214 void WebFrame::setParent(WebFrame* parent) | 203 void WebFrame::setParent(WebFrame* parent) |
215 { | 204 { |
216 m_parent = parent; | 205 m_parent = parent; |
217 } | 206 } |
218 | 207 |
219 WebFrame* WebFrame::parent() const | 208 WebFrame* WebFrame::parent() const |
220 { | 209 { |
221 return m_parent; | 210 return m_parent; |
(...skipping 22 matching lines...) Expand all Loading... | |
244 return m_previousSibling; | 233 return m_previousSibling; |
245 } | 234 } |
246 | 235 |
247 WebFrame* WebFrame::nextSibling() const | 236 WebFrame* WebFrame::nextSibling() const |
248 { | 237 { |
249 return m_nextSibling; | 238 return m_nextSibling; |
250 } | 239 } |
251 | 240 |
252 WebFrame* WebFrame::traversePrevious(bool wrap) const | 241 WebFrame* WebFrame::traversePrevious(bool wrap) const |
253 { | 242 { |
254 if (Frame* frame = toCoreFrame(this)) | 243 if (Frame* frame = toImplBase()->frame()) |
255 return fromFrame(frame->tree().traversePreviousWithWrap(wrap)); | 244 return fromFrame(frame->tree().traversePreviousWithWrap(wrap)); |
256 return 0; | 245 return 0; |
257 } | 246 } |
258 | 247 |
259 WebFrame* WebFrame::traverseNext(bool wrap) const | 248 WebFrame* WebFrame::traverseNext(bool wrap) const |
260 { | 249 { |
261 if (Frame* frame = toCoreFrame(this)) | 250 if (Frame* frame = toImplBase()->frame()) |
262 return fromFrame(frame->tree().traverseNextWithWrap(wrap)); | 251 return fromFrame(frame->tree().traverseNextWithWrap(wrap)); |
263 return 0; | 252 return 0; |
264 } | 253 } |
265 | 254 |
266 WebFrame* WebFrame::findChildByName(const WebString& name) const | 255 WebFrame* WebFrame::findChildByName(const WebString& name) const |
267 { | 256 { |
268 Frame* frame = toCoreFrame(this); | 257 Frame* frame = toImplBase()->frame(); |
269 if (!frame) | 258 if (!frame) |
270 return 0; | 259 return 0; |
271 // FIXME: It's not clear this should ever be called to find a remote frame. | 260 // FIXME: It's not clear this should ever be called to find a remote frame. |
272 // Perhaps just disallow that completely? | 261 // Perhaps just disallow that completely? |
273 return fromFrame(frame->tree().child(name)); | 262 return fromFrame(frame->tree().child(name)); |
274 } | 263 } |
275 | 264 |
276 WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& webElement) | 265 WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& webElement) |
277 { | 266 { |
278 Element* element = PassRefPtrWillBeRawPtr<Element>(webElement).get(); | 267 Element* element = PassRefPtrWillBeRawPtr<Element>(webElement).get(); |
279 | 268 |
280 if (!isHTMLFrameElementBase(element)) | 269 if (!isHTMLFrameElementBase(element)) |
281 return nullptr; | 270 return nullptr; |
282 return fromFrame(toHTMLFrameElementBase(element)->contentFrame()); | 271 return fromFrame(toHTMLFrameElementBase(element)->contentFrame()); |
283 } | 272 } |
284 | 273 |
285 bool WebFrame::isLoading() const | 274 bool WebFrame::isLoading() const |
286 { | 275 { |
287 if (Frame* frame = toCoreFrame(this)) | 276 if (Frame* frame = toImplBase()->frame()) |
288 return frame->isLoading(); | 277 return frame->isLoading(); |
289 return false; | 278 return false; |
290 } | 279 } |
291 | 280 |
292 WebFrame* WebFrame::fromFrame(Frame* frame) | 281 WebFrame* WebFrame::fromFrame(Frame* frame) |
293 { | 282 { |
294 if (!frame) | 283 if (!frame) |
295 return 0; | 284 return 0; |
296 | 285 |
297 if (frame->isLocalFrame()) | 286 if (frame->isLocalFrame()) |
(...skipping 12 matching lines...) Expand all Loading... | |
310 , m_openedFrameTracker(new OpenedFrameTracker) | 299 , m_openedFrameTracker(new OpenedFrameTracker) |
311 { | 300 { |
312 } | 301 } |
313 | 302 |
314 WebFrame::~WebFrame() | 303 WebFrame::~WebFrame() |
315 { | 304 { |
316 m_openedFrameTracker.reset(0); | 305 m_openedFrameTracker.reset(0); |
317 } | 306 } |
318 | 307 |
319 #if ENABLE(OILPAN) | 308 #if ENABLE(OILPAN) |
320 ALWAYS_INLINE bool WebFrame::isFrameAlive(const WebFrame* frame) | 309 ALWAYS_INLINE bool WebFrame::isFrameAlive(const WebFrame* frame) |
dcheng
2015/11/23 09:00:17
It's possible to take advantage of the shared impl
| |
321 { | 310 { |
322 if (!frame) | 311 if (!frame) |
323 return true; | 312 return true; |
324 | 313 |
325 if (frame->isWebLocalFrame()) | 314 if (frame->isWebLocalFrame()) |
326 return Heap::isHeapObjectAlive(toWebLocalFrameImpl(frame)); | 315 return Heap::isHeapObjectAlive(toWebLocalFrameImpl(frame)); |
327 | 316 |
328 return Heap::isHeapObjectAlive(toWebRemoteFrameImpl(frame)); | 317 return Heap::isHeapObjectAlive(toWebRemoteFrameImpl(frame)); |
329 } | 318 } |
330 | 319 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \ | 352 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \ |
364 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); } | 353 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); } |
365 | 354 |
366 DEFINE_VISITOR_METHOD(Visitor*) | 355 DEFINE_VISITOR_METHOD(Visitor*) |
367 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) | 356 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) |
368 | 357 |
369 #undef DEFINE_VISITOR_METHOD | 358 #undef DEFINE_VISITOR_METHOD |
370 #endif | 359 #endif |
371 | 360 |
372 } // namespace blink | 361 } // namespace blink |
OLD | NEW |