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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 29 matching lines...) Expand all
40 #include "core/dom/FrameRequestCallback.h" 40 #include "core/dom/FrameRequestCallback.h"
41 #include "core/dom/SandboxFlags.h" 41 #include "core/dom/SandboxFlags.h"
42 #include "core/dom/custom/CustomElementRegistry.h" 42 #include "core/dom/custom/CustomElementRegistry.h"
43 #include "core/editing/Editor.h" 43 #include "core/editing/Editor.h"
44 #include "core/events/DOMWindowEventQueue.h" 44 #include "core/events/DOMWindowEventQueue.h"
45 #include "core/events/HashChangeEvent.h" 45 #include "core/events/HashChangeEvent.h"
46 #include "core/events/MessageEvent.h" 46 #include "core/events/MessageEvent.h"
47 #include "core/events/PageTransitionEvent.h" 47 #include "core/events/PageTransitionEvent.h"
48 #include "core/events/PopStateEvent.h" 48 #include "core/events/PopStateEvent.h"
49 #include "core/events/ScopedEventQueue.h" 49 #include "core/events/ScopedEventQueue.h"
50 #include "core/fetch/ResourceFetcher.h"
50 #include "core/frame/BarProp.h" 51 #include "core/frame/BarProp.h"
51 #include "core/frame/DOMVisualViewport.h" 52 #include "core/frame/DOMVisualViewport.h"
52 #include "core/frame/EventHandlerRegistry.h" 53 #include "core/frame/EventHandlerRegistry.h"
53 #include "core/frame/FrameConsole.h" 54 #include "core/frame/FrameConsole.h"
54 #include "core/frame/FrameView.h" 55 #include "core/frame/FrameView.h"
55 #include "core/frame/History.h" 56 #include "core/frame/History.h"
56 #include "core/frame/LocalFrame.h" 57 #include "core/frame/LocalFrame.h"
57 #include "core/frame/Navigator.h" 58 #include "core/frame/Navigator.h"
58 #include "core/frame/Screen.h" 59 #include "core/frame/Screen.h"
59 #include "core/frame/ScrollToOptions.h" 60 #include "core/frame/ScrollToOptions.h"
(...skipping 16 matching lines...) Expand all
76 #include "platform/EventDispatchForbiddenScope.h" 77 #include "platform/EventDispatchForbiddenScope.h"
77 #include "platform/weborigin/SecurityOrigin.h" 78 #include "platform/weborigin/SecurityOrigin.h"
78 #include "platform/weborigin/Suborigin.h" 79 #include "platform/weborigin/Suborigin.h"
79 #include "public/platform/Platform.h" 80 #include "public/platform/Platform.h"
80 #include "public/platform/WebFrameScheduler.h" 81 #include "public/platform/WebFrameScheduler.h"
81 #include "public/platform/WebScreenInfo.h" 82 #include "public/platform/WebScreenInfo.h"
82 #include <memory> 83 #include <memory>
83 84
84 namespace blink { 85 namespace blink {
85 86
87 // Timeout for link preloads to be used after window.onload
88 static const int unusedPreloadTimeoutInSeconds = 3;
89
86 class PostMessageTimer final : public GarbageCollectedFinalized<PostMessageTimer >, public SuspendableTimer { 90 class PostMessageTimer final : public GarbageCollectedFinalized<PostMessageTimer >, public SuspendableTimer {
87 USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer); 91 USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer);
88 public: 92 public:
89 PostMessageTimer(LocalDOMWindow& window, MessageEvent* event, PassRefPtr<Sec urityOrigin> targetOrigin, std::unique_ptr<SourceLocation> location, UserGesture Token* userGestureToken) 93 PostMessageTimer(LocalDOMWindow& window, MessageEvent* event, PassRefPtr<Sec urityOrigin> targetOrigin, std::unique_ptr<SourceLocation> location, UserGesture Token* userGestureToken)
90 : SuspendableTimer(window.document()) 94 : SuspendableTimer(window.document())
91 , m_event(event) 95 , m_event(event)
92 , m_window(&window) 96 , m_window(&window)
93 , m_targetOrigin(targetOrigin) 97 , m_targetOrigin(targetOrigin)
94 , m_location(std::move(location)) 98 , m_location(std::move(location))
95 , m_userGestureToken(userGestureToken) 99 , m_userGestureToken(userGestureToken)
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 257 }
254 258
255 bool LocalDOMWindow::allowPopUp() 259 bool LocalDOMWindow::allowPopUp()
256 { 260 {
257 return frame() && allowPopUp(*frame()); 261 return frame() && allowPopUp(*frame());
258 } 262 }
259 263
260 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame) 264 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame)
261 : m_frame(&frame) 265 : m_frame(&frame)
262 , m_visualViewport(DOMVisualViewport::create(this)) 266 , m_visualViewport(DOMVisualViewport::create(this))
267 , m_unusedPreloadsTimer(this, &LocalDOMWindow::warnUnusedPreloads)
263 , m_shouldPrintWhenFinishedLoading(false) 268 , m_shouldPrintWhenFinishedLoading(false)
264 { 269 {
265 ThreadState::current()->registerPreFinalizer(this); 270 ThreadState::current()->registerPreFinalizer(this);
266 } 271 }
267 272
268 void LocalDOMWindow::clearDocument() 273 void LocalDOMWindow::clearDocument()
269 { 274 {
270 if (!m_document) 275 if (!m_document)
271 return; 276 return;
272 277
273 ASSERT(!m_document->isActive()); 278 ASSERT(!m_document->isActive());
274 279
275 // FIXME: This should be part of ActiveDOMObject shutdown 280 // FIXME: This should be part of ActiveDOMObject shutdown
276 clearEventQueue(); 281 clearEventQueue();
277 282
283 m_unusedPreloadsTimer.stop();
278 m_document->clearDOMWindow(); 284 m_document->clearDOMWindow();
279 m_document = nullptr; 285 m_document = nullptr;
280 } 286 }
281 287
282 void LocalDOMWindow::clearEventQueue() 288 void LocalDOMWindow::clearEventQueue()
283 { 289 {
284 if (!m_eventQueue) 290 if (!m_eventQueue)
285 return; 291 return;
286 m_eventQueue->close(); 292 m_eventQueue->close();
287 m_eventQueue.clear(); 293 m_eventQueue.clear();
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 it->didRemoveEventListener(this, eventType); 1335 it->didRemoveEventListener(this, eventType);
1330 } 1336 }
1331 1337
1332 if (eventType == EventTypeNames::unload) { 1338 if (eventType == EventTypeNames::unload) {
1333 removeUnloadEventListener(this); 1339 removeUnloadEventListener(this);
1334 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi steners(this)) { 1340 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi steners(this)) {
1335 removeBeforeUnloadEventListener(this); 1341 removeBeforeUnloadEventListener(this);
1336 } 1342 }
1337 } 1343 }
1338 1344
1345 void LocalDOMWindow::warnUnusedPreloads(TimerBase* base)
1346 {
1347 if (frame() && frame()->loader().documentLoader()) {
1348 ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher() ;
1349 DCHECK(fetcher);
1350 if (fetcher->countPreloads())
1351 fetcher->warnUnusedPreloads();
1352 }
1353 }
1354
1339 void LocalDOMWindow::dispatchLoadEvent() 1355 void LocalDOMWindow::dispatchLoadEvent()
1340 { 1356 {
1341 Event* loadEvent(Event::create(EventTypeNames::load)); 1357 Event* loadEvent(Event::create(EventTypeNames::load));
1342 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu mentLoader()->timing().loadEventStart()) { 1358 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu mentLoader()->timing().loadEventStart()) {
1343 DocumentLoader* documentLoader = frame()->loader().documentLoader(); 1359 DocumentLoader* documentLoader = frame()->loader().documentLoader();
1344 DocumentLoadTiming& timing = documentLoader->timing(); 1360 DocumentLoadTiming& timing = documentLoader->timing();
1345 timing.markLoadEventStart(); 1361 timing.markLoadEventStart();
1346 dispatchEvent(loadEvent, document()); 1362 dispatchEvent(loadEvent, document());
1347 timing.markLoadEventEnd(); 1363 timing.markLoadEventEnd();
1364 DCHECK(documentLoader->fetcher());
1365 if (frame() && documentLoader == frame()->loader().documentLoader() && d ocumentLoader->fetcher()->countPreloads())
1366 m_unusedPreloadsTimer.startOneShot(unusedPreloadTimeoutInSeconds, BL INK_FROM_HERE);
1348 } else { 1367 } else {
1349 dispatchEvent(loadEvent, document()); 1368 dispatchEvent(loadEvent, document());
1350 } 1369 }
1351 1370
1352 // For load events, send a separate load event to the enclosing frame only. 1371 // For load events, send a separate load event to the enclosing frame only.
1353 // This is a DOM extension and is independent of bubbling/capturing rules of 1372 // This is a DOM extension and is independent of bubbling/capturing rules of
1354 // the DOM. 1373 // the DOM.
1355 FrameOwner* owner = frame() ? frame()->owner() : nullptr; 1374 FrameOwner* owner = frame() ? frame()->owner() : nullptr;
1356 if (owner) 1375 if (owner)
1357 owner->dispatchLoad(); 1376 owner->dispatchLoad();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 LocalFrame* LocalDOMWindow::frame() const 1512 LocalFrame* LocalDOMWindow::frame() const
1494 { 1513 {
1495 // If the LocalDOMWindow still has a frame reference, that frame must point 1514 // If the LocalDOMWindow still has a frame reference, that frame must point
1496 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1515 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1497 // where script execution leaks between different LocalDOMWindows. 1516 // where script execution leaks between different LocalDOMWindows.
1498 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); 1517 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this);
1499 return m_frame; 1518 return m_frame;
1500 } 1519 }
1501 1520
1502 } // namespace blink 1521 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698