|
|
Chromium Code Reviews|
Created:
4 years, 9 months ago by Marijn Kruisselbrink Modified:
4 years, 8 months ago CC:
blink-reviews, chasej+watch_chromium.org, chromium-reviews, gavinp+loader_chromium.org, Nate Chapin, kinuko+watch, loading-reviews_chromium.org, tyoshino+watch_chromium.org Base URL:
https://chromium.googlesource.com/chromium/src.git@master Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionSupport loading trial tokens from HTTP headers.
Adds support for the Origin-Trial header as specified in
https://jpchase.github.io/OriginTrials/#header
BUG=582045
Committed: https://crrev.com/7b6fa286a1a152601fe32fc988df4083986c0a2e
Cr-Commit-Position: refs/heads/master@{#389569}
Patch Set 1 #Patch Set 2 : #Patch Set 3 : trim whitespace after splitting header #Patch Set 4 : rebase #
Total comments: 4
Patch Set 5 : rebase #Patch Set 6 : make quoted strings as tokens work #
Total comments: 1
Patch Set 7 : rebase #Patch Set 8 : Don't use //net for parsing headers #
Total comments: 13
Patch Set 9 : address comments #
Total comments: 2
Patch Set 10 : clarify comment #
Total comments: 8
Messages
Total messages: 32 (13 generated)
Description was changed from ========== WIP trial tokens in headers BUG= ========== to ========== Support loading trial tokens from HTTP headers. BUG=582045 ==========
mek@chromium.org changed reviewers: + iclelland@chromium.org
I'm not entirely happy with how I'm getting from FrameLoader to DocumentOriginTrialContext in this patch. Maybe in the context of bug 588151 there will be a better place to do this (which might even eliminate the need for separate OriginTrialContext implementations if extracting the tokens gets separated from looking up the tokens for a specific execution context). So comments welcome.
I rebased this on top of https://codereview.chromium.org/1833063002, which made the changes here a lot simpler.
https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/build/scripts/templates/OriginTrials.cpp.tmpl (right): https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/OriginTrials.cpp.tmpl:34: if (headerValue.isEmpty()) return; I don't know how much we care about formatting in generated code, but if I try this in a blink cpp file, the presubmit hooks make me move the return to another line. https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp (right): https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp:41: headerValue.split(',', headers); Is there a method which takes into account quoted strings? This makes ',' a reserved character which can't appear in a token now. (Which is probably fine, as long as we document it,
+esprehn: does exposing part of net::HttpUtil this way in blink platform/network/HTTPParsers.h seem at all reasonable? The std::string vs wtf::String disconnect makes this a bit of an awkward way of doing things (although at least as far as I can tell the way content passes HTTP headers to blink guarantees that they are always 8 bit, so at least the conversions should be safe...). Maybe slightly nicer would be if net::HttpUtil had overloads for all the methods that currently take std::string::const_iterator pairs to accept either const char* pairs or even more generic character-type pointers (or StringPiece overloads). That way at least some of the copying/conversions could be avoided. Long term it might make sense to keep http headers as net::HttpResponseHeaders all the way into the blink code, rather than converting headers at the content/blink boundary (which would also help by making it clear that headers are always byte arrays rather than strings). https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/build/scripts/templates/OriginTrials.cpp.tmpl (right): https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/OriginTrials.cpp.tmpl:34: if (headerValue.isEmpty()) return; On 2016/04/05 at 17:01:30, iclelland wrote: > I don't know how much we care about formatting in generated code, but if I try this in a blink cpp file, the presubmit hooks make me move the return to another line. Yeah, was already fixed in the patch I uploaded yesterday (by no longer modifying any of the generated code). https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... File third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp (right): https://codereview.chromium.org/1802773002/diff/60001/third_party/WebKit/Sour... third_party/WebKit/Source/core/origin_trials/OriginTrialsBase.cpp:41: headerValue.split(',', headers); On 2016/04/05 at 17:01:30, iclelland wrote: > Is there a method which takes into account quoted strings? This makes ',' a reserved character which can't appear in a token now. (Which is probably fine, as long as we document it, Ah, good point. In the spec I started writing I even explicitly allowed quoted and unquoted tokens, which this code doesn't handle at all. Should probably use net::HttpUtil::ValuesIterator, but that's tricky because blink doesn't (yet?) depend on net (and it seems every part of blink that parses headers mostly rolls their own implementation, and mostly gets quoted strings wrong afaict). I added wrappers around some net::HttpUtil methods in blink platform/network/HTTPParsers, and used those here. Hopefully blink platform owners are happy with something like this.
Description was changed from ========== Support loading trial tokens from HTTP headers. BUG=582045 ========== to ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/ExperimentalFramework/#header BUG=582045 ==========
mek@chromium.org changed reviewers: + esprehn@chromium.org
Actually +esprehn this time: see my previous message; but basically I'm wondering if trying to use net::HttpUtil to parse http headers from blink like this is at all a reasonable thing to do, or if I should just reimplement base::StringTokenizer/net::HttpUtil::ValuesIterator and related code in blink...
On 2016/04/06 18:52:14, Marijn Kruisselbrink wrote: > Actually +esprehn this time: see my previous message; but basically I'm > wondering if trying to use net::HttpUtil to parse http headers from blink like > this is at all a reasonable thing to do, or if I should just reimplement > base::StringTokenizer/net::HttpUtil::ValuesIterator and related code in blink... This lgtm, assuming that referencing net/ like this is okay.
https://codereview.chromium.org/1802773002/diff/100001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/100001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:58: // Parse a Origin-Trial header as specified in nit: an
Patchset #8 (id:140001) has been deleted
Patchset #8 (id:160001) has been deleted
mek@chromium.org changed reviewers: + chasej@chromium.org - esprehn@chromium.org
After discussing this offline with esprehn, the conclusion was to not depend on //net for this particular case (since the parsing is relatively straight forward anyway). So I implemented the logic to parse comma separated lists of possibly quoted strings (with \ escaping inside those strings) inside OriginTrialContext. +chasej since iclelland is OOO
Description was changed from ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/ExperimentalFramework/#header BUG=582045 ========== to ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/OriginTrials/#header BUG=582045 ==========
https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Lay... File third_party/WebKit/LayoutTests/http/tests/origin_trials/sample-api-enabled-header.php (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Lay... third_party/WebKit/LayoutTests/http/tests/origin_trials/sample-api-enabled-header.php:5: header("Origin-Trial: 1|tZPW/JJ2Sxm4z7k/Eb1/upMsppozWpTwEuGwhgQko0zWS6ebvjQ+EXPP/ftoMX8/PCoDgOS3xlrXElMgDDvbCg==|http://127.0.0.1:8000|Frobulate|2000000000"); Probably stating the obvious, but this is the old token format. This applies to the other tests as well. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:104: return nullptr; The comment for this method says it returns null if the header value is malformed. This check indicates that empty (length = 0) is considered malformed. What happens if headerValue has length > 0, but is all whitespace? Does String::isEmpty() return true or false in that case? Based on the skipWhitespace() method, I'm assuming that String doesn't handle whitespace for you. If String::isEmpty returns false for a string with only whitespace chars, it seems that the result of this method will be a vector of length 1, with that token being an empty string. I think that case should be handled the same as input with length = 0. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:109: tokens->append(extractTokenOrQuotedString(headerValue, pos)); The extractTokenOrQuotedString() method can return an empty string. I would suggest that empty tokens should not be added to the vector. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:130: { As in the earlier comment, perhaps there should be a check here to ignore empty tokens. That would guarantee that m_tokens only contains non-empty tokens, regardless of where they came from. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:45: static PassOwnPtr<Vector<String>> parseHeaderValue(const String& headerValue); Should this be using std::unique_ptr? The recent PSA said unique_ptr can be used in Blink: https://groups.google.com/a/chromium.org/forum/?pli=1#!searchin/blink-dev/uni... https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp:259: EXPECT_EQ("ef'g", (*tokens)[1]); Add a test for a header with length > 0, but contains only whitespace? Alternatively, should document that the method assumes it will not receive whitespace-only values to parse? https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp:259: EXPECT_EQ("ef'g", (*tokens)[1]); As far as I can tell from the implementation, parseHeaderValue() will allow commas in quoted values. Probably useful to have tests for that behaviour.
https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Lay... File third_party/WebKit/LayoutTests/http/tests/origin_trials/sample-api-enabled-header.php (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Lay... third_party/WebKit/LayoutTests/http/tests/origin_trials/sample-api-enabled-header.php:5: header("Origin-Trial: 1|tZPW/JJ2Sxm4z7k/Eb1/upMsppozWpTwEuGwhgQko0zWS6ebvjQ+EXPP/ftoMX8/PCoDgOS3xlrXElMgDDvbCg==|http://127.0.0.1:8000|Frobulate|2000000000"); On 2016/04/21 at 18:24:29, chasej wrote: > Probably stating the obvious, but this is the old token format. This applies to the other tests as well. Ah yes, good point. Updated. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:104: return nullptr; On 2016/04/21 at 18:24:29, chasej wrote: > The comment for this method says it returns null if the header value is malformed. This check indicates that empty (length = 0) is considered malformed. > > What happens if headerValue has length > 0, but is all whitespace? Does String::isEmpty() return true or false in that case? Based on the skipWhitespace() method, I'm assuming that String doesn't handle whitespace for you. > > If String::isEmpty returns false for a string with only whitespace chars, it seems that the result of this method will be a vector of length 1, with that token being an empty string. I think that case should be handled the same as input with length = 0. Maybe it's more consistent to not special case empty-string and/or empty vector. So I removed this check to make the implementation match the comment: empty string and any other string that is arguably "valid" but doesn't contain any tokens will now just return an empty vector. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:109: tokens->append(extractTokenOrQuotedString(headerValue, pos)); On 2016/04/21 at 18:24:29, chasej wrote: > The extractTokenOrQuotedString() method can return an empty string. I would suggest that empty tokens should not be added to the vector. Done https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:130: { On 2016/04/21 at 18:24:30, chasej wrote: > As in the earlier comment, perhaps there should be a check here to ignore empty tokens. That would guarantee that m_tokens only contains non-empty tokens, regardless of where they came from. Done https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:45: static PassOwnPtr<Vector<String>> parseHeaderValue(const String& headerValue); On 2016/04/21 at 18:24:30, chasej wrote: > Should this be using std::unique_ptr? The recent PSA said unique_ptr can be used in Blink: > https://groups.google.com/a/chromium.org/forum/?pli=1#!searchin/blink-dev/uni... Good point, done. https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp (right): https://codereview.chromium.org/1802773002/diff/180001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp:259: EXPECT_EQ("ef'g", (*tokens)[1]); On 2016/04/21 at 18:24:30, chasej wrote: > Add a test for a header with length > 0, but contains only whitespace? Alternatively, should document that the method assumes it will not receive whitespace-only values to parse? Done On 2016/04/21 at 18:24:30, chasej wrote: > As far as I can tell from the implementation, parseHeaderValue() will allow commas in quoted values. Probably useful to have tests for that behaviour. Done
LGTM, with nits. https://codereview.chromium.org/1802773002/diff/200001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/200001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:44: // Returns null if the header value was malformed. Nit: update comment to reflect new behaviour (i.e. returns empty vector).
mek@chromium.org changed reviewers: + japhet@chromium.org
+japhet for core/ OWNERS https://codereview.chromium.org/1802773002/diff/200001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/200001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:44: // Returns null if the header value was malformed. On 2016/04/21 at 20:54:50, chasej wrote: > Nit: update comment to reflect new behaviour (i.e. returns empty vector). Done
LGTM w/nits https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:29: bool isWhitespace(UChar chr) platform/network/HTTPParsers.h has this? https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:34: bool skipWhiteSpace(const String& str, unsigned& pos) Ditto? https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:46: static std::unique_ptr<Vector<String>> parseHeaderValue(const String& headerValue); Is this public only for testing? If so, can we add a comment about it?
https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:29: bool isWhitespace(UChar chr) On 2016/04/21 at 22:09:10, Nate Chapin wrote: > platform/network/HTTPParsers.h has this? HTTPParsers.cpp has these, but they're file-static and not exposed via HTTPParsers.h. Also if they would be exposed they would probably need more descriptive names to make it clear what kind of whitespace is matched exactly. https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:46: static std::unique_ptr<Vector<String>> parseHeaderValue(const String& headerValue); On 2016/04/21 at 22:09:10, Nate Chapin wrote: > Is this public only for testing? If so, can we add a comment about it? It's also public because in a follow-up patch (https://codereview.chromium.org/1828063002, haven't rebased it onto the latest version of this CL yet though) the method is used from WorkerScriptLoader as well. In earlier version of this CL I didn't have a separate parseHeaderValue method, but since I need one anyway for that followup change, and since it makes testing easier I figured I might as well make it a separate public method here. So not sure if there is much point in adding a comment now, to then remove it again fairly soon after.
https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:29: bool isWhitespace(UChar chr) On 2016/04/21 22:22:47, Marijn Kruisselbrink wrote: > On 2016/04/21 at 22:09:10, Nate Chapin wrote: > > platform/network/HTTPParsers.h has this? > > HTTPParsers.cpp has these, but they're file-static and not exposed via > HTTPParsers.h. Also if they would be exposed they would probably need more > descriptive names to make it clear what kind of whitespace is matched exactly. That's unfortunate. Have we considered putting parseHeaderValue() (with a more specific name of course) in HTTPParsers? https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.h:46: static std::unique_ptr<Vector<String>> parseHeaderValue(const String& headerValue); On 2016/04/21 22:22:47, Marijn Kruisselbrink wrote: > On 2016/04/21 at 22:09:10, Nate Chapin wrote: > > Is this public only for testing? If so, can we add a comment about it? > > It's also public because in a follow-up patch > (https://codereview.chromium.org/1828063002, haven't rebased it onto the latest > version of this CL yet though) the method is used from WorkerScriptLoader as > well. In earlier version of this CL I didn't have a separate parseHeaderValue > method, but since I need one anyway for that followup change, and since it makes > testing easier I figured I might as well make it a separate public method here. > > So not sure if there is much point in adding a comment now, to then remove it > again fairly soon after. Makes sense.
https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... File third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp (right): https://codereview.chromium.org/1802773002/diff/220001/third_party/WebKit/Sou... third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp:29: bool isWhitespace(UChar chr) On 2016/04/21 at 22:25:56, Nate Chapin wrote: > On 2016/04/21 22:22:47, Marijn Kruisselbrink wrote: > > On 2016/04/21 at 22:09:10, Nate Chapin wrote: > > > platform/network/HTTPParsers.h has this? > > > > HTTPParsers.cpp has these, but they're file-static and not exposed via > > HTTPParsers.h. Also if they would be exposed they would probably need more > > descriptive names to make it clear what kind of whitespace is matched exactly. > > That's unfortunate. Have we considered putting parseHeaderValue() (with a more specific name of course) in HTTPParsers? In Patch 7 I added two methods to HTTPParsers that just wrapped matching methods in net::HTTPUtils, rather than reimplementing the parsing behavior. But after chatting offline with esprehn@ the conclusion was that for this particular case we don't gain that much by trying to reuse net::HTTPUtils code. I could definitely move this parseHeaderValue method to HTTPParsers as well. Not sure what a sensible name would be though; something like "parseCommaDelimitedStringsOrTokens" maybe. Or it might make sense to go back to the separation in two methods I had in patch 7, just implemented without using net::HTTPUtils, since those would be more generically useful.
The CQ bit was checked by mek@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from iclelland@chromium.org, chasej@chromium.org Link to the patchset: https://codereview.chromium.org/1802773002/#ps220001 (title: "clarify comment")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1802773002/220001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1802773002/220001
Message was sent while issue was closed.
Description was changed from ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/OriginTrials/#header BUG=582045 ========== to ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/OriginTrials/#header BUG=582045 ==========
Message was sent while issue was closed.
Committed patchset #10 (id:220001)
Message was sent while issue was closed.
Description was changed from ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/OriginTrials/#header BUG=582045 ========== to ========== Support loading trial tokens from HTTP headers. Adds support for the Origin-Trial header as specified in https://jpchase.github.io/OriginTrials/#header BUG=582045 Committed: https://crrev.com/7b6fa286a1a152601fe32fc988df4083986c0a2e Cr-Commit-Position: refs/heads/master@{#389569} ==========
Message was sent while issue was closed.
Patchset 10 (id:??) landed as https://crrev.com/7b6fa286a1a152601fe32fc988df4083986c0a2e Cr-Commit-Position: refs/heads/master@{#389569} |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
