Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: Source/web/WebFrameImpl.cpp

Issue 156123004: Move the frame tree into the embedder. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix tests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 return fromFrame(frame()->loader().opener()); 640 return fromFrame(frame()->loader().opener());
641 } 641 }
642 642
643 void WebFrameImpl::setOpener(const WebFrame* webFrame) 643 void WebFrameImpl::setOpener(const WebFrame* webFrame)
644 { 644 {
645 frame()->loader().setOpener(webFrame ? toWebFrameImpl(webFrame)->frame() : 0 ); 645 frame()->loader().setOpener(webFrame ? toWebFrameImpl(webFrame)->frame() : 0 );
646 } 646 }
647 647
648 void WebFrameImpl::appendChild(WebFrame* child) 648 void WebFrameImpl::appendChild(WebFrame* child)
649 { 649 {
650 // FIXME: Implement after this revision rolls into Chrome. 650 // FIXME: Original code asserts that the frames have the same Page. We
651 // should add an equivalent check... figure out what.
652 WebFrameImpl* childImpl = toWebFrameImpl(child);
653 childImpl->m_parent = this;
654 WebFrameImpl* oldLast = m_lastChild;
655 m_lastChild = childImpl;
656
657 if (oldLast) {
658 childImpl->m_previousSibling = oldLast;
659 oldLast->m_nextSibling = childImpl;
660 } else {
661 m_firstChild = childImpl;
662 }
663 // FIXME: Not sure if this is a legitimate assert.
664 ASSERT(frame());
665 frame()->tree().invalidateScopedChildCount();
651 } 666 }
652 667
653 void WebFrameImpl::removeChild(WebFrame* child) 668 void WebFrameImpl::removeChild(WebFrame* child)
654 { 669 {
655 // FIXME: Implement after this revision rolls into Chrome. 670 WebFrameImpl* childImpl = toWebFrameImpl(child);
671 childImpl->m_parent = 0;
672
673 if (m_firstChild == childImpl)
674 m_firstChild = childImpl->m_nextSibling;
675 else
676 childImpl->m_previousSibling->m_nextSibling = childImpl->m_nextSibling;
677
678 if (m_lastChild == childImpl)
679 m_lastChild = childImpl->m_previousSibling;
680 else
681 childImpl->m_nextSibling->m_previousSibling = childImpl->m_previousSibli ng;
682
683 childImpl->m_previousSibling = childImpl->m_nextSibling = 0;
684 // FIXME: Not sure if this is a legitimate assert.
685 ASSERT(frame());
686 frame()->tree().invalidateScopedChildCount();
656 } 687 }
657 688
658 WebFrame* WebFrameImpl::parent() const 689 WebFrame* WebFrameImpl::parent() const
659 { 690 {
660 if (!frame()) 691 return m_parent;
661 return 0;
662 return fromFrame(frame()->tree().parent());
663 } 692 }
664 693
665 WebFrame* WebFrameImpl::top() const 694 WebFrame* WebFrameImpl::top() const
666 { 695 {
667 if (!frame()) 696 // FIXME: I am a bad person.
eseidel 2014/02/13 23:49:40 This is not particularly helpful. :) It's not cle
dcheng 2014/02/14 20:29:28 The original versions were const. Making these non
668 return 0; 697 WebFrameImpl* frame = const_cast<WebFrameImpl*>(this);
669 return fromFrame(frame()->tree().top()); 698 for (WebFrameImpl* parent = frame; parent; parent = parent->m_parent)
699 frame = parent;
700 return frame;
701 }
702
703 WebFrame* WebFrameImpl::previousSibling() const
704 {
705 return m_previousSibling;
706 }
707
708 WebFrame* WebFrameImpl::nextSibling() const
709 {
710 return m_nextSibling;
670 } 711 }
671 712
672 WebFrame* WebFrameImpl::firstChild() const 713 WebFrame* WebFrameImpl::firstChild() const
673 { 714 {
674 if (!frame()) 715 return m_firstChild;
675 return 0;
676 return fromFrame(frame()->tree().firstChild());
677 } 716 }
678 717
679 WebFrame* WebFrameImpl::lastChild() const 718 WebFrame* WebFrameImpl::lastChild() const
680 { 719 {
681 if (!frame()) 720 return m_lastChild;
682 return 0;
683 return fromFrame(frame()->tree().lastChild());
684 } 721 }
685 722
686 WebFrame* WebFrameImpl::nextSibling() const 723 WebFrame* WebFrameImpl::traversePrevious(bool wrap) const
687 { 724 {
688 if (!frame()) 725 if (!frame())
689 return 0; 726 return 0;
690 return fromFrame(frame()->tree().nextSibling()); 727 return fromFrame(frame()->tree().traversePreviousWithWrap(wrap));
691 }
692
693 WebFrame* WebFrameImpl::previousSibling() const
694 {
695 if (!frame())
696 return 0;
697 return fromFrame(frame()->tree().previousSibling());
698 } 728 }
699 729
700 WebFrame* WebFrameImpl::traverseNext(bool wrap) const 730 WebFrame* WebFrameImpl::traverseNext(bool wrap) const
701 { 731 {
702 if (!frame()) 732 if (!frame())
703 return 0; 733 return 0;
704 return fromFrame(frame()->tree().traverseNextWithWrap(wrap)); 734 return fromFrame(frame()->tree().traverseNextWithWrap(wrap));
705 } 735 }
706 736
707 WebFrame* WebFrameImpl::traversePrevious(bool wrap) const
708 {
709 if (!frame())
710 return 0;
711 return fromFrame(frame()->tree().traversePreviousWithWrap(wrap));
712 }
713
714 WebFrame* WebFrameImpl::findChildByName(const WebString& name) const 737 WebFrame* WebFrameImpl::findChildByName(const WebString& name) const
715 { 738 {
716 if (!frame()) 739 if (!frame())
717 return 0; 740 return 0;
718 return fromFrame(frame()->tree().child(name)); 741 return fromFrame(frame()->tree().child(name));
719 } 742 }
720 743
721 WebFrame* WebFrameImpl::findChildByExpression(const WebString& xpath) const 744 WebFrame* WebFrameImpl::findChildByExpression(const WebString& xpath) const
722 { 745 {
723 if (xpath.isEmpty()) 746 if (xpath.isEmpty())
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 return WebFrameImpl::create(client, generateEmbedderIdentifier()); 2109 return WebFrameImpl::create(client, generateEmbedderIdentifier());
2087 } 2110 }
2088 2111
2089 WebFrameImpl* WebFrameImpl::create(WebFrameClient* client, long long embedderIde ntifier) 2112 WebFrameImpl* WebFrameImpl::create(WebFrameClient* client, long long embedderIde ntifier)
2090 { 2113 {
2091 return adoptRef(new WebFrameImpl(client, embedderIdentifier)).leakRef(); 2114 return adoptRef(new WebFrameImpl(client, embedderIdentifier)).leakRef();
2092 } 2115 }
2093 2116
2094 WebFrameImpl::WebFrameImpl(WebFrameClient* client, long long embedderIdentifier) 2117 WebFrameImpl::WebFrameImpl(WebFrameClient* client, long long embedderIdentifier)
2095 : m_frameInit(WebFrameInit::create(this, embedderIdentifier)) 2118 : m_frameInit(WebFrameInit::create(this, embedderIdentifier))
2119 , m_parent(0)
2120 , m_previousSibling(0)
2121 , m_nextSibling(0)
2122 , m_firstChild(0)
2123 , m_lastChild(0)
2096 , m_client(client) 2124 , m_client(client)
2097 , m_permissionClient(0) 2125 , m_permissionClient(0)
2098 , m_currentActiveMatchFrame(0) 2126 , m_currentActiveMatchFrame(0)
2099 , m_activeMatchIndexInCurrentFrame(-1) 2127 , m_activeMatchIndexInCurrentFrame(-1)
2100 , m_locatingActiveRect(false) 2128 , m_locatingActiveRect(false)
2101 , m_resumeScopingFromRange(0) 2129 , m_resumeScopingFromRange(0)
2102 , m_lastMatchCount(-1) 2130 , m_lastMatchCount(-1)
2103 , m_totalMatchCount(-1) 2131 , m_totalMatchCount(-1)
2104 , m_framesScopingCount(-1) 2132 , m_framesScopingCount(-1)
2105 , m_findRequestIdentifier(-1) 2133 , m_findRequestIdentifier(-1)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 if (!webframe) 2172 if (!webframe)
2145 return 0; 2173 return 0;
2146 2174
2147 webframe->m_frameInit->setFrameHost(frame()->host()); 2175 webframe->m_frameInit->setFrameHost(frame()->host());
2148 webframe->m_frameInit->setOwnerElement(ownerElement); 2176 webframe->m_frameInit->setOwnerElement(ownerElement);
2149 RefPtr<Frame> childFrame = Frame::create(webframe->m_frameInit); 2177 RefPtr<Frame> childFrame = Frame::create(webframe->m_frameInit);
2150 webframe->setWebCoreFrame(childFrame); 2178 webframe->setWebCoreFrame(childFrame);
2151 2179
2152 childFrame->tree().setName(request.frameName()); 2180 childFrame->tree().setName(request.frameName());
2153 2181
2154 frame()->tree().appendChild(childFrame); 2182 // FIXME: This comment is not quite accurate anymore.
2155
2156 // Frame::init() can trigger onload event in the parent frame, 2183 // Frame::init() can trigger onload event in the parent frame,
2157 // which may detach this frame and trigger a null-pointer access 2184 // which may detach this frame and trigger a null-pointer access
2158 // in FrameTree::removeChild. Move init() after appendChild call 2185 // in FrameTree::removeChild. Move init() after appendChild call
2159 // so that webframe->mFrame is in the tree before triggering 2186 // so that webframe->mFrame is in the tree before triggering
2160 // onload event handler. 2187 // onload event handler.
2161 // Because the event handler may set webframe->mFrame to null, 2188 // Because the event handler may set webframe->mFrame to null,
2162 // it is necessary to check the value after calling init() and 2189 // it is necessary to check the value after calling init() and
2163 // return without loading URL. 2190 // return without loading URL.
2164 // NOTE: m_client will be null if this frame has been detached. 2191 // NOTE: m_client will be null if this frame has been detached.
2165 // (b:791612) 2192 // (b:791612)
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 2513
2487 // There is a possibility that the frame being detached was the only 2514 // There is a possibility that the frame being detached was the only
2488 // pending one. We need to make sure final replies can be sent. 2515 // pending one. We need to make sure final replies can be sent.
2489 flushCurrentScopingEffort(m_findRequestIdentifier); 2516 flushCurrentScopingEffort(m_findRequestIdentifier);
2490 2517
2491 cancelPendingScopingEffort(); 2518 cancelPendingScopingEffort();
2492 } 2519 }
2493 } 2520 }
2494 2521
2495 } // namespace blink 2522 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698