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

Side by Side Diff: Source/core/frame/LocalFrame.cpp

Issue 517043003: Move Frame to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Back out non-Oilpan experiment + tidy up by adding frame() ref accessors Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Simon Hausmann <hausmann@kde.org> 5 * 2000 Simon Hausmann <hausmann@kde.org>
6 * 2000 Stefan Schimanski <1Stein@gmx.de> 6 * 2000 Stefan Schimanski <1Stein@gmx.de>
7 * 2001 George Staikos <staikos@kde.org> 7 * 2001 George Staikos <staikos@kde.org>
8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> 9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com>
10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 , m_selection(FrameSelection::create(this)) 99 , m_selection(FrameSelection::create(this))
100 , m_eventHandler(adoptPtrWillBeNoop(new EventHandler(this))) 100 , m_eventHandler(adoptPtrWillBeNoop(new EventHandler(this)))
101 , m_console(FrameConsole::create(*this)) 101 , m_console(FrameConsole::create(*this))
102 , m_inputMethodController(InputMethodController::create(*this)) 102 , m_inputMethodController(InputMethodController::create(*this))
103 , m_pageZoomFactor(parentPageZoomFactor(this)) 103 , m_pageZoomFactor(parentPageZoomFactor(this))
104 , m_textZoomFactor(parentTextZoomFactor(this)) 104 , m_textZoomFactor(parentTextZoomFactor(this))
105 , m_inViewSourceMode(false) 105 , m_inViewSourceMode(false)
106 { 106 {
107 } 107 }
108 108
109 PassRefPtr<LocalFrame> LocalFrame::create(FrameLoaderClient* client, FrameHost* host, FrameOwner* owner) 109 PassRefPtrWillBeRawPtr<LocalFrame> LocalFrame::create(FrameLoaderClient* client, FrameHost* host, FrameOwner* owner)
110 { 110 {
111 RefPtr<LocalFrame> frame = adoptRef(new LocalFrame(client, host, owner)); 111 RefPtrWillBeRawPtr<LocalFrame> frame = adoptRefWillBeNoop(new LocalFrame(cli ent, host, owner));
112 InspectorInstrumentation::frameAttachedToParent(frame.get()); 112 InspectorInstrumentation::frameAttachedToParent(frame.get());
113 return frame.release(); 113 return frame.release();
114 } 114 }
115 115
116 LocalFrame::~LocalFrame() 116 LocalFrame::~LocalFrame()
117 { 117 {
118 #if ENABLE(OILPAN)
119 // Verify that the FrameView and FrameLoader have instead been
120 // cleared as part of detaching the frame owner.
121 ASSERT(!m_owner);
122 ASSERT(!m_view);
123 // Oilpan: see setDOMWindow() comment why it is acceptable not to
124 // mirror the non-Oilpan call below.
125 //
126 // Also, FrameDestructionObservers that live longer than this
127 // frame object keep weak references to the frame; those will be
128 // automatically cleared by the garbage collector. Hence, explicit
129 // frameDestroyed() notifications aren't needed.
130 #else
131 // FIXME: follow Oilpan and clear the FrameView and FrameLoader
132 // during FrameOwner detachment instead, see LocalFrame::disconnectOwnerElem ent().
118 setView(nullptr); 133 setView(nullptr);
119 loader().clear(); 134 m_loader.clear();
120 setDOMWindow(nullptr); 135 setDOMWindow(nullptr);
121 136
122 // FIXME: What to do here... some of this is redundant with ~Frame. 137 HashSet<RawPtr<FrameDestructionObserver> >::iterator stop = m_destructionObs ervers.end();
123 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 138 for (HashSet<RawPtr<FrameDestructionObserver> >::iterator it = m_destruction Observers.begin(); it != stop; ++it)
124 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it)
125 (*it)->frameDestroyed(); 139 (*it)->frameDestroyed();
140 #endif
141 }
142
143 void LocalFrame::trace(Visitor* visitor)
144 {
145 #if ENABLE(OILPAN)
146 visitor->trace(m_destructionObservers);
147 #endif
148 visitor->trace(m_loader);
149 visitor->trace(m_navigationScheduler);
150 visitor->trace(m_pagePopupOwner);
151 visitor->trace(m_editor);
152 visitor->trace(m_spellChecker);
153 visitor->trace(m_selection);
154 visitor->trace(m_eventHandler);
155 visitor->trace(m_console);
156 visitor->trace(m_inputMethodController);
157 Frame::trace(visitor);
158 WillBeHeapSupplementable<LocalFrame>::trace(visitor);
126 } 159 }
127 160
128 void LocalFrame::detach() 161 void LocalFrame::detach()
129 { 162 {
130 // A lot of the following steps can result in the current frame being 163 // A lot of the following steps can result in the current frame being
131 // detached, so protect a reference to it. 164 // detached, so protect a reference to it.
132 RefPtr<LocalFrame> protect(this); 165 RefPtrWillBeRawPtr<LocalFrame> protect(this);
133 m_loader.stopAllLoaders(); 166 m_loader.stopAllLoaders();
134 m_loader.closeURL(); 167 m_loader.closeURL();
135 detachChildren(); 168 detachChildren();
136 // stopAllLoaders() needs to be called after detachChildren(), because detac hChildren() 169 // stopAllLoaders() needs to be called after detachChildren(), because detac hChildren()
137 // will trigger the unload event handlers of any child frames, and those eve nt 170 // will trigger the unload event handlers of any child frames, and those eve nt
138 // handlers might start a new subresource load in this frame. 171 // handlers might start a new subresource load in this frame.
139 m_loader.stopAllLoaders(); 172 m_loader.stopAllLoaders();
140 m_loader.detachFromParent(); 173 m_loader.detachFromParent();
141 } 174 }
142 175
143 bool LocalFrame::inScope(TreeScope* scope) const 176 bool LocalFrame::inScope(TreeScope* scope) const
144 { 177 {
145 ASSERT(scope); 178 ASSERT(scope);
146 Document* doc = document(); 179 Document* doc = document();
147 if (!doc) 180 if (!doc)
148 return false; 181 return false;
149 // FIXME: This check is broken in for OOPI. 182 // FIXME: This check is broken in for OOPI.
150 HTMLFrameOwnerElement* owner = doc->ownerElement(); 183 HTMLFrameOwnerElement* owner = doc->ownerElement();
151 if (!owner) 184 if (!owner)
152 return false; 185 return false;
153 return owner->treeScope() == scope; 186 return owner->treeScope() == scope;
154 } 187 }
155 188
189 void LocalFrame::detachView()
190 {
191 // We detach the FrameView's custom scroll bars as early as
192 // possible to prevent m_doc->detach() from messing with the view
193 // such that its scroll bars won't be torn down.
194 //
195 // FIXME: We should revisit this.
196 if (m_view)
197 m_view->prepareForDetach();
198 }
199
156 void LocalFrame::setView(PassRefPtr<FrameView> view) 200 void LocalFrame::setView(PassRefPtr<FrameView> view)
157 { 201 {
158 // We the custom scroll bars as early as possible to prevent m_doc->detach() 202 detachView();
159 // from messing with the view such that its scroll bars won't be torn down.
160 // FIXME: We should revisit this.
161 if (m_view)
162 m_view->prepareForDetach();
163 203
164 // Prepare for destruction now, so any unload event handlers get run and the LocalDOMWindow is 204 // Prepare for destruction now, so any unload event handlers get run and the LocalDOMWindow is
165 // notified. If we wait until the view is destroyed, then things won't be ho oked up enough for 205 // notified. If we wait until the view is destroyed, then things won't be ho oked up enough for
166 // these calls to work. 206 // these calls to work.
167 if (!view && document() && document()->isActive()) { 207 if (!view && document() && document()->isActive()) {
168 // FIXME: We don't call willRemove here. Why is that OK? 208 // FIXME: We don't call willRemove here. Why is that OK?
169 document()->prepareForDestruction(); 209 document()->prepareForDestruction();
170 } 210 }
171 211
172 eventHandler().clear(); 212 eventHandler().clear();
(...skipping 19 matching lines...) Expand all
192 232
193 document()->styleResolverChanged(); 233 document()->styleResolverChanged();
194 if (shouldUsePrintingLayout()) { 234 if (shouldUsePrintingLayout()) {
195 view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShri nkRatio); 235 view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShri nkRatio);
196 } else { 236 } else {
197 view()->forceLayout(); 237 view()->forceLayout();
198 view()->adjustViewSize(); 238 view()->adjustViewSize();
199 } 239 }
200 240
201 // Subframes of the one we're printing don't lay out to the page size. 241 // Subframes of the one we're printing don't lay out to the page size.
202 for (RefPtr<Frame> child = tree().firstChild(); child; child = child->tree() .nextSibling()) { 242 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
203 if (child->isLocalFrame()) 243 if (child->isLocalFrame())
204 toLocalFrame(child.get())->setPrinting(printing, FloatSize(), FloatS ize(), 0); 244 toLocalFrame(child.get())->setPrinting(printing, FloatSize(), FloatS ize(), 0);
205 } 245 }
206 } 246 }
207 247
208 bool LocalFrame::shouldUsePrintingLayout() const 248 bool LocalFrame::shouldUsePrintingLayout() const
209 { 249 {
210 // Only top frame being printed should be fit to page size. 250 // Only top frame being printed should be fit to page size.
211 // Subframes should be constrained by parents only. 251 // Subframes should be constrained by parents only.
212 return document()->printing() && (!tree().parent() || !tree().parent()->isLo calFrame() || !toLocalFrame(tree().parent())->document()->printing()); 252 return document()->printing() && (!tree().parent() || !tree().parent()->isLo calFrame() || !toLocalFrame(tree().parent())->document()->printing());
(...skipping 15 matching lines...) Expand all
228 float ratio = originalSize.width() / originalSize.height(); 268 float ratio = originalSize.width() / originalSize.height();
229 resultSize.setHeight(floorf(expectedSize.height())); 269 resultSize.setHeight(floorf(expectedSize.height()));
230 resultSize.setWidth(floorf(resultSize.height() * ratio)); 270 resultSize.setWidth(floorf(resultSize.height() * ratio));
231 } 271 }
232 return resultSize; 272 return resultSize;
233 } 273 }
234 274
235 void LocalFrame::setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow> domWindow) 275 void LocalFrame::setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow> domWindow)
236 { 276 {
237 if (m_domWindow) { 277 if (m_domWindow) {
278 // Oilpan: the assumption is that FrameDestructionObserver::willDetachFr ameHost()
279 // on LocalWindow will have signalled these frameWindowDiscarded() notif ications.
280 //
281 // It is not invoked when finalizing the LocalFrame, as setDOMWindow() i sn't
282 // performed (accessing the m_domWindow heap object is unsafe then.)
haraken 2014/09/22 05:35:23 This comment now looks a bit strange. Now that set
sof 2014/09/22 09:52:51 I think it makes some sense to document the reason
238 console().messageStorage()->frameWindowDiscarded(m_domWindow.get()); 283 console().messageStorage()->frameWindowDiscarded(m_domWindow.get());
239 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get()); 284 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get());
240 } 285 }
241 if (domWindow) 286 if (domWindow)
242 script().clearWindowProxy(); 287 script().clearWindowProxy();
243 Frame::setDOMWindow(domWindow); 288 Frame::setDOMWindow(domWindow);
244 } 289 }
245 290
246 void LocalFrame::didChangeVisibilityState() 291 void LocalFrame::didChangeVisibilityState()
247 { 292 {
248 if (document()) 293 if (document())
249 document()->didChangeVisibilityState(); 294 document()->didChangeVisibilityState();
250 295
251 Vector<RefPtr<LocalFrame> > childFrames; 296 WillBeHeapVector<RefPtrWillBeMember<LocalFrame> > childFrames;
252 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling()) { 297 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling()) {
253 if (child->isLocalFrame()) 298 if (child->isLocalFrame())
254 childFrames.append(toLocalFrame(child)); 299 childFrames.append(toLocalFrame(child));
255 } 300 }
256 301
257 for (size_t i = 0; i < childFrames.size(); ++i) 302 for (size_t i = 0; i < childFrames.size(); ++i)
258 childFrames[i]->didChangeVisibilityState(); 303 childFrames[i]->didChangeVisibilityState();
259 } 304 }
260 305
261 void LocalFrame::addDestructionObserver(FrameDestructionObserver* observer) 306 void LocalFrame::addDestructionObserver(FrameDestructionObserver* observer)
262 { 307 {
263 m_destructionObservers.add(observer); 308 m_destructionObservers.add(observer);
264 } 309 }
265 310
266 void LocalFrame::removeDestructionObserver(FrameDestructionObserver* observer) 311 void LocalFrame::removeDestructionObserver(FrameDestructionObserver* observer)
267 { 312 {
268 m_destructionObservers.remove(observer); 313 m_destructionObservers.remove(observer);
269 } 314 }
270 315
271 void LocalFrame::willDetachFrameHost() 316 void LocalFrame::willDetachFrameHost()
272 { 317 {
273 // We should never be detatching the page during a Layout. 318 // We should never be detatching the page during a Layout.
274 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 319 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
275 320
276 Frame* parent = tree().parent(); 321 Frame* parent = tree().parent();
277 if (parent && parent->isLocalFrame()) 322 if (parent && parent->isLocalFrame())
278 toLocalFrame(parent)->loader().checkLoadComplete(); 323 toLocalFrame(parent)->loader().checkLoadComplete();
279 324
280 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 325 WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::iterat or stop = m_destructionObservers.end();
281 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it) 326 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::i terator it = m_destructionObservers.begin(); it != stop; ++it)
282 (*it)->willDetachFrameHost(); 327 (*it)->willDetachFrameHost();
283 328
284 // FIXME: Page should take care of updating focus/scrolling instead of Frame . 329 // FIXME: Page should take care of updating focus/scrolling instead of Frame .
285 // FIXME: It's unclear as to why this is called more than once, but it is, 330 // FIXME: It's unclear as to why this is called more than once, but it is,
286 // so page() could be null. 331 // so page() could be null.
287 if (page() && page()->focusController().focusedFrame() == this) 332 if (page() && page()->focusController().focusedFrame() == this)
288 page()->focusController().setFocusedFrame(nullptr); 333 page()->focusController().setFocusedFrame(nullptr);
289 script().clearScriptObjects(); 334 script().clearScriptObjects();
290 335
291 if (page() && page()->scrollingCoordinator() && m_view) 336 if (page() && page()->scrollingCoordinator() && m_view)
292 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get()); 337 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get());
293 } 338 }
294 339
295 void LocalFrame::detachFromFrameHost() 340 void LocalFrame::detachFromFrameHost()
296 { 341 {
297 // We should never be detatching the page during a Layout. 342 // We should never be detaching the page during a Layout.
298 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 343 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
299 m_host = 0; 344 m_host = nullptr;
300 } 345 }
301 346
302 String LocalFrame::documentTypeString() const 347 String LocalFrame::documentTypeString() const
303 { 348 {
304 if (DocumentType* doctype = document()->doctype()) 349 if (DocumentType* doctype = document()->doctype())
305 return createMarkup(doctype); 350 return createMarkup(doctype);
306 351
307 return String(); 352 return String();
308 } 353 }
309 354
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // Update the scroll position when doing a full page zoom, so the co ntent stays in relatively the same position. 551 // Update the scroll position when doing a full page zoom, so the co ntent stays in relatively the same position.
507 LayoutPoint scrollPosition = view->scrollPosition(); 552 LayoutPoint scrollPosition = view->scrollPosition();
508 float percentDifference = (pageZoomFactor / m_pageZoomFactor); 553 float percentDifference = (pageZoomFactor / m_pageZoomFactor);
509 view->setScrollPosition(IntPoint(scrollPosition.x() * percentDiffere nce, scrollPosition.y() * percentDifference)); 554 view->setScrollPosition(IntPoint(scrollPosition.x() * percentDiffere nce, scrollPosition.y() * percentDifference));
510 } 555 }
511 } 556 }
512 557
513 m_pageZoomFactor = pageZoomFactor; 558 m_pageZoomFactor = pageZoomFactor;
514 m_textZoomFactor = textZoomFactor; 559 m_textZoomFactor = textZoomFactor;
515 560
516 for (RefPtr<Frame> child = tree().firstChild(); child; child = child->tree() .nextSibling()) { 561 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
517 if (child->isLocalFrame()) 562 if (child->isLocalFrame())
518 toLocalFrame(child.get())->setPageAndTextZoomFactors(m_pageZoomFacto r, m_textZoomFactor); 563 toLocalFrame(child.get())->setPageAndTextZoomFactors(m_pageZoomFacto r, m_textZoomFactor);
519 } 564 }
520 565
521 document->setNeedsStyleRecalc(SubtreeStyleChange); 566 document->setNeedsStyleRecalc(SubtreeStyleChange);
522 document->updateLayoutIgnorePendingStylesheets(); 567 document->updateLayoutIgnorePendingStylesheets();
523 } 568 }
524 569
525 void LocalFrame::deviceOrPageScaleFactorChanged() 570 void LocalFrame::deviceOrPageScaleFactorChanged()
526 { 571 {
527 document()->mediaQueryAffectingValueChanged(); 572 document()->mediaQueryAffectingValueChanged();
528 for (RefPtr<Frame> child = tree().firstChild(); child; child = child->tree() .nextSibling()) { 573 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
529 if (child->isLocalFrame()) 574 if (child->isLocalFrame())
530 toLocalFrame(child.get())->deviceOrPageScaleFactorChanged(); 575 toLocalFrame(child.get())->deviceOrPageScaleFactorChanged();
531 } 576 }
532 } 577 }
533 578
534 bool LocalFrame::isURLAllowed(const KURL& url) const 579 bool LocalFrame::isURLAllowed(const KURL& url) const
535 { 580 {
536 // We allow one level of self-reference because some sites depend on that, 581 // We allow one level of self-reference because some sites depend on that,
537 // but we don't allow more than one. 582 // but we don't allow more than one.
538 if (page()->subframeCount() >= Page::maxNumberOfFrames) 583 if (page()->subframeCount() >= Page::maxNumberOfFrames)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return 0; 703 return 0;
659 704
660 double ratio = m_host->deviceScaleFactor(); 705 double ratio = m_host->deviceScaleFactor();
661 ratio *= pageZoomFactor(); 706 ratio *= pageZoomFactor();
662 return ratio; 707 return ratio;
663 } 708 }
664 709
665 void LocalFrame::disconnectOwnerElement() 710 void LocalFrame::disconnectOwnerElement()
666 { 711 {
667 if (owner()) { 712 if (owner()) {
668 if (Document* doc = document()) 713 if (Document* document = this->document())
669 doc->topDocument().clearAXObjectCache(); 714 document->topDocument().clearAXObjectCache();
715 #if ENABLE(OILPAN)
716 // Clear the FrameView and FrameLoader right here rather than
717 // during finalization. Too late to access various heap objects
718 // at that stage.
719 setView(nullptr);
720 loader().clear();
haraken 2014/09/22 05:35:23 Don't we need to call setDOMWindow(nullptr) here?
sof 2014/09/22 09:52:51 That's a bit too strong, as you then will observab
haraken 2014/09/22 10:07:47 Makes sense. I now understand that we should let t
721 #endif
670 } 722 }
671 Frame::disconnectOwnerElement(); 723 Frame::disconnectOwnerElement();
672 } 724 }
673 725
674 LocalFrame* LocalFrame::localFrameRoot() 726 LocalFrame* LocalFrame::localFrameRoot()
675 { 727 {
676 LocalFrame* curFrame = this; 728 LocalFrame* curFrame = this;
677 while (curFrame && curFrame->tree().parent() && curFrame->tree().parent()->i sLocalFrame()) 729 while (curFrame && curFrame->tree().parent() && curFrame->tree().parent()->i sLocalFrame())
678 curFrame = toLocalFrame(curFrame->tree().parent()); 730 curFrame = toLocalFrame(curFrame->tree().parent());
679 731
680 return curFrame; 732 return curFrame;
681 } 733 }
682 734
683 void LocalFrame::setPagePopupOwner(Element& owner) 735 void LocalFrame::setPagePopupOwner(Element& owner)
684 { 736 {
685 m_pagePopupOwner = &owner; 737 m_pagePopupOwner = &owner;
686 } 738 }
687 739
688 } // namespace blink 740 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698