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

Unified Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 2343623002: Add a warning whenever link preloads are not used (Closed)
Patch Set: Removed the counter, since it was not accurate Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
diff --git a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
index 76827a89668652c30a26a5156694a0096f837c0d..d3cf7b3c34971190f1b2cd78f9a660bbf2826000 100644
--- a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
@@ -47,6 +47,7 @@
#include "core/events/PageTransitionEvent.h"
#include "core/events/PopStateEvent.h"
#include "core/events/ScopedEventQueue.h"
+#include "core/fetch/ResourceFetcher.h"
#include "core/frame/BarProp.h"
#include "core/frame/DOMVisualViewport.h"
#include "core/frame/EventHandlerRegistry.h"
@@ -83,6 +84,9 @@
namespace blink {
+// Timeout for link preloads to be used after window.onload
+static const int unusedPreloadTimeoutInSeconds = 3;
+
class PostMessageTimer final : public GarbageCollectedFinalized<PostMessageTimer>, public SuspendableTimer {
USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer);
public:
@@ -260,6 +264,7 @@ bool LocalDOMWindow::allowPopUp()
LocalDOMWindow::LocalDOMWindow(LocalFrame& frame)
: m_frame(&frame)
, m_visualViewport(DOMVisualViewport::create(this))
+ , m_unusedPreloadsTimer(this, &LocalDOMWindow::warnUnusedPreloads)
, m_shouldPrintWhenFinishedLoading(false)
{
ThreadState::current()->registerPreFinalizer(this);
@@ -275,6 +280,7 @@ void LocalDOMWindow::clearDocument()
// FIXME: This should be part of ActiveDOMObject shutdown
clearEventQueue();
+ m_unusedPreloadsTimer.stop();
m_document->clearDOMWindow();
m_document = nullptr;
}
@@ -1336,6 +1342,16 @@ void LocalDOMWindow::removedEventListener(const AtomicString& eventType, const R
}
}
+void LocalDOMWindow::warnUnusedPreloads(TimerBase* base)
+{
+ if (frame() && frame()->loader().documentLoader()) {
+ ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher();
+ DCHECK(fetcher);
+ if (fetcher->countPreloads())
+ fetcher->warnUnusedPreloads();
+ }
+}
+
void LocalDOMWindow::dispatchLoadEvent()
{
Event* loadEvent(Event::create(EventTypeNames::load));
@@ -1345,6 +1361,9 @@ void LocalDOMWindow::dispatchLoadEvent()
timing.markLoadEventStart();
dispatchEvent(loadEvent, document());
timing.markLoadEventEnd();
+ DCHECK(documentLoader->fetcher());
+ if (frame() && documentLoader == frame()->loader().documentLoader() && documentLoader->fetcher()->countPreloads())
+ m_unusedPreloadsTimer.startOneShot(unusedPreloadTimeoutInSeconds, BLINK_FROM_HERE);
} else {
dispatchEvent(loadEvent, document());
}

Powered by Google App Engine
This is Rietveld 408576698