Repository: servo/servo
File: ports/servoshell/running_app_state.rs (Rust)

Code before:
    #[allow(dead_code)]
    fn base_mut(&mut self) -> &mut RunningAppStateBase;
    fn webview_by_id(&self, _: WebViewId) -> Option<WebView>;
    fn dismiss_embedder_controls_for_webview(&self, _webview_id: WebViewId) {}

    fn servoshell_preferences(&self) -> &ServoShellPreferences {
        &self.base().servoshell_preferences
    }

    fn servo(&self) -> &Servo {
        &self.base().servo
    }

    fn webdriver_receiver(&self) -> Option<&Receiver<WebDriverCommandMsg>> {
        self.base().webdriver_receiver.as_ref()
    }

    fn webview_collection(&self) -> std::cell::Ref<'_, WebViewCollection> {
        self.base().webview_collection.borrow()
    }

    fn webview_collection_mut(&self) -> std::cell::RefMut<'_, WebViewCollection> {
        self.base().webview_collection.borrow_mut()
    }

    /// Returns all webviews in creation order.
    fn webviews(&self) -> Vec<(WebViewId, WebView)> {
        self.webview_collection()
            .all_in_creation_order()
            .map(|(id, webview)| (id, webview.clone()))
            .collect()
    }

    fn add_webview(&self, webview: WebView) {
        let webview_id = webview.id();
        self.webview_collection_mut().add(webview);
        let total = self.webview_collection().len();
        info!("Added webview with ID: {webview_id:?}, total webviews: {total}");
    }

    fn focused_webview(&self) -> Option<WebView> {
        self.webview_collection().focused().cloned()
    }

    #[allow(dead_code)]
    fn newest_webview(&self) -> Option<WebView> {
        self.webview_collection().newest().cloned()
    }

    /// Gets the "active" webview: the focused webview if there is one,
    /// otherwise the most recently created webview.

Review comment (suggestion):
```suggestion
    /// Returns all [`WebView`]s in creation order.
```

Code after:
    fn webdriver_receiver(&self) -> Option<&Receiver<WebDriverCommandMsg>> {
        self.base().webdriver_receiver.as_ref()
    }

    fn webview_collection(&self) -> std::cell::Ref<'_, WebViewCollection> {
        self.base().webview_collection.borrow()
    }

    fn webview_collection_mut(&self) -> std::cell::RefMut<'_, WebViewCollection> {
        self.base().webview_collection.borrow_mut()
    }

    /// Returns all [`WebView`]s in creation order.
    fn webviews(&self) -> Vec<(WebViewId, WebView)> {
        self.webview_collection()
            .all_in_creation_order()
            .map(|(id, webview)| (id, webview.clone()))
            .collect()
    }

    fn add_webview(&self, webview: WebView) {
        let webview_id = webview.id();
        self.webview_collection_mut().add(webview);
        let total = self.webview_collection().len();
        info!("Added webview with ID: {webview_id:?}, total webviews: {total}");
    }

    fn focused_webview(&self) -> Option<WebView> {
        self.webview_collection().focused().cloned()
    }

    #[allow(dead_code)]
    fn newest_webview(&self) -> Option<WebView> {
        self.webview_collection().newest().cloned()
    }

    /// Gets the "active" [`WebView`]: the focused [`WebView`] if there is one,
    /// otherwise the most recently created [`WebView`].
    #[allow(dead_code)]
    fn active_webview(&self) -> Option<WebView> {
        self.webview_collection().active().cloned()
    }

    /// Gets the "active" [`WebView`], panicking if there is none.
    /// This is a convenience method for platforms that assume there's always an active [`WebView`].
    #[allow(dead_code)]
    fn active_webview_or_panic(&self) -> WebView {
        self.active_webview()
            .expect("Should always have an active WebView")
    }