New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 674329 link

Starred by 3 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocked on:
issue 743311



Sign in to add a comment

We should have only one Content-Type / MIME type parser.

Project Member Reported by kouhei@chromium.org, Dec 15 2016

Issue description

Thread: https://groups.google.com/a/chromium.org/forum/#!topic/platform-architecture-dev/JQGYumK3aSQ

We have at least 4 Content-Type (MIME Type) parser in Chromium codebase:
- Blink extractMIMETypeFromMediaType
-- has tests in HTTPParsersTest
- Blink ContentType.cpp
-- No test.
-- Caveat: ContentType::parameter() has an obvious bug
- net/base/mime_util.h
- net/http HttpUtil::ParseContentType

We should have only one.

Blink should have a std::string/StringPiece -> WTFString/StringPiece converter in platform and use that to route to net/ impl.

 

Comment 1 by kinuko@chromium.org, Feb 20 2017

Cc: yhirano@chromium.org
platform/network/ParsedContent.{h,cpp} seem to be another one, which looks slightly better than ContentType.{h,cpp} (and yhirano@'s adding a test).  Probably Blink impls should be able to be merged into one at least.
I'm making ParsedContentType more conformant. See  issue 689731 .

Comment 3 by kinuko@chromium.org, Feb 20 2017

We can probably merge ContentType.{h,cpp} and code in HTTPParsers.cpp into ParsedContentType.

Comment 4 by kouhei@google.com, Feb 23 2017

Consolidating info about mime type confusion.

FAQ: How are ResourceResponse::httpContentType and mimeType different?
A: httpContentType is modified by mime sniffer, mimeType is raw.

 httpContentType() does strip charset (which is confusing)
- May be the difference is how it deals w/ mime sniffer?
-- mime sniffer rewrites mimeType but not content type
-- however current Blink httpContentType() callers can deai w/ rewritten mimeType()
- We should simply kill httpContentType() and only use mimeType()
-- httpContentType is more "raw" compared to mimeType() which may go through more processing, but Blink shouldn't care / it's too confusing to choose the right one correctly.

Comment 5 by kinuko@chromium.org, Feb 23 2017

Cc: jrumm...@chromium.org
From jrummel@, who did a little more investigation around ParsedContentType and ContentType:

As far as getting rid of ContentType, I don't see any problem with moving all the media code to use ParsedContentType once parameters become case-insensitive. The only remaining hold-out is ContentType::type(), which does trivial parsing of the type. It is called in numerous places (commonly ContentType(type).type();) so I think a static method should replace it. Calling ParsedContentType(type).mimeType() might slow things down (due to it fully parsing the type), and change behavior (since it currently ignores anything after the ;).

Comment 6 by kinuko@chromium.org, Feb 23 2017

This is the CL jrummell@ tried for replacing ContentType with ParsedContentType:
https://codereview.chromium.org/2683083002/

"It looks only the media tests that try case-insensitive lookups fail." - so promising, mod some nits reg: implementation details & efficiency issue noted above
Cc: -csharrison@chromium.org asankacsharrison@chromium.org
+asanka

I know in the past we've run into mismatched expectations between the code in browser process which decides if a resource should be handled via download and render process/blink code for deciding whether the mime type can be handled. Consolidating would be nice.
Cc: -asankacsharrison@chromium.org asanka@chromium.org csharrison@chromium.org
:)
Project Member

Comment 9 by bugdroid1@chromium.org, Apr 7 2017

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

commit 9049bebd837e0af0c1e9cba1669779c14978ccf4
Author: jrummell <jrummell@chromium.org>
Date: Fri Apr 07 05:53:21 2017

Add UMA logging to track bad MIME types passed to HTMLMediaElement

It would be nice to change HTMLMediaElement to use ParsedContentType when
checking MIME types passed to it. However, it currently uses ContentType
which is not properly spec compliant. Adding a UMA to determine how much
real world usage actually provides MIME types that don't parse according to
RFC 2045.

BUG=674329
TEST=media layout tests pass

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

[modify] https://crrev.com/9049bebd837e0af0c1e9cba1669779c14978ccf4/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
[modify] https://crrev.com/9049bebd837e0af0c1e9cba1669779c14978ccf4/third_party/WebKit/Source/core/html/HTMLMediaElement.h
[modify] https://crrev.com/9049bebd837e0af0c1e9cba1669779c14978ccf4/tools/metrics/histograms/histograms.xml

Re: ExtractCharsetFromMediaType() in Blink, it's very casual implementation (see FindCharsetInMediaType()). It should simply be replaced with something else.
Blockedon: 743311
Project Member

Comment 12 by bugdroid1@chromium.org, Jul 15 2017

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

commit ef9c803b58398f3b2f531103e024035210fb367d
Author: Takeshi Yoshino <tyoshino@chromium.org>
Date: Sat Jul 15 06:43:17 2017

Mark the charset parsing methods in HTTPParser as deprecated

FindCharsetInMediaType() looks for a substring that is likely to be
indicating the charset parameter loosely without performing ABNF
validation. New code should use the strict version in HttpUtil.

Bug: 674329, 743311
Change-Id: I9faa60dcb63e983a62aff74601ac16257da28e80
Reviewed-on: https://chromium-review.googlesource.com/564749
Commit-Queue: Takeshi Yoshino <tyoshino@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486983}
[modify] https://crrev.com/ef9c803b58398f3b2f531103e024035210fb367d/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
[modify] https://crrev.com/ef9c803b58398f3b2f531103e024035210fb367d/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
[modify] https://crrev.com/ef9c803b58398f3b2f531103e024035210fb367d/third_party/WebKit/Source/platform/network/HTTPParsers.h

We also have components/mime_util/mime_util.h
components/mime_util/ doesn't have a parser but another place for MIME related utilities.
Project Member

Comment 15 by bugdroid1@chromium.org, Nov 14 2017

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

commit 402bf1aba03abbcdb30774ccbc5ea6726df6aa1d
Author: Yutaka Hirano <yhirano@chromium.org>
Date: Tue Nov 14 12:33:06 2017

Add a UseCounter for charset replacement in XHR

Bug: 674329
Change-Id: Iac71ae590f2a94f47ae36e052b67f4ed91c4898d
Reviewed-on: https://chromium-review.googlesource.com/768309
Commit-Queue: Philip Jägenstedt <foolip@chromium.org>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516277}
[modify] https://crrev.com/402bf1aba03abbcdb30774ccbc5ea6726df6aa1d/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
[modify] https://crrev.com/402bf1aba03abbcdb30774ccbc5ea6726df6aa1d/third_party/WebKit/public/platform/web_feature.mojom
[modify] https://crrev.com/402bf1aba03abbcdb30774ccbc5ea6726df6aa1d/tools/metrics/histograms/enums.xml

516277 is included from branch 3269.
Project Member

Comment 17 by bugdroid1@chromium.org, Nov 20 2017

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

commit cd0f2361061be8f3942d7d25b24989012eaa88cd
Author: Takeshi Yoshino <tyoshino@chromium.org>
Date: Mon Nov 20 03:09:04 2017

Clean up XMLHttpRequest::FindCharsetInMediaType() and fix a bug in a while-loop condition in it

Bug: 674329
Change-Id: Ia815eb26487c09b69dabf61db018eb075c6b19e1
Reviewed-on: https://chromium-review.googlesource.com/773759
Commit-Queue: Takeshi Yoshino <tyoshino@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517749}
[modify] https://crrev.com/cd0f2361061be8f3942d7d25b24989012eaa88cd/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Project Member

Comment 18 by bugdroid1@chromium.org, Feb 6 2018

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

commit 5d204ea44f62696cf8fec7ec2e9005b86e1228e8
Author: Yutaka Hirano <yhirano@chromium.org>
Date: Tue Feb 06 06:49:18 2018

[XHR] Add UseCounter for mime type replacement ignoring case

I added kReplaceCharsetInXHR a while ago, but it reported much larger
replacement usage than I originally expected. It is still possible that
the replacement is only lower-casing (e.g., charset=UTF-8 to
charset=utf-8), so this CL adds a use counter for it.

Bug: 674329
Change-Id: I208dff802e0129baaa885e9915893920eea6da44
Reviewed-on: https://chromium-review.googlesource.com/903383
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: Takeshi Yoshino <tyoshino@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534646}
[modify] https://crrev.com/5d204ea44f62696cf8fec7ec2e9005b86e1228e8/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
[modify] https://crrev.com/5d204ea44f62696cf8fec7ec2e9005b86e1228e8/third_party/WebKit/public/platform/web_feature.mojom
[modify] https://crrev.com/5d204ea44f62696cf8fec7ec2e9005b86e1228e8/tools/metrics/histograms/enums.xml

Labels: Network-Triaged

Sign in to add a comment