mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Implement BCC's "content document" concept according to spec
This commit is contained in:
parent
5e8bfb5efc
commit
75dd4fbd16
Notes:
sideshowbarker
2024-07-17 18:47:53 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/75dd4fbd16 Pull-request: https://github.com/SerenityOS/serenity/pull/12531
2 changed files with 21 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -35,25 +36,28 @@ void BrowsingContextContainer::inserted()
|
|||
}
|
||||
}
|
||||
|
||||
Origin BrowsingContextContainer::content_origin() const
|
||||
{
|
||||
if (!m_nested_browsing_context || !m_nested_browsing_context->active_document())
|
||||
return {};
|
||||
return m_nested_browsing_context->active_document()->origin();
|
||||
}
|
||||
|
||||
bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) const
|
||||
{
|
||||
if (auto* page = document().page()) {
|
||||
if (!page->is_same_origin_policy_enabled())
|
||||
return true;
|
||||
}
|
||||
return origin.is_same_origin(content_origin());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#concept-bcc-content-document
|
||||
const DOM::Document* BrowsingContextContainer::content_document() const
|
||||
{
|
||||
return m_nested_browsing_context ? m_nested_browsing_context->active_document() : nullptr;
|
||||
// 1. If container's nested browsing context is null, then return null.
|
||||
if (m_nested_browsing_context == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// 2. Let context be container's nested browsing context.
|
||||
auto const& context = *m_nested_browsing_context;
|
||||
|
||||
// 3. Let document be context's active document.
|
||||
auto const* document = context.active_document();
|
||||
|
||||
VERIFY(document);
|
||||
VERIFY(m_document);
|
||||
|
||||
// 4. If document's origin and container's node document's origin are not same origin-domain, then return null.
|
||||
if (!document->origin().is_same_origin_domain(m_document->origin()))
|
||||
return nullptr;
|
||||
|
||||
// 5. Return document.
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@ public:
|
|||
|
||||
const DOM::Document* content_document() const;
|
||||
|
||||
Origin content_origin() const;
|
||||
bool may_access_from_origin(const Origin&) const;
|
||||
|
||||
virtual void inserted() override;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Reference in a new issue