diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-07 22:56:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-07 23:01:45 +0200 |
commit | 7382b27c220327470a84a2e920277be93224a6d3 (patch) | |
tree | fb8116bcd7c0c467e6c5a64e17dba202e82c4411 /Libraries/LibWeb/DOM | |
parent | 53f63058b9714bfda4cae5b0ab70fd84e921c91a (diff) | |
download | serenity-7382b27c220327470a84a2e920277be93224a6d3.zip |
LibWeb: Add Origin concept (protocol, host, port tuple)
Every Document now has an Origin, found via Document::origin().
It's based on the URL of the document.
This will be used to implement things like the same-origin policy.
Diffstat (limited to 'Libraries/LibWeb/DOM')
-rw-r--r-- | Libraries/LibWeb/DOM/Document.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Document.h | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 43c881ce8f..6162deaac2 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -52,14 +52,16 @@ #include <LibWeb/HtmlView.h> #include <LibWeb/Layout/LayoutDocument.h> #include <LibWeb/Layout/LayoutTreeBuilder.h> +#include <LibWeb/Origin.h> #include <LibWeb/Parser/CSSParser.h> #include <stdio.h> namespace Web { -Document::Document() +Document::Document(const URL& url) : ParentNode(*this, NodeType::DOCUMENT_NODE) , m_style_resolver(make<StyleResolver>(*this)) + , m_url(url) , m_window(Window::create_with_document(*this)) { m_style_update_timer = Core::Timer::create_single_shot(0, [this] { @@ -71,6 +73,13 @@ Document::~Document() { } +Origin Document::origin() const +{ + if (!m_url.is_valid()) + return {}; + return { m_url.protocol(), m_url.host(), m_url.port() }; +} + void Document::schedule_style_update() { if (m_style_update_timer->is_active()) diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 18110088ad..66161a8742 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -48,12 +48,14 @@ class Document public: using WrapperType = Bindings::DocumentWrapper; - Document(); + explicit Document(const URL& = {}); virtual ~Document() override; void set_url(const URL& url) { m_url = url; } const URL& url() const { return m_url; } + Origin origin() const; + URL complete_url(const String&) const; void fixup(); |