8000 android: Add setting to control experimental web platform features. · servo/servo@fc4be3f · GitHub
[go: up one dir, main page]

Skip to content

Commit fc4be3f

Browse files
committed
android: Add setting to control experimental web platform features.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
1 parent 70bc925 commit fc4be3f

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

ports/servoshell/egl/android.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ use raw_window_handle::{
2222
};
2323
use servo::{
2424
AlertResponse, EventLoopWaker, LoadStatus, MediaSessionActionType, MouseButton,
25-
PermissionRequest, SimpleDialog, WebView,
25+
PermissionRequest, PrefValue, SimpleDialog, WebView,
2626
};
2727
use simpleservo::{APP, DeviceIntRect, InitOptions, InputMethodType, MediaSessionPlaybackState};
2828

2929
use super::app_state::{Coordinates, RunningAppState};
3030
use super::host_trait::HostTrait;
31+
use crate::prefs::EXPERIMENTAL_PREFS;
3132

3233
struct HostCallbacks {
3334
callbacks: GlobalRef,
@@ -147,6 +148,20 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_init<'local>(
147148
};
148149
}
149150

151+
#[unsafe(no_mangle)]
152+
pub extern "C" fn Java_org_servo_servoview_JNIServo_setExperimentalMode<'local>(
153+
mut env: JNIEnv<'local>,
154+
_class: JClass<'local>,
155+
enable: jboolean,
156+
) {
157+
debug!("setExperimentalMode {enable}");
158+
call(&mut env, |s| {
159+
for pref in EXPERIMENTAL_PREFS {
160+
s.servo().set_preference(pref, PrefValue::Bool(enable != 0));
161+
}
162+
});
163+
}
164+
150165
#[unsafe(no_mangle)]
151166
pub extern "C" fn Java_org_servo_servoview_JNIServo_requestShutdown<'local>(
152167
mut env: JNIEnv<'local>,
@@ -853,6 +868,9 @@ fn get_options<'local>(
853868
let url = get_field_as_string(env, opts, "url")?;
854869
let log_str = get_field_as_string(env, opts, "logStr")?;
855870
let gst_debug_str = get_field_as_string(env, opts, "gstDebugStr")?;
871+
let experimental_mode = get_non_null_field(env, opts, "experimentalMode", "Z")?
872+
.z()
873+
.map_err(|_| "experimentalMode not a boolean")?;
856874
let density = get_non_null_field(env, opts, "density", "F")?
857875
.f()
858876
.map_err(|_| "density not a float")? as f32;
@@ -869,15 +887,19 @@ fn get_options<'local>(
869887
.map_err(|_| "coordinates is not an object")?;
870888
let coordinates = jni_coords_to_rust_coords(env, &coordinates)?;
871889

872-
let args = match args {
890+
let mut args: Vec<String> = match args {
873891
Some(args) => serde_json::from_str(&args)
874892
.map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?,
875893
None => None,
876-
};
894+
}
895+
.unwrap_or_default();
896+
if experimental_mode {
897+
args.push("--enable-experimental-web-platform-features".to_owned());
898+
}
877899

878900
let (display_handle, window_handle) = display_and_window_handle(env, surface);
879901
let opts = InitOptions {
880-
args: args.unwrap_or(vec![]),
902+
args,
881903
url,
882904
coordinates,
883905
density,

support/android/apk/servoapp/src/main/java/org/servo/servoshell/MainActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public class MainActivity extends Activity implements Servo.Client {
5050
class Settings {
5151
Settings(SharedPreferences preferences) {
5252
showAnimatingIndicator = preferences.getBoolean("animating_indicator", false);
53+
experimental = preferences.getBoolean("experimental", false);
5354
}
5455

5556
boolean showAnimatingIndicator;
57+
boolean experimental;
5658
}
5759
Settings mSettings;
5860

@@ -95,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) {
9597
Intent intent = getIntent();
9698
String args = intent.getStringExtra("servoargs");
9799
String log = intent.getStringExtra("servolog");
98-
mServoView.setServoArgs(args, log);
100+
mServoView.setServoArgs(args, log, mSettings.experimental);
99101

100102
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
101103
mServoView.loadUri(intent.getData().toString());
@@ -319,6 +321,10 @@ public void onAnimatingIndicatorPrefChanged(boolean value) {
319321
}
320322
}
321323

324+
public void onExperimentalPrefChanged(boolean value) {
325+
mServoView.setExperimentalMode(value);
326+
}
327+
322328
public void updateSettingsIfNecessary(boolean force) {
323329
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
324330
Settings updated = new Settings(preferences);
@@ -327,6 +333,10 @@ public void updateSettingsIfNecessary(boolean force) {
327333
onAnimatingIndicatorPrefChanged(updated.showAnimatingIndicator);
328334
}
329335

336+
if (force || updated.experimental != mSettings.experimental) {
337+
onExperimentalPrefChanged(updated.experimental);
338+
}
339+
330340
mSettings = updated;
331341
}
332342
}

support/android/apk/servoapp/src/main/res/xml/preferences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44

5+
<SwitchPreferenceCompat
6+
android:key="experimental"
7+
android:defaultValue="false"
8+
android:title="Enable experimental web platform features"/>
9+
510
<SwitchPreferenceCompat
611
android:key="animating_indicator"
712
android:defaultValue="false"

support/android/apk/servoview/src/main/java/org/servo/servoview/JNIServo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class JNIServo {
6767

6868
public native void mediaSessionAction(int action);
6969

70+
public native void setExperimentalMode(boolean enable);
71+
7072
public static class ServoOptions {
7173
public String args;
7274
public String url;
@@ -77,6 +79,7 @@ public static class ServoOptions {
7779
public String logStr;
7880
public String gstDebugStr;
7981
public boolean enableLogs = false;
82+
public boolean experimentalMode = false;
8083
}
8184

8285
public static class ServoCoordinates {

support/android/apk/servoview/src/main/java/org/servo/servoview/Servo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public void mediaSessionAction(int action) {
167167
mRunCallback.inGLThread(() -> mJNI.mediaSessionAction(action));
168168
}
169169

170+
public void setExperimentalMode(boolean enable) {
171+
mRunCallback.inGLThread(() -> mJNI.setExperimentalMode(enable));
172+
}
173+
170174
public interface Client {
171175
void onAlert(String message);
172176

support/android/apk/servoview/src/main/java/org/servo/servoview/ServoView.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class ServoView extends SurfaceView
5959
private ScaleGestureDetector mScaleGestureDetector;
6060
private OverScroller mScroller;
6161

62+
private boolean mExperimentalMode;
6263
private boolean mZooming;
6364
private float mZoomFactor = 1;
6465
private boolean mRedrawing;
@@ -95,9 +96,10 @@ public void setClient(Client client) {
9596
mClient = client;
9697
}
9798

98-
public void setServoArgs(String args, String log) {
99+
public void setServoArgs(String args, String log, boolean experimentalMode) {
99100
mServoArgs = args;
100101
mServoLog = log;
102+
mExperimentalMode = experimentalMode;
101103
}
102104

103105
// RunCallback
@@ -361,6 +363,12 @@ public void mediaSessionAction(int action) {
361363
mServo.mediaSessionAction(action);
362364
}
363365

366+
public void setExperimentalMode(boolean enable) {
367+
if (mServo != null) {
368+
mServo.setExperimentalMode(enable);
369+
}
370+
}
371+
364372
class GLThread extends Thread implements SurfaceHolder.Callback {
365373
private Activity mActivity;
366374
private ServoView mServoView;
@@ -383,6 +391,7 @@ public void surfaceCreated(SurfaceHolder holder) {
383391
options.coordinates = coords;
384392
options.enableLogs = true;
385393
options.enableSubpixelTextAntialiasing = true;
394+
options.experimentalMode = mServoView.mExperimentalMode;
386395

387396
DisplayMetrics metrics = new DisplayMetrics();
388397
mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

0 commit comments

Comments
 (0)
0