| 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 | |
| 16 namespace blink { | 15 namespace blink { |
| 17 | 16 |
| 18 Frame* toCoreFrame(const WebFrame* frame) | 17 Frame* toCoreFrame(const WebFrame* frame) |
| 19 { | 18 { |
| 20 if (!frame) | 19 if (!frame) |
| 21 return 0; | 20 return 0; |
| 22 | 21 |
| 23 return frame->isWebLocalFrame() | 22 return frame->isWebLocalFrame() |
| 24 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) | 23 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) |
| 25 : toWebRemoteFrameImpl(frame)->frame(); | 24 : toWebRemoteFrameImpl(frame)->frame(); |
| 26 } | 25 } |
| 27 | 26 |
| 28 void WebFrame::swap(WebFrame* frame) | 27 void WebFrame::swap(WebFrame* frame) |
| 29 { | 28 { |
| 30 using std::swap; | 29 using std::swap; |
| 31 | 30 |
| 32 // All child frames must have been detached first. | 31 // All child frames must have been detached first. |
| 33 ASSERT(!m_firstChild && !m_lastChild); | 32 ASSERT(!m_firstChild && !m_lastChild); |
| 34 // The frame being swapped in should not have a blink::Frame associated | 33 // The frame being swapped in should not have a Frame associated |
| 35 // with it yet. | 34 // with it yet. |
| 36 ASSERT(!toCoreFrame(frame)); | 35 ASSERT(!toCoreFrame(frame)); |
| 37 | 36 |
| 38 if (m_parent) { | 37 if (m_parent) { |
| 39 if (m_parent->m_firstChild == this) | 38 if (m_parent->m_firstChild == this) |
| 40 m_parent->m_firstChild = frame; | 39 m_parent->m_firstChild = frame; |
| 41 if (m_parent->m_lastChild == this) | 40 if (m_parent->m_lastChild == this) |
| 42 m_parent->m_lastChild = frame; | 41 m_parent->m_lastChild = frame; |
| 43 swap(m_parent, frame->m_parent); | 42 swap(m_parent, frame->m_parent); |
| 44 } | 43 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 if (m_opener) { | 54 if (m_opener) { |
| 56 m_opener->m_openedFrameTracker->remove(this); | 55 m_opener->m_openedFrameTracker->remove(this); |
| 57 m_opener->m_openedFrameTracker->add(frame); | 56 m_opener->m_openedFrameTracker->add(frame); |
| 58 swap(m_opener, frame->m_opener); | 57 swap(m_opener, frame->m_opener); |
| 59 } | 58 } |
| 60 if (!m_openedFrameTracker->isEmpty()) { | 59 if (!m_openedFrameTracker->isEmpty()) { |
| 61 m_openedFrameTracker->updateOpener(frame); | 60 m_openedFrameTracker->updateOpener(frame); |
| 62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); | 61 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); |
| 63 } | 62 } |
| 64 | 63 |
| 65 // Finally, clone the state of the current blink::Frame into one matching | 64 // Finally, clone the state of the current Frame into one matching |
| 66 // the type of the passed in WebFrame. | 65 // the type of the passed in WebFrame. |
| 67 // FIXME: This is a bit clunky; this results in pointless decrements and | 66 // FIXME: This is a bit clunky; this results in pointless decrements and |
| 68 // increments of connected subframes. | 67 // increments of connected subframes. |
| 69 Frame* oldFrame = toCoreFrame(this); | 68 Frame* oldFrame = toCoreFrame(this); |
| 70 FrameOwner* owner = oldFrame->owner(); | 69 FrameOwner* owner = oldFrame->owner(); |
| 71 oldFrame->disconnectOwnerElement(); | 70 oldFrame->disconnectOwnerElement(); |
| 72 if (frame->isWebLocalFrame()) { | 71 if (frame->isWebLocalFrame()) { |
| 73 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner,
oldFrame->tree().name(), nullAtom); | 72 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner,
oldFrame->tree().name(), nullAtom); |
| 74 } else { | 73 } else { |
| 75 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner
, oldFrame->tree().name()); | 74 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner
, oldFrame->tree().name()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 WebFrame* WebFrame::findChildByName(const WebString& name) const | 176 WebFrame* WebFrame::findChildByName(const WebString& name) const |
| 178 { | 177 { |
| 179 Frame* frame = toCoreFrame(this); | 178 Frame* frame = toCoreFrame(this); |
| 180 if (!frame) | 179 if (!frame) |
| 181 return 0; | 180 return 0; |
| 182 // FIXME: It's not clear this should ever be called to find a remote frame. | 181 // FIXME: It's not clear this should ever be called to find a remote frame. |
| 183 // Perhaps just disallow that completely? | 182 // Perhaps just disallow that completely? |
| 184 return fromFrame(frame->tree().child(name)); | 183 return fromFrame(frame->tree().child(name)); |
| 185 } | 184 } |
| 186 | 185 |
| 187 WebFrame* WebFrame::fromFrame(blink::Frame* frame) | 186 WebFrame* WebFrame::fromFrame(Frame* frame) |
| 188 { | 187 { |
| 189 if (!frame) | 188 if (!frame) |
| 190 return 0; | 189 return 0; |
| 191 | 190 |
| 192 if (frame->isLocalFrame()) | 191 if (frame->isLocalFrame()) |
| 193 return WebLocalFrameImpl::fromFrame(toLocalFrame(*frame)); | 192 return WebLocalFrameImpl::fromFrame(toLocalFrame(*frame)); |
| 194 return WebRemoteFrameImpl::fromFrame(toRemoteFrame(*frame)); | 193 return WebRemoteFrameImpl::fromFrame(toRemoteFrame(*frame)); |
| 195 } | 194 } |
| 196 | 195 |
| 197 WebFrame::WebFrame() | 196 WebFrame::WebFrame() |
| 198 : m_parent(0) | 197 : m_parent(0) |
| 199 , m_previousSibling(0) | 198 , m_previousSibling(0) |
| 200 , m_nextSibling(0) | 199 , m_nextSibling(0) |
| 201 , m_firstChild(0) | 200 , m_firstChild(0) |
| 202 , m_lastChild(0) | 201 , m_lastChild(0) |
| 203 , m_opener(0) | 202 , m_opener(0) |
| 204 , m_openedFrameTracker(new OpenedFrameTracker) | 203 , m_openedFrameTracker(new OpenedFrameTracker) |
| 205 { | 204 { |
| 206 } | 205 } |
| 207 | 206 |
| 208 WebFrame::~WebFrame() | 207 WebFrame::~WebFrame() |
| 209 { | 208 { |
| 210 m_openedFrameTracker.reset(0); | 209 m_openedFrameTracker.reset(0); |
| 211 } | 210 } |
| 212 | 211 |
| 213 } // namespace blink | 212 } // namespace blink |
| OLD | NEW |