From 9d1336a1c98c3285848d4224b884708ff69a1177 Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 29 Sep 2022 01:37:44 +0200 Subject: [PATCH] LibWeb: Rename an origin's protocol to origin scheme This patch updates the naming of an origin's protocol to be called scheme according to the specification. See https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme --- .../LibWeb/HTML/BrowsingContextContainer.cpp | 2 +- .../LibWeb/HTML/HTMLIFrameElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Origin.h | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp index 6ddbad68e9..2e2fc05411 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp @@ -168,7 +168,7 @@ void BrowsingContextContainer::shared_attribute_processing_steps_for_iframe_and_ // FIXME: Set the referrer policy. // AD-HOC: - if (url.scheme() == "file" && document().origin().protocol() != "file") { + if (url.scheme() == "file" && document().origin().scheme() != "file") { dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url); return; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 34ba6df919..93ce002b9a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -117,7 +117,7 @@ void HTMLIFrameElement::load_src(String const& value) dbgln("iframe failed to load URL: Invalid URL: {}", value); return; } - if (url.scheme() == "file" && document().origin().protocol() != "file") { + if (url.scheme() == "file" && document().origin().scheme() != "file") { dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url); return; } diff --git a/Userland/Libraries/LibWeb/HTML/Origin.h b/Userland/Libraries/LibWeb/HTML/Origin.h index e74e8eb986..c8a6e1a2a8 100644 --- a/Userland/Libraries/LibWeb/HTML/Origin.h +++ b/Userland/Libraries/LibWeb/HTML/Origin.h @@ -14,17 +14,17 @@ namespace Web::HTML { class Origin { public: Origin() = default; - Origin(String const& protocol, String const& host, u16 port) - : m_protocol(protocol) + Origin(String const& scheme, String const& host, u16 port) + : m_scheme(scheme) , m_host(host) , m_port(port) { } // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque - bool is_opaque() const { return m_protocol.is_null() && m_host.is_null() && m_port == 0; } + bool is_opaque() const { return m_scheme.is_null() && m_host.is_null() && m_port == 0; } - String const& protocol() const { return m_protocol; } + String const& scheme() const { return m_scheme; } String const& host() const { return m_host; } u16 port() const { return m_port; } @@ -37,7 +37,7 @@ public: // 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() + return scheme() == other.scheme() && host() == other.host() && port() == other.port(); } @@ -53,7 +53,7 @@ public: if (!is_opaque() && !other.is_opaque()) { // 1. If A and B's schemes are identical, and their domains are identical and non-null, then return true. // FIXME: Check domains once supported. - if (protocol() == other.protocol()) + if (scheme() == other.scheme()) return true; // 2. Otherwise, if A and B are same origin and their domains are identical and null, then return true. @@ -75,7 +75,7 @@ public: // 2. Otherwise, let result be origin's scheme. StringBuilder result; - result.append(protocol()); + result.append(scheme()); // 3. Append "://" to result. result.append("://"sv); @@ -109,7 +109,7 @@ public: bool operator!=(Origin const& other) const { return !is_same_origin(other); } private: - String m_protocol; + String m_scheme; String m_host; u16 m_port { 0 }; }; @@ -121,7 +121,7 @@ template<> struct Traits : public GenericTraits { static unsigned hash(Web::HTML::Origin const& origin) { - return pair_int_hash(origin.protocol().hash(), pair_int_hash(int_hash(origin.port()), origin.host().hash())); + return pair_int_hash(origin.scheme().hash(), pair_int_hash(int_hash(origin.port()), origin.host().hash())); } }; } // namespace AK