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

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: Rebase past r182224 conflict 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 // With Oilpan, the FrameView is detached. A more complete
120 // setView(nullptr) will touch other on-heap objects, which
121 // is not allowed.
122 detachView();
123 m_view = nullptr;
124 // Oilpan: loader() is disposed during frame owner detach instead,
125 // as it needs to happen while the heap objects it accesses are
126 // still alive. See LocalFrame::disconnectOwnerElement().
127 //
128 // See setDOMWindow() comment why it is acceptable not to mirror
129 // the non-Oilpan call below.
130 //
131 // Also, FrameDestructionObservers that live longer than this
132 // frame object keep weak references to the frame; those will be
133 // automatically cleared by the garbage collector. Hence, explicit
134 // frameDestroyed() notifications aren't needed.
135 #else
118 setView(nullptr); 136 setView(nullptr);
119 loader().clear(); 137 loader().dispose();
120 setDOMWindow(nullptr); 138 setDOMWindow(nullptr);
121 139
122 // FIXME: What to do here... some of this is redundant with ~Frame. 140 HashSet<RawPtr<FrameDestructionObserver> >::iterator stop = m_destructionObs ervers.end();
123 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 141 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(); 142 (*it)->frameDestroyed();
143 #endif
144 }
145
146 void LocalFrame::trace(Visitor* visitor)
147 {
148 #if ENABLE(OILPAN)
149 visitor->trace(m_destructionObservers);
150 #endif
151 visitor->trace(m_loader);
152 visitor->trace(m_navigationScheduler);
153 visitor->trace(m_pagePopupOwner);
154 visitor->trace(m_editor);
155 visitor->trace(m_spellChecker);
156 visitor->trace(m_selection);
157 visitor->trace(m_eventHandler);
158 visitor->trace(m_console);
159 visitor->trace(m_inputMethodController);
160 Frame::trace(visitor);
161 WillBeHeapSupplementable<LocalFrame>::trace(visitor);
126 } 162 }
127 163
128 void LocalFrame::detach() 164 void LocalFrame::detach()
129 { 165 {
130 // A lot of the following steps can result in the current frame being 166 // A lot of the following steps can result in the current frame being
131 // detached, so protect a reference to it. 167 // detached, so protect a reference to it.
132 RefPtr<LocalFrame> protect(this); 168 RefPtrWillBeRawPtr<LocalFrame> protect(this);
133 m_loader.stopAllLoaders(); 169 m_loader.stopAllLoaders();
134 m_loader.closeURL(); 170 m_loader.closeURL();
135 detachChildren(); 171 detachChildren();
136 // stopAllLoaders() needs to be called after detachChildren(), because detac hChildren() 172 // 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 173 // 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. 174 // handlers might start a new subresource load in this frame.
139 m_loader.stopAllLoaders(); 175 m_loader.stopAllLoaders();
140 m_loader.detachFromParent(); 176 m_loader.detachFromParent();
141 } 177 }
142 178
143 bool LocalFrame::inScope(TreeScope* scope) const 179 bool LocalFrame::inScope(TreeScope* scope) const
144 { 180 {
145 ASSERT(scope); 181 ASSERT(scope);
146 Document* doc = document(); 182 Document* doc = document();
147 if (!doc) 183 if (!doc)
148 return false; 184 return false;
149 // FIXME: This check is broken in for OOPI. 185 // FIXME: This check is broken in for OOPI.
150 HTMLFrameOwnerElement* owner = doc->ownerElement(); 186 HTMLFrameOwnerElement* owner = doc->ownerElement();
151 if (!owner) 187 if (!owner)
152 return false; 188 return false;
153 return owner->treeScope() == scope; 189 return owner->treeScope() == scope;
154 } 190 }
155 191
192 void LocalFrame::detachView()
193 {
194 // We detach the FrameView's custom scroll bars as early as
195 // possible to prevent m_doc->detach() from messing with the view
196 // such that its scroll bars won't be torn down.
197 //
198 // FIXME: We should revisit this.
199 if (m_view)
200 m_view->prepareForDetach();
201 }
202
156 void LocalFrame::setView(PassRefPtr<FrameView> view) 203 void LocalFrame::setView(PassRefPtr<FrameView> view)
157 { 204 {
158 // We the custom scroll bars as early as possible to prevent m_doc->detach() 205 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 206
164 // Prepare for destruction now, so any unload event handlers get run and the LocalDOMWindow is 207 // 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 208 // notified. If we wait until the view is destroyed, then things won't be ho oked up enough for
166 // these calls to work. 209 // these calls to work.
167 if (!view && document() && document()->isActive()) { 210 if (!view && document() && document()->isActive()) {
168 // FIXME: We don't call willRemove here. Why is that OK? 211 // FIXME: We don't call willRemove here. Why is that OK?
169 document()->prepareForDestruction(); 212 document()->prepareForDestruction();
170 } 213 }
171 214
172 eventHandler().clear(); 215 eventHandler().clear();
(...skipping 19 matching lines...) Expand all
192 235
193 document()->styleResolverChanged(); 236 document()->styleResolverChanged();
194 if (shouldUsePrintingLayout()) { 237 if (shouldUsePrintingLayout()) {
195 view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShri nkRatio); 238 view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShri nkRatio);
196 } else { 239 } else {
197 view()->forceLayout(); 240 view()->forceLayout();
198 view()->adjustViewSize(); 241 view()->adjustViewSize();
199 } 242 }
200 243
201 // Subframes of the one we're printing don't lay out to the page size. 244 // 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()) { 245 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
203 if (child->isLocalFrame()) 246 if (child->isLocalFrame())
204 toLocalFrame(child.get())->setPrinting(printing, FloatSize(), FloatS ize(), 0); 247 toLocalFrame(child.get())->setPrinting(printing, FloatSize(), FloatS ize(), 0);
205 } 248 }
206 } 249 }
207 250
208 bool LocalFrame::shouldUsePrintingLayout() const 251 bool LocalFrame::shouldUsePrintingLayout() const
209 { 252 {
210 // Only top frame being printed should be fit to page size. 253 // Only top frame being printed should be fit to page size.
211 // Subframes should be constrained by parents only. 254 // Subframes should be constrained by parents only.
212 return document()->printing() && (!tree().parent() || !tree().parent()->isLo calFrame() || !toLocalFrame(tree().parent())->document()->printing()); 255 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(); 271 float ratio = originalSize.width() / originalSize.height();
229 resultSize.setHeight(floorf(expectedSize.height())); 272 resultSize.setHeight(floorf(expectedSize.height()));
230 resultSize.setWidth(floorf(resultSize.height() * ratio)); 273 resultSize.setWidth(floorf(resultSize.height() * ratio));
231 } 274 }
232 return resultSize; 275 return resultSize;
233 } 276 }
234 277
235 void LocalFrame::setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow> domWindow) 278 void LocalFrame::setDOMWindow(PassRefPtrWillBeRawPtr<LocalDOMWindow> domWindow)
236 { 279 {
237 if (m_domWindow) { 280 if (m_domWindow) {
281 // Oilpan: the assumption is that FrameDestructionObserver::willDetachFr ameHost()
282 // on LocalWindow will have signalled these frameWindowDiscarded() notif ications.
283 //
284 // It is not invoked when finalizing the LocalFrame, as setDOMWindow() i sn't
285 // performed (accessing the m_domWindow heap object is unsafe then.)
238 console().messageStorage()->frameWindowDiscarded(m_domWindow.get()); 286 console().messageStorage()->frameWindowDiscarded(m_domWindow.get());
239 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get()); 287 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get());
240 } 288 }
241 if (domWindow) 289 if (domWindow)
242 script().clearWindowProxy(); 290 script().clearWindowProxy();
243 Frame::setDOMWindow(domWindow); 291 Frame::setDOMWindow(domWindow);
244 } 292 }
245 293
246 void LocalFrame::didChangeVisibilityState() 294 void LocalFrame::didChangeVisibilityState()
247 { 295 {
248 if (document()) 296 if (document())
249 document()->didChangeVisibilityState(); 297 document()->didChangeVisibilityState();
250 298
251 Vector<RefPtr<LocalFrame> > childFrames; 299 WillBeHeapVector<RefPtrWillBeMember<LocalFrame> > childFrames;
252 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling()) { 300 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling()) {
253 if (child->isLocalFrame()) 301 if (child->isLocalFrame())
254 childFrames.append(toLocalFrame(child)); 302 childFrames.append(toLocalFrame(child));
255 } 303 }
256 304
257 for (size_t i = 0; i < childFrames.size(); ++i) 305 for (size_t i = 0; i < childFrames.size(); ++i)
258 childFrames[i]->didChangeVisibilityState(); 306 childFrames[i]->didChangeVisibilityState();
259 } 307 }
260 308
261 void LocalFrame::addDestructionObserver(FrameDestructionObserver* observer) 309 void LocalFrame::addDestructionObserver(FrameDestructionObserver* observer)
262 { 310 {
263 m_destructionObservers.add(observer); 311 m_destructionObservers.add(observer);
264 } 312 }
265 313
266 void LocalFrame::removeDestructionObserver(FrameDestructionObserver* observer) 314 void LocalFrame::removeDestructionObserver(FrameDestructionObserver* observer)
267 { 315 {
268 m_destructionObservers.remove(observer); 316 m_destructionObservers.remove(observer);
269 } 317 }
270 318
271 void LocalFrame::willDetachFrameHost() 319 void LocalFrame::willDetachFrameHost()
272 { 320 {
273 // We should never be detatching the page during a Layout. 321 // We should never be detatching the page during a Layout.
274 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 322 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
275 323
276 Frame* parent = tree().parent(); 324 Frame* parent = tree().parent();
277 if (parent && parent->isLocalFrame()) 325 if (parent && parent->isLocalFrame())
278 toLocalFrame(parent)->loader().checkLoadComplete(); 326 toLocalFrame(parent)->loader().checkLoadComplete();
279 327
280 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 328 WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::iterat or stop = m_destructionObservers.end();
281 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it) 329 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::i terator it = m_destructionObservers.begin(); it != stop; ++it)
282 (*it)->willDetachFrameHost(); 330 (*it)->willDetachFrameHost();
283 331
284 // FIXME: Page should take care of updating focus/scrolling instead of Frame . 332 // 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, 333 // FIXME: It's unclear as to why this is called more than once, but it is,
286 // so page() could be null. 334 // so page() could be null.
287 if (page() && page()->focusController().focusedFrame() == this) 335 if (page() && page()->focusController().focusedFrame() == this)
288 page()->focusController().setFocusedFrame(nullptr); 336 page()->focusController().setFocusedFrame(nullptr);
289 script().clearScriptObjects(); 337 script().clearScriptObjects();
290 338
291 if (page() && page()->scrollingCoordinator() && m_view) 339 if (page() && page()->scrollingCoordinator() && m_view)
292 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get()); 340 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get());
293 } 341 }
294 342
295 void LocalFrame::detachFromFrameHost() 343 void LocalFrame::detachFromFrameHost()
296 { 344 {
297 // We should never be detatching the page during a Layout. 345 // We should never be detaching the page during a Layout.
298 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 346 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
299 m_host = 0; 347 m_host = nullptr;
300 } 348 }
301 349
302 String LocalFrame::documentTypeString() const 350 String LocalFrame::documentTypeString() const
303 { 351 {
304 if (DocumentType* doctype = document()->doctype()) 352 if (DocumentType* doctype = document()->doctype())
305 return createMarkup(doctype); 353 return createMarkup(doctype);
306 354
307 return String(); 355 return String();
308 } 356 }
309 357
(...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. 554 // 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(); 555 LayoutPoint scrollPosition = view->scrollPosition();
508 float percentDifference = (pageZoomFactor / m_pageZoomFactor); 556 float percentDifference = (pageZoomFactor / m_pageZoomFactor);
509 view->setScrollPosition(IntPoint(scrollPosition.x() * percentDiffere nce, scrollPosition.y() * percentDifference)); 557 view->setScrollPosition(IntPoint(scrollPosition.x() * percentDiffere nce, scrollPosition.y() * percentDifference));
510 } 558 }
511 } 559 }
512 560
513 m_pageZoomFactor = pageZoomFactor; 561 m_pageZoomFactor = pageZoomFactor;
514 m_textZoomFactor = textZoomFactor; 562 m_textZoomFactor = textZoomFactor;
515 563
516 for (RefPtr<Frame> child = tree().firstChild(); child; child = child->tree() .nextSibling()) { 564 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
517 if (child->isLocalFrame()) 565 if (child->isLocalFrame())
518 toLocalFrame(child.get())->setPageAndTextZoomFactors(m_pageZoomFacto r, m_textZoomFactor); 566 toLocalFrame(child.get())->setPageAndTextZoomFactors(m_pageZoomFacto r, m_textZoomFactor);
519 } 567 }
520 568
521 document->setNeedsStyleRecalc(SubtreeStyleChange); 569 document->setNeedsStyleRecalc(SubtreeStyleChange);
522 document->updateLayoutIgnorePendingStylesheets(); 570 document->updateLayoutIgnorePendingStylesheets();
523 } 571 }
524 572
525 void LocalFrame::deviceOrPageScaleFactorChanged() 573 void LocalFrame::deviceOrPageScaleFactorChanged()
526 { 574 {
527 document()->mediaQueryAffectingValueChanged(); 575 document()->mediaQueryAffectingValueChanged();
528 for (RefPtr<Frame> child = tree().firstChild(); child; child = child->tree() .nextSibling()) { 576 for (RefPtrWillBeRawPtr<Frame> child = tree().firstChild(); child; child = c hild->tree().nextSibling()) {
529 if (child->isLocalFrame()) 577 if (child->isLocalFrame())
530 toLocalFrame(child.get())->deviceOrPageScaleFactorChanged(); 578 toLocalFrame(child.get())->deviceOrPageScaleFactorChanged();
531 } 579 }
532 } 580 }
533 581
534 bool LocalFrame::isURLAllowed(const KURL& url) const 582 bool LocalFrame::isURLAllowed(const KURL& url) const
535 { 583 {
536 // We allow one level of self-reference because some sites depend on that, 584 // We allow one level of self-reference because some sites depend on that,
537 // but we don't allow more than one. 585 // but we don't allow more than one.
538 if (page()->subframeCount() >= Page::maxNumberOfFrames) 586 if (page()->subframeCount() >= Page::maxNumberOfFrames)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return 0; 706 return 0;
659 707
660 double ratio = m_host->deviceScaleFactor(); 708 double ratio = m_host->deviceScaleFactor();
661 ratio *= pageZoomFactor(); 709 ratio *= pageZoomFactor();
662 return ratio; 710 return ratio;
663 } 711 }
664 712
665 void LocalFrame::disconnectOwnerElement() 713 void LocalFrame::disconnectOwnerElement()
666 { 714 {
667 if (owner()) { 715 if (owner()) {
668 if (Document* doc = document()) 716 if (Document* document = this->document())
669 doc->topDocument().clearAXObjectCache(); 717 document->topDocument().clearAXObjectCache();
718 #if ENABLE(OILPAN)
719 // FIXME: Oilpan: this might not be sufficiently strong, but
720 // cannot perform a full FrameLoader dispose when LocalFrame is finalize d,
721 // so do it here when the FrameOwner is detached instead.
722 loader().dispose();
Mads Ager (chromium) 2014/09/18 12:00:59 Just verifying my understanding: This will lead to
sof 2014/09/18 13:31:15 Yes, it will lead to prepareForDestruction(). If s
723 #endif
670 } 724 }
671 Frame::disconnectOwnerElement(); 725 Frame::disconnectOwnerElement();
672 } 726 }
673 727
674 LocalFrame* LocalFrame::localFrameRoot() 728 LocalFrame* LocalFrame::localFrameRoot()
675 { 729 {
676 LocalFrame* curFrame = this; 730 LocalFrame* curFrame = this;
677 while (curFrame && curFrame->tree().parent() && curFrame->tree().parent()->i sLocalFrame()) 731 while (curFrame && curFrame->tree().parent() && curFrame->tree().parent()->i sLocalFrame())
678 curFrame = toLocalFrame(curFrame->tree().parent()); 732 curFrame = toLocalFrame(curFrame->tree().parent());
679 733
680 return curFrame; 734 return curFrame;
681 } 735 }
682 736
683 void LocalFrame::setPagePopupOwner(Element& owner) 737 void LocalFrame::setPagePopupOwner(Element& owner)
684 { 738 {
685 m_pagePopupOwner = &owner; 739 m_pagePopupOwner = &owner;
686 } 740 }
687 741
688 } // namespace blink 742 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698