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

Commit

Permalink
Servo support enabled via user.properties (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget authored and MortimerGoro committed Oct 17, 2018
1 parent 7e614e7 commit 388bfe3
Show file tree
Hide file tree
Showing 20 changed files with 723 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ geckoViewLocalX86=/path/to/your/build/geckoview-nightly-x86-64.0.20180924100359.
- You can use `adb shell setprop debug.oculus.enableVideoCapture 1`to record videos on the Oculus Go. Remember to disable it when your video is ready.


## Experimental Servo support

To compile with Servo support, create a file called `user.properties` in the top-level project directory and add `enableServo=1`. Then to enable Servo in Firefox Reality, go the Developer Options panel in the Settings, and toggle the Servo option. Then a new button will be added to the navigation bar. Clicking that button will reload the current page with Servo.

[![Task Status](https://github.taskcluster.net/v1/repository/MozillaReality/FirefoxReality/master/badge.svg)](https://github.taskcluster.net/v1/repository/MozillaReality/FirefoxReality/master/latest) [Build results](https://github.taskcluster.net/v1/repository/MozillaReality/FirefoxReality/master/latest)
13 changes: 12 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ android {
} else {
project.archivesBaseName = "FirefoxReality"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
Expand Down Expand Up @@ -231,6 +235,13 @@ dependencies {
implementation "com.github.mozilla:mozillaspeechlibrary:1.0.4"
}

if (findProject(':servo')) {
dependencies {
oculusvrImplementation project(':servo')
googlevrImplementation project(':servo')
}
}

if (findProject(':wavesdk')) {
dependencies {
wavevrImplementation project(':wavesdk')
Expand Down Expand Up @@ -288,4 +299,4 @@ android.applicationVariants.all { variant ->
println("Build type: " + buildType)
println("Flavor: " + variant.flavorName)
println("Version code: " + variant.mergedFlavor.versionCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.util.List;
import java.util.Map;

import static org.mozilla.vrbrowser.utils.ServoUtils.*;

public class SessionStore implements GeckoSession.NavigationDelegate, GeckoSession.ProgressDelegate,
GeckoSession.ContentDelegate, GeckoSession.TextInputDelegate, GeckoSession.TrackingProtectionDelegate,
GeckoSession.PromptDelegate {
Expand Down Expand Up @@ -78,6 +80,7 @@ class SessionSettings {
boolean trackingProtection = true;
boolean suspendMediaWhenInactive = true;
int userAgentMode = SettingsStore.getInstance(mContext).getUaMode();
boolean servo = false;
}

class State {
Expand Down Expand Up @@ -307,7 +310,17 @@ public int createSession() {
int createSession(SessionSettings aSettings) {
State state = new State();
state.mSettings = aSettings;
state.mSession = new GeckoSession();

if (aSettings.servo) {
if (isServoAvailable()) {
state.mSession = createServoSession(mContext);
} else {
Log.e(LOGTAG, "Attempt to create a ServoSession. Servo hasn't been enable at build time. Using a GeckoSession instead.");
state.mSession = new GeckoSession();
}
} else {
state.mSession = new GeckoSession();
}

int result = state.mSession.hashCode();
mSessions.put(result, state);
Expand Down Expand Up @@ -555,6 +568,20 @@ public void loadUri(String aUri) {
mCurrentSession.loadUri(aUri);
}

public void toggleServo() {
if (mCurrentSession == null) {
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);
}

public boolean isInFullScreen() {
if (mCurrentSession == null) {
return false;
Expand Down Expand Up @@ -714,6 +741,15 @@ public void setMaxWindowSize(int width, int height) {
GeckoAppShell.setScreenSizeOverride(new Rect(0, 0, width, height));
}

public void setServo(final boolean enabled) {
if (!enabled && mCurrentSession != null && isInstanceOfServoSession(mCurrentSession)) {
String uri = getCurrentUri();
int id = createSession();
setCurrentSession(id);
loadUri(uri);
}
}

public void setMultiprocess(final boolean enabled) {
if (mCurrentSession != null) {
final GeckoResult<GeckoSession.SessionState> state = mCurrentSession.saveState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;

public class SettingsStore {

Expand All @@ -35,6 +36,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = false;
public final static boolean SERVO_DEFAULT = false;
public final static int UA_MODE_DEFAULT = 0;
public final static int INPUT_MODE_DEFAULT = 1;
public final static float DISPLAY_DENSITY_DEFAULT = 1.0f;
Expand Down Expand Up @@ -148,6 +150,16 @@ public void setMultiprocessEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isServoEnabled() {
return isServoAvailable() && mPrefs.getBoolean(mContext.getString(R.string.settings_key_servo), SERVO_DEFAULT);
}

public void setServoEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_servo), isEnabled);
editor.commit();
}

public int getUaMode() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_desktop_version), UA_MODE_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.mozilla.vrbrowser.ui.settings.RadioGroupSetting;
import org.mozilla.vrbrowser.ui.settings.SwitchSetting;

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;

public class DeveloperOptionsWidget extends UIWidget {

private static final String LOGTAG = "VRB";
Expand All @@ -33,6 +35,7 @@ public class DeveloperOptionsWidget extends UIWidget {
private SwitchSetting mConsoleLogsSwitch;
private SwitchSetting mEnvOverrideSwitch;
private SwitchSetting mMultiprocessSwitch;
private SwitchSetting mServoSwitch;

private RadioGroupSetting mEnvironmentsRadio;
private RadioGroupSetting mPointerColorRadio;
Expand Down Expand Up @@ -97,6 +100,14 @@ public void onClick(View view) {
mMultiprocessSwitch.setOnCheckedChangeListener(mMultiprocessListener);
setMultiprocess(SettingsStore.getInstance(getContext()).isMultiprocessEnabled(), false);

mServoSwitch = findViewById(R.id.servo_switch);
if (!isServoAvailable()) {
mServoSwitch.setVisibility(View.GONE);
} else {
mServoSwitch.setOnCheckedChangeListener(mServoListener);
setServo(SettingsStore.getInstance(getContext()).isServoEnabled(), false);
}

String env = SettingsStore.getInstance(getContext()).getEnvironment();
mEnvironmentsRadio = findViewById(R.id.environment_radio);
mEnvironmentsRadio.setOnCheckedChangeListener(mEnvsListener);
Expand Down Expand Up @@ -218,6 +229,14 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean value, boole
}
};

private SwitchSetting.OnCheckedChangeListener mServoListener = new SwitchSetting.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b, boolean doApply) {
setServo(b, true);
}
};


private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = new RadioGroupSetting.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) {
Expand Down Expand Up @@ -303,6 +322,7 @@ public void onClick(View view) {

setConsoleLogs(SettingsStore.CONSOLE_LOGS_DEFAULT, true);
setMultiprocess(SettingsStore.MULTIPROCESS_DEFAULT, true);
setServo(SettingsStore.SERVO_DEFAULT, true);

if (mEnvOverrideSwitch.isChecked() != SettingsStore.ENV_OVERRIDE_DEFAULT) {
setEnvOverride(SettingsStore.ENV_OVERRIDE_DEFAULT);
Expand Down Expand Up @@ -373,6 +393,18 @@ private void setMultiprocess(boolean value, boolean doApply) {
}
}

private void setServo(boolean value, boolean doApply) {
mServoSwitch.setOnCheckedChangeListener(null);
mServoSwitch.setValue(value, false);
mServoSwitch.setOnCheckedChangeListener(mServoListener);

SettingsStore.getInstance(getContext()).setServoEnabled(value);

if (doApply) {
SessionStore.get().setServo(value);
}
}

private void setUaMode(int checkId, boolean doApply) {
mUaModeRadio.setOnCheckedChangeListener(null);
mUaModeRadio.setChecked(checkId, doApply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package org.mozilla.vrbrowser.ui.widgets;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
Expand All @@ -33,7 +35,8 @@
public class NavigationBarWidget extends UIWidget implements GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate,
WidgetManagerDelegate.UpdateListener, SessionStore.SessionChangeListener,
NavigationURLBar.NavigationURLBarDelegate, VoiceSearchWidget.VoiceSearchDelegate {
NavigationURLBar.NavigationURLBarDelegate, VoiceSearchWidget.VoiceSearchDelegate,
SharedPreferences.OnSharedPreferenceChangeListener {

private static final String LOGTAG = "VRB";

Expand All @@ -42,6 +45,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private UIButton mForwardButton;
private UIButton mReloadButton;
private UIButton mHomeButton;
private UIButton mServoButton;
private NavigationURLBar mURLBar;
private ViewGroup mNavigationContainer;
private ViewGroup mFocusModeContainer;
Expand All @@ -60,6 +64,8 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private ArrayList<CustomUIButton> mButtons;
private int mURLBarLayoutIndex;
private VoiceSearchWidget mVoiceSearchWidget;
private Context mAppContext;
private SharedPreferences mPrefs;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand All @@ -77,12 +83,14 @@ public NavigationBarWidget(Context aContext, AttributeSet aAttrs, int aDefStyle)
}

private void initialize(Context aContext) {
mAppContext = aContext.getApplicationContext();
inflate(aContext, R.layout.navigation_bar, this);
mAudio = AudioEngine.fromContext(aContext);
mBackButton = findViewById(R.id.backButton);
mForwardButton = findViewById(R.id.forwardButton);
mReloadButton = findViewById(R.id.reloadButton);
mHomeButton = findViewById(R.id.homeButton);
mServoButton = findViewById(R.id.servoButton);
mURLBar = findViewById(R.id.urlBar);
mNavigationContainer = findViewById(R.id.navigationBarContainer);
mFocusModeContainer = findViewById(R.id.focusModeContainer);
Expand Down Expand Up @@ -147,6 +155,17 @@ public void onClick(View v) {
}
});

mServoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.requestFocusFromTouch();
SessionStore.get().toggleServo();
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
}
});

mResizeEnterButton = findViewById(R.id.resizeEnterButton);
mResizeExitButton = findViewById(R.id.resizeExitButton);
mPreset0 = findViewById(R.id.resizePreset0);
Expand Down Expand Up @@ -223,7 +242,7 @@ public void onClick(View view) {
mButtons = new ArrayList<>();
mButtons.addAll(Arrays.<CustomUIButton>asList(
mBackButton, mForwardButton, mReloadButton, mHomeButton, mResizeEnterButton, mResizeExitButton,
mPreset0, mPreset1, mPreset2, mPreset3));
mServoButton, mPreset0, mPreset1, mPreset2, mPreset3));

mURLBar.setDelegate(this);

Expand All @@ -236,11 +255,16 @@ public void onClick(View view) {
mVoiceSearchWidget.setDelegate(this);

SessionStore.get().addSessionChangeListener(this);

mPrefs = PreferenceManager.getDefaultSharedPreferences(mAppContext);
mPrefs.registerOnSharedPreferenceChangeListener(this);
updateServoButton();
}

@Override
public void releaseWidget() {
mWidgetManager.removeUpdateListener(this);
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
SessionStore.get().removeNavigationListener(this);
SessionStore.get().removeProgressListener(this);
SessionStore.get().removeContentListener(this);
Expand Down Expand Up @@ -365,6 +389,14 @@ public void showVoiceSearch() {
mURLBar.showVoiceSearch(true);
}

public void updateServoButton() {
if (SettingsStore.getInstance(mAppContext).isServoEnabled()) {
mServoButton.setVisibility(View.VISIBLE);
} else {
mServoButton.setVisibility(View.GONE);
}
}

@Override
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @NonNull String aUri) {
return null;
Expand Down Expand Up @@ -606,4 +638,11 @@ public void OnVoiceSearchCanceled() {
public void OnVoiceSearchError() {
// Nothing to do yet
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key == mAppContext.getString(R.string.settings_key_servo)) {
updateServoButton();
}
}
}
41 changes: 41 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/utils/ServoUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.mozilla.vrbrowser.utils;

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

import org.mozilla.geckoview.GeckoSession;

import java.lang.reflect.Constructor;

public class ServoUtils {
private static final String CLASSNAME = "org.mozilla.servo.ServoSession";
private static final String LOGTAG = "ServoUtils";

public static boolean isServoAvailable() {
try {
Class.forName(CLASSNAME);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

public static boolean isInstanceOfServoSession(Object obj) {
try {
return Class.forName(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);
return (GeckoSession) constructor.newInstance(context);
} catch (Exception e) {
Log.e(LOGTAG, "Can't load or instanciate ServoSession: " + e);
return null;
}
}
}
Binary file added app/src/main/res/drawable/ic_icon_servo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 388bfe3

Please sign in to comment.