1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:28:11 +00:00

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.
This commit is contained in:
Andreas Kling 2020-04-07 22:56:13 +02:00
parent 53f63058b9
commit 7382b27c22
6 changed files with 71 additions and 6 deletions

View file

@ -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())

View file

@ -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();