Repository: servo/servo
File: components/webdriver_server/lib.rs (Rust)

Code before:
                extension_routes(),
            ) {
                Ok(listening) => info!("WebDriver server listening on {}", listening.socket),
                Err(_) => panic!("Unable to start WebDriver HTTPD server"),
            }
        })
        .expect("Thread spawning failed");
}

/// Represents the current WebDriver session and holds relevant session state.
/// Currently, only 1 webview is supported per session.
/// So only there is only 1 InputState.
pub struct WebDriverSession {
    /// <https://www.w3.org/TR/webdriver2/#dfn-session-id>
    id: Uuid,

    /// <https://www.w3.org/TR/webdriver2/#dfn-current-top-level-browsing-context>
    webview_id: WebViewId,

    /// <https://www.w3.org/TR/webdriver2/#dfn-current-browsing-context>
    browsing_context_id: BrowsingContextId,

    /// <https://www.w3.org/TR/webdriver2/#dfn-window-handles>
    window_handles: HashMap<WebViewId, String>,

    timeouts: TimeoutsConfiguration,

    page_loading_strategy: PageLoadStrategy,

    strict_file_interactability: bool,

    user_prompt_handler: UserPromptHandler,

    /// <https://w3c.github.io/webdriver/#dfn-input-state-map>
    input_state_table: RefCell<HashMap<String, InputSourceState>>,

    /// <https://w3c.github.io/webdriver/#dfn-input-cancel-list>
    input_cancel_list: RefCell<Vec<(String, ActionItem)>>,
}

impl WebDriverSession {
    pub fn new(browsing_context_id: BrowsingContextId, webview_id: WebViewId) -> WebDriverSession {
        let mut window_handles = HashMap::new();
        let handle = Uuid::new_v4().to_string();
        window_handles.insert(webview_id, handle);

        WebDriverSession {
            id: Uuid::new_v4(),
            webview_id,
            browsing_context_id,
            window_handles,

Review comment (performance):
```suggestion
```
With current code, this can be removed. As the cache is never directly used, and we always refreshing it by consulting `script`.

Code after:
                extension_routes(),
            ) {
                Ok(listening) => info!("WebDriver server listening on {}", listening.socket),
                Err(_) => panic!("Unable to start WebDriver HTTPD server"),
            }
        })
        .expect("Thread spawning failed");
}

/// Represents the current WebDriver session and holds relevant session state.
/// Currently, only 1 webview is supported per session.
/// So only there is only 1 InputState.
pub struct WebDriverSession {
    /// <https://www.w3.org/TR/webdriver2/#dfn-session-id>
    id: Uuid,

    /// <https://www.w3.org/TR/webdriver2/#dfn-current-top-level-browsing-context>
    webview_id: WebViewId,

    /// <https://www.w3.org/TR/webdriver2/#dfn-current-browsing-context>
    browsing_context_id: BrowsingContextId,

    /// <https://www.w3.org/TR/webdriver2/#dfn-window-handles>
    /// The spec said each browsing context has an associated window handle.
    /// Actually, each webview has a unique window handle.
    window_handles: HashMap<WebViewId, String>,

    timeouts: TimeoutsConfiguration,

    page_loading_strategy: PageLoadStrategy,

    strict_file_interactability: bool,

    user_prompt_handler: UserPromptHandler,

    /// <https://w3c.github.io/webdriver/#dfn-input-state-map>
    input_state_table: RefCell<HashMap<String, InputSourceState>>,

    /// <https://w3c.github.io/webdriver/#dfn-input-cancel-list>
    input_cancel_list: RefCell<Vec<(String, ActionItem)>>,
}

impl WebDriverSession {
    pub fn new(browsing_context_id: BrowsingContextId, webview_id: WebViewId) -> WebDriverSession {
        WebDriverSession {
            id: Uuid::new_v4(),
            webview_id,
            browsing_context_id,
            window_handles: HashMap::new(),
            timeouts: TimeoutsConfiguration::default(),
            page_loading_strategy: PageLoadStrategy::Normal,