mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Add support for market:// urls
This commit is contained in:
parent
a2b195aff8
commit
027514c3e6
6 changed files with 60 additions and 2 deletions
|
@ -350,6 +350,9 @@ impl HostTrait for HostCallbacks {
|
||||||
fn on_load_started(&self) {}
|
fn on_load_started(&self) {}
|
||||||
fn on_load_ended(&self) {}
|
fn on_load_ended(&self) {}
|
||||||
fn on_title_changed(&self, _title: String) {}
|
fn on_title_changed(&self, _title: String) {}
|
||||||
|
fn on_allow_navigation(&self, _url: String) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
fn on_url_changed(&self, url: String) {
|
fn on_url_changed(&self, url: String) {
|
||||||
if let Ok(cstr) = CString::new(url.as_str()) {
|
if let Ok(cstr) = CString::new(url.as_str()) {
|
||||||
if let Some(url_update) = self.url_update.0 {
|
if let Some(url_update) = self.url_update.0 {
|
||||||
|
|
|
@ -97,6 +97,8 @@ pub trait HostTrait {
|
||||||
fn on_load_ended(&self);
|
fn on_load_ended(&self);
|
||||||
/// Page title has changed.
|
/// Page title has changed.
|
||||||
fn on_title_changed(&self, title: String);
|
fn on_title_changed(&self, title: String);
|
||||||
|
/// Allow Navigation.
|
||||||
|
fn on_allow_navigation(&self, url: String) -> bool;
|
||||||
/// Page URL has changed.
|
/// Page URL has changed.
|
||||||
fn on_url_changed(&self, url: String);
|
fn on_url_changed(&self, url: String);
|
||||||
/// Back/forward state has changed.
|
/// Back/forward state has changed.
|
||||||
|
@ -474,9 +476,13 @@ impl ServoGlue {
|
||||||
let title = format!("{} - Servo", title);
|
let title = format!("{} - Servo", title);
|
||||||
self.callbacks.host_callbacks.on_title_changed(title);
|
self.callbacks.host_callbacks.on_title_changed(title);
|
||||||
},
|
},
|
||||||
EmbedderMsg::AllowNavigationRequest(pipeline_id, _url) => {
|
EmbedderMsg::AllowNavigationRequest(pipeline_id, url) => {
|
||||||
if let Some(_browser_id) = browser_id {
|
if let Some(_browser_id) = browser_id {
|
||||||
let window_event = WindowEvent::AllowNavigationResponse(pipeline_id, true);
|
let data: bool = self
|
||||||
|
.callbacks
|
||||||
|
.host_callbacks
|
||||||
|
.on_allow_navigation(url.to_string());
|
||||||
|
let window_event = WindowEvent::AllowNavigationResponse(pipeline_id, data);
|
||||||
let _ = self.process_event(window_event);
|
let _ = self.process_event(window_event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,6 +37,7 @@ pub struct CHostCallbacks {
|
||||||
pub on_load_started: extern "C" fn(),
|
pub on_load_started: extern "C" fn(),
|
||||||
pub on_load_ended: extern "C" fn(),
|
pub on_load_ended: extern "C" fn(),
|
||||||
pub on_title_changed: extern "C" fn(title: *const c_char),
|
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_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_history_changed: extern "C" fn(can_go_back: bool, can_go_forward: bool),
|
||||||
pub on_animating_changed: extern "C" fn(animating: bool),
|
pub on_animating_changed: extern "C" fn(animating: bool),
|
||||||
|
@ -322,6 +323,14 @@ impl HostTrait for HostCallbacks {
|
||||||
(self.0.on_title_changed)(title_ptr);
|
(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) {
|
fn on_url_changed(&self, url: String) {
|
||||||
debug!("on_url_changed");
|
debug!("on_url_changed");
|
||||||
let url = CString::new(url).expect("Can't create string");
|
let url = CString::new(url).expect("Can't create string");
|
||||||
|
|
|
@ -411,6 +411,26 @@ impl HostTrait for HostCallbacks {
|
||||||
.unwrap();
|
.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) {
|
fn on_url_changed(&self, url: String) {
|
||||||
debug!("on_url_changed");
|
debug!("on_url_changed");
|
||||||
let env = self.jvm.get_env().unwrap();
|
let env = self.jvm.get_env().unwrap();
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.mozilla.servoview.ServoView;
|
import org.mozilla.servoview.ServoView;
|
||||||
import org.mozilla.servoview.Servo;
|
import org.mozilla.servoview.Servo;
|
||||||
|
@ -162,6 +163,19 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
mCanGoBack = canGoBack;
|
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) {
|
public void onRedrawing(boolean redrawing) {
|
||||||
if (redrawing) {
|
if (redrawing) {
|
||||||
mIdleText.setText("LOOP");
|
mIdleText.setText("LOOP");
|
||||||
|
|
|
@ -169,6 +169,8 @@ public class Servo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Client {
|
public interface Client {
|
||||||
|
boolean onAllowNavigation(String url);
|
||||||
|
|
||||||
void onLoadStarted();
|
void onLoadStarted();
|
||||||
|
|
||||||
void onLoadEnded();
|
void onLoadEnded();
|
||||||
|
@ -234,6 +236,10 @@ public class Servo {
|
||||||
mRunCallback.inGLThread(() -> mGfxCb.animationStateChanged(animating));
|
mRunCallback.inGLThread(() -> mGfxCb.animationStateChanged(animating));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onAllowNavigation(String url) {
|
||||||
|
return mClient.onAllowNavigation(url);
|
||||||
|
}
|
||||||
|
|
||||||
public void onLoadStarted() {
|
public void onLoadStarted() {
|
||||||
mRunCallback.inUIThread(() -> mClient.onLoadStarted());
|
mRunCallback.inUIThread(() -> mClient.onLoadStarted());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue