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

Commit

Permalink
GeckoView update (#936)
Browse files Browse the repository at this point in the history
* GeckoView update: ContentBlocking API update

* GeckoView update: version bump

* GeckoView update: copy moz_external_vr.h from m-c

* GeckoView update: moz_external_vr.h variable renaming

* GeckoView update: Settings API update

* ServoView update: version bump

* GeckoView update: switch between Gecko and Servo browserState/Mutex/Cond

* ServoView update: support onSurfaceChanged
  • Loading branch information
paulrouget authored and MortimerGoro committed Feb 6, 2019
1 parent 1f68ddf commit 208ebf2
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ public void popBackHandler(Runnable aRunnable) {
mBackHandlers.removeLastOccurrence(aRunnable);
}

@Override
public void setIsServoSession(boolean aIsServo) {
queueRunnable(() -> setIsServo(aIsServo));
}

@Override
public void pushWorldBrightness(Object aKey, float aBrightness) {
if (mCurrentBrightness.second != aBrightness) {
Expand Down Expand Up @@ -1005,4 +1010,5 @@ public void setCylinderDensity(final float aDensity) {
private native void setControllersVisibleNative(boolean aVisible);
private native void runCallbackNative(long aCallback);
private native void setCylinderDensityNative(float aDensity);
private native void setIsServo(boolean aIsServo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.MediaElement;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoRuntime;
Expand Down Expand Up @@ -57,8 +58,8 @@
import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession;
import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;

public class SessionStore implements GeckoSession.NavigationDelegate, GeckoSession.ProgressDelegate,
GeckoSession.ContentDelegate, GeckoSession.TextInputDelegate, GeckoSession.TrackingProtectionDelegate,
public class SessionStore implements ContentBlocking.Delegate, GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate, GeckoSession.TextInputDelegate,
GeckoSession.PromptDelegate, GeckoSession.MediaDelegate, SharedPreferences.OnSharedPreferenceChangeListener {

private static SessionStore mInstance;
Expand Down Expand Up @@ -160,7 +161,9 @@ public void setContext(Context aContext, Bundle aExtras) {
vrPrefsWorkAround(aContext, aExtras);
GeckoRuntimeSettings.Builder runtimeSettingsBuilder = new GeckoRuntimeSettings.Builder();
runtimeSettingsBuilder.crashHandler(CrashReporterService.class);
runtimeSettingsBuilder.trackingProtectionCategories(GeckoSession.TrackingProtectionDelegate.CATEGORY_AD | GeckoSession.TrackingProtectionDelegate.CATEGORY_SOCIAL | GeckoSession.TrackingProtectionDelegate.CATEGORY_ANALYTIC);
runtimeSettingsBuilder.contentBlocking((new ContentBlocking.Settings.Builder())
.categories(ContentBlocking.AT_AD | ContentBlocking.AT_SOCIAL | ContentBlocking.AT_ANALYTIC)
.build());
runtimeSettingsBuilder.consoleOutput(SettingsStore.getInstance(aContext).isConsoleLogsEnabled());
runtimeSettingsBuilder.displayDensityOverride(SettingsStore.getInstance(aContext).getDisplayDensity());
runtimeSettingsBuilder.remoteDebuggingEnabled(SettingsStore.getInstance(aContext).isRemoteDebuggingEnabled());
Expand Down Expand Up @@ -329,32 +332,35 @@ int createSession(SessionSettings aSettings) {
State state = new State();
state.mSettings = aSettings;

GeckoSessionSettings geckoSettings = new GeckoSessionSettings.Builder()
.useMultiprocess(aSettings.multiprocess)
.usePrivateMode(aSettings.privateMode)
.useTrackingProtection(aSettings.trackingProtection)
.build();

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();
state.mSession = new GeckoSession(geckoSettings);
}
} else {
state.mSession = new GeckoSession();
state.mSession = new GeckoSession(geckoSettings);
}

int result = state.mSession.hashCode();
mSessions.put(result, state);

state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, aSettings.multiprocess);
state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_PRIVATE_MODE, aSettings.privateMode);
state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_TRACKING_PROTECTION, aSettings.trackingProtection);
state.mSession.getSettings().setBoolean(GeckoSessionSettings.SUSPEND_MEDIA_WHEN_INACTIVE, aSettings.suspendMediaWhenInactive);
state.mSession.getSettings().setInt(GeckoSessionSettings.USER_AGENT_MODE, aSettings.userAgentMode);
state.mSession.getSettings().setSuspendMediaWhenInactive(aSettings.suspendMediaWhenInactive);
state.mSession.getSettings().setUserAgentMode(aSettings.userAgentMode);
state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setPromptDelegate(this);
state.mSession.setContentDelegate(this);
state.mSession.getTextInput().setDelegate(this);
state.mSession.setPermissionDelegate(mPermissionDelegate);
state.mSession.setTrackingProtectionDelegate(this);
state.mSession.setContentBlockingDelegate(this);
state.mSession.setMediaDelegate(this);
for (SessionChangeListener listener: mSessionChangeListeners) {
listener.onNewSession(state.mSession, result);
Expand All @@ -372,7 +378,7 @@ public void removeSession(int aSessionId) {
session.getTextInput().setDelegate(null);
session.setPromptDelegate(null);
session.setPermissionDelegate(null);
session.setTrackingProtectionDelegate(null);
session.setContentBlockingDelegate(null);
session.setMediaDelegate(null);
mSessions.remove(aSessionId);
for (SessionChangeListener listener: mSessionChangeListeners) {
Expand All @@ -385,23 +391,23 @@ public void removeSession(int aSessionId) {
}

private void pushSession(int aSessionId) {
boolean isPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (isPrivateMode)
mPrivateSessionsStack.push(aSessionId);
else
mSessionsStack.push(aSessionId);
}

private Integer popSession() {
boolean isPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (isPrivateMode)
return mPrivateSessionsStack.pop();
else
return mSessionsStack.pop();
}

private Integer peekSession() {
boolean isPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (isPrivateMode)
return mPrivateSessionsStack.peek();
else
Expand Down Expand Up @@ -446,7 +452,7 @@ public List<Integer> getSessionsByPrivateMode(boolean aUsingPrivateMode) {
ArrayList<Integer> result = new ArrayList<>();
for (Integer sessionId : mSessions.keySet()) {
GeckoSession session = getSession(sessionId);
if (session != null && session.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE) == aUsingPrivateMode) {
if (session != null && session.getSettings().getUsePrivateMode() == aUsingPrivateMode) {
result.add(sessionId);
}
}
Expand Down Expand Up @@ -750,7 +756,7 @@ public void switchPrivateMode() {
if (mCurrentSession == null)
return;

boolean isPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (!isPrivateMode) {
if (mPreviousSessionId == SessionStore.NO_SESSION_ID) {
mPreviousSessionId = getCurrentSessionId();
Expand Down Expand Up @@ -778,7 +784,7 @@ public void switchPrivateMode() {

public void setUaMode(int mode) {
if (mCurrentSession != null) {
mCurrentSession.getSettings().setInt(GeckoSessionSettings.USER_AGENT_MODE, mode);
mCurrentSession.getSettings().setUserAgentMode(mode);
mCurrentSession.reload();
}
}
Expand All @@ -787,7 +793,7 @@ public void exitPrivateMode() {
if (mCurrentSession == null)
return;

boolean isPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (isPrivateMode) {
int privateSessionId = getCurrentSessionId();
setCurrentSession(mPreviousSessionId);
Expand All @@ -807,7 +813,7 @@ public void exitPrivateMode() {

public boolean isCurrentSessionPrivate() {
if (mCurrentSession != null)
return mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
return mCurrentSession.getSettings().getUsePrivateMode();

return false;
}
Expand Down Expand Up @@ -873,9 +879,10 @@ public GeckoResult<Object> onValue(@Nullable GeckoSession.SessionState value) th
mCurrentSession.close();

int oldSessionId = getCurrentSessionId();
int sessionId = createSession();
SessionStore.SessionSettings settings = new SessionStore.SessionSettings();
settings.multiprocess = enabled;
int sessionId = createSession(settings);
GeckoSession session = getSession(sessionId);
session.getSettings().setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, enabled);
session.restoreState(value);
setCurrentSession(sessionId);
removeSession(oldSessionId);
Expand Down Expand Up @@ -966,7 +973,7 @@ public void onCanGoForward(GeckoSession aSession, boolean aCanGoForward) {
Log.d(LOGTAG, "onLoadRequest: " + aRequest.uri);
if (mFirstOnLoadRequest && (aSession == mCurrentSession)) {
Log.d(LOGTAG, "Testing for UA override");
aSession.getSettings().setString(GeckoSessionSettings.USER_AGENT_OVERRIDE, mUserAgentOverride.lookupOverride(aRequest.uri));
aSession.getSettings().setUserAgentOverride(mUserAgentOverride.lookupOverride(aRequest.uri));
mFirstOnLoadRequest = false;
}
if (PRIVATE_BROWSING_URI.equalsIgnoreCase(aRequest.uri)) {
Expand Down Expand Up @@ -1030,7 +1037,7 @@ public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @N
pushSession(getCurrentSessionId());

int sessionId;
boolean isPreviousPrivateMode = mCurrentSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPreviousPrivateMode = mCurrentSession.getSettings().getUsePrivateMode();
if (isPreviousPrivateMode) {
SessionStore.SessionSettings settings = new SessionStore.SessionSettings();
settings.privateMode = true;
Expand Down Expand Up @@ -1272,21 +1279,21 @@ public void notifyAutoFill(GeckoSession session, int notification, int virtualId
}

@Override
public void onTrackerBlocked(GeckoSession session, String uri, int categories) {
if ((categories & GeckoSession.TrackingProtectionDelegate.CATEGORY_AD) != 0) {
Log.i(LOGTAG, "Blocking Ad: " + uri);
public void onContentBlocked(final GeckoSession session, final ContentBlocking.BlockEvent event) {
if ((event.categories & ContentBlocking.AT_AD) != 0) {
Log.i(LOGTAG, "Blocking Ad: " + event.uri);
}

if ((categories & GeckoSession.TrackingProtectionDelegate.CATEGORY_ANALYTIC) != 0) {
Log.i(LOGTAG, "Blocking Analytic: " + uri);
if ((event.categories & ContentBlocking.AT_ANALYTIC) != 0) {
Log.i(LOGTAG, "Blocking Analytic: " + event.uri);
}

if ((categories & GeckoSession.TrackingProtectionDelegate.CATEGORY_CONTENT) != 0) {
Log.i(LOGTAG, "Blocking Content: " + uri);
if ((event.categories & ContentBlocking.AT_CONTENT) != 0) {
Log.i(LOGTAG, "Blocking Content: " + event.uri);
}

if ((categories & GeckoSession.TrackingProtectionDelegate.CATEGORY_SOCIAL) != 0) {
Log.i(LOGTAG, "Blocking Social: " + uri);
if ((event.categories & ContentBlocking.AT_SOCIAL) != 0) {
Log.i(LOGTAG, "Blocking Social: " + event.uri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface WorldClickListener {
void setTrayVisible(boolean visible);
void setControllersVisible(boolean visible);
void setWindowSize(float targetWidth, float targetHeight);
void setIsServoSession(boolean aIsServo);
void keyboardDismissed();
void updateEnvironment();
void updatePointerColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;

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

public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener,
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, TrayListener, BookmarkListener {
Expand Down Expand Up @@ -469,13 +470,15 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) {
mDisplay = null;
}

mWidgetManager.setIsServoSession(isInstanceOfServoSession(aSession));

mSessionId = aId;
mDisplay = aSession.acquireDisplay();
Log.d(LOGTAG, "surfaceChanged: " + aId);
callSurfaceChanged();
aSession.getTextInput().setView(this);

boolean isPrivateMode = aSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
boolean isPrivateMode = aSession.getSettings().getUsePrivateMode();
if (isPrivateMode)
setPrivateBrowsingEnabled(true);
else
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,11 @@ BrowserWorld::SetCylinderDensity(const float aDensity) {
}
}

void
BrowserWorld::SetIsServo(const bool aIsServo) {
m.externalVR->SetSourceBrowser(aIsServo ? ExternalVR::VRBrowserType::Servo : ExternalVR::VRBrowserType::Gecko);
}

JNIEnv*
BrowserWorld::GetJNIEnv() const {
ASSERT_ON_RENDER_THREAD(nullptr);
Expand Down Expand Up @@ -1306,5 +1311,9 @@ JNI_METHOD(void, runCallbackNative)
}
}

JNI_METHOD(void, setIsServo)
(JNIEnv* aEnv, jboolean aIsServo) {
crow::BrowserWorld::Instance().SetIsServo(aIsServo);
}

} // extern "C"
1 change: 1 addition & 0 deletions app/src/main/cpp/BrowserWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BrowserWorld {
void SetControllersVisible(const bool aVisible);
void ResetUIYaw();
void SetCylinderDensity(const float aDensity);
void SetIsServo(const bool aIsServo);
JNIEnv* GetJNIEnv() const;
protected:
struct State;
Expand Down
Loading

0 comments on commit 208ebf2

Please sign in to comment.