New issue
Advanced search Search tips

Issue 671533 link

Starred by 0 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 23
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Clean up FrameFetchContext

Project Member Reported by tyoshino@chromium.org, Dec 6 2016

Issue description

FrameFetchContext contains too much logic than needed. Ideally, it should hold stuff for ResourceFetcher.
 
Project Member

Comment 1 by bugdroid1@chromium.org, Dec 6 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/092e72e03beccd15b99748e51df91cb47a79dd74

commit 092e72e03beccd15b99748e51df91cb47a79dd74
Author: tyoshino <tyoshino@chromium.org>
Date: Tue Dec 06 09:51:40 2016

Clean up around FrameFetchContext

- Split FrameFetchContext::createContextAndFetcher() into two methods
  and give more descriptive name to them.
- Add DCHECKs to clarify where instances are expected to be
  null/non-null
- Factor out frameOfImportsController() from FrameFetchContext::frame()
  to ease understanding where the returned LocalFrame came from and
  call frameOfImportsController() directly where it's clear than calling
  frame().

R=yhirano@chromium.org,hayato@chromium.org
BUG= 671533 

Review-Url: https://codereview.chromium.org/2545023002
Cr-Commit-Position: refs/heads/master@{#436556}

[modify] https://crrev.com/092e72e03beccd15b99748e51df91cb47a79dd74/third_party/WebKit/Source/core/dom/Document.cpp
[modify] https://crrev.com/092e72e03beccd15b99748e51df91cb47a79dd74/third_party/WebKit/Source/core/loader/DocumentLoader.cpp
[modify] https://crrev.com/092e72e03beccd15b99748e51df91cb47a79dd74/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
[modify] https://crrev.com/092e72e03beccd15b99748e51df91cb47a79dd74/third_party/WebKit/Source/core/loader/FrameFetchContext.h
[modify] https://crrev.com/092e72e03beccd15b99748e51df91cb47a79dd74/third_party/WebKit/Source/core/loader/FrameLoader.cpp

Project Member

Comment 2 by bugdroid1@chromium.org, Dec 13 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/3b099320199a62fcb0e8b66f50e87fd1726c2449

commit 3b099320199a62fcb0e8b66f50e87fd1726c2449
Author: tyoshino <tyoshino@chromium.org>
Date: Tue Dec 13 07:11:45 2016

Split methods for ClientHintsPreferences from FrameFetchContext

FrameFetchContext is containing too many things. We'd like to slim it
down to hold basically only things that receive and handle notifications
from ResourceFetcher.

The methods for ClientHintsPreferences on FrameFetchContext is placed
there (I guess) just not to introduce dependencies from core/fetch to
core/loader, core/frame, etc. See
https://codereview.chromium.org/1189523015 which introduced this logic
initially.

----

Compatibility analysis:

It's safe to directly pass frame() to FrameClientHintsPreferencesContext
in FrameFetchContext::dispatchDidReceiveResponseInternal(). If the
passed ResourceFetcher is already clearContext()-ed, we never reach
dispatchDidReceiveResponseInternal(). So, we can assume that the
ResourceFetcher passed to updateFromAcceptClientHintsHeader() was
always not yet clearContext()-ed.

HttpEquiv::processHttpEquivAcceptCH() was passing document.fetcher()
to updateFromAcceptClientHintsHeader(). Document::m_fetcher is cleared
only in Document::shutdown(). Therefore, document.frame() being non-null
at the beginning of processHttpEquivAcceptCH() means that the Document
hasn't yet shutdown.

context().frame() call on document.fetcher() returns document.frame()
unless clearContext() was called. This is true even when
setImportsController() was called on the Document. This is clarified by
a separate CL https://codereview.chromium.org/2547843002/.

There're three callers of ResourceFetcher::clearContext(). One of them
is Document::shutdown(). So, we don't need to care it. The other cases
are:
- setImportsController() called by LinkImport::process() while
  Document::loader() is null
- DocumentLoader::detachFromFrame() was called

However, I think this behavior was not intended initially and was
introduced just accidentally as stated above.

R=yhirano@chromium.org
BUG= 671533 

Review-Url: https://codereview.chromium.org/2544933003
Cr-Commit-Position: refs/heads/master@{#438090}

[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/fetch/ClientHintsPreferences.cpp
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/fetch/ClientHintsPreferences.h
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/fetch/FetchContext.h
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/BUILD.gn
[add] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/FrameClientHintsPreferencesContext.cpp
[add] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/FrameClientHintsPreferencesContext.h
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/FrameFetchContext.h
[modify] https://crrev.com/3b099320199a62fcb0e8b66f50e87fd1726c2449/third_party/WebKit/Source/core/loader/HttpEquiv.cpp

Project Member

Comment 4 by bugdroid1@chromium.org, Jan 18 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/78f5a0c23df6926c73cf92839638868e982aae7e

commit 78f5a0c23df6926c73cf92839638868e982aae7e
Author: tyoshino <tyoshino@chromium.org>
Date: Wed Jan 18 11:23:36 2017

Clarify when DocumentLoader's FrameLoader/FrameLoaderClient accessors can be used

- Change frameLoader() to return a reference after DCHECK on m_frame
- Get FrameLoaderClient directly from m_frame when needed than getting
  the FrameLoader and then calling client() on it. FrameLoader::client()
  is just calling m_frame->client().
- Replace code checking nullness of frameLoader() with m_frame
- Use m_frame inside DocumentLoader than calling frame() which doesn't
  add any value.

R=yhirano@chromium.org,tkent@chromium.org
BUG= 671533 

Review-Url: https://codereview.chromium.org/2556053002
Cr-Commit-Position: refs/heads/master@{#444333}

[modify] https://crrev.com/78f5a0c23df6926c73cf92839638868e982aae7e/third_party/WebKit/Source/core/loader/DocumentLoader.cpp
[modify] https://crrev.com/78f5a0c23df6926c73cf92839638868e982aae7e/third_party/WebKit/Source/core/loader/DocumentLoader.h
[modify] https://crrev.com/78f5a0c23df6926c73cf92839638868e982aae7e/third_party/WebKit/Source/core/loader/EmptyClients.cpp
[modify] https://crrev.com/78f5a0c23df6926c73cf92839638868e982aae7e/third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp
[modify] https://crrev.com/78f5a0c23df6926c73cf92839638868e982aae7e/third_party/WebKit/Source/web/WebDataSourceImpl.cpp

Owner: kinuko@chromium.org
Assigning to kinuko@ as kinuko@ has been actively working on FrameFetchContext redesigning recently. Feel free to use this or close.
Project Member

Comment 6 by bugdroid1@chromium.org, Jun 9 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/74a7fb2fa4307c69812945586b39018ae4f231b2

commit 74a7fb2fa4307c69812945586b39018ae4f231b2
Author: kinuko <kinuko@chromium.org>
Date: Fri Jun 09 03:50:22 2017

Remove dup'ed code for RequestorOrigin and FirstPartyCookie

- Remove RequestorOrigin and FirstPartyCookie code in RenderFrameImpl
  (except for PlzNavigate's main frame resource case)
- Most of the code now lives in FrameFetchContext
- Also fix TODO to initialize ResourceRequest::RequestorOrigin with null

Some implementation notes:

Before this change, the logic was like:
1. When ResourceFetcher populates an initial resource request
   FetchContext::SetFirstPartyCookieAndRequestorOrigin was called in
   PopulateResourceRequest, and this used to do:

  if (!GetDocument())
    return;

  if (request.FirstPartyForCookies().IsNull()) {
    request.SetFirstPartyForCookies(
        GetDocument() ? GetDocument()->FirstPartyForCookies()  // [A]
                      : SecurityOrigin::UrlWithUniqueSecurityOrigin());  // [B]
  }

  if (request.GetFrameType() == WebURLRequest::kFrameTypeNone &&
      request.RequestorOrigin()->IsUnique()) {
    request.SetRequestorOrigin(GetDocument()->IsSandboxed(kSandboxOrigin)
                                   ? SecurityOrigin::Create(document_->Url()) // [a]
                                   : document_->GetSecurityOrigin()); // [b]
  }

2. After that, FrameFetchContext::WillSendRequest does:

  if (request.FirstPartyForCookies().IsEmpty()) {
    if (request.GetFrameType() == blink::WebURLRequest::kFrameTypeTopLevel)
      request.SetFirstPartyForCookies(request.Url());  // [C]
    else
      request.SetFirstPartyForCookies(
          frame_->GetDocument().FirstPartyForCookies());  // [D]
  }

  WebDocument frame_document = frame_->GetDocument();
  if (request.RequestorOrigin().IsUnique() &&
      !frame_document.GetSecurityOrigin().IsUnique()) {
    request.SetRequestorOrigin(frame_document.GetSecurityOrigin()); // [c]
  }

  This logic is also called on redirects.

  Note that:
  - [B] case is invalid as we return null-document case
  - [C],[D],[c] happens only if document is null, and for initial
    top-level frame request case this is always the case
  - Therefore: [A][C][D] are the valid cases for first-party-cookie,
    and [a][b][c] are for requestor-origin

After this change, FrameFetchContext::WillSendRequest does:

  if (request.FirstPartyForCookies().IsNull()) {
    if (request.GetFrameType() == WebURLRequest::kFrameTypeTopLevel) {
      request.SetFirstPartyForCookies(request.Url());  // == [C] (document is null)
    } else {
      Document* document =
          GetDocument() ? GetDocument() : GetFrame()->GetDocument();
      request.SetFirstPartyForCookies(document->FirstPartyForCookies()); // == [A][D]
    }
  }

  if (!request.RequestorOrigin()) {
    if (request.GetFrameType() == WebURLRequest::kFrameTypeNone) {
      Document* document = GetDocument();
      request.SetRequestorOrigin(document->IsSandboxed(kSandboxOrigin)
                                     ? SecurityOrigin::Create(document->Url()) // [a]
                                     : document->GetSecurityOrigin());  // [b]
    } else {
      request.SetRequestorOrigin(
          GetFrame()->GetDocument()->GetSecurityOrigin()); // [c]
    }
  }

BUG= 671533 ,  625969 

Review-Url: https://codereview.chromium.org/2918653004
Cr-Commit-Position: refs/heads/master@{#478191}

[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/content/renderer/fetchers/resource_fetcher_impl.cc
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/content/renderer/render_frame_impl.cc
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/third_party/WebKit/Source/platform/loader/fetch/ResourceRequest.cpp
[modify] https://crrev.com/74a7fb2fa4307c69812945586b39018ae4f231b2/third_party/WebKit/Source/platform/loader/fetch/ResourceRequestTest.cpp

Components: Blink>Network
Labels: Hotlist-CodeHealth
Status: Fixed (was: Started)
I have no immediate plan to work further on this one, let me close this.

Sign in to add a comment