Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
[package]
name = "tauri-runtime-cef"
version = "0.1.0"
description = "CEF runtime for Tauri, ported from tauri feat/cef branch onto published crates."
authors = ["Tauri Programme within The Commons Conservancy", "byeongsu-hong"]
homepage = "https://github.com/SableClient/tauri-runtime-cef"
repository = "https://github.com/SableClient/tauri-runtime-cef"
categories = ["gui"]
license = "Apache-2.0 OR MIT"
edition = "2024"
rust-version = "1.88"
# lets `tauri-build` detect the CEF runtime through the `DEP_TAURI_RUNTIME_CEF_RUNTIME` env var
links = "tauri_runtime_cef"
authors.workspace = true
homepage.workspace = true
repository.workspace = true
categories.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true

[[test]]
name = "macos-application-bootstrap"
harness = false

[dependencies]
tauri = { workspace = true }
tauri-macros = { workspace = true }
base64 = "0.22"
cef = { version = "=151.8.1", features = ["build-util", "linux-x11"] }
# Not actually used directly, just locking it.
cef = { version = "=150.2.1", features = ["build-util", "linux-x11"] }
# Not actually used directly, just locking it.
cef-dll-sys = { version = "=150.2.1", default-features = false }
cef-dll-sys = { version = "=151.8.1", default-features = false }
dirs = "6"
dioxus-debug-cell = "0.1"
http = "1"
Expand All @@ -26,12 +32,12 @@ raw-window-handle = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
tauri-runtime = "2.11.2"
tauri-utils = { version = "2.9.2", features = [
tauri-runtime = { version = "2.11.2", path = "../tauri-runtime" }
tauri-utils = { version = "2.9.2", path = "../tauri-utils", features = [
"html-manipulation",
] }
url = "2"
winit = "0.31.0-beta.2"
winit = "=0.31.0-beta.2"

[target."cfg(windows)".dependencies]
softbuffer = { version = "0.4", default-features = false }
Expand All @@ -47,7 +53,6 @@ windows = { version = "0.61", features = [
] }

[target."cfg(target_os = \"macos\")".dependencies]
dispatch2 = "0.3"
objc2 = "0.6"
objc2-application-services = { version = "0.3", default-features = false, features = [
"HIServices",
Expand Down Expand Up @@ -78,6 +83,10 @@ objc2-quartz-core = { version = "0.3", default-features = false, features = [
] }
objc2-foundation = { version = "0.3", default-features = false, features = [
"NSArray",
# NSDate gates the performSelector:withObject:afterDelay: binding used to
# restore the traffic light position after an appearance change.
"NSDate",
"NSNotification",
"NSObject",
"NSValue",
"NSRunLoop",
Expand All @@ -95,10 +104,13 @@ x11-dl = "2.21"

[features]
default = ["sandbox"]
devtools = []
macos-private-api = ["tauri-runtime/macos-private-api"]
# also enables devtools on `tauri` so the feature only needs to be enabled on this crate
devtools = ["tauri-runtime/devtools", "tauri/devtools"]
# also enables macos-private-api on `tauri` so the feature only needs to be enabled on this crate
macos-private-api = [
"tauri-runtime/macos-private-api",
"tauri/macos-private-api",
]
sandbox = ["cef/sandbox"]

[dev-dependencies]
tauri = { version = "2", default-features = false, features = ["test"] }
tempfile = "3"
# exposes the extension traits for `tauri::webview::WebviewBuilder`
unstable = ["tauri/unstable"]
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

fn main() {
println!("cargo:rerun-if-changed=build.rs");
// exposed to the build scripts of crates depending on this one as `DEP_TAURI_RUNTIME_CEF_RUNTIME`,
// which is how `tauri-build` detects that the application uses the CEF runtime.
println!("cargo:runtime=cef");
}
22 changes: 9 additions & 13 deletions src/cef_impl/client/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::webview::INITIAL_LOAD_URL;

wrap_display_handler! {
pub struct TauriCefDisplayHandler {
document_title_changed_handler: Option<Arc<crate::compat::DocumentTitleChangedHandler>>,
address_changed_handler: Option<Arc<crate::compat::AddressChangedHandler>>,
document_title_changed_handler: Option<Arc<tauri_runtime::webview::DocumentTitleChangedHandler>>,
frame_event_handler: Option<Arc<crate::FrameEventHandler>>,
}

impl DisplayHandler {
Expand All @@ -32,19 +32,10 @@ wrap_display_handler! {

fn on_address_change(
&self,
_browser: Option<&mut Browser>,
browser: Option<&mut Browser>,
frame: Option<&mut Frame>,
url: Option<&CefString>,
) {
// Only fire for main frame URL changes (matches on_before_browse behavior).
if let Some(frame) = frame
&& frame.is_main() == 0
{
return;
}
let Some(handler) = &self.address_changed_handler else {
return;
};
let Some(url) = url else {
return;
};
Expand All @@ -55,7 +46,12 @@ wrap_display_handler! {
}

if let Ok(url) = url::Url::parse(&url) {
handler(&url);
crate::frame::emit_frame_event(
&self.frame_event_handler,
browser,
frame,
crate::FrameEventKind::AddressChanged { url },
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cef_impl/client/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cef::*;

wrap_download_handler! {
pub struct TauriCefDownloadHandler {
download_handler: Arc<crate::compat::DownloadHandler>,
download_handler: Arc<tauri_runtime::webview::DownloadHandler>,
}

impl DownloadHandler {
Expand Down
9 changes: 7 additions & 2 deletions src/cef_impl/client/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use tauri_runtime::{
};
use url::Url;

use crate::runtime::{Message, RuntimeContext};
use crate::{
macros::wrap_with_args,
runtime::{Message, RuntimeContext},
};

const DRAG_DROP_BRIDGE_PATH: &str = "/__tauri_cef_drag_drop__";

Expand Down Expand Up @@ -206,7 +209,9 @@ pub(crate) fn event_from_script_event(
}
}

wrap_resource_request_handler! {
wrap_with_args! {
wrap_resource_request_handler => WebDragDropResourceRequestHandlerArgs;

pub(crate) struct WebDragDropResourceRequestHandler<T: UserEvent> {
context: RuntimeContext<T>,
window_id: WindowId,
Expand Down
37 changes: 37 additions & 0 deletions src/cef_impl/client/frame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::sync::Arc;

use cef::*;

use crate::{FrameEventHandler, FrameEventKind, frame::emit_frame_event};

wrap_frame_handler! {
pub struct TauriCefFrameHandler {
handler: Option<Arc<FrameEventHandler>>,
}

impl FrameHandler {
fn on_frame_created(&self, browser: Option<&mut Browser>, frame: Option<&mut Frame>) {
emit_frame_event(&self.handler, browser, frame, FrameEventKind::Created);
}

fn on_frame_attached(&self, browser: Option<&mut Browser>, frame: Option<&mut Frame>, _reattached: ::std::os::raw::c_int) {
emit_frame_event(&self.handler, browser, frame, FrameEventKind::Attached);
}

fn on_frame_detached(&self, browser: Option<&mut Browser>, frame: Option<&mut Frame>) {
emit_frame_event(&self.handler, browser, frame, FrameEventKind::Detached);
}

fn on_frame_destroyed(&self, browser: Option<&mut Browser>, frame: Option<&mut Frame>) {
emit_frame_event(&self.handler, browser, frame, FrameEventKind::Destroyed);
}

fn on_main_frame_changed(&self, browser: Option<&mut Browser>, _old_frame: Option<&mut Frame>, new_frame: Option<&mut Frame>) {
emit_frame_event(&self.handler, browser, new_frame, FrameEventKind::MainFrameChanged);
}
}
}
Loading