Commit aaf5ece4 authored by hiroshige's avatar hiroshige Committed by Commit bot

Remove EventSender from HTMLLinkElement

This CL replaces EventSender in HTMLLinkElement with postTask():
Instead of calling HTMLLinkElement::dispatchPendingLoadEvents() in
Document::implicitClose() to enforce <link>'s onload events to be executed
before the document's onload event, this CL blocks document's onload until
<link>'s onload event using IncrementLoadEventDelayCount.

This CL also modifies SimTest:
This CL potentially makes onload events of <link> and documents async and
delayed, and thus SimTest can be destructed before document's onload event,
which cause assertion failure.
This CL calls testing::runPendingTasks() in ~SimTest() to flush scheduled
onload events to make Document to be loaded before SimTest's destruction.

BUG=624697

Review-Url: https://codereview.chromium.org/2275493002
Cr-Commit-Position: refs/heads/master@{#418835}
parent e7ac1bbe
...@@ -2642,7 +2642,6 @@ void Document::implicitClose() ...@@ -2642,7 +2642,6 @@ void Document::implicitClose()
ImageLoader::dispatchPendingLoadEvents(); ImageLoader::dispatchPendingLoadEvents();
ImageLoader::dispatchPendingErrorEvents(); ImageLoader::dispatchPendingErrorEvents();
HTMLLinkElement::dispatchPendingLoadEvents();
HTMLStyleElement::dispatchPendingLoadEvents(); HTMLStyleElement::dispatchPendingLoadEvents();
} }
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
#include "core/dom/Attribute.h" #include "core/dom/Attribute.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/dom/StyleEngine.h" #include "core/dom/StyleEngine.h"
#include "core/dom/TaskRunnerHelper.h"
#include "core/events/Event.h" #include "core/events/Event.h"
#include "core/events/EventSender.h"
#include "core/fetch/CSSStyleSheetResource.h" #include "core/fetch/CSSStyleSheetResource.h"
#include "core/fetch/FetchRequest.h" #include "core/fetch/FetchRequest.h"
#include "core/fetch/ResourceFetcher.h" #include "core/fetch/ResourceFetcher.h"
...@@ -64,12 +64,6 @@ namespace blink { ...@@ -64,12 +64,6 @@ namespace blink {
using namespace HTMLNames; using namespace HTMLNames;
static LinkEventSender& linkLoadEventSender()
{
DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (LinkEventSender::create(EventTypeNames::load)));
return sharedLoadEventSender;
}
static bool styleSheetTypeIsSupported(const String& type) static bool styleSheetTypeIsSupported(const String& type)
{ {
String trimmedType = ContentType(type).type(); String trimmedType = ContentType(type).type();
...@@ -308,14 +302,8 @@ void HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources(LoadedSheetErr ...@@ -308,14 +302,8 @@ void HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources(LoadedSheetErr
linkStyle()->notifyLoadedSheetAndAllCriticalSubresources(errorStatus); linkStyle()->notifyLoadedSheetAndAllCriticalSubresources(errorStatus);
} }
void HTMLLinkElement::dispatchPendingLoadEvents() void HTMLLinkElement::dispatchPendingEvent(std::unique_ptr<IncrementLoadEventDelayCount>)
{
linkLoadEventSender().dispatchPendingEvents();
}
void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender)
{ {
DCHECK_EQ(eventSender, &linkLoadEventSender());
DCHECK(m_link); DCHECK(m_link);
if (m_link->hasLoaded()) if (m_link->hasLoaded())
linkLoaded(); linkLoaded();
...@@ -325,7 +313,7 @@ void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender) ...@@ -325,7 +313,7 @@ void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender)
void HTMLLinkElement::scheduleEvent() void HTMLLinkElement::scheduleEvent()
{ {
linkLoadEventSender().dispatchEventSoon(this); TaskRunnerHelper::get(TaskType::DOMManipulation, &document())->postTask(BLINK_FROM_HERE, WTF::bind(&HTMLLinkElement::dispatchPendingEvent, wrapPersistent(this), passed(IncrementLoadEventDelayCount::create(document()))));
} }
void HTMLLinkElement::startLoadingDynamicSheet() void HTMLLinkElement::startLoadingDynamicSheet()
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "core/css/CSSStyleSheet.h" #include "core/css/CSSStyleSheet.h"
#include "core/dom/DOMTokenList.h" #include "core/dom/DOMTokenList.h"
#include "core/dom/IconURL.h" #include "core/dom/IconURL.h"
#include "core/dom/IncrementLoadEventDelayCount.h"
#include "core/dom/StyleEngineContext.h" #include "core/dom/StyleEngineContext.h"
#include "core/fetch/ResourceOwner.h" #include "core/fetch/ResourceOwner.h"
#include "core/fetch/StyleSheetResource.h" #include "core/fetch/StyleSheetResource.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include "core/html/RelList.h" #include "core/html/RelList.h"
#include "core/loader/LinkLoader.h" #include "core/loader/LinkLoader.h"
#include "core/loader/LinkLoaderClient.h" #include "core/loader/LinkLoaderClient.h"
#include <memory>
namespace blink { namespace blink {
...@@ -45,9 +47,6 @@ class HTMLLinkElement; ...@@ -45,9 +47,6 @@ class HTMLLinkElement;
class KURL; class KURL;
class LinkImport; class LinkImport;
template<typename T> class EventSender;
using LinkEventSender = EventSender<HTMLLinkElement>;
// //
// LinkStyle handles dynamically change-able link resources, which is // LinkStyle handles dynamically change-able link resources, which is
// typically @rel="stylesheet". // typically @rel="stylesheet".
...@@ -166,10 +165,8 @@ public: ...@@ -166,10 +165,8 @@ public:
DOMTokenList* sizes() const; DOMTokenList* sizes() const;
void dispatchPendingEvent(LinkEventSender*); void dispatchPendingEvent(std::unique_ptr<IncrementLoadEventDelayCount>);
void scheduleEvent(); void scheduleEvent();
void dispatchEventImmediately();
static void dispatchPendingLoadEvents();
// From LinkLoaderClient // From LinkLoaderClient
bool shouldLoadLink() override; bool shouldLoadLink() override;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "platform/LayoutTestSupport.h" #include "platform/LayoutTestSupport.h"
#include "platform/scroll/ScrollbarTheme.h" #include "platform/scroll/ScrollbarTheme.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/WebSecurityOrigin.h" #include "public/platform/WebSecurityOrigin.h"
#include "public/web/WebCache.h" #include "public/web/WebCache.h"
#include "web/WebLocalFrameImpl.h" #include "web/WebLocalFrameImpl.h"
...@@ -32,6 +33,9 @@ SimTest::SimTest() ...@@ -32,6 +33,9 @@ SimTest::SimTest()
SimTest::~SimTest() SimTest::~SimTest()
{ {
// Pump the message loop to process the load event.
testing::runPendingTasks();
Document::setThreadedParsingEnabledForTesting(true); Document::setThreadedParsingEnabledForTesting(true);
LayoutTestSupport::setMockThemeEnabledForTest(false); LayoutTestSupport::setMockThemeEnabledForTest(false);
ScrollbarTheme::setMockScrollbarsEnabled(false); ScrollbarTheme::setMockScrollbarsEnabled(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment