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
44 changes: 44 additions & 0 deletions src/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,28 @@ impl<'a> MainPipe<'a> {
reload(&mut self.env, webview.as_obj())?;
}
}
WebViewMessage::GoForward => {
if let Some(webview) = get_webview(activity_id) {
go_forward(&mut self.env, webview.as_obj())?;
}
}
WebViewMessage::GoBack => {
if let Some(webview) = get_webview(activity_id) {
go_back(&mut self.env, webview.as_obj())?;
}
}
WebViewMessage::CanGoForward(tx) => {
if let Some(webview) = get_webview(activity_id) {
tx.send(can_go_forward(&mut self.env, webview.as_obj())?)
.unwrap();
}
}
WebViewMessage::CanGoBack(tx) => {
if let Some(webview) = get_webview(activity_id) {
tx.send(can_go_back(&mut self.env, webview.as_obj())?)
.unwrap();
}
}
WebViewMessage::GetCookies(tx, url) => {
if let Some(webview) = get_webview(activity_id) {
let url = self.env.new_string(url)?;
Expand Down Expand Up @@ -549,6 +571,24 @@ fn reload<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>) -> JniResult<()> {
Ok(())
}

fn go_forward<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>) -> JniResult<()> {
env.call_method(webview, "goForward", "()V", &[])?;
Ok(())
}

fn go_back<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>) -> JniResult<()> {
env.call_method(webview, "goBack", "()V", &[])?;
Ok(())
}

fn can_go_forward<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>) -> JniResult<bool> {
Ok(env.call_method(webview, "canGoForward", "()Z", &[])?.z()?)
}

fn can_go_back<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>) -> JniResult<bool> {
Ok(env.call_method(webview, "canGoBack", "()Z", &[])?.z()?)
}

fn set_background_color<'a>(
env: &mut JNIEnv<'a>,
webview: &JObject<'a>,
Expand All @@ -570,6 +610,10 @@ pub(crate) enum WebViewMessage {
LoadUrl(String, Option<http::HeaderMap>),
LoadHtml(String),
Reload,
GoForward,
GoBack,
CanGoForward(Sender<bool>),
CanGoBack(Sender<bool>),
ClearAllBrowsingData,
OnDestroy {
activity_id: ActivityId,
Expand Down
22 changes: 22 additions & 0 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,28 @@ impl InnerWebView {
Ok(())
}

pub fn go_forward(&self) -> Result<()> {
MainPipe::send(self.activity_id, WebViewMessage::GoForward);
Ok(())
}

pub fn go_back(&self) -> Result<()> {
MainPipe::send(self.activity_id, WebViewMessage::GoBack);
Ok(())
}

pub fn can_go_forward(&self) -> Result<bool> {
let (tx, rx) = bounded(1);
MainPipe::send(self.activity_id, WebViewMessage::CanGoForward(tx));
rx.recv_timeout(MAIN_PIPE_TIMEOUT).map_err(Into::into)
}

pub fn can_go_back(&self) -> Result<bool> {
let (tx, rx) = bounded(1);
MainPipe::send(self.activity_id, WebViewMessage::CanGoBack(tx));
rx.recv_timeout(MAIN_PIPE_TIMEOUT).map_err(Into::into)
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
MainPipe::send(self.activity_id, WebViewMessage::ClearAllBrowsingData);
Ok(())
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,24 @@ impl WebView {
self.webview.reload()
}

/// Go to the next page.
pub fn go_forward(&self) -> Result<()> {
self.webview.go_forward()
}

/// Go to the previous page.
pub fn go_back(&self) -> Result<()> {
self.webview.go_back()
}

pub fn can_go_forward(&self) -> Result<bool> {
self.webview.can_go_forward()
}

pub fn can_go_back(&self) -> Result<bool> {
self.webview.can_go_back()
}

/// Navigate to the specified url using the specified headers
pub fn load_url_with_headers(&self, url: &str, headers: http::HeaderMap) -> Result<()> {
self.webview.load_url_with_headers(url, headers)
Expand Down
18 changes: 18 additions & 0 deletions src/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,24 @@ impl InnerWebView {
Ok(())
}

pub fn go_forward(&self) -> Result<()> {
self.webview.go_forward();
Ok(())
}

pub fn go_back(&self) -> Result<()> {
self.webview.go_back();
Ok(())
}

pub fn can_go_forward(&self) -> Result<bool> {
Ok(self.webview.can_go_forward())
}

pub fn can_go_back(&self) -> Result<bool> {
Ok(self.webview.can_go_back())
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
if let Some(context) = self.webview.context() {
if let Some(data_manger) = context.website_data_manager() {
Expand Down
20 changes: 20 additions & 0 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,26 @@ impl InnerWebView {
unsafe { self.webview.Reload() }.map_err(Into::into)
}

pub fn go_forward(&self) -> Result<()> {
unsafe { self.webview.GoForward() }.map_err(Into::into)
}

pub fn go_back(&self) -> Result<()> {
unsafe { self.webview.GoBack() }.map_err(Into::into)
}

pub fn can_go_forward(&self) -> Result<bool> {
let mut can_go_forward = FALSE;
unsafe { self.webview.CanGoForward(&mut can_go_forward) }.map_err(Into::<Error>::into)?;
Ok(can_go_forward.into())
}

pub fn can_go_back(&self) -> Result<bool> {
let mut can_go_back = FALSE;
unsafe { self.webview.CanGoBack(&mut can_go_back) }.map_err(Into::<Error>::into)?;
Ok(can_go_back.into())
}

pub fn bounds(&self) -> Result<Rect> {
let mut bounds = Rect::default();
let mut rect = RECT::default();
Expand Down
18 changes: 18 additions & 0 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,24 @@ r#"Object.defineProperty(window, 'ipc', {
Ok(())
}

pub fn go_forward(&self) -> Result<()> {
unsafe { self.webview.goForward() };
Ok(())
}

pub fn go_back(&self) -> Result<()> {
unsafe { self.webview.goBack() };
Ok(())
}

pub fn can_go_forward(&self) -> Result<bool> {
Ok(unsafe { self.webview.canGoForward() })
}

pub fn can_go_back(&self) -> Result<bool> {
Ok(unsafe { self.webview.canGoBack() })
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
unsafe {
let config = self.webview.configuration();
Expand Down