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

Fixes #3605 Link FxA login flow to the originating session #3618

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Accounts constructor(val context: Context) {

var profilePicture: BitmapDrawable? = loadDefaultProfilePicture()
var loginOrigin: LoginOrigin = LoginOrigin.NONE
private set
var originSessionId: String? = null
private set
var accountStatus = AccountStatus.SIGNED_OUT
private val accountListeners = ArrayList<AccountObserver>()
private val syncListeners = ArrayList<SyncStatusObserver>()
Expand Down Expand Up @@ -137,10 +140,11 @@ class Accounts constructor(val context: Context) {
)

account.deviceConstellation().refreshDevicesAsync()
accountListeners.toMutableList().forEach {
Handler(Looper.getMainLooper()).post {
Handler(Looper.getMainLooper()).post {
accountListeners.toMutableList().forEach {
it.onAuthenticated(account, authType)
}
originSessionId = null
}
}

Expand All @@ -149,6 +153,8 @@ class Accounts constructor(val context: Context) {

GleanMetricsService.FxA.signInResult(false)

originSessionId = null

accountStatus = AccountStatus.NEEDS_RECONNECT
accountListeners.toMutableList().forEach {
Handler(Looper.getMainLooper()).post {
Expand All @@ -160,6 +166,8 @@ class Accounts constructor(val context: Context) {
override fun onLoggedOut() {
Log.d(LOGTAG, "The user has been logged out")

originSessionId = null

accountStatus = AccountStatus.SIGNED_OUT
accountListeners.toMutableList().forEach {
Handler(Looper.getMainLooper()).post {
Expand Down Expand Up @@ -380,4 +388,9 @@ class Accounts constructor(val context: Context) {
return (services.accountManager.authenticatedAccount() as FirefoxAccount).getConnectionSuccessURL()
}

fun setOrigin(origin: LoginOrigin, sessionId: String?) {
loginOrigin = origin
originSessionId = sessionId
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserActivity;
import org.mozilla.vrbrowser.VRBrowserApplication;
Expand All @@ -37,7 +36,6 @@
import org.mozilla.vrbrowser.ui.callbacks.BookmarksCallback;
import org.mozilla.vrbrowser.ui.callbacks.LibraryContextMenuCallback;
import org.mozilla.vrbrowser.ui.viewmodel.BookmarksViewModel;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.Windows;
import org.mozilla.vrbrowser.ui.widgets.menus.library.BookmarksContextMenuWidget;
Expand Down Expand Up @@ -240,10 +238,12 @@ public void onFxALogin(@NonNull View view) {
mAccounts.logoutAsync();

} else {
mAccounts.setLoginOrigin(Accounts.LoginOrigin.BOOKMARKS);
WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
widgetManager.openNewTabForeground(url);
widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
mWidgetManager.openNewTabForeground(url);
Session currentSession = mWidgetManager.getFocusedWindow().getSession();
String sessionId = currentSession != null ? currentSession.getId() : null;

mAccounts.setOrigin(Accounts.LoginOrigin.BOOKMARKS, sessionId);

GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

WindowWidget window = mWidgetManager.getFocusedWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserActivity;
import org.mozilla.vrbrowser.VRBrowserApplication;
Expand Down Expand Up @@ -246,9 +245,12 @@ public void onFxALogin(@NonNull View view) {
mAccounts.logoutAsync();

} else {
mAccounts.setLoginOrigin(Accounts.LoginOrigin.HISTORY);
mWidgetManager.openNewTabForeground(url);
mWidgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
Session currentSession = mWidgetManager.getFocusedWindow().getSession();
String sessionId = currentSession != null ? currentSession.getId() : null;

mAccounts.setOrigin(Accounts.LoginOrigin.HISTORY, sessionId);

GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

WindowWidget window = mWidgetManager.getFocusedWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.io.Writer;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -991,9 +990,11 @@ public void onLoggedOut() {
public void onAuthenticated(@NonNull OAuthAccount oAuthAccount, @NonNull AuthType authType) {
if (authType == AuthType.Signin.INSTANCE || authType == AuthType.Signup.INSTANCE) {
UIDialog.closeAllDialogs();
Session session = mFocusedWindow.getSession();
addTab(mFocusedWindow, mAccounts.getConnectionSuccessURL());
onTabsClose(new ArrayList<>(Collections.singletonList(session)));

Session fxaSession = SessionStore.get().getSession(mAccounts.getOriginSessionId());
if (fxaSession != null) {
fxaSession.loadUri(mAccounts.getConnectionSuccessURL(), GeckoSession.LOAD_FLAGS_REPLACE_HISTORY);
}

switch (mAccounts.getLoginOrigin()) {
case BOOKMARKS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import android.content.Context;
import android.util.Log;

import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;

import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -88,10 +88,12 @@ private void signIn() {
mAccounts.logoutAsync();

} else {
mAccounts.setLoginOrigin(mLoginOrigin);
mWidgetManager.openNewTabForeground(url);
mWidgetManager.getFocusedWindow().getSession().loadUri(url);
mWidgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
Session currentSession = mWidgetManager.getFocusedWindow().getSession();
String sessionId = currentSession != null ? currentSession.getId() : null;

mAccounts.setOrigin(mLoginOrigin, sessionId);

GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ private void manageAccount() {
mAccounts.logoutAsync();

} else {
mAccounts.setLoginOrigin(Accounts.LoginOrigin.SETTINGS);
mWidgetManager.openNewTabForeground(url);
Session currentSession = mWidgetManager.getFocusedWindow().getSession();
String sessionId = currentSession != null ? currentSession.getId() : null;

mAccounts.setOrigin(Accounts.LoginOrigin.SETTINGS, sessionId);

GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);
}

Expand Down