Commit 67d68372 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Revert "Remove all non-DocumentLoader uses of LocalDOMWindow::InstallNewDocument"

This reverts commit 46c7d082.

Reason for revert: https://bugs.chromium.org/p/chromium/issues/detail?id=1090597#c4

Original change's description:
> Remove all non-DocumentLoader uses of LocalDOMWindow::InstallNewDocument
> 
> LocalFrame::ForceSynchronousDocumentInstall and a few unit tests
> manually replace the Document of a LocalDOMWindow. They can be switched
> to go through the static-response navigation commit path relatively
> easily. This establishes the rule that only DocumentLoader is allowed
> to create a LocalDOMWindow or replace its Document.
> 
> Bug: 1029822
> Change-Id: I84b37f35be5387556999f9bc24f7ba5fa74b4ff8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222776
> Commit-Queue: Nate Chapin <japhet@chromium.org>
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#773720}

TBR=dcheng@chromium.org,haraken@chromium.org,japhet@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1029822
Change-Id: I58b897f7bb5327765c86f907a5179bb76fcccf34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229104Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774775}
parent 3b2e3012
...@@ -156,8 +156,6 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow, ...@@ -156,8 +156,6 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
void CountUse(mojom::WebFeature feature) final; void CountUse(mojom::WebFeature feature) final;
void CountDeprecation(mojom::WebFeature feature) final; void CountDeprecation(mojom::WebFeature feature) final;
// Initialize and install a Document for navigation. Should only be used by
// DocumentLoader.
Document* InstallNewDocument(const DocumentInit&); Document* InstallNewDocument(const DocumentInit&);
// EventTarget overrides: // EventTarget overrides:
......
...@@ -1673,12 +1673,30 @@ void LocalFrame::ForceSynchronousDocumentInstall( ...@@ -1673,12 +1673,30 @@ void LocalFrame::ForceSynchronousDocumentInstall(
scoped_refptr<SharedBuffer> data) { scoped_refptr<SharedBuffer> data) {
CHECK(loader_.StateMachine()->IsDisplayingInitialEmptyDocument()); CHECK(loader_.StateMachine()->IsDisplayingInitialEmptyDocument());
DCHECK(!Client()->IsLocalFrameClientImpl()); DCHECK(!Client()->IsLocalFrameClientImpl());
auto params = std::make_unique<WebNavigationParams>();
WebNavigationParams::FillStaticResponse( // Any Document requires Shutdown() before detach, even the initial empty
params.get(), mime_type, "UTF-8", // document.
base::make_span(data->Data(), data->size())); GetDocument()->Shutdown();
loader_.CommitNavigation(std::move(params), nullptr,
CommitReason::kForcedSync); DomWindow()->InstallNewDocument(
DocumentInit::Create()
.WithDocumentLoader(loader_.GetDocumentLoader(),
MakeGarbageCollected<ContentSecurityPolicy>())
.WithTypeFrom(mime_type));
loader_.StateMachine()->AdvanceTo(
FrameLoaderStateMachine::kCommittedFirstRealLoad);
GetDocument()->OpenForNavigation(kForceSynchronousParsing, mime_type,
AtomicString("UTF-8"));
for (const auto& segment : *data)
GetDocument()->Parser()->AppendBytes(segment.data(), segment.size());
GetDocument()->Parser()->Finish();
// Upon loading of SVGImages, log PageVisits in UseCounter.
// Do not track PageVisits for inspector, web page popups, and validation
// message overlays (the other callers of this method).
if (GetDocument()->IsSVGDocument())
loader_.GetDocumentLoader()->GetUseCounterHelper().DidCommitLoad(this);
} }
bool LocalFrame::IsProvisional() const { bool LocalFrame::IsProvisional() const {
......
...@@ -1823,7 +1823,6 @@ void DocumentLoader::CreateParserPostCommit() { ...@@ -1823,7 +1823,6 @@ void DocumentLoader::CreateParserPostCommit() {
? kAllowDeferredParsing ? kAllowDeferredParsing
: kAllowAsynchronousParsing; : kAllowAsynchronousParsing;
if (IsJavaScriptURLOrXSLTCommit() || if (IsJavaScriptURLOrXSLTCommit() ||
commit_reason_ == CommitReason::kForcedSync ||
!Document::ThreadedParsingEnabledForTesting()) { !Document::ThreadedParsingEnabledForTesting()) {
parsing_policy = kForceSynchronousParsing; parsing_policy = kForceSynchronousParsing;
} }
......
...@@ -1197,13 +1197,7 @@ void FrameLoader::CommitDocumentLoader( ...@@ -1197,13 +1197,7 @@ void FrameLoader::CommitDocumentLoader(
if (commit_reason != CommitReason::kInitialization) { if (commit_reason != CommitReason::kInitialization) {
// Note: this must be called after DispatchDidCommitLoad() for // Note: this must be called after DispatchDidCommitLoad() for
// metrics to be correctly sent to the browser process. // metrics to be correctly sent to the browser process.
// kForcedSync is used in two broad cases: internal UI (inspector, web page document_loader_->GetUseCounterHelper().DidCommitLoad(frame_);
// popups, and validation message overlays) and svg images. Don't track
// page visits for the internal UI cases.
bool is_internal_ui = commit_reason == CommitReason::kForcedSync &&
document_loader_->MimeType() != "image/svg+xml";
if (!is_internal_ui)
document_loader_->GetUseCounterHelper().DidCommitLoad(frame_);
} }
if (document_loader_->LoadType() == WebFrameLoadType::kBackForward) { if (document_loader_->LoadType() == WebFrameLoadType::kBackForward) {
if (Page* page = frame_->GetPage()) if (Page* page = frame_->GetPage())
......
...@@ -90,8 +90,6 @@ enum class CommitReason { ...@@ -90,8 +90,6 @@ enum class CommitReason {
kJavascriptUrl, kJavascriptUrl,
// Committing a replacement document from XSLT. // Committing a replacement document from XSLT.
kXSLT, kXSLT,
// Used to populate certain internal-implementation frames (e.g., overlays).
kForcedSync,
// All other navigations. // All other navigations.
kRegular kRegular
}; };
......
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