Define the "extract an origin" operation.#892
Conversation
whatwg/html#11846 added an `Origin` interface, which relies on an "extract an origin" operation to support the creation of new `Origin` objects via `Origin.from(...)`. This PR defines that operation for `URL` objects. Addresses a remaining portion of whatwg/html#11534.
|
|
||
| <div algorithm> | ||
| <p>Objects implementing the {{URL}} interface's <a for="platform object">extract an origin</a> steps are | ||
| to return <a>this</a>'s <a for=URL>URL</a>'s <a for=url>origin</a>. [[!HTML]] |
There was a problem hiding this comment.
I think it's a little weird that we use "this" here, but it's probably okay.
There was a problem hiding this comment.
This mirrors what we did in HTML (e.g. https://html.spec.whatwg.org/multipage/browsers.html#the-origin-interface:extract-an-origin and https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin:extract-an-origin). We could replace it with something like "the object's" throughout if that would be preferable?
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
|
WPT comments:
|
You're right, I didn't think about this when we moved
I can add those, thanks for the suggestion! |
You were right; Chromium's implementation was returning an opaque origin rather than throwing on |
When extracting an origin from `<a>` and `<area>` elements without an `href` attribute, we're currently returning an opaque `Origin`. We should throw instead, as there's not an origin to extract from these elements (see [1]). Thanks to @annevk for pointing this out in [2]. [1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin [2]: whatwg/url#892 (comment) Bug: 434131026 Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Cr-Commit-Position: refs/heads/main@{#1554582}
When extracting an origin from `<a>` and `<area>` elements without an `href` attribute, we're currently returning an opaque `Origin`. We should throw instead, as there's not an origin to extract from these elements (see [1]). Thanks to @annevk for pointing this out in [2]. [1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin [2]: whatwg/url#892 (comment) Bug: 434131026 Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Cr-Commit-Position: refs/heads/main@{#1554582}
When extracting an origin from `<a>` and `<area>` elements without an `href` attribute, we're currently returning an opaque `Origin`. We should throw instead, as there's not an origin to extract from these elements (see [1]). Thanks to @annevk for pointing this out in [2]. [1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin [2]: whatwg/url#892 (comment) Bug: 434131026 Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Cr-Commit-Position: refs/heads/main@{#1554582}
|
|
||
| <div algorithm="URL/extract an origin"> | ||
| <p>Objects implementing the {{URL}} interface's <a for="platform object">extract an origin</a> steps are | ||
| to return <a>this</a>'s <a for=URL>URL</a>'s <a for=url>origin</a>. [[!HTML]] |
There was a problem hiding this comment.
Something that I noticed is not covered by WPT (just incase this case was not considered in the design) is the below case:
let url = new URL('data:text/plain,opaque');
const origin1 = Origin.from(url);
const origin2 = Origin.from(url);
console.log(origin1.isSameOrigin(origin2));Which from https://url.spec.whatwg.org/#concept-url-origin the result will be false:
-> Otherwise
Return a new opaque origin.NOTE: This does indeed mean that these URLs cannot be same origin with themselves.
A similar case also happens for https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin I believe.
I can make the updates to WPT, just thought I'd double check I have the right understanding, since I suppose it is possible to hold on to the origin for those objects to have different behaviour if-so desired
There was a problem hiding this comment.
Yeah, we should test that and I think it should return false indeed.
There was a problem hiding this comment.
👍 I thought I'd added tests like that to https://wpt.fyi/results/html/browsers/origin/api/origin-comparison.any.html?label=master&label=experimental&aligned, but I didn't. If you have a PR, great! If not, I'll put one up this morning (as I need to fix the IDL test anyway).
There was a problem hiding this comment.
Nothing comprehensive so far unfortunately sorry! Only have so far the URL & hyperlink element case from hacking around my implementation locally. I haven't built up anything more comprehensive for the other cases like for WindowOrWorkerGlobal scope which seem like would be a bit different in that the ESO returns the same origin origin instance (besides from data URL workers, which create a new opaque one when callef).
There was a problem hiding this comment.
Sorry for the delay, I have been busy with day-job and other stuff lately rather than hacking on web-platform stuff like I would like to do, finally got around to raising something now web-platform-tests/wpt#56922
Edit: Unrelated question - but will this new section of the specification be linkable somehow? At least locally I can't figure out what such a link will end up being. For the HTML spec it's things like https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin:extract-an-origin, but I only managed to find that from cross-links which doesn't work in the URL specification at a standalone document. Probably some other method of getting it I am missing though!
…<a>` and `<area>`., a=testonly Automatic update from web-platform-tests [Origin API] `.from()` should throw on `<a>` and `<area>`. When extracting an origin from `<a>` and `<area>` elements without an `href` attribute, we're currently returning an opaque `Origin`. We should throw instead, as there's not an origin to extract from these elements (see [1]). Thanks to @annevk for pointing this out in [2]. [1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin [2]: whatwg/url#892 (comment) Bug: 434131026 Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Cr-Commit-Position: refs/heads/main@{#1554582} -- wpt-commits: 97bfa0053605daefab920aded71c705030ff7f39 wpt-pr: 56522
|
Now that the tests have landed let me merge this. There's still one outstanding issue surrounding |
whatwg/html#11846 added an
Origininterface, which relies on an "extract an origin" operation to support the creation of newOriginobjects viaOrigin.from(...). This PR defines that operation forURLobjects.Addresses a remaining portion of whatwg/html#11534.
Origininterface. (#11534) html#11846 records the support for the underlying change.(See WHATWG Working Mode: Changes for more details.)
Preview | Diff