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

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 2516473002: Cross-origin iframes: collect data under hypothetical loading strategies (Closed)
Patch Set: Do arithmetic instead of intersects Created 3 years, 12 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 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #include "platform/json/JSONValues.h" 118 #include "platform/json/JSONValues.h"
119 #include "platform/scroll/ScrollAnimatorBase.h" 119 #include "platform/scroll/ScrollAnimatorBase.h"
120 #include "platform/scroll/ScrollbarTheme.h" 120 #include "platform/scroll/ScrollbarTheme.h"
121 #include "platform/text/TextStream.h" 121 #include "platform/text/TextStream.h"
122 #include "platform/tracing/TraceEvent.h" 122 #include "platform/tracing/TraceEvent.h"
123 #include "platform/tracing/TracedValue.h" 123 #include "platform/tracing/TracedValue.h"
124 #include "public/platform/WebDisplayItemList.h" 124 #include "public/platform/WebDisplayItemList.h"
125 #include "wtf/CurrentTime.h" 125 #include "wtf/CurrentTime.h"
126 #include "wtf/PtrUtil.h" 126 #include "wtf/PtrUtil.h"
127 #include "wtf/StdLibExtras.h" 127 #include "wtf/StdLibExtras.h"
128 #include <algorithm>
128 #include <memory> 129 #include <memory>
129 130
130 // Used to check for dirty layouts violating document lifecycle rules. 131 // Used to check for dirty layouts violating document lifecycle rules.
131 // If arg evaluates to true, the program will continue. If arg evaluates to 132 // If arg evaluates to true, the program will continue. If arg evaluates to
132 // false, program will crash if DCHECK_IS_ON() or return false from the current 133 // false, program will crash if DCHECK_IS_ON() or return false from the current
133 // function. 134 // function.
134 #define CHECK_FOR_DIRTY_LAYOUT(arg) \ 135 #define CHECK_FOR_DIRTY_LAYOUT(arg) \
135 do { \ 136 do { \
136 if (!(arg)) { \ 137 if (!(arg)) { \
137 NOTREACHED(); \ 138 NOTREACHED(); \
(...skipping 30 matching lines...) Expand all
168 m_baseBackgroundColor(Color::white), 169 m_baseBackgroundColor(Color::white),
169 m_mediaType(MediaTypeNames::screen), 170 m_mediaType(MediaTypeNames::screen),
170 m_safeToPropagateScrollToParent(true), 171 m_safeToPropagateScrollToParent(true),
171 m_scrollCorner(nullptr), 172 m_scrollCorner(nullptr),
172 m_stickyPositionObjectCount(0), 173 m_stickyPositionObjectCount(0),
173 m_inputEventsScaleFactorForEmulation(1), 174 m_inputEventsScaleFactorForEmulation(1),
174 m_layoutSizeFixedToFrameSize(true), 175 m_layoutSizeFixedToFrameSize(true),
175 m_didScrollTimer(this, &FrameView::didScrollTimerFired), 176 m_didScrollTimer(this, &FrameView::didScrollTimerFired),
176 m_browserControlsViewportAdjustment(0), 177 m_browserControlsViewportAdjustment(0),
177 m_needsUpdateWidgetGeometries(false), 178 m_needsUpdateWidgetGeometries(false),
178 m_needsUpdateViewportIntersection(true),
179 #if ENABLE(ASSERT) 179 #if ENABLE(ASSERT)
180 m_hasBeenDisposed(false), 180 m_hasBeenDisposed(false),
181 #endif 181 #endif
182 m_horizontalScrollbarMode(ScrollbarAuto), 182 m_horizontalScrollbarMode(ScrollbarAuto),
183 m_verticalScrollbarMode(ScrollbarAuto), 183 m_verticalScrollbarMode(ScrollbarAuto),
184 m_horizontalScrollbarLock(false), 184 m_horizontalScrollbarLock(false),
185 m_verticalScrollbarLock(false), 185 m_verticalScrollbarLock(false),
186 m_scrollbarsSuppressed(false), 186 m_scrollbarsSuppressed(false),
187 m_inUpdateScrollbars(false), 187 m_inUpdateScrollbars(false),
188 m_frameTimingRequestsDirty(true), 188 m_frameTimingRequestsDirty(true),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // frames whose owner element is remote. 308 // frames whose owner element is remote.
309 Element* targetElement = frame().deprecatedLocalOwner(); 309 Element* targetElement = frame().deprecatedLocalOwner();
310 if (!targetElement) 310 if (!targetElement)
311 return; 311 return;
312 312
313 m_visibilityObserver = new ElementVisibilityObserver( 313 m_visibilityObserver = new ElementVisibilityObserver(
314 targetElement, WTF::bind( 314 targetElement, WTF::bind(
315 [](FrameView* frameView, bool isVisible) { 315 [](FrameView* frameView, bool isVisible) {
316 frameView->updateRenderThrottlingStatus( 316 frameView->updateRenderThrottlingStatus(
317 !isVisible, frameView->m_subtreeThrottled); 317 !isVisible, frameView->m_subtreeThrottled);
318 frameView->maybeRecordLoadReason(); 318 frameView->recordDeferredLoadingStats();
319 }, 319 },
320 wrapWeakPersistent(this))); 320 wrapWeakPersistent(this)));
321 m_visibilityObserver->start(); 321 m_visibilityObserver->start();
322 } 322 }
323 323
324 void FrameView::dispose() { 324 void FrameView::dispose() {
325 RELEASE_ASSERT(!isInPerformLayout()); 325 RELEASE_ASSERT(!isInPerformLayout());
326 326
327 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) 327 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
328 scrollAnimator->cancelAnimation(); 328 scrollAnimator->cancelAnimation();
(...skipping 4188 matching lines...) Expand 10 before | Expand all | Expand 10 after
4517 } 4517 }
4518 4518
4519 void FrameView::setNeedsUpdateViewportIntersection() { 4519 void FrameView::setNeedsUpdateViewportIntersection() {
4520 for (FrameView* parent = parentFrameView(); parent; 4520 for (FrameView* parent = parentFrameView(); parent;
4521 parent = parent->parentFrameView()) 4521 parent = parent->parentFrameView())
4522 parent->m_needsUpdateViewportIntersectionInSubtree = true; 4522 parent->m_needsUpdateViewportIntersectionInSubtree = true;
4523 } 4523 }
4524 4524
4525 void FrameView::updateViewportIntersectionsForSubtree( 4525 void FrameView::updateViewportIntersectionsForSubtree(
4526 DocumentLifecycle::LifecycleState targetState) { 4526 DocumentLifecycle::LifecycleState targetState) {
4527 // Notify javascript IntersectionObservers 4527 if (targetState == DocumentLifecycle::PaintClean) {
4528 if (targetState == DocumentLifecycle::PaintClean && 4528 recordDeferredLoadingStats();
4529 frame().document()->intersectionObserverController()) 4529 // Notify javascript IntersectionObservers
4530 frame() 4530 if (frame().document()->intersectionObserverController()) {
4531 .document() 4531 frame()
4532 ->intersectionObserverController() 4532 .document()
4533 ->computeTrackedIntersectionObservations(); 4533 ->intersectionObserverController()
4534 ->computeTrackedIntersectionObservations();
4535 }
4536 }
4534 4537
4535 if (!m_needsUpdateViewportIntersectionInSubtree) 4538 if (!m_needsUpdateViewportIntersectionInSubtree)
4536 return; 4539 return;
4537 m_needsUpdateViewportIntersectionInSubtree = false; 4540 m_needsUpdateViewportIntersectionInSubtree = false;
4538 4541
4539 for (Frame* child = m_frame->tree().firstChild(); child; 4542 for (Frame* child = m_frame->tree().firstChild(); child;
4540 child = child->tree().nextSibling()) { 4543 child = child->tree().nextSibling()) {
4541 if (!child->isLocalFrame()) 4544 if (!child->isLocalFrame())
4542 continue; 4545 continue;
4543 if (FrameView* view = toLocalFrame(child)->view()) 4546 if (FrameView* view = toLocalFrame(child)->view())
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4611 #if DCHECK_IS_ON() 4614 #if DCHECK_IS_ON()
4612 // Make sure we never have an unthrottled frame inside a throttled one. 4615 // Make sure we never have an unthrottled frame inside a throttled one.
4613 FrameView* parent = parentFrameView(); 4616 FrameView* parent = parentFrameView();
4614 while (parent) { 4617 while (parent) {
4615 DCHECK(canThrottleRendering() || !parent->canThrottleRendering()); 4618 DCHECK(canThrottleRendering() || !parent->canThrottleRendering());
4616 parent = parent->parentFrameView(); 4619 parent = parent->parentFrameView();
4617 } 4620 }
4618 #endif 4621 #endif
4619 } 4622 }
4620 4623
4621 // TODO(esprehn): Rename this and the method on Document to 4624 void FrameView::recordDeferredLoadingStats() {
4622 // recordDeferredLoadReason(). 4625 if (!frame().document()->frame() || !frame().isCrossOriginSubframe())
4623 void FrameView::maybeRecordLoadReason() { 4626 return;
4624 FrameView* parent = parentFrameView(); 4627 FrameView* parent = parentFrameView();
4625 if (frame().document()->frame()) { 4628 if (!parent) {
4626 if (!parent) { 4629 HTMLFrameOwnerElement* element = frame().deprecatedLocalOwner();
4627 HTMLFrameOwnerElement* element = frame().deprecatedLocalOwner(); 4630 // We would fall into an else block on some teardowns and other weird cases.
4628 if (!element) 4631 if (!element || !element->layoutObject())
4629 frame().document()->maybeRecordLoadReason(WouldLoadOutOfProcess); 4632 frame().document()->recordDeferredLoadReason(WouldLoadNoParent);
4630 // Having no layout object means the frame is not drawn. 4633 return;
4631 else if (!element->layoutObject())
4632 frame().document()->maybeRecordLoadReason(WouldLoadDisplayNone);
4633 } else {
4634 // Assume the main frame has always loaded since we don't track its
4635 // visibility.
4636 bool parentLoaded =
4637 !parent->parentFrameView() ||
4638 parent->frame().document()->wouldLoadReason() > Created;
4639 // If the parent wasn't loaded, the children won't be either.
4640 if (parentLoaded) {
4641 if (frameRect().isEmpty())
4642 frame().document()->maybeRecordLoadReason(WouldLoadZeroByZero);
4643 else if (frameRect().maxY() < 0 && frameRect().maxX() < 0)
4644 frame().document()->maybeRecordLoadReason(WouldLoadAboveAndLeft);
4645 else if (frameRect().maxY() < 0)
4646 frame().document()->maybeRecordLoadReason(WouldLoadAbove);
4647 else if (frameRect().maxX() < 0)
4648 frame().document()->maybeRecordLoadReason(WouldLoadLeft);
4649 else if (!m_hiddenForThrottling)
4650 frame().document()->maybeRecordLoadReason(WouldLoadVisible);
4651 }
4652 }
4653 } 4634 }
4635 // Small inaccuracy: frames with origins that match the top level might be
4636 // nested in a cross-origin frame. To keep code simpler, count such frames as
4637 // WouldLoadVisible, even when their parent is offscreen.
4638 WouldLoadReason whyParentLoaded = WouldLoadVisible;
4639 if (parent->parentFrameView() && parent->frame().isCrossOriginSubframe())
4640 whyParentLoaded = parent->frame().document()->deferredLoadReason();
4641
4642 // If the parent wasn't loaded, the children won't be either.
4643 if (whyParentLoaded == Created)
4644 return;
4645 // These frames are never meant to be seen so we will need to load them.
4646 if (frameRect().isEmpty() || frameRect().maxY() < 0 ||
4647 frameRect().maxX() < 0) {
4648 frame().document()->recordDeferredLoadReason(whyParentLoaded);
4649 return;
4650 }
4651 IntRect parentRect = parent->frameRect();
4652 // First clause is checking if the child frame misses its parent laterally.
4653 if (frameRect().x() >= parentRect.width() || parentRect.height() <= 0)
4654 return;
4655
4656 int screensAway = frameRect().y() / parentRect.height();
ojan 2017/01/18 00:55:01 Does this need to take scroll position into accoun
4657
4658 // We're collecting data for frames that are at most 3 screens away.
4659 if (screensAway > 3)
4660 return;
4661
4662 // This means that the top of the child frame is positioned above the parent.
4663 // But the above check for maxY() < 0 means that maxY() is positive -> the
4664 // child stretches at least into the first screen and possibly lower.
4665 if (screensAway < 0)
4666 screensAway = 0;
4667
4668 frame().document()->recordDeferredLoadReason(
4669 static_cast<WouldLoadReason>(std::min(static_cast<int>(whyParentLoaded),
4670 WouldLoadVisible - screensAway)));
4654 } 4671 }
4655 4672
4656 bool FrameView::shouldThrottleRendering() const { 4673 bool FrameView::shouldThrottleRendering() const {
4657 return canThrottleRendering() && m_frame->document() && 4674 return canThrottleRendering() && m_frame->document() &&
4658 lifecycle().throttlingAllowed(); 4675 lifecycle().throttlingAllowed();
4659 } 4676 }
4660 4677
4661 bool FrameView::canThrottleRendering() const { 4678 bool FrameView::canThrottleRendering() const {
4662 if (m_lifecycleUpdatesThrottled) 4679 if (m_lifecycleUpdatesThrottled)
4663 return true; 4680 return true;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4845 return result; 4862 return result;
4846 } 4863 }
4847 4864
4848 String result(MainThreadScrollingReason::mainThreadScrollingReasonsAsText( 4865 String result(MainThreadScrollingReason::mainThreadScrollingReasonsAsText(
4849 m_mainThreadScrollingReasons) 4866 m_mainThreadScrollingReasons)
4850 .c_str()); 4867 .c_str());
4851 return result; 4868 return result;
4852 } 4869 }
4853 4870
4854 } // namespace blink 4871 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.h ('k') | third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698