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

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp

Issue 2048853002: IntersectionObserver: Warn when target is not a descendant of root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix test expectation Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/containing-block-warning-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
index f853921b9106c69b9035349d8a1941f22c9884c2..31e48e706a65e6e7d9043d97fdb0899ecafc1f49 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
@@ -19,6 +19,7 @@
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLFrameOwnerElement.h"
+#include "core/inspector/ConsoleMessage.h"
#include "core/layout/LayoutView.h"
#include "core/timing/DOMWindowPerformance.h"
#include "core/timing/Performance.h"
@@ -179,13 +180,29 @@ void IntersectionObserver::observe(Element* target)
return;
bool shouldReportRootBounds = false;
+ bool isDOMDescendant = false;
LocalFrame* targetFrame = target->document().frame();
- LocalFrame* rootFrame = rootNode()->document().frame();
- if (targetFrame && rootFrame)
+ LocalFrame* rootFrame = m_root->document().frame();
+
+ if (target->document() == rootNode()->document()) {
+ shouldReportRootBounds = true;
+ isDOMDescendant = target->isDescendantOf(rootNode());
+ } else if (targetFrame && rootFrame) {
shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrigin()->canAccess(rootFrame->securityContext()->getSecurityOrigin());
+ isDOMDescendant = (targetFrame->tree().top() == rootFrame);
+ }
+
IntersectionObservation* observation = new IntersectionObservation(*this, *target, shouldReportRootBounds);
target->ensureIntersectionObserverData().addObservation(*observation);
m_observations.add(observation);
+
+ if (!isDOMDescendant) {
+ m_root->document().addConsoleMessage(ConsoleMessage::create(
+ JSMessageSource, WarningMessageLevel,
+ "IntersectionObserver.observe(target): target element is not a descendant of root."));
+ return;
+ }
+
if (!rootFrame)
return;
if (FrameView* rootFrameView = rootFrame->view())
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/containing-block-warning-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698