Commit 64c04972 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Stop trying to execute a print() command if loading failed.

LocalDOMWindow::should_print_when_finished_loading_ stores whether
a print command happened while the window was still loading, in order
to run the print once loading has completed.

If the load fails, the print should not happen, because it makes
no sense, and also because it might cause a crash (see bug).

Bug: 982974

Change-Id: I5222a55d6280403296f532049d8302723ef9ed59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716397Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681937}
parent e5c43277
...@@ -3945,8 +3945,10 @@ void Document::Abort() { ...@@ -3945,8 +3945,10 @@ void Document::Abort() {
} }
void Document::CheckCompleted() { void Document::CheckCompleted() {
if (CheckCompletedInternal()) if (CheckCompletedInternal()) {
frame_->Loader().DidFinishNavigation(); frame_->Loader().DidFinishNavigation(
FrameLoader::NavigationFinishState::kSuccess);
}
} }
bool Document::CheckCompletedInternal() { bool Document::CheckCompletedInternal() {
......
...@@ -1412,9 +1412,13 @@ void LocalDOMWindow::RemoveAllEventListeners() { ...@@ -1412,9 +1412,13 @@ void LocalDOMWindow::RemoveAllEventListeners() {
UntrackAllBeforeUnloadEventListeners(this); UntrackAllBeforeUnloadEventListeners(this);
} }
void LocalDOMWindow::FinishedLoading() { void LocalDOMWindow::FinishedLoading(FrameLoader::NavigationFinishState state) {
if (should_print_when_finished_loading_) { bool was_should_print_when_finished_loading =
should_print_when_finished_loading_ = false; should_print_when_finished_loading_;
should_print_when_finished_loading_ = false;
if (was_should_print_when_finished_loading &&
state == FrameLoader::NavigationFinishState::kSuccess) {
print(nullptr); print(nullptr);
} }
} }
......
...@@ -293,7 +293,7 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow, ...@@ -293,7 +293,7 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
using EventTarget::DispatchEvent; using EventTarget::DispatchEvent;
DispatchEventResult DispatchEvent(Event&, EventTarget*); DispatchEventResult DispatchEvent(Event&, EventTarget*);
void FinishedLoading(); void FinishedLoading(FrameLoader::NavigationFinishState);
// Dispatch the (deprecated) orientationchange event to this DOMWindow and // Dispatch the (deprecated) orientationchange event to this DOMWindow and
// recurse on its child frames. // recurse on its child frames.
......
...@@ -1725,8 +1725,8 @@ void LocalFrame::CountUseIfFeatureWouldBeBlockedByFeaturePolicy( ...@@ -1725,8 +1725,8 @@ void LocalFrame::CountUseIfFeatureWouldBeBlockedByFeaturePolicy(
} }
} }
void LocalFrame::FinishedLoading() { void LocalFrame::FinishedLoading(FrameLoader::NavigationFinishState state) {
DomWindow()->FinishedLoading(); DomWindow()->FinishedLoading(state);
if (pending_lifecycle_state_) { if (pending_lifecycle_state_) {
DCHECK(!IsLoading()); DCHECK(!IsLoading());
......
...@@ -453,7 +453,7 @@ class CORE_EXPORT LocalFrame final : public Frame, ...@@ -453,7 +453,7 @@ class CORE_EXPORT LocalFrame final : public Frame,
mojom::WebFeature blocked_cross_origin, mojom::WebFeature blocked_cross_origin,
mojom::WebFeature blocked_same_origin); mojom::WebFeature blocked_same_origin);
void FinishedLoading(); void FinishedLoading(FrameLoader::NavigationFinishState);
private: private:
friend class FrameNavigationDisabler; friend class FrameNavigationDisabler;
......
...@@ -614,7 +614,8 @@ void DocumentLoader::LoadFailed(const ResourceError& error) { ...@@ -614,7 +614,8 @@ void DocumentLoader::LoadFailed(const ResourceError& error) {
frame_->GetDocument()->Parser()->StopParsing(); frame_->GetDocument()->Parser()->StopParsing();
state_ = kSentDidFinishLoad; state_ = kSentDidFinishLoad;
GetLocalFrameClient().DispatchDidFailLoad(error, history_commit_type); GetLocalFrameClient().DispatchDidFailLoad(error, history_commit_type);
GetFrameLoader().DidFinishNavigation(); GetFrameLoader().DidFinishNavigation(
FrameLoader::NavigationFinishState::kFailure);
DCHECK_EQ(kSentDidFinishLoad, state_); DCHECK_EQ(kSentDidFinishLoad, state_);
params_ = nullptr; params_ = nullptr;
} }
...@@ -966,7 +967,8 @@ void DocumentLoader::CommitSameDocumentNavigationInternal( ...@@ -966,7 +967,8 @@ void DocumentLoader::CommitSameDocumentNavigationInternal(
// scroll should cancel it. // scroll should cancel it.
GetFrameLoader().DetachProvisionalDocumentLoader(); GetFrameLoader().DetachProvisionalDocumentLoader();
GetFrameLoader().CancelClientNavigation(); GetFrameLoader().CancelClientNavigation();
GetFrameLoader().DidFinishNavigation(); GetFrameLoader().DidFinishNavigation(
FrameLoader::NavigationFinishState::kSuccess);
if (!frame_->GetPage()) if (!frame_->GetPage())
return; return;
......
...@@ -362,7 +362,7 @@ void FrameLoader::FinishedParsing() { ...@@ -362,7 +362,7 @@ void FrameLoader::FinishedParsing() {
// TODO(dgozman): we are calling this method too often, hoping that it // TODO(dgozman): we are calling this method too often, hoping that it
// does not do anything when navigation is in progress, or when loading // does not do anything when navigation is in progress, or when loading
// has finished already. We should call it at the right times. // has finished already. We should call it at the right times.
void FrameLoader::DidFinishNavigation() { void FrameLoader::DidFinishNavigation(NavigationFinishState state) {
// We should have either finished the provisional or committed navigation if // We should have either finished the provisional or committed navigation if
// this is called. Only delcare the whole frame finished if neither is in // this is called. Only delcare the whole frame finished if neither is in
// progress. // progress.
...@@ -383,7 +383,7 @@ void FrameLoader::DidFinishNavigation() { ...@@ -383,7 +383,7 @@ void FrameLoader::DidFinishNavigation() {
RestoreScrollPositionAndViewState(); RestoreScrollPositionAndViewState();
if (document_loader_) if (document_loader_)
document_loader_->SetLoadType(WebFrameLoadType::kStandard); document_loader_->SetLoadType(WebFrameLoadType::kStandard);
frame_->FinishedLoading(); frame_->FinishedLoading(state);
} }
// When a subframe finishes loading, the parent should check if *all* // When a subframe finishes loading, the parent should check if *all*
...@@ -893,7 +893,7 @@ void FrameLoader::CommitNavigation( ...@@ -893,7 +893,7 @@ void FrameLoader::CommitNavigation(
FillStaticResponseIfNeeded(navigation_params.get(), frame_); FillStaticResponseIfNeeded(navigation_params.get(), frame_);
if (!ShouldNavigate(navigation_params.get(), frame_)) { if (!ShouldNavigate(navigation_params.get(), frame_)) {
DidFinishNavigation(); DidFinishNavigation(FrameLoader::NavigationFinishState::kSuccess);
return; return;
} }
...@@ -988,7 +988,7 @@ void FrameLoader::StopAllLoaders() { ...@@ -988,7 +988,7 @@ void FrameLoader::StopAllLoaders() {
document_loader_->StopLoading(); document_loader_->StopLoading();
DetachDocumentLoader(provisional_document_loader_); DetachDocumentLoader(provisional_document_loader_);
CancelClientNavigation(); CancelClientNavigation();
DidFinishNavigation(); DidFinishNavigation(FrameLoader::NavigationFinishState::kSuccess);
TakeObjectSnapshot(); TakeObjectSnapshot();
} }
...@@ -1212,7 +1212,7 @@ void FrameLoader::Detach() { ...@@ -1212,7 +1212,7 @@ void FrameLoader::Detach() {
} }
ClearClientNavigation(); ClearClientNavigation();
committing_navigation_ = false; committing_navigation_ = false;
DidFinishNavigation(); DidFinishNavigation(FrameLoader::NavigationFinishState::kSuccess);
if (progress_tracker_) { if (progress_tracker_) {
progress_tracker_->Dispose(); progress_tracker_->Dispose();
...@@ -1242,7 +1242,7 @@ bool FrameLoader::MaybeRenderFallbackContent() { ...@@ -1242,7 +1242,7 @@ bool FrameLoader::MaybeRenderFallbackContent() {
frame_->Owner()->RenderFallbackContent(frame_); frame_->Owner()->RenderFallbackContent(frame_);
ClearClientNavigation(); ClearClientNavigation();
DidFinishNavigation(); DidFinishNavigation(FrameLoader::NavigationFinishState::kSuccess);
return true; return true;
} }
...@@ -1367,7 +1367,7 @@ void FrameLoader::DidDropNavigation() { ...@@ -1367,7 +1367,7 @@ void FrameLoader::DidDropNavigation() {
// TODO(dgozman): should we ClearClientNavigation instead and not // TODO(dgozman): should we ClearClientNavigation instead and not
// notify the client in response to its own call? // notify the client in response to its own call?
CancelClientNavigation(); CancelClientNavigation();
DidFinishNavigation(); DidFinishNavigation(FrameLoader::NavigationFinishState::kSuccess);
// Forcibly instantiate WindowProxy for initial frame document. // Forcibly instantiate WindowProxy for initial frame document.
// This is only required when frame navigation is aborted, e.g. due to // This is only required when frame navigation is aborted, e.g. due to
......
...@@ -167,7 +167,8 @@ class CORE_EXPORT FrameLoader final { ...@@ -167,7 +167,8 @@ class CORE_EXPORT FrameLoader final {
void Detach(); void Detach();
void FinishedParsing(); void FinishedParsing();
void DidFinishNavigation(); enum class NavigationFinishState { kSuccess, kFailure };
void DidFinishNavigation(NavigationFinishState);
void DidFinishSameDocumentNavigation(const KURL&, void DidFinishSameDocumentNavigation(const KURL&,
WebFrameLoadType, WebFrameLoadType,
......
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