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

Commit

Permalink
Added User-Agent multi-window support and fixed session restore issues
Browse files Browse the repository at this point in the history
The home page was being loaded after a session restore. Now the home page is only loaded if the session is not restored. Also fixed some session restore issues to also restore session settings.
  • Loading branch information
keianhzo authored and MortimerGoro committed Jul 26, 2019
1 parent 73e66b8 commit 9e3f9c2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void loadFromIntent(final Intent intent) {
activeStore.loadUri(uri.toString());

} else {
mWindows.getFocusedWindow().loadHome();
mWindows.getFocusedWindow().loadHomeIfNotRestored();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public boolean isServoEnabled() {
return isServoEnabled;
}

public void setServoEnabled(boolean enabled) {
isServoEnabled = enabled;
}

public static class Builder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,19 @@ public void restore(SessionStore store, int currentSessionId) {
mRegion = store.mRegion;
mUsePrivateMode = store.mUsePrivateMode;

SessionSettings settings = new SessionSettings.Builder()
.withDefaultSettings(mContext)
.build();

GeckoSessionSettings geckoSettings = new GeckoSessionSettings.Builder()
.useMultiprocess(settings.isMultiprocessEnabled())
.usePrivateMode(mUsePrivateMode)
.useTrackingProtection(settings.isTrackingProtectionEnabled())
.build();

HashMap<Integer, Integer> oldNewSessionId = new HashMap<>();
for (Map.Entry<Integer, SessionState> entry : store.mSessions.entrySet()) {
SessionState state = entry.getValue();

if (settings.isServoEnabled()) {
GeckoSessionSettings geckoSettings = new GeckoSessionSettings.Builder()
.useMultiprocess(state.mSettings.isMultiprocessEnabled())
.usePrivateMode(mUsePrivateMode)
.userAgentMode(state.mSettings.getUserAgentMode())
.suspendMediaWhenInactive(state.mSettings.isSuspendMediaWhenInactiveEnabled())
.useTrackingProtection(state.mSettings.isTrackingProtectionEnabled())
.build();

if (state.mSettings.isServoEnabled()) {
if (isServoAvailable()) {
state.mSession = createServoSession(mContext);
} else {
Expand All @@ -298,8 +296,6 @@ public void restore(SessionStore store, int currentSessionId) {
int newSessionId = state.mSession.hashCode();
oldNewSessionId.put(entry.getKey(), newSessionId);

state.mSession.getSettings().setSuspendMediaWhenInactive(settings.isSuspendMediaWhenInactiveEnabled());
state.mSession.getSettings().setUserAgentMode(settings.getUserAgentMode());
state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setPromptDelegate(this);
Expand Down Expand Up @@ -763,6 +759,10 @@ public boolean isPrivateMode() {
// Session Settings

protected void setServo(final boolean enabled) {
SessionState state = mSessions.get(mCurrentSession.hashCode());
if (state != null) {
state.mSettings.setServoEnabled(enabled);
}
if (!enabled && mCurrentSession != null && isInstanceOfServoSession(mCurrentSession)) {
String uri = getCurrentUri();
int id = createSession();
Expand All @@ -777,8 +777,12 @@ public int getUaMode() {

public void setUaMode(int mode) {
if (mCurrentSession != null) {
mCurrentSession.getSettings().setUserAgentMode(mode);
mCurrentSession.reload();
SessionState state = mSessions.get(mCurrentSession.hashCode());
if (state != null && state.mSettings.getUserAgentMode() != mode) {
state.mSettings.setUserAgentMode(mode);
mCurrentSession.getSettings().setUserAgentMode(mode);
mCurrentSession.reload();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void initialize(Context aContext) {
mUAModeButton = findViewById(R.id.uaModeButton);
mUAModeButton.setTag(R.string.view_id_tag, R.id.uaModeButton);
mUAModeButton.setOnClickListener(mUAModeListener);
setUAMode(SettingsStore.getInstance(aContext).getUaMode());
setUAMode(mSessionStore.getUaMode());

mURLLeftContainer = findViewById(R.id.urlLeftContainer);
mInsecureIcon = findViewById(R.id.insecureIcon);
Expand Down Expand Up @@ -183,6 +183,7 @@ private void initialize(Context aContext) {

public void setSessionStore(SessionStore sessionStore) {
mSessionStore = sessionStore;
setUAMode(mSessionStore.getUaMode());
}

public void onPause() {
Expand Down Expand Up @@ -501,13 +502,13 @@ public void setClickable(boolean clickable) {
view.requestFocusFromTouch();

int uaMode = mSessionStore.getUaMode();
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_VR) {
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
mSessionStore.setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);

}else {
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_DESKTOP) {
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
mSessionStore.setUaMode(GeckoSessionSettings.USER_AGENT_MODE_VR);

}else {
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
mSessionStore.setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
}

TelemetryWrapper.voiceInputEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private ArrayList<BookmarkListener> mBookmarksListeners;
private Windows.WindowPlacement mWindowPlacement = Windows.WindowPlacement.FRONT;
private float mMaxWindowScale = 3;
private boolean mIsRestored = false;

public WindowWidget(Context aContext, int windowId, boolean privateMode) {
super(aContext);
Expand Down Expand Up @@ -178,6 +179,11 @@ public void close() {
SessionManager.get().destroySessionStore(mWindowId);
}

public void loadHomeIfNotRestored() {
if (!mIsRestored)
loadHome();
}

public void loadHome() {
if (mSessionStore.isPrivateMode()) {
InternalPages.PageResources pageResources = InternalPages.PageResources.create(R.raw.private_mode, R.raw.private_style);
Expand All @@ -187,6 +193,10 @@ public void loadHome() {
}
}

protected void setRestored(boolean restored) {
mIsRestored = restored;
}

private void setView(View view) {
pauseCompositor();
mView = view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private WindowWidget addWindow(WindowState aState) {
newWindow.getPlacement().width = aState.textureWidth;
newWindow.getPlacement().height = aState.textureHeight;
newWindow.getPlacement().worldWidth = aState.worldWidth;
newWindow.setRestored(true);
placeWindow(newWindow, aState.placement);

mWidgetManager.addWidget(newWindow);
Expand Down

0 comments on commit 9e3f9c2

Please sign in to comment.