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

Commit

Permalink
GeckoView update: Settings API update
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Feb 4, 2019
1 parent 308d51e commit 9acfc9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,25 +332,28 @@ 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);
Expand Down Expand Up @@ -388,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 @@ -449,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 @@ -753,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 @@ -781,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 @@ -790,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 @@ -810,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 @@ -876,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 @@ -969,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 @@ -1033,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
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void onCurrentSessionChange(GeckoSession aSession, int 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

0 comments on commit 9acfc9f

Please sign in to comment.