Bug 208424 - Add referrerpolicy attribute support for anchors
Summary: Add referrerpolicy attribute support for anchors
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-03-01 06:29 PST by Rob Buis
Modified: 2020-03-02 06:20 PST (History)
20 users (show)

See Also:


Attachments
Patch (94.98 KB, patch)
2020-03-01 06:37 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (677.44 KB, patch)
2020-03-01 07:52 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (140.81 KB, patch)
2020-03-01 09:13 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (149.10 KB, patch)
2020-03-01 10:23 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (148.63 KB, patch)
2020-03-01 23:53 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (179.73 KB, patch)
2020-03-02 04:56 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Buis 2020-03-01 06:29:18 PST
Add referrerpolicy attribute support for anchors
Comment 1 Rob Buis 2020-03-01 06:37:44 PST
Created attachment 392095 [details]
Patch
Comment 2 Rob Buis 2020-03-01 07:52:51 PST
Created attachment 392096 [details]
Patch
Comment 3 Rob Buis 2020-03-01 09:13:08 PST
Created attachment 392098 [details]
Patch
Comment 4 Rob Buis 2020-03-01 10:23:46 PST
Created attachment 392100 [details]
Patch
Comment 5 Darin Adler 2020-03-01 17:52:39 PST
Comment on attachment 392100 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=392100&action=review

All these frame load request with all these default policies listed over and over again point to poor design patterns; we should figure out a way to construct these things where we don’t write so much boilerplate code. I’d say we should use a struct so we can set named properties, but FrameLoadRequest already is a bit like that. Seriously the number of places with these ridiculously long lists of arguments and policy settings is out of hand.

> Source/WebCore/html/HTMLAnchorElement.cpp:497
> +    ReferrerPolicy referrerPolicy = hasRel(Relation::NoReferrer) ? ReferrerPolicy::NoReferrer : this->referrerPolicy();

I’d use auto here for the variable type. No reason to repeat the name ReferrerPolicy extra times.

> Source/WebCore/html/HTMLAnchorElement.cpp:622
> +void HTMLAnchorElement::setReferrerPolicyForBindings(const AtomString& value)
> +{
> +    setAttributeWithoutSynchronization(referrerpolicyAttr, value);
> +}
> +
> +String HTMLAnchorElement::referrerPolicyForBindings() const
> +{
> +    return referrerPolicyToString(referrerPolicy());
> +}
> +
> +ReferrerPolicy HTMLAnchorElement::referrerPolicy() const
> +{
> +    if (RuntimeEnabledFeatures::sharedFeatures().referrerPolicyAttributeEnabled())
> +        return parseReferrerPolicy(attributeWithoutSynchronization(referrerpolicyAttr), ReferrerPolicySource::ReferrerPolicyAttribute).valueOr(ReferrerPolicy::EmptyString);
> +    return ReferrerPolicy::EmptyString;
> +}

Would be nicer to share a little bit more code with image element, but not sure I know how to do that.

> Source/WebCore/loader/FrameLoadRequest.cpp:65
> +    , m_referrerPolicy { ReferrerPolicy::EmptyString }

These defaults should be in the class definition instead of here. Unless there’s some reason not to do that.

> Source/WebCore/loader/FrameLoadRequest.h:113
> +    ReferrerPolicy m_referrerPolicy;

Like here:

    ReferrerPolicy m_referrerPolicy { ReferrerPolicy::EmptyString };

> LayoutTests/http/tests/referrer-policy-anchor/no-referrer-when-downgrade/cross-origin-http-http-expected.txt:9
> +Tests the behavior of no-referrer-when-downgrade referrer policy when same origin.
> +
> +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
> +
> +
> +PASS referrer is expected
> +PASS successfullyParsed is true
> +
> +TEST COMPLETE

This is a frustrating style of test output. The entire text amounts to a single "PASS"; nothing about the test is visible. Even the title of the test has been copied and pasted and so does not make clear what is being tested and how this differs from other tests.

The standard form writes out a value and what the expected value was. That gives the person running the test more insight into what is going on.

We should put some thought into the design of the test output. Seems like the tests have pretty good coverage.

Maybe a single test that covers multiple cases would be practical, too.

These tests are OK, much better than not having test coverage, but the design here is not the intent of the test framework.
Comment 6 Rob Buis 2020-03-01 23:53:40 PST
Created attachment 392117 [details]
Patch
Comment 7 Rob Buis 2020-03-02 02:47:21 PST
Comment on attachment 392100 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=392100&action=review

>> Source/WebCore/html/HTMLAnchorElement.cpp:497
>> +    ReferrerPolicy referrerPolicy = hasRel(Relation::NoReferrer) ? ReferrerPolicy::NoReferrer : this->referrerPolicy();
> 
> I’d use auto here for the variable type. No reason to repeat the name ReferrerPolicy extra times.

Done.

>> Source/WebCore/html/HTMLAnchorElement.cpp:622
>> +}
> 
> Would be nicer to share a little bit more code with image element, but not sure I know how to do that.

There are multiple places now with this code, but indeed hard to share.

>> Source/WebCore/loader/FrameLoadRequest.cpp:65
>> +    , m_referrerPolicy { ReferrerPolicy::EmptyString }
> 
> These defaults should be in the class definition instead of here. Unless there’s some reason not to do that.

Done.

>> Source/WebCore/loader/FrameLoadRequest.h:113
>> +    ReferrerPolicy m_referrerPolicy;
> 
> Like here:
> 
>     ReferrerPolicy m_referrerPolicy { ReferrerPolicy::EmptyString };

Done.

>> LayoutTests/http/tests/referrer-policy-anchor/no-referrer-when-downgrade/cross-origin-http-http-expected.txt:9
>> +TEST COMPLETE
> 
> This is a frustrating style of test output. The entire text amounts to a single "PASS"; nothing about the test is visible. Even the title of the test has been copied and pasted and so does not make clear what is being tested and how this differs from other tests.
> 
> The standard form writes out a value and what the expected value was. That gives the person running the test more insight into what is going on.
> 
> We should put some thought into the design of the test output. Seems like the tests have pretty good coverage.
> 
> Maybe a single test that covers multiple cases would be practical, too.
> 
> These tests are OK, much better than not having test coverage, but the design here is not the intent of the test framework.

Agreed, the output is not great, but at least it covers everything. Note that the real problem is that we can't import the WPT tests because of the problem illustrated here https://github.com/web-platform-tests/wpt/pull/19381.
Comment 8 Rob Buis 2020-03-02 02:48:44 PST
(In reply to Darin Adler from comment #5)
> Comment on attachment 392100 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=392100&action=review
> 
> All these frame load request with all these default policies listed over and
> over again point to poor design patterns; we should figure out a way to
> construct these things where we don’t write so much boilerplate code. I’d
> say we should use a struct so we can set named properties, but
> FrameLoadRequest already is a bit like that. Seriously the number of places
> with these ridiculously long lists of arguments and policy settings is out
> of hand.

Agreed, it is not pretty. I am likely to touch FrameLoadRequest in the future so I will keep it in the back of my mind.
Comment 9 WebKit Commit Bot 2020-03-02 03:36:06 PST
Comment on attachment 392117 [details]
Patch

Clearing flags on attachment: 392117

Committed r257707: <https://trac.webkit.org/changeset/257707>
Comment 10 WebKit Commit Bot 2020-03-02 03:36:08 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2020-03-02 03:37:17 PST
<rdar://problem/59945018>
Comment 12 youenn fablet 2020-03-02 04:55:55 PST
Reopening to attach new patch.
Comment 13 youenn fablet 2020-03-02 04:56:00 PST
Created attachment 392132 [details]
Patch
Comment 14 Rob Buis 2020-03-02 05:26:14 PST
Wrong bug?
Comment 15 youenn fablet 2020-03-02 06:19:59 PST
(In reply to Rob Buis from comment #14)
> Wrong bug?

Definitely....