BrowsingContextContainer.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/BrowsingContext.h>
  9. #include <LibWeb/HTML/BrowsingContextContainer.h>
  10. #include <LibWeb/Origin.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* browsing_context = document().browsing_context()) {
  26. VERIFY(browsing_context->page());
  27. m_nested_browsing_context = BrowsingContext::create_nested(*browsing_context->page(), *this);
  28. m_nested_browsing_context->set_frame_nesting_levels(browsing_context->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_origin(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. }