BrowsingContextContainer.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. namespace Web::HTML {
  12. BrowsingContextContainer::BrowsingContextContainer(DOM::Document& document, QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. BrowsingContextContainer::~BrowsingContextContainer()
  17. {
  18. }
  19. void BrowsingContextContainer::inserted()
  20. {
  21. HTMLElement::inserted();
  22. if (!is_connected())
  23. return;
  24. if (auto* frame = document().browsing_context()) {
  25. m_nested_browsing_context = BrowsingContext::create_nested(*this, frame->top_level_browsing_context());
  26. m_nested_browsing_context->set_frame_nesting_levels(frame->frame_nesting_levels());
  27. m_nested_browsing_context->register_frame_nesting(document().url());
  28. }
  29. }
  30. Origin BrowsingContextContainer::content_origin() const
  31. {
  32. if (!m_nested_browsing_context || !m_nested_browsing_context->document())
  33. return {};
  34. return m_nested_browsing_context->document()->origin();
  35. }
  36. bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) const
  37. {
  38. return origin.is_same(content_origin());
  39. }
  40. const DOM::Document* BrowsingContextContainer::content_document() const
  41. {
  42. return m_nested_browsing_context ? m_nested_browsing_context->document() : nullptr;
  43. }
  44. void BrowsingContextContainer::nested_browsing_context_did_load(Badge<FrameLoader>)
  45. {
  46. dispatch_event(DOM::Event::create(EventNames::load));
  47. }
  48. }