2019-07-04 06:17:16 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-08-20 19:00:49 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.customtabs
|
2019-07-04 06:17:16 +02:00
|
|
|
|
|
|
|
import mozilla.components.concept.sync.AccountObserver
|
2019-09-04 22:56:22 +02:00
|
|
|
import mozilla.components.concept.sync.AuthType
|
2019-07-04 06:17:16 +02:00
|
|
|
import mozilla.components.concept.sync.OAuthAccount
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
|
2019-08-29 21:36:46 +02:00
|
|
|
/**
|
|
|
|
* A special custom tab for signing into a Firefox Account. The activity is closed once the user is signed in.
|
|
|
|
*/
|
2019-09-19 18:12:42 +02:00
|
|
|
class AuthCustomTabActivity : ExternalAppBrowserActivity() {
|
2019-07-04 06:17:16 +02:00
|
|
|
|
|
|
|
private val accountStateObserver = object : AccountObserver {
|
2019-08-29 21:36:46 +02:00
|
|
|
/**
|
|
|
|
* Navigate away from this activity when we have successful authentication
|
|
|
|
*/
|
2019-09-04 22:56:22 +02:00
|
|
|
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
|
2019-08-29 21:36:46 +02:00
|
|
|
finish()
|
2019-07-04 06:17:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2019-08-29 21:36:46 +02:00
|
|
|
val accountManager = components.backgroundServices.accountManager
|
2019-07-04 06:17:16 +02:00
|
|
|
accountManager.register(accountStateObserver, this, true)
|
|
|
|
}
|
2019-09-09 20:42:52 +02:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val EXTRA_AUTH_CUSTOM_TAB = "support.customtabs.extra.AUTH"
|
|
|
|
}
|
2019-07-04 06:17:16 +02:00
|
|
|
}
|