< Summary

Information
Class: /home/runner/work/TauriQt/TauriQt/tauri-runtime-qt/src/bridge/webview.rs
Assembly: Default
File(s): /home/runner/work/TauriQt/TauriQt/tauri-runtime-qt/src/bridge/webview.rs
Line coverage
27%
Covered lines: 8
Uncovered lines: 21
Coverable lines: 29
Total lines: 101
Line coverage: 27.5%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

/home/runner/work/TauriQt/TauriQt/tauri-runtime-qt/src/bridge/webview.rs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik
 2// SPDX-License-Identifier: MIT OR Apache-2.0
 3
 4//! Webview declarations (owned by the webview worker).
 5//!
 6//! C++ translation units include the cxx-generated header for this bridge:
 7//! `#include "tauri-runtime-qt/src/bridge/webview.rs.h"`.
 8
 9#[cxx::bridge]
 10pub mod ffi {
 11    /// Live geometry of a webview widget, in **physical (device) pixels**.
 12    ///
 13    /// Qt reports widget geometry in device-independent pixels, so
 14    /// `qt_webview.cpp` multiplies by the widget's `devicePixelRatioF()` before
 15    /// filling this in. `ok == false` (all other fields zero) means the handle
 16    /// is unknown: Rust turns that into an `Err` instead of inventing numbers.
 17    struct QtWebviewGeometry {
 18        ok: bool,
 19        x: i32,
 20        y: i32,
 21        width: i32,
 22        height: i32,
 23    }
 24
 25    unsafe extern "C++" {
 26        include!("qt_webview.hpp");
 27
 28        // ---- webviews (qt_webview.cpp) ----
 2129        fn qt_webview_create(window_id: u64, url: &str) -> u64;
 30        /// Injects a tauri initialization script at document creation.
 18931        fn qt_webview_add_init_script(id: u64, script: &str, main_frame_only: bool);
 2132        fn qt_webview_native_handle(id: u64) -> u64;
 2133        fn qt_webview_navigate(id: u64, url: &str);
 6334        fn qt_webview_url(id: u64) -> String;
 035        fn qt_webview_reload(id: u64);
 036        fn qt_webview_eval(id: u64, script: &str);
 037        fn qt_webview_set_zoom(id: u64, factor: f64);
 038        fn qt_webview_set_background_color(id: u64, r: i32, g: i32, b: i32, a: i32);
 039        fn qt_webview_show(id: u64);
 040        fn qt_webview_hide(id: u64);
 041        fn qt_webview_open_devtools(id: u64);
 042        fn qt_webview_close_devtools(id: u64);
 043        fn qt_webview_is_devtools_open(id: u64) -> bool;
 044        fn qt_webview_print(id: u64);
 045        fn qt_webview_close(id: u64);
 46
 47        // ---- geometry / focus / reparenting ----
 48        /// Live widget geometry in physical pixels (see `QtWebviewGeometry`).
 049        fn qt_webview_geometry(id: u64) -> QtWebviewGeometry;
 50        /// Resizes the widget; `physical == true` means the caller passed
 51        /// physical pixels, which are divided by the widget's devicePixelRatio
 52        /// (`false` = Qt device-independent pixels, used as-is). `false` as a
 53        /// return value means the handle is unknown. The first positional call
 54        /// takes the view out of the window's layout (see `ops/webview.rs`).
 055        fn qt_webview_set_size(id: u64, width: i32, height: i32, physical: bool) -> bool;
 56        /// Moves the widget relative to its parent window; same unit rule as
 57        /// `qt_webview_set_size`.
 058        fn qt_webview_set_position(id: u64, x: i32, y: i32, physical: bool) -> bool;
 59        /// `QWebEngineView::setFocus()`.
 060        fn qt_webview_set_focus(id: u64) -> bool;
 61        /// Runs `script` and delivers the result as a JSON string to
 62        /// `qt_on_eval_result(request_id, result)`.
 063        fn qt_webview_eval_with_callback(id: u64, request_id: u64, script: &str) -> bool;
 64        /// Reparents the view into the window identified by the
 65        /// `qt_window_create` handle `window_native`.
 066        fn qt_webview_reparent(id: u64, window_native: u64) -> bool;
 67        /// Clears the browsing data Qt can clear (HTTP cache, cookies, visited
 68        /// links); see the C++ implementation for what cannot be cleared.
 069        fn qt_webview_clear_browsing_data(id: u64) -> bool;
 70    }
 71
 72    extern "Rust" {
 73        /// Result of a `QWebEnginePage::runJavaScript` started by
 74        /// `qt_webview_eval_with_callback`, as a JSON string (`null` for an
 75        /// undefined/unrepresentable value). Called on the Qt GUI thread;
 76        /// `request_id` is the id Rust allocated. Unknown/expired ids are
 77        /// dropped.
 78        fn qt_on_eval_result(request_id: u64, result: &str);
 79
 80        /// Diagnostic trigger: the first webview calls this once when its first
 81        /// page load finishes. Rust runs the `TAURIQT_EVAL_DEBUG` smoke test
 82        /// (`document.title = 'eval-ok'` through `eval_with_callback`) and does
 83        /// nothing when the environment variable is unset.
 84        fn qt_webview_on_first_load(webview_id: u64);
 85    }
 86}
 87
 88/// Delivers a `runJavaScript` result to the webview area.
 89///
 90/// cxx requires an `extern "Rust"` function to be defined in the module that
 91/// declares the bridge, so this stays a thin forwarder and the pending-request
 92/// registry lives with the rest of the webview logic in `crate::ops::webview`.
 093pub fn qt_on_eval_result(request_id: u64, result: &str) {
 094    crate::ops::webview::on_eval_result(request_id, result);
 095}
 96
 97/// `TAURIQT_EVAL_DEBUG` smoke-test trigger; see
 98/// `crate::ops::webview::debug_hook_first_load`.
 2199pub fn qt_webview_on_first_load(webview_id: u64) {
 21100    crate::ops::webview::debug_hook_first_load(webview_id);
 21101}

Methods/Properties

_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi17qt_webview_create
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi26qt_webview_add_init_script
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi24qt_webview_native_handle
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi19qt_webview_navigate
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi14qt_webview_url
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi17qt_webview_reload
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi15qt_webview_eval
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi19qt_webview_set_zoom
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi31qt_webview_set_background_color
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi15qt_webview_show
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi15qt_webview_hide
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi24qt_webview_open_devtools
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi25qt_webview_close_devtools
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi27qt_webview_is_devtools_open
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi16qt_webview_print
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi16qt_webview_close
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi19qt_webview_geometry
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi19qt_webview_set_size
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi23qt_webview_set_position
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi20qt_webview_set_focus
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi29qt_webview_eval_with_callback
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi19qt_webview_reparent
_RNvNtNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview3ffi30qt_webview_clear_browsing_data
_RNvNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview17qt_on_eval_result
_RNvNtNtCsdgr7Em4UC3i_16tauri_runtime_qt6bridge7webview24qt_webview_on_first_load