| 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 "core/html/HTMLFrameOwnerElement.h" |
| 10 #include "web/OpenedFrameTracker.h" | 10 #include "web/OpenedFrameTracker.h" |
| 11 #include "web/WebLocalFrameImpl.h" | 11 #include "web/WebLocalFrameImpl.h" |
| 12 #include "web/WebRemoteFrameImpl.h" | 12 #include "web/WebRemoteFrameImpl.h" |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 blink::Frame* toWebCoreFrame(const WebFrame* frame) | 18 Frame* toCoreFrame(const WebFrame* frame) |
| 19 { | 19 { |
| 20 if (!frame) | 20 if (!frame) |
| 21 return 0; | 21 return 0; |
| 22 | 22 |
| 23 return frame->isWebLocalFrame() | 23 return frame->isWebLocalFrame() |
| 24 ? static_cast<blink::Frame*>(toWebLocalFrameImpl(frame)->frame()) | 24 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) |
| 25 : toWebRemoteFrameImpl(frame)->frame(); | 25 : toWebRemoteFrameImpl(frame)->frame(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void WebFrame::swap(WebFrame* frame) | 28 void WebFrame::swap(WebFrame* frame) |
| 29 { | 29 { |
| 30 using std::swap; | 30 using std::swap; |
| 31 | 31 |
| 32 // All child frames must have been detached first. | 32 // All child frames must have been detached first. |
| 33 ASSERT(!m_firstChild && !m_lastChild); | 33 ASSERT(!m_firstChild && !m_lastChild); |
| 34 // The frame being swapped in should not have a blink::Frame associated | 34 // The frame being swapped in should not have a blink::Frame associated |
| 35 // with it yet. | 35 // with it yet. |
| 36 ASSERT(!toWebCoreFrame(frame)); | 36 ASSERT(!toCoreFrame(frame)); |
| 37 | 37 |
| 38 if (m_parent) { | 38 if (m_parent) { |
| 39 if (m_parent->m_firstChild == this) | 39 if (m_parent->m_firstChild == this) |
| 40 m_parent->m_firstChild = frame; | 40 m_parent->m_firstChild = frame; |
| 41 if (m_parent->m_lastChild == this) | 41 if (m_parent->m_lastChild == this) |
| 42 m_parent->m_lastChild = frame; | 42 m_parent->m_lastChild = frame; |
| 43 swap(m_parent, frame->m_parent); | 43 swap(m_parent, frame->m_parent); |
| 44 } | 44 } |
| 45 | 45 |
| 46 if (m_previousSibling) { | 46 if (m_previousSibling) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 } | 59 } |
| 60 if (!m_openedFrameTracker->isEmpty()) { | 60 if (!m_openedFrameTracker->isEmpty()) { |
| 61 m_openedFrameTracker->updateOpener(frame); | 61 m_openedFrameTracker->updateOpener(frame); |
| 62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); | 62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Finally, clone the state of the current blink::Frame into one matching | 65 // Finally, clone the state of the current blink::Frame into one matching |
| 66 // the type of the passed in WebFrame. | 66 // the type of the passed in WebFrame. |
| 67 // FIXME: This is a bit clunky; this results in pointless decrements and | 67 // FIXME: This is a bit clunky; this results in pointless decrements and |
| 68 // increments of connected subframes. | 68 // increments of connected subframes. |
| 69 blink::Frame* oldFrame = toWebCoreFrame(this); | 69 Frame* oldFrame = toCoreFrame(this); |
| 70 blink::FrameOwner* owner = oldFrame->owner(); | 70 FrameOwner* owner = oldFrame->owner(); |
| 71 oldFrame->disconnectOwnerElement(); | 71 oldFrame->disconnectOwnerElement(); |
| 72 if (frame->isWebLocalFrame()) { | 72 if (frame->isWebLocalFrame()) { |
| 73 toWebLocalFrameImpl(frame)->initializeWebCoreFrame(oldFrame->host(), own
er, oldFrame->tree().name(), nullAtom); | 73 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner,
oldFrame->tree().name(), nullAtom); |
| 74 } else { | 74 } else { |
| 75 toWebRemoteFrameImpl(frame)->initializeWebCoreFrame(oldFrame->host(), ow
ner, oldFrame->tree().name()); | 75 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner
, oldFrame->tree().name()); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 WebFrame* WebFrame::opener() const | 79 WebFrame* WebFrame::opener() const |
| 80 { | 80 { |
| 81 return m_opener; | 81 return m_opener; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void WebFrame::setOpener(WebFrame* opener) | 84 void WebFrame::setOpener(WebFrame* opener) |
| 85 { | 85 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 WebFrame* oldLast = m_lastChild; | 98 WebFrame* oldLast = m_lastChild; |
| 99 m_lastChild = child; | 99 m_lastChild = child; |
| 100 | 100 |
| 101 if (oldLast) { | 101 if (oldLast) { |
| 102 child->m_previousSibling = oldLast; | 102 child->m_previousSibling = oldLast; |
| 103 oldLast->m_nextSibling = child; | 103 oldLast->m_nextSibling = child; |
| 104 } else { | 104 } else { |
| 105 m_firstChild = child; | 105 m_firstChild = child; |
| 106 } | 106 } |
| 107 | 107 |
| 108 toWebCoreFrame(this)->tree().invalidateScopedChildCount(); | 108 toCoreFrame(this)->tree().invalidateScopedChildCount(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void WebFrame::removeChild(WebFrame* child) | 111 void WebFrame::removeChild(WebFrame* child) |
| 112 { | 112 { |
| 113 child->m_parent = 0; | 113 child->m_parent = 0; |
| 114 | 114 |
| 115 if (m_firstChild == child) | 115 if (m_firstChild == child) |
| 116 m_firstChild = child->m_nextSibling; | 116 m_firstChild = child->m_nextSibling; |
| 117 else | 117 else |
| 118 child->m_previousSibling->m_nextSibling = child->m_nextSibling; | 118 child->m_previousSibling->m_nextSibling = child->m_nextSibling; |
| 119 | 119 |
| 120 if (m_lastChild == child) | 120 if (m_lastChild == child) |
| 121 m_lastChild = child->m_previousSibling; | 121 m_lastChild = child->m_previousSibling; |
| 122 else | 122 else |
| 123 child->m_nextSibling->m_previousSibling = child->m_previousSibling; | 123 child->m_nextSibling->m_previousSibling = child->m_previousSibling; |
| 124 | 124 |
| 125 child->m_previousSibling = child->m_nextSibling = 0; | 125 child->m_previousSibling = child->m_nextSibling = 0; |
| 126 | 126 |
| 127 toWebCoreFrame(this)->tree().invalidateScopedChildCount(); | 127 toCoreFrame(this)->tree().invalidateScopedChildCount(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 WebFrame* WebFrame::parent() const | 130 WebFrame* WebFrame::parent() const |
| 131 { | 131 { |
| 132 return m_parent; | 132 return m_parent; |
| 133 } | 133 } |
| 134 | 134 |
| 135 WebFrame* WebFrame::top() const | 135 WebFrame* WebFrame::top() const |
| 136 { | 136 { |
| 137 WebFrame* frame = const_cast<WebFrame*>(this); | 137 WebFrame* frame = const_cast<WebFrame*>(this); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 return m_previousSibling; | 155 return m_previousSibling; |
| 156 } | 156 } |
| 157 | 157 |
| 158 WebFrame* WebFrame::nextSibling() const | 158 WebFrame* WebFrame::nextSibling() const |
| 159 { | 159 { |
| 160 return m_nextSibling; | 160 return m_nextSibling; |
| 161 } | 161 } |
| 162 | 162 |
| 163 WebFrame* WebFrame::traversePrevious(bool wrap) const | 163 WebFrame* WebFrame::traversePrevious(bool wrap) const |
| 164 { | 164 { |
| 165 blink::Frame* frame = toWebCoreFrame(this); | 165 if (Frame* frame = toCoreFrame(this)) |
| 166 if (!frame) | 166 return fromFrame(frame->tree().traversePreviousWithWrap(wrap)); |
| 167 return 0; | 167 return 0; |
| 168 return fromFrame(frame->tree().traversePreviousWithWrap(wrap)); | |
| 169 } | 168 } |
| 170 | 169 |
| 171 WebFrame* WebFrame::traverseNext(bool wrap) const | 170 WebFrame* WebFrame::traverseNext(bool wrap) const |
| 172 { | 171 { |
| 173 blink::Frame* frame = toWebCoreFrame(this); | 172 if (Frame* frame = toCoreFrame(this)) |
| 174 if (!frame) | 173 return fromFrame(frame->tree().traverseNextWithWrap(wrap)); |
| 175 return 0; | 174 return 0; |
| 176 return fromFrame(frame->tree().traverseNextWithWrap(wrap)); | |
| 177 } | 175 } |
| 178 | 176 |
| 179 WebFrame* WebFrame::findChildByName(const WebString& name) const | 177 WebFrame* WebFrame::findChildByName(const WebString& name) const |
| 180 { | 178 { |
| 181 blink::Frame* frame = toWebCoreFrame(this); | 179 Frame* frame = toCoreFrame(this); |
| 182 if (!frame) | 180 if (!frame) |
| 183 return 0; | 181 return 0; |
| 184 // FIXME: It's not clear this should ever be called to find a remote frame. | 182 // FIXME: It's not clear this should ever be called to find a remote frame. |
| 185 // Perhaps just disallow that completely? | 183 // Perhaps just disallow that completely? |
| 186 return fromFrame(frame->tree().child(name)); | 184 return fromFrame(frame->tree().child(name)); |
| 187 } | 185 } |
| 188 | 186 |
| 189 WebFrame* WebFrame::fromFrame(blink::Frame* frame) | 187 WebFrame* WebFrame::fromFrame(blink::Frame* frame) |
| 190 { | 188 { |
| 191 if (!frame) | 189 if (!frame) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 206 , m_openedFrameTracker(new OpenedFrameTracker) | 204 , m_openedFrameTracker(new OpenedFrameTracker) |
| 207 { | 205 { |
| 208 } | 206 } |
| 209 | 207 |
| 210 WebFrame::~WebFrame() | 208 WebFrame::~WebFrame() |
| 211 { | 209 { |
| 212 m_openedFrameTracker.reset(0); | 210 m_openedFrameTracker.reset(0); |
| 213 } | 211 } |
| 214 | 212 |
| 215 } // namespace blink | 213 } // namespace blink |
| OLD | NEW |