Index: third_party/WebKit/Source/core/dom/Document.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp |
index 3de8c5c17c52a9d1f2f54b6c522aa896b04d0adb..019d228e16e8560e2a587c2fdf95ec8f42e634cb 100644 |
--- a/third_party/WebKit/Source/core/dom/Document.cpp |
+++ b/third_party/WebKit/Source/core/dom/Document.cpp |
@@ -488,7 +488,7 @@ |
this, |
&Document::UpdateFocusAppearanceTimerFired), |
css_target_(nullptr), |
- load_event_progress_(kLoadEventCompleted), |
+ load_event_progress_(kLoadEventNotRun), |
start_time_(CurrentTime()), |
script_runner_(ScriptRunner::Create(this)), |
xml_version_("1.0"), |
@@ -2770,6 +2770,9 @@ |
if (frame_) |
frame_->Loader().DidExplicitOpen(); |
+ if (load_event_progress_ != kLoadEventInProgress && |
+ PageDismissalEventBeingDispatched() == kNoDismissal) |
+ load_event_progress_ = kLoadEventNotRun; |
} |
void Document::DetachParser() { |
@@ -2784,11 +2787,12 @@ |
DetachParser(); |
SetParsingState(kFinishedParsing); |
SetReadyState(kComplete); |
- SuppressLoadEvent(); |
} |
DocumentParser* Document::ImplicitOpen( |
ParserSynchronizationPolicy parser_sync_policy) { |
+ DetachParser(); |
+ |
RemoveChildren(); |
DCHECK(!focused_element_); |
@@ -2802,16 +2806,11 @@ |
parser_sync_policy = kForceSynchronousParsing; |
} |
- DetachParser(); |
parser_sync_policy_ = parser_sync_policy; |
parser_ = CreateParser(); |
DocumentParserTiming::From(*this).MarkParserStart(); |
SetParsingState(kParsing); |
SetReadyState(kLoading); |
- if (load_event_progress_ != kLoadEventInProgress && |
- PageDismissalEventBeingDispatched() == kNoDismissal) { |
- load_event_progress_ = kLoadEventNotRun; |
- } |
return parser_; |
} |
@@ -2953,15 +2952,30 @@ |
!GetScriptableDocumentParser()->IsParsing()) |
return; |
- parser_->Finish(); |
- if (!parser_ || !parser_->IsParsing()) |
- SetReadyState(kComplete); |
- CheckCompleted(); |
+ if (DocumentParser* parser = parser_) |
+ parser->Finish(); |
+ |
+ if (!frame_) { |
+ // Because we have no frame, we don't know if all loading has completed, |
+ // so we just call implicitClose() immediately. FIXME: This might fire |
+ // the load event prematurely |
+ // <http://bugs.webkit.org/show_bug.cgi?id=14568>. |
+ ImplicitClose(); |
+ return; |
+ } |
+ |
+ frame_->Loader().CheckCompleted(); |
} |
void Document::ImplicitClose() { |
DCHECK(!InStyleRecalc()); |
- DCHECK(parser_); |
+ if (ProcessingLoadEvent() || !parser_) |
+ return; |
+ if (GetFrame() && |
+ GetFrame()->GetNavigationScheduler().LocationChangePending()) { |
+ SuppressLoadEvent(); |
+ return; |
+ } |
load_event_progress_ = kLoadEventInProgress; |
@@ -3041,69 +3055,6 @@ |
if (SvgExtensions()) |
AccessSVGExtensions().StartAnimations(); |
-} |
- |
-static bool AllDescendantsAreComplete(Frame* frame) { |
- if (!frame) |
- return true; |
- for (Frame* child = frame->Tree().FirstChild(); child; |
- child = child->Tree().TraverseNext(frame)) { |
- if (child->IsLoading()) |
- return false; |
- } |
- return true; |
-} |
- |
-bool Document::ShouldComplete() { |
- return parsing_state_ == kFinishedParsing && HaveImportsLoaded() && |
- !fetcher_->BlockingRequestCount() && !IsDelayingLoadEvent() && |
- load_event_progress_ != kLoadEventInProgress && |
- AllDescendantsAreComplete(frame_); |
-} |
- |
-void Document::CheckCompleted() { |
- if (!ShouldComplete()) |
- return; |
- |
- if (frame_) { |
- frame_->Client()->RunScriptsAtDocumentIdle(); |
- |
- // Injected scripts may have disconnected this frame. |
- if (!frame_) |
- return; |
- |
- // Check again, because runScriptsAtDocumentIdle() may have delayed the load |
- // event. |
- if (!ShouldComplete()) |
- return; |
- } |
- |
- // OK, completed. Fire load completion events as needed. |
- SetReadyState(kComplete); |
- if (LoadEventStillNeeded()) |
- ImplicitClose(); |
- |
- // The readystatechanged or load event may have disconnected this frame. |
- if (!frame_ || !frame_->IsAttached()) |
- return; |
- frame_->GetNavigationScheduler().StartTimer(); |
- View()->HandleLoadCompleted(); |
- // The document itself is complete, but if a child frame was restarted due to |
- // an event, this document is still considered to be in progress. |
- if (!AllDescendantsAreComplete(frame_)) |
- return; |
- |
- // No need to repeat if we've already notified this load as finished. |
- if (!Loader()->SentDidFinishLoad()) { |
- if (frame_->IsMainFrame()) |
- ViewportDescription().ReportMobilePageStats(frame_); |
- Loader()->SetSentDidFinishLoad(); |
- frame_->Client()->DispatchDidFinishLoad(); |
- if (!frame_) |
- return; |
- } |
- |
- frame_->Loader().DidFinishNavigation(); |
} |
bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, |
@@ -6029,8 +5980,8 @@ |
DCHECK(load_event_delay_count_); |
--load_event_delay_count_; |
- if (!load_event_delay_count_) |
- CheckCompleted(); |
+ if (!load_event_delay_count_ && GetFrame()) |
+ GetFrame()->Loader().CheckCompleted(); |
} |
void Document::CheckLoadEventSoon() { |
@@ -6052,7 +6003,8 @@ |
} |
void Document::LoadEventDelayTimerFired(TimerBase*) { |
- CheckCompleted(); |
+ if (GetFrame()) |
+ GetFrame()->Loader().CheckCompleted(); |
} |
void Document::LoadPluginsSoon() { |