Parcourir la source

LibWeb: Make BrowsingContext store Page member as NonnullGCPtr

No need to use WeakPtr anymore.

Co-Authored-By: Andreas Kling <kling@serenityos.org>
Andreas Kling il y a 2 ans
Parent
commit
bf4c8f4a09

+ 6 - 5
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -79,7 +79,7 @@ HTML::Origin determine_the_origin(AK::URL const& url, SandboxingFlagSet sandbox_
 }
 
 // https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-auxiliary-browsing-context
-WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext::create_a_new_auxiliary_browsing_context_and_document(Page& page, JS::NonnullGCPtr<HTML::BrowsingContext> opener)
+WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext::create_a_new_auxiliary_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::NonnullGCPtr<HTML::BrowsingContext> opener)
 {
     // 1. Let openerTopLevelBrowsingContext be opener's top-level traversable's active browsing context.
     auto opener_top_level_browsing_context = opener->top_level_traversable()->active_browsing_context();
@@ -110,7 +110,7 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
 }
 
 // https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context
-WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext::create_a_new_browsing_context_and_document(Page& page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group)
+WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext::create_a_new_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group)
 {
     auto& vm = group->vm();
 
@@ -263,7 +263,7 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
     return BrowsingContext::BrowsingContextAndDocument { browsing_context, document };
 }
 
-BrowsingContext::BrowsingContext(Page& page, HTML::NavigableContainer* container)
+BrowsingContext::BrowsingContext(JS::NonnullGCPtr<Page> page, HTML::NavigableContainer* container)
     : m_page(page)
     , m_event_handler({}, *this)
     , m_container(container)
@@ -284,6 +284,7 @@ void BrowsingContext::visit_edges(Cell::Visitor& visitor)
 {
     Base::visit_edges(visitor);
 
+    visitor.visit(m_page);
     for (auto& entry : m_session_history)
         visitor.visit(entry);
     visitor.visit(m_container);
@@ -335,7 +336,7 @@ bool BrowsingContext::is_top_level() const
 
 bool BrowsingContext::is_focused_context() const
 {
-    return m_page && &m_page->focused_context() == this;
+    return &m_page->focused_context() == this;
 }
 
 void BrowsingContext::scroll_to(CSSPixelPoint position)
@@ -347,7 +348,7 @@ void BrowsingContext::scroll_to(CSSPixelPoint position)
             active_document()->update_layout();
     }
 
-    if (m_page && this == &m_page->top_level_browsing_context())
+    if (this == &m_page->top_level_browsing_context())
         m_page->client().page_did_request_scroll_to(position);
 }
 

+ 4 - 4
Userland/Libraries/LibWeb/HTML/BrowsingContext.h

@@ -43,8 +43,8 @@ public:
         JS::NonnullGCPtr<DOM::Document> document;
     };
 
-    static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_browsing_context_and_document(Page& page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group);
-    static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_auxiliary_browsing_context_and_document(Page& page, JS::NonnullGCPtr<HTML::BrowsingContext> opener);
+    static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group);
+    static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_auxiliary_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::NonnullGCPtr<HTML::BrowsingContext> opener);
 
     virtual ~BrowsingContext() override;
 
@@ -183,13 +183,13 @@ public:
     virtual void set_window_handle(String handle) override { m_window_handle = move(handle); }
 
 private:
-    explicit BrowsingContext(Page&, HTML::NavigableContainer*);
+    explicit BrowsingContext(JS::NonnullGCPtr<Page>, HTML::NavigableContainer*);
 
     virtual void visit_edges(Cell::Visitor&) override;
 
     void reset_cursor_blink_cycle();
 
-    WeakPtr<Page> m_page;
+    JS::NonnullGCPtr<Page> m_page;
 
     Web::EventHandler m_event_handler;