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 "core/frame/RemoteFrame.h" | 8 #include "core/frame/RemoteFrame.h" |
| 9 #include "core/html/HTMLFrameOwnerElement.h" |
9 #include "web/OpenedFrameTracker.h" | 10 #include "web/OpenedFrameTracker.h" |
10 #include "web/WebLocalFrameImpl.h" | 11 #include "web/WebLocalFrameImpl.h" |
11 #include "web/WebRemoteFrameImpl.h" | 12 #include "web/WebRemoteFrameImpl.h" |
12 #include <algorithm> | 13 #include <algorithm> |
13 | 14 |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 WebCore::Frame* toWebCoreFrame(const WebFrame* frame) | 18 WebCore::Frame* toWebCoreFrame(const WebFrame* frame) |
18 { | 19 { |
19 if (!frame) | 20 if (!frame) |
20 return 0; | 21 return 0; |
21 | 22 |
22 return frame->isWebLocalFrame() | 23 return frame->isWebLocalFrame() |
23 ? static_cast<WebCore::Frame*>(toWebLocalFrameImpl(frame)->frame()) | 24 ? static_cast<WebCore::Frame*>(toWebLocalFrameImpl(frame)->frame()) |
24 : toWebRemoteFrameImpl(frame)->frame(); | 25 : toWebRemoteFrameImpl(frame)->frame(); |
25 } | 26 } |
26 | 27 |
27 void WebFrame::swap(WebFrame* frame) | 28 void WebFrame::swap(WebFrame* frame) |
28 { | 29 { |
29 using std::swap; | 30 using std::swap; |
30 | 31 |
| 32 // All child frames must have been detached first. |
| 33 ASSERT(!m_firstChild && !m_lastChild); |
| 34 // The frame being swapped in should not have a WebCore::Frame associated |
| 35 // with it yet. |
| 36 ASSERT(!toWebCoreFrame(frame)); |
| 37 |
31 if (m_parent) { | 38 if (m_parent) { |
32 if (m_parent->m_firstChild == this) | 39 if (m_parent->m_firstChild == this) |
33 m_parent->m_firstChild = frame; | 40 m_parent->m_firstChild = frame; |
34 if (m_parent->m_lastChild == this) | 41 if (m_parent->m_lastChild == this) |
35 m_parent->m_lastChild = frame; | 42 m_parent->m_lastChild = frame; |
36 swap(m_parent, frame->m_parent); | 43 swap(m_parent, frame->m_parent); |
37 } | 44 } |
| 45 |
38 if (m_previousSibling) { | 46 if (m_previousSibling) { |
39 m_previousSibling->m_nextSibling = frame; | 47 m_previousSibling->m_nextSibling = frame; |
40 swap(m_previousSibling, frame->m_previousSibling); | 48 swap(m_previousSibling, frame->m_previousSibling); |
41 } | 49 } |
42 if (m_nextSibling) { | 50 if (m_nextSibling) { |
43 m_nextSibling->m_previousSibling = frame; | 51 m_nextSibling->m_previousSibling = frame; |
44 swap(m_nextSibling, frame->m_nextSibling); | 52 swap(m_nextSibling, frame->m_nextSibling); |
45 } | 53 } |
| 54 |
46 if (m_opener) { | 55 if (m_opener) { |
47 m_opener->m_openedFrameTracker->remove(this); | 56 m_opener->m_openedFrameTracker->remove(this); |
48 m_opener->m_openedFrameTracker->add(frame); | 57 m_opener->m_openedFrameTracker->add(frame); |
49 swap(m_opener, frame->m_opener); | 58 swap(m_opener, frame->m_opener); |
50 } | 59 } |
51 if (!m_openedFrameTracker->isEmpty()) { | 60 if (!m_openedFrameTracker->isEmpty()) { |
52 m_openedFrameTracker->updateOpener(frame); | 61 m_openedFrameTracker->updateOpener(frame); |
53 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); | 62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); |
54 } | 63 } |
| 64 |
| 65 // Finally, clone the state of the current WebCore::Frame into one matching |
| 66 // the type of the passed in WebFrame. |
| 67 // FIXME: This is a bit clunky; this results in pointless decrements and |
| 68 // increments of connected subframes. |
| 69 WebCore::Frame* oldFrame = toWebCoreFrame(this); |
| 70 WebCore::FrameOwner* owner = oldFrame->owner(); |
| 71 oldFrame->disconnectOwnerElement(); |
| 72 if (frame->isWebLocalFrame()) { |
| 73 toWebLocalFrameImpl(frame)->initializeWebCoreFrame(oldFrame->host(), own
er, oldFrame->tree().name(), nullAtom); |
| 74 } else { |
| 75 toWebRemoteFrameImpl(frame)->initializeWebCoreFrame(oldFrame->host(), ow
ner, oldFrame->tree().name()); |
| 76 } |
55 } | 77 } |
56 | 78 |
57 WebFrame* WebFrame::opener() const | 79 WebFrame* WebFrame::opener() const |
58 { | 80 { |
59 return m_opener; | 81 return m_opener; |
60 } | 82 } |
61 | 83 |
62 void WebFrame::setOpener(WebFrame* opener) | 84 void WebFrame::setOpener(WebFrame* opener) |
63 { | 85 { |
64 if (m_opener) | 86 if (m_opener) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 , m_openedFrameTracker(new OpenedFrameTracker) | 206 , m_openedFrameTracker(new OpenedFrameTracker) |
185 { | 207 { |
186 } | 208 } |
187 | 209 |
188 WebFrame::~WebFrame() | 210 WebFrame::~WebFrame() |
189 { | 211 { |
190 m_openedFrameTracker.reset(0); | 212 m_openedFrameTracker.reset(0); |
191 } | 213 } |
192 | 214 |
193 } // namespace blink | 215 } // namespace blink |
OLD | NEW |