//! The web engine: WebKitGTK 6.0 views in the GTK 4 window (D-032, D-033, D-035). //! //! Everything WebKit tells the browser arrives as signals on the main thread. The signal handlers in `host.rs` only //! turn them into `Event`s on the `Hub` queue (they never touch the `App`, which may be borrowed while WebKit emits //! a signal synchronously); `App::handle_event` handles them from a GLib idle right after (`app::pump`). //! //! The rest of Nacre sees only the types here: a Nacre-owned `ViewId` per web view (D-041), `View` (a handle with //! the page actions), and engine-neutral payloads that hold the WebKit request object the answer needs. The //! `ViewId ↔ WebView` map lives in `host.rs` and nowhere else. pub mod host; pub mod view; use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; use url::Url; use webkit::prelude::*; pub use host::Engine; pub use view::View; /// A view's back/forward list, kept while a tab has no view (unloaded, or showing one of Nacre's pages). pub use webkit::WebViewSessionState as HistoryState; use crate::adblock::AdBlocker; use crate::inject::PageMessage; pub use crate::net::policy::HubConfig; use crate::util; /// A web view's id. The same number as the tab id it was made for (`App::new_tab_id`), so tabs and views never /// share a number by accident; pop-ups take a fresh one from the same counter. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ViewId(pub u64); /// What `evaluate_javascript` gives back: the completion value as JSON (`undefined` and unserializable values are /// `Null`). pub type JsValue = serde_json::Value; /// Where a page load is. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum LoadState { /// The request went out (WebKit `Started`). Started, /// The first bytes arrived and the new document replaced the old one (WebKit `Committed`). Committed, /// Done (WebKit `Finished`, also after a failure). Complete, } pub enum Event { UrlChanged(ViewId, Url), TitleChanged(ViewId, Option), /// The link under the pointer (shown at the bottom left), or none. StatusText(ViewId, Option), Load(ViewId, LoadState), /// WebKit's estimated load progress, 0..1. Progress(ViewId, f64), Favicon(ViewId), /// Back/forward list: entries and the index of the current one. History(ViewId, Vec, usize), /// The page asked to close (`window.close()`). Closed(ViewId), /// The web process died (crash, memory limit). Crashed(ViewId, String), /// WebKit's `is-web-process-responsive` changed (false: the page's process didn't answer in time). Responsive(ViewId, bool), Fullscreen(ViewId, bool), /// A main-frame navigation waits for `NavigationRequest::allow`/`deny`. Navigation(ViewId, NavigationRequest), /// A response WebKit can't show, or one the server marked as an attachment: Nacre downloads it itself. The /// file name the server suggested, if any. Download(ViewId, Url, Option), /// A download only WebKit can make (`blob:`, `data:`): it waits for `WebDownload::save_to`. WebDownload(Option, WebDownload), /// The page's certificate can't be trusted: Nacre shows its warning. CertError(ViewId, CertError), /// A load failed (not a cancel): url, error text. LoadFailed(ViewId, String, String), /// A pop-up (`window.open`, target=_blank): its view, already made as a related view of the opener, and the /// address it will load (none for `about:blank`-style opens). /// A page opened a window: opener, the new view, its address, and whether a click or key press opened it. CreateNew(ViewId, View, Option, bool), /// A link clicked with the middle button or Ctrl: open it in a new tab (true: in front). OpenLink(ViewId, Url, bool), Permission(ViewId, crate::store::permissions::Kind, PermissionAsk), Auth(ViewId, AuthRequest), Control(ViewId, Control), Notification(Option, Notification), Page(ViewId, PageMessage), /// Find in page: how many matches the last search or step found (0: none). Find(ViewId, u32), /// WebKit's `is-playing-audio` changed. Audio(ViewId, bool), /// A cookie was added, changed or deleted. CookiesChanged, /// What a host keeps (`Engine::site_data`). SiteData(String, SiteData), } /// Cookies and stored data of one site, for the site info flyout. #[derive(Clone, Debug, Default)] pub struct SiteData { /// Cookies the page's address gets. pub cookies: usize, /// Kinds of stored data under the host's name ("local storage", …). pub stored: Vec<&'static str>, } /// A user style sheet (`store::scripts`), added at author level so it acts like the page's own last `