- The `request_target_url` is usually available as `GURL`. It probably doesn't make sense to compare origins if the url is an about:blank or about:srcdoc. I don't have a strong opinion on urls like data: or blob: URLs
Given above, I think I would like to propose adding the following method to url::Origin:
- bool Origin::IsSameOriginWith(const GURL& target_url)
- This is easy to discover (by being next to `bool Origin::IsSameOriginWith(const Origin& other_origin)`)
- We can DCHECK that `target_url` is not an about:blank (and maybe that it is not a blob: or filesystem: URL since these are tricky for dealing with inner URLs/origins)
Alternatives that I thought about and liked less than the proposal above:
- Separate, free function: bool IsSameOriginNetworkRequest(const absl::optional<url::Origin>& request_initiator, const GURL& target_url)
- Cons: This is less discoverable.
- Pros: The `request_initiator` parameter is explicitly named
- Neutral: Using `absl::optional` is orthogonal to the free-function-VS-method angle. I think that implicit handling of `absl::optional` here would make things less, rather than more readable.
- Avoiding GURL: bool Origin::IsSameOriginWith(const SchemeHostPost& target_scheme_host_post)
- Pros: More explicit that this is about scheme+host+port tuple (and that we are ignoring GURL's path, query, etc)
- Cons
- inconvenient to use (callers have to do the conversion themselves)
- explicit conversion doesn't really solve the trickiness of GURL -> SchemeHostPort conversions (e.g. for about:blank, or blob: URLs)
WDYT? Does `bool Origin::IsSameOriginWith(const GURL& target_url)` sound okay?Thanks,Lukasz
--
You received this message because you are subscribed to the Google Groups "net-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to net-dev+u...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/net-dev/CAA_NCUFEhLjJmYpwg5EcWOSyyv_iWQ-9ej34qUKm3%3DEcDBPo_g%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to net-dev+unsubscribe@chromium.org.
Does it make sense to return a tri-state kSameOrigin / kDifferentOrigin / kGURLHasNoOrigin? Then the caller doesn't need to remember all the side cases that need handling, but does need to decide what to do if the origin check simply doesn't make sense.
This is now implemented in a WIP CL at https://chromium-review.googlesource.com/c/chromium/src/+/3309669One issue is that (as Daniel points out in a code review comment) having a url::Origin::IsSameOriginWith(const GURL&) overload means that it is now possible to write: rfh->GetLastCommittedOrigin().IsSameOriginWith(main_rfh->GetLastCommittedURL())This does seem to be a problem / I don't know how to address this concern. Some initial/random notes:
- We could in theory provide instead a url::Origin::IsSameOriginWith(const url::SchemeHostPort&) overload (as suggested by Joe above). This would make the GURL-wielding callsites slightly more verbose (and therefore might steer the callers toward similarily verbose: rfh->GetLastCommittedOrigin().IsSameOriginWith(url::Origin::Create(main_rfh->GetLastCommittedURL()))
- In general, moving the url::Origin::Create into the new overload just centralizes the problem at hand (the problem of comparing the origin of about:blank + the problem of ignoring iframe.sandbox). We can hope that in the future we'll be able to DCHECK against this in the new overload, but today many callers assume that they can pass any GURL in (including about:blank, blob:..., etc.)
- Maybe it is possible to have a clang-plugin-based compile check: if a value came from GetLastCommittedURL, then it is an error to pass this value to 1) methods that also have overloads accepting an url::Origin and/or 2) url::Origin::Create?
- Or maybe GetLastCommittedURL should return a GURLThatWontConvertToOrigin (not sure how exactly this would work in practice though - in the end this would probably need to provide a conversion to GURL, and after such conversion all protections would be gone...)
- Maybe we would still want to proceed with this change (not sure how to weigh the various considerations here: the problem is not new, but maybe the new pattern is more problematic? the CL still provides other benefits: shorter callsites, getting rid of the error-prone url::Origin::Create [or rather, centralizing the problem])
-Lukasz
To unsubscribe from this group and stop receiving emails from it, send an email to net-dev+u...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/net-dev/CAA_NCUFEhLjJmYpwg5EcWOSyyv_iWQ-9ej34qUKm3%3DEcDBPo_g%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "navigation-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to navigation-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/navigation-dev/e9f814b8-64e6-49a2-b512-474ecf0707abn%40chromium.org.