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

Unified Diff: third_party/WebKit/Source/core/fileapi/FileReader.cpp

Issue 2143353003: FileReader shouldn't mark itself as inactive before firing events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 5 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/Source/core/fileapi/FileReader.h ('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/fileapi/FileReader.cpp
diff --git a/third_party/WebKit/Source/core/fileapi/FileReader.cpp b/third_party/WebKit/Source/core/fileapi/FileReader.cpp
index 648352ed2addfc10b4b0a2af2b9286921e032568..f1d323748eee8d113e4817d22f168595f03f8b5d 100644
--- a/third_party/WebKit/Source/core/fileapi/FileReader.cpp
+++ b/third_party/WebKit/Source/core/fileapi/FileReader.cpp
@@ -45,6 +45,7 @@
#include "wtf/CurrentTime.h"
#include "wtf/Deque.h"
#include "wtf/HashSet.h"
+#include "wtf/TemporaryChange.h"
#include "wtf/text/CString.h"
namespace blink {
@@ -199,6 +200,7 @@ FileReader::FileReader(ExecutionContext* context)
, ActiveDOMObject(context)
, m_state(EMPTY)
, m_loadingState(LoadingStateNone)
+ , m_stillFiringEvents(false)
, m_readType(FileReaderLoader::ReadAsBinaryString)
, m_lastProgressNotificationTimeMS(0)
{
@@ -227,7 +229,7 @@ void FileReader::stop()
bool FileReader::hasPendingActivity() const
{
- return m_state == LOADING;
+ return m_state == LOADING || m_stillFiringEvents;
}
void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState)
@@ -341,6 +343,7 @@ void FileReader::abort()
void FileReader::doAbort()
{
ASSERT(m_state != DONE);
+ TemporaryChange<bool> firingEvents(m_stillFiringEvents, true);
terminate();
@@ -380,6 +383,7 @@ void FileReader::terminate()
void FileReader::didStartLoading()
{
+ TemporaryChange<bool> firingEvents(m_stillFiringEvents, true);
fireEvent(EventTypeNames::loadstart);
}
@@ -390,6 +394,7 @@ void FileReader::didReceiveData()
if (!m_lastProgressNotificationTimeMS) {
m_lastProgressNotificationTimeMS = now;
} else if (now - m_lastProgressNotificationTimeMS > progressNotificationIntervalMS) {
+ TemporaryChange<bool> firingEvents(m_stillFiringEvents, true);
fireEvent(EventTypeNames::progress);
m_lastProgressNotificationTimeMS = now;
}
@@ -401,6 +406,13 @@ void FileReader::didFinishLoading()
return;
ASSERT(m_loadingState == LoadingStateLoading);
+ // TODO(jochen): When we set m_state to DONE below, we still need to fire
+ // the load and loadend events. To avoid GC to collect this FileReader, we
+ // use this separate variable to keep the wrapper of this FileReader alive.
+ // An alternative would be to keep any active DOM object alive that is on
+ // the stack.
+ TemporaryChange<bool> firingEvents(m_stillFiringEvents, true);
+
// It's important that we change m_loadingState before firing any events
// since any of the events could call abort(), which internally checks
// if we're still loading (therefore we need abort process) or not.
@@ -425,6 +437,9 @@ void FileReader::didFail(FileError::ErrorCode errorCode)
{
if (m_loadingState == LoadingStateAborted)
return;
+
+ TemporaryChange<bool> firingEvents(m_stillFiringEvents, true);
+
ASSERT(m_loadingState == LoadingStateLoading);
m_loadingState = LoadingStateNone;
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698