BrowsingContextContainer.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/DOM/Event.h>
  8. #include <LibWeb/HTML/BrowsingContextContainer.h>
  9. #include <LibWeb/Origin.h>
  10. #include <LibWeb/Page/BrowsingContext.h>
  11. #include <LibWeb/Page/Page.h>
  12. namespace Web::HTML {
  13. BrowsingContextContainer::BrowsingContextContainer(DOM::Document& document, QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. BrowsingContextContainer::~BrowsingContextContainer()
  18. {
  19. }
  20. void BrowsingContextContainer::inserted()
  21. {
  22. HTMLElement::inserted();
  23. if (!is_connected())
  24. return;
  25. if (auto* frame = document().browsing_context()) {
  26. VERIFY(frame->page());
  27. m_nested_browsing_context = BrowsingContext::create_nested(*frame->page(), *this);
  28. m_nested_browsing_context->set_frame_nesting_levels(frame->frame_nesting_levels());
  29. m_nested_browsing_context->register_frame_nesting(document().url());
  30. }
  31. }
  32. Origin BrowsingContextContainer::content_origin() const
  33. {
  34. if (!m_nested_browsing_context || !m_nested_browsing_context->active_document())
  35. return {};
  36. return m_nested_browsing_context->active_document()->origin();
  37. }
  38. bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) const
  39. {
  40. if (auto* page = document().page()) {
  41. if (!page->is_same_origin_policy_enabled())
  42. return true;
  43. }
  44. return origin.is_same(content_origin());
  45. }
  46. const DOM::Document* BrowsingContextContainer::content_document() const
  47. {
  48. return m_nested_browsing_context ? m_nested_browsing_context->active_document() : nullptr;
  49. }
  50. void BrowsingContextContainer::nested_browsing_context_did_load(Badge<FrameLoader>)
  51. {
  52. dispatch_event(DOM::Event::create(EventNames::load));
  53. }
  54. }