summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-02-14 21:54:20 +0000
committerAndreas Kling <kling@serenityos.org>2022-02-15 01:31:03 +0100
commit6d0e6e381166607808dba4bcbbdf3ac7185c5a73 (patch)
tree2629b539f7daac40f42d5d266f119619307087fa /Userland
parentf2ee62e2684dfd1e66a0e26656d8bc32e7673de9 (diff)
downloadserenity-6d0e6e381166607808dba4bcbbdf3ac7185c5a73.zip
LibWeb: Rename Origin::is_same() to Origin::is_same_origin()
The HTML Origin spec has two similar but slightly different concepts of origin equality: "same origin" and "same origin-domain". Let's be explicit with the naming here :^) Also add spec comments.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Origin.h13
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp2
3 files changed, 12 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
index c6f04e9291..3279798a6c 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
@@ -48,7 +48,7 @@ bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) cons
if (!page->is_same_origin_policy_enabled())
return true;
}
- return origin.is_same(content_origin());
+ return origin.is_same_origin(content_origin());
}
const DOM::Document* BrowsingContextContainer::content_document() const
diff --git a/Userland/Libraries/LibWeb/Origin.h b/Userland/Libraries/LibWeb/Origin.h
index 6ce0097e09..aa19f36aa1 100644
--- a/Userland/Libraries/LibWeb/Origin.h
+++ b/Userland/Libraries/LibWeb/Origin.h
@@ -28,15 +28,22 @@ public:
const String& host() const { return m_host; }
u16 port() const { return m_port; }
- bool is_same(const Origin& other) const
+ // https://html.spec.whatwg.org/multipage/origin.html#same-origin
+ bool is_same_origin(Origin const& other) const
{
+ // 1. If A and B are the same opaque origin, then return true.
+ if (is_opaque() && other.is_opaque())
+ return true;
+
+ // 2. If A and B are both tuple origins and their schemes, hosts, and port are identical, then return true.
+ // 3. Return false.
return protocol() == other.protocol()
&& host() == other.host()
&& port() == other.port();
}
- bool operator==(Origin const& other) const { return is_same(other); }
- bool operator!=(Origin const& other) const { return !is_same(other); }
+ bool operator==(Origin const& other) const { return is_same_origin(other); }
+ bool operator!=(Origin const& other) const { return !is_same_origin(other); }
private:
String m_protocol;
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index 314284673e..a1dd3244b3 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -394,7 +394,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(String body)
if (auto* page = m_window->page())
should_enforce_same_origin_policy = page->is_same_origin_policy_enabled();
- if (should_enforce_same_origin_policy && !m_window->associated_document().origin().is_same(request_url_origin)) {
+ if (should_enforce_same_origin_policy && !m_window->associated_document().origin().is_same_origin(request_url_origin)) {
dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->associated_document().url(), request_url);
set_ready_state(ReadyState::Done);
dispatch_event(DOM::Event::create(HTML::EventNames::error));