Permalink
Browse files

Add support for market:// urls

  • Loading branch information...
akshitkrnagpal committed Nov 2, 2018
1 parent da2d9b2 commit 7a209a23aa7accf41cdce130e0563c32c9940bfd
@@ -63,6 +63,8 @@ pub trait HostTrait {
fn on_load_ended(&self);
/// Page title has changed.
fn on_title_changed(&self, title: String);
/// Allow Navigation.
fn on_allow_navigation(&self, url: String) -> bool;
/// Page URL has changed.
fn on_url_changed(&self, url: String);
/// Back/forward state has changed.
@@ -364,8 +366,12 @@ impl ServoGlue {
let title = format!("{} - Servo", title);
self.callbacks.host_callbacks.on_title_changed(title);
},
EmbedderMsg::AllowNavigation(_url, response_chan) => {
if let Err(e) = response_chan.send(true) {
EmbedderMsg::AllowNavigation(url, response_chan) => {
let data: bool = self
.callbacks
.host_callbacks
.on_allow_navigation(url.to_string());
if let Err(e) = response_chan.send(data) {
warn!("Failed to send allow_navigation() response: {}", e);
};
},
@@ -35,6 +35,7 @@ pub struct CHostCallbacks {
pub on_load_started: extern "C" fn(),
pub on_load_ended: extern "C" fn(),
pub on_title_changed: extern "C" fn(title: *const c_char),
pub on_allow_navigation: extern "C" fn(url: *const c_char) -> bool,
pub on_url_changed: extern "C" fn(url: *const c_char),
pub on_history_changed: extern "C" fn(can_go_back: bool, can_go_forward: bool),
pub on_animating_changed: extern "C" fn(animating: bool),
@@ -302,6 +303,14 @@ impl HostTrait for HostCallbacks {
(self.0.on_title_changed)(title_ptr);
}
fn on_allow_navigation(&self, url: String) -> bool {
debug!("on_allow_navigation");
let url = CString::new(url).expect("Can't create string");
let url_ptr = url.as_ptr();
mem::forget(url);
(self.0.on_allow_navigation)(url_ptr)
}
fn on_url_changed(&self, url: String) {
debug!("on_url_changed");
let url = CString::new(url).expect("Can't create string");
@@ -395,6 +395,26 @@ impl HostTrait for HostCallbacks {
.unwrap();
}
fn on_allow_navigation(&self, url: String) -> bool {
debug!("on_allow_navigation");
let env = self.jvm.get_env().unwrap();
let s = match new_string(&env, &url) {
Ok(s) => s,
Err(_) => return false,
};
let s = JValue::from(JObject::from(s));
let allow = env.call_method(
self.callbacks.as_obj(),
"onAllowNavigation",
"(Ljava/lang/String;)Z",
&[s],
);
match allow {
Ok(allow) => return allow.z().unwrap(),
Err(_) => return true,
}
}
fn on_url_changed(&self, url: String) {
debug!("on_url_changed");
let env = self.jvm.get_env().unwrap();
@@ -20,6 +20,7 @@
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.util.Log;
import org.mozilla.servoview.ServoView;
import org.mozilla.servoview.Servo;
@@ -162,6 +163,19 @@ public void onHistoryChanged(boolean canGoBack, boolean canGoForward) {
mCanGoBack = canGoBack;
}
@Override
public boolean onAllowNavigation(String url) {
if (url.startsWith("market://")) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return false;
} catch (Exception e) {
Log.e("onAllowNavigation", e.toString());
}
}
return true;
}
public void onRedrawing(boolean redrawing) {
if (redrawing) {
mIdleText.setText("LOOP");
@@ -128,6 +128,8 @@ public void suspend(boolean suspended) {
}
public interface Client {
boolean onAllowNavigation(String url);
void onLoadStarted();
void onLoadEnded();
@@ -191,6 +193,10 @@ public void onAnimatingChanged(boolean animating) {
mRunCallback.inGLThread(() -> mGfxCb.animationStateChanged(animating));
}
public boolean onAllowNavigation(String url) {
return mClient.onAllowNavigation(url);
}
public void onLoadStarted() {
mRunCallback.inUIThread(() -> mClient.onLoadStarted());
}

0 comments on commit 7a209a2

Please sign in to comment.