Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge latest Servo-related changes (#927)
Browse files Browse the repository at this point in the history
* Only show servo button for few websites (#632)

* Make it obvious to which engine we're switching to (#659)

* Less naive engine switch mechanism (#674)

* Servo update

* GeckoView API udpate

* Servo version update
  • Loading branch information
paulrouget authored and MortimerGoro committed Jan 18, 2019
1 parent a7a3472 commit ad0b9a1
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class State {
private Deque<Integer> mPrivateSessionsStack;
private GeckoSession.PermissionDelegate mPermissionDelegate;
private int mPreviousSessionId = SessionStore.NO_SESSION_ID;
private int mPreviousGeckoSessionId = SessionStore.NO_SESSION_ID;
private String mRegion;
private Context mContext;
private SharedPreferences mPrefs;
Expand Down Expand Up @@ -638,13 +639,25 @@ public void toggleServo() {
return;
}

boolean was_servo = isInstanceOfServoSession(mCurrentSession);
String uri = getCurrentUri();
SessionStore.SessionSettings settings = new SessionStore.SessionSettings();
settings.servo = !was_servo;
int id = createSession(settings);
setCurrentSession(id);
loadUri(uri);
Log.v("servo", "toggleServo");

if (!isInstanceOfServoSession(mCurrentSession)) {
if (mPreviousGeckoSessionId == SessionStore.NO_SESSION_ID) {
mPreviousGeckoSessionId = getCurrentSessionId();
String uri = getCurrentUri();
SessionStore.SessionSettings settings = new SessionStore.SessionSettings();
settings.servo = true;
int id = createSession(settings);
setCurrentSession(id);
loadUri(uri);
} else {
Log.e(LOGTAG, "Multiple Servo sessions not supported yet.");
}
} else {
removeSession(getCurrentSessionId());
setCurrentSession(mPreviousGeckoSessionId);
mPreviousGeckoSessionId = SessionStore.NO_SESSION_ID;
}
}

public boolean isInFullScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
import org.mozilla.vrbrowser.utils.AnimationHelper;
import org.mozilla.vrbrowser.utils.UrlUtils;
import org.mozilla.vrbrowser.utils.ServoUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -558,8 +559,22 @@ public void showVoiceSearch() {
}

public void updateServoButton() {
if (SettingsStore.getInstance(mAppContext).isServoEnabled()) {
// We show the Servo button if:
// 1. the current session is using Servo. No matter what, we need the toggle button to go back to Gecko.
// 2. Or, if the pref is enabled and the current url is white listed.
boolean show = false;
boolean isServoSession = false;
GeckoSession currentSession = SessionStore.get().getCurrentSession();
if (currentSession != null) {
String currentUri = SessionStore.get().getCurrentUri();
boolean isPrefEnabled = SettingsStore.getInstance(mAppContext).isServoEnabled();
boolean isUrlWhiteListed = ServoUtils.isUrlInServoWhiteList(mAppContext, currentUri);
isServoSession = ServoUtils.isInstanceOfServoSession(currentSession);
show = isServoSession || (isPrefEnabled && isUrlWhiteListed);
}
if (show) {
mServoButton.setVisibility(View.VISIBLE);
mServoButton.setImageResource(isServoSession ? R.drawable.ic_icon_gecko : R.drawable.ic_icon_servo);
} else {
mServoButton.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -605,6 +620,7 @@ public void onLocationChange(GeckoSession session, String url) {
mURLBar.setURL(url);
mReloadButton.setEnabled(true);
}
updateServoButton();
}

@Override
Expand Down
32 changes: 27 additions & 5 deletions app/src/common/shared/org/mozilla/vrbrowser/utils/ServoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import org.mozilla.geckoview.GeckoSession;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ServoUtils {
private static final String CLASSNAME = "org.mozilla.servo.ServoSession";
private static final String SESSION_CLASSNAME = "org.mozilla.servo.ServoSession";
private static final String WHITELIST_CLASSNAME = "org.mozilla.servo.ServoWhiteList";
private static final String LOGTAG = "ServoUtils";
private static Object mServoWhiteList = null;

public static boolean isServoAvailable() {
try {
Class.forName(CLASSNAME);
Class.forName(SESSION_CLASSNAME);
return true;
} catch (ClassNotFoundException e) {
return false;
Expand All @@ -22,20 +25,39 @@ public static boolean isServoAvailable() {

public static boolean isInstanceOfServoSession(Object obj) {
try {
return Class.forName(CLASSNAME).isInstance(obj);
return Class.forName(SESSION_CLASSNAME).isInstance(obj);
} catch (ClassNotFoundException e) {
return false;
}
}

public static GeckoSession createServoSession(Context context) {
try {
Class servoClass = Class.forName(CLASSNAME);
Constructor<?> constructor = servoClass.getConstructor(Context.class);
Class clazz = Class.forName(SESSION_CLASSNAME);
Constructor<?> constructor = clazz.getConstructor(Context.class);
return (GeckoSession) constructor.newInstance(context);
} catch (Exception e) {
Log.e(LOGTAG, "Can't load or instanciate ServoSession: " + e);
return null;
}
}

public static boolean isUrlInServoWhiteList(Context context, String url) {
if (isServoAvailable()) {
try {
Class clazz = Class.forName(WHITELIST_CLASSNAME);
if (mServoWhiteList == null) {
Constructor<?> constructor = clazz.getConstructor(Context.class);
mServoWhiteList = constructor.newInstance(context);
}
Method isAllowed = clazz.getMethod("isAllowed", String.class);
return (boolean) isAllowed.invoke(mServoWhiteList, url);
} catch (Exception e) {
Log.e(LOGTAG, "Failed to call ServoWhiteList::isAllowed: " + e);
return false;
}
} else {
return false;
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_icon_gecko.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="200.0"
android:viewportWidth="200.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M 142.905 94.201 C 145.538 94.201 147.722 95.068 149.455 96.801 C 151.188 98.541 152.055 100.784 152.055 103.531 L 152.055 146.411 C 152.055 149.278 151.098 151.491 149.185 153.051 C 136.632 163.451 121.982 168.651 105.235 168.651 C 92.435 168.651 80.745 165.484 70.165 159.151 C 59.578 152.811 51.235 144.138 45.135 133.131 C 39.035 122.131 35.985 109.991 35.985 96.711 C 35.985 83.558 39.035 71.511 45.135 60.571 C 51.235 49.624 59.578 40.951 70.165 34.551 C 80.745 28.151 92.435 24.951 105.235 24.951 C 114.322 24.951 122.185 26.148 128.825 28.541 C 135.465 30.934 142.192 34.881 149.005 40.381 C 150.445 41.461 151.402 42.568 151.875 43.701 C 152.355 44.841 152.595 46.188 152.595 47.741 C 152.595 50.134 151.728 52.108 149.995 53.661 C 148.262 55.214 146.198 55.991 143.805 55.991 C 141.652 55.991 139.618 55.214 137.705 53.661 C 132.805 49.474 128.022 46.454 123.355 44.601 C 118.688 42.748 112.648 41.821 105.235 41.821 C 95.908 41.821 87.328 44.271 79.495 49.171 C 71.662 54.078 65.442 60.748 60.835 69.181 C 56.228 77.608 53.925 86.784 53.925 96.711 C 53.925 106.758 56.228 115.968 60.835 124.341 C 65.442 132.714 71.662 139.354 79.495 144.261 C 87.328 149.161 95.908 151.611 105.235 151.611 C 115.282 151.611 124.908 148.621 134.115 142.641 L 134.115 110.711 L 109.365 110.711 C 106.612 110.711 104.368 109.934 102.635 108.381 C 100.902 106.821 100.035 104.848 100.035 102.461 C 100.035 100.068 100.902 98.094 102.635 96.541 C 104.368 94.981 106.612 94.201 109.365 94.201 L 142.905 94.201 Z"/>
</vector>
Binary file removed app/src/main/res/drawable/ic_icon_servo.png
Binary file not shown.
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_icon_servo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="20dp" android:viewportHeight="200.0"
android:viewportWidth="200.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M 97.42 26.252 C 107.707 26.252 116.38 28.345 123.44 32.532 C 130.493 36.719 136.473 42.699 141.38 50.472 C 142.813 52.745 143.53 54.899 143.53 56.932 C 143.53 59.565 142.333 61.719 139.94 63.392 C 138.627 64.232 137.073 64.652 135.28 64.652 C 133.487 64.652 131.81 64.202 130.25 63.302 C 128.697 62.402 127.503 61.175 126.67 59.622 C 123.437 54.242 119.4 50.145 114.56 47.332 C 109.713 44.525 103.583 43.122 96.17 43.122 C 87.077 43.122 79.72 44.885 74.1 48.412 C 68.48 51.939 65.67 57.052 65.67 63.752 C 65.67 69.972 68.18 75.175 73.2 79.362 C 78.227 83.549 87.197 86.299 100.11 87.612 C 114.463 89.045 125.587 93.382 133.48 100.622 C 141.373 107.855 145.32 117.392 145.32 129.232 C 145.32 137.845 142.99 145.232 138.33 151.392 C 133.663 157.545 127.473 162.149 119.76 165.202 C 112.047 168.249 103.763 169.772 94.91 169.772 C 83.31 169.772 72.757 167.142 63.25 161.882 C 53.737 156.622 47.187 149.745 43.6 141.252 C 43.007 139.819 42.71 138.622 42.71 137.662 C 42.71 135.869 43.367 134.285 44.68 132.912 C 45.993 131.532 47.787 130.605 50.06 130.132 C 50.42 130.012 51.02 129.952 51.86 129.952 C 53.773 129.952 55.597 130.519 57.33 131.652 C 59.063 132.792 60.347 134.319 61.18 136.232 C 63.333 140.892 67.58 144.839 73.92 148.072 C 80.26 151.299 87.257 152.912 94.91 152.912 C 103.883 152.912 111.48 150.849 117.7 146.722 C 123.913 142.595 127.02 136.945 127.02 129.772 C 127.02 122.952 124.39 117.122 119.13 112.282 C 113.87 107.435 105.857 104.475 95.09 103.402 C 80.263 101.962 68.603 97.625 60.11 90.392 C 51.617 83.159 47.37 74.099 47.37 63.212 C 47.37 55.559 49.553 48.952 53.92 43.392 C 58.287 37.825 64.267 33.579 71.86 30.652 C 79.453 27.719 87.973 26.252 97.42 26.252 Z"/>
</vector>
14 changes: 7 additions & 7 deletions app/src/main/res/layout/navigation_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
android:layout_marginStart="10dp"
android:src="@drawable/ic_icon_home" />

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/servoButton"
style="?attr/navigationBarButtonStyle"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:src="@drawable/ic_icon_servo" />

<org.mozilla.vrbrowser.ui.views.NavigationURLBar
android:id="@+id/urlBar"
android:layout_width="wrap_content"
Expand All @@ -56,6 +49,13 @@
android:layout_weight="100"
android:layout_marginStart="10dp" />

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/servoButton"
style="?attr/navigationBarButtonStyle"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:src="@drawable/ic_icon_servo" />

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/resizeEnterButton"
style="?attr/navigationBarButtonStyle"
Expand Down
4 changes: 2 additions & 2 deletions servo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (findProject(':geckoview-local')) {
}
} else {
dependencies {
compileOnly "org.mozilla.geckoview:geckoview-nightly-armeabi-v7a:${rootProject.ext.geckoNightly['version']}"
compileOnly deps.gecko_view.nightly_armv7a
}
}

Expand All @@ -47,6 +47,6 @@ if (gradle.hasProperty('servoViewLocal')) {
dependencies {
// To see what the latest servoview version is go here:
// https://download.servo.org/nightly/maven/org/mozilla/servoview/servoview-armv7/maven-metadata.xml
implementation 'org.mozilla.servoview:servoview-armv7:0.0.1.20181015.5327758'
implementation 'org.mozilla.servoview:servoview-armv7:0.0.1.20190116.96ad67'
}
}
8 changes: 7 additions & 1 deletion servo/src/main/java/org/mozilla/servo/ServoDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ public ServoDisplay(final GeckoSession session) {

@Override
public void surfaceChanged(final Surface surface, final int width, final int height) {
mServoSession.onSurfaceReady(surface, width, height);
mServoSession.onSurfaceReady(surface, 0, 0, width, height);
}

@Override
public void surfaceChanged(final Surface surface, int left, int top, int width, int height) {
mServoSession.onSurfaceReady(surface, left, top, width, height);
}


@Override
public void surfaceDestroyed() {
mServoSession.onSurfaceDestroyed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.view.InputDevice;
import android.view.MotionEvent;

import org.mozilla.gecko.gfx.PanZoomController;
import org.mozilla.geckoview.PanZoomController;

import java.util.ArrayList;

Expand Down
6 changes: 3 additions & 3 deletions servo/src/main/java/org/mozilla/servo/ServoSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ServoSession(Context aContext) {
mActivity = (Activity) aContext;
}

public void onSurfaceReady(Surface surface, int width, int height) {
public void onSurfaceReady(Surface surface, int left, int top, int width, int height) {
Log.d(LOGTAG, "onSurfaceReady()");
if (mServo == null) {
mWidth = width;
Expand All @@ -49,6 +49,7 @@ public void onSurfaceReady(Surface surface, int width, int height) {
}

public void onSurfaceDestroyed() {
Log.d(LOGTAG, "onSurfaceDestroyed");
// FIXME: Pause compositor.
// See: https://github.com/servo/servo/issues/21860
}
Expand Down Expand Up @@ -113,8 +114,7 @@ public void open(GeckoRuntime runtime) {
@Override
public void close() {
Log.d(LOGTAG, "close()");
// FIXME: mServo.stopLoop();
// See: https://github.com/servo/servo/issues/21834
mServo.shutdown();
mServo = null;
mIsOpen = false;
mUrl = "about:blank";
Expand Down
23 changes: 23 additions & 0 deletions servo/src/main/java/org/mozilla/servo/ServoWhiteList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.mozilla.servo;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;

import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class ServoWhiteList {
private final Pattern[] mRules;

public ServoWhiteList(Context context) {
Resources res = context.getResources();
Stream<String> rules = Stream.of(res.getStringArray(R.array.servo_white_list));
mRules = rules.map(Pattern::compile).toArray(Pattern[]::new);
}

public boolean isAllowed(String url) {
return url != null && Stream.of(mRules).anyMatch(r -> r.matcher(url).matches());
}
}
20 changes: 20 additions & 0 deletions servo/src/main/res/values/servo_white_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="servo_white_list">
<!--
Matches:
https://servo.org
https://download.servo.org
https://download.servo.org
https://servo.org/
https://servo.org/ddd
Doesn't match:
https://.servo.org/ddd
https://servo.orgd
http://servo.org
-->
<item>https:\/\/(.+\.)?servo\.org(\/.*)?$</item>
<!-- All examples hosted under threejs.org/examples/ -->
<item>https:\/\/threejs\.org\/examples\/.*</item>
</string-array>
</resources>

0 comments on commit ad0b9a1

Please sign in to comment.