2019-01-09 23:22:58 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +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/. */
|
2019-01-09 23:22:58 +01:00
|
|
|
|
2018-12-07 21:11:50 +01:00
|
|
|
package org.mozilla.fenix
|
|
|
|
|
2019-01-19 00:33:40 +01:00
|
|
|
import android.content.Context
|
2019-03-04 23:32:10 +01:00
|
|
|
import android.content.Intent
|
2020-01-27 14:33:57 +01:00
|
|
|
import android.content.res.Configuration
|
2018-12-07 21:11:50 +01:00
|
|
|
import android.os.Bundle
|
2019-01-19 00:33:40 +01:00
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
2019-08-20 19:00:49 +02:00
|
|
|
import androidx.annotation.CallSuper
|
2019-06-06 21:40:10 +02:00
|
|
|
import androidx.annotation.IdRes
|
2019-08-20 19:00:49 +02:00
|
|
|
import androidx.annotation.VisibleForTesting
|
|
|
|
import androidx.annotation.VisibleForTesting.PROTECTED
|
2020-01-16 19:03:18 +01:00
|
|
|
import androidx.appcompat.app.ActionBar
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.appcompat.widget.Toolbar
|
2019-06-13 02:13:24 +02:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2019-08-20 19:00:49 +02:00
|
|
|
import androidx.navigation.NavDestination
|
2019-10-25 23:25:09 +02:00
|
|
|
import androidx.navigation.NavDirections
|
2019-02-06 23:31:39 +01:00
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.navigation.ui.AppBarConfiguration
|
|
|
|
import androidx.navigation.ui.NavigationUI
|
2020-01-27 14:33:57 +01:00
|
|
|
import kotlinx.android.synthetic.main.activity_home.navigationToolbarStub
|
2020-02-04 07:41:52 +01:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
2019-05-29 00:26:36 +02:00
|
|
|
import kotlinx.coroutines.launch
|
2019-03-29 21:49:50 +01:00
|
|
|
import mozilla.components.browser.search.SearchEngine
|
2019-02-28 18:25:37 +01:00
|
|
|
import mozilla.components.browser.session.Session
|
2019-04-26 09:43:02 +02:00
|
|
|
import mozilla.components.browser.session.SessionManager
|
2020-02-04 07:41:52 +01:00
|
|
|
import mozilla.components.browser.state.state.WebExtensionState
|
2019-01-19 00:33:40 +01:00
|
|
|
import mozilla.components.concept.engine.EngineView
|
2019-08-23 01:56:13 +02:00
|
|
|
import mozilla.components.service.fxa.sync.SyncReason
|
2019-11-28 00:02:47 +01:00
|
|
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
2019-02-28 18:25:37 +01:00
|
|
|
import mozilla.components.support.ktx.kotlin.isUrl
|
|
|
|
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
2020-01-04 03:15:35 +01:00
|
|
|
import mozilla.components.support.locale.LocaleAwareAppCompatActivity
|
2019-02-06 23:31:39 +01:00
|
|
|
import mozilla.components.support.utils.SafeIntent
|
2019-08-20 19:00:49 +02:00
|
|
|
import mozilla.components.support.utils.toSafeIntent
|
2020-02-04 07:41:52 +01:00
|
|
|
import mozilla.components.support.webextensions.WebExtensionPopupFeature
|
2019-09-24 04:23:12 +02:00
|
|
|
import org.mozilla.fenix.browser.UriOpenedObserver
|
2019-08-21 17:33:59 +02:00
|
|
|
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
|
|
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
|
|
|
import org.mozilla.fenix.browser.browsingmode.DefaultBrowsingModeManager
|
2019-09-03 23:47:43 +02:00
|
|
|
import org.mozilla.fenix.components.metrics.BreadcrumbsRecorder
|
2019-09-18 18:47:30 +02:00
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.exceptions.ExceptionsFragmentDirections
|
|
|
|
import org.mozilla.fenix.ext.alreadyOnDestination
|
2019-01-23 22:39:53 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-06-06 21:40:10 +02:00
|
|
|
import org.mozilla.fenix.ext.nav
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.home.HomeFragmentDirections
|
2019-08-22 20:31:40 +02:00
|
|
|
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
|
|
|
|
import org.mozilla.fenix.home.intent.DeepLinkIntentProcessor
|
|
|
|
import org.mozilla.fenix.home.intent.OpenBrowserIntentProcessor
|
|
|
|
import org.mozilla.fenix.home.intent.SpeechProcessingIntentProcessor
|
|
|
|
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections
|
|
|
|
import org.mozilla.fenix.library.history.HistoryFragmentDirections
|
2019-12-06 19:46:17 +01:00
|
|
|
import org.mozilla.fenix.perf.HotStartPerformanceMonitor
|
2020-01-17 01:58:12 +01:00
|
|
|
import org.mozilla.fenix.perf.Performance
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.search.SearchFragmentDirections
|
2019-10-10 20:16:21 +02:00
|
|
|
import org.mozilla.fenix.settings.DefaultBrowserSettingsFragmentDirections
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.settings.SettingsFragmentDirections
|
2019-09-10 22:29:21 +02:00
|
|
|
import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
|
2020-01-09 20:28:21 +01:00
|
|
|
import org.mozilla.fenix.settings.about.AboutFragmentDirections
|
2020-01-25 03:13:44 +01:00
|
|
|
import org.mozilla.fenix.settings.logins.SavedLoginsFragmentDirections
|
2019-08-21 17:33:59 +02:00
|
|
|
import org.mozilla.fenix.theme.DefaultThemeManager
|
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
2020-01-04 10:35:46 +01:00
|
|
|
import org.mozilla.fenix.utils.BrowsersCache
|
2018-12-07 21:11:50 +01:00
|
|
|
|
2019-06-15 01:46:40 +02:00
|
|
|
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
2020-01-04 03:15:35 +01:00
|
|
|
open class HomeActivity : LocaleAwareAppCompatActivity() {
|
2019-03-18 22:32:03 +01:00
|
|
|
|
2020-02-04 07:41:52 +01:00
|
|
|
private var webExtScope: CoroutineScope? = null
|
2019-05-31 00:49:58 +02:00
|
|
|
lateinit var themeManager: ThemeManager
|
2019-08-20 19:00:49 +02:00
|
|
|
lateinit var browsingModeManager: BrowsingModeManager
|
|
|
|
|
|
|
|
private var sessionObserver: SessionManager.Observer? = null
|
2019-05-31 00:49:58 +02:00
|
|
|
|
2019-12-06 19:46:17 +01:00
|
|
|
private val hotStartMonitor = HotStartPerformanceMonitor()
|
|
|
|
|
2020-01-16 19:03:18 +01:00
|
|
|
private var isToolbarInflated = false
|
|
|
|
|
2020-02-04 07:41:52 +01:00
|
|
|
private val webExtensionPopupFeature by lazy {
|
|
|
|
WebExtensionPopupFeature(components.core.store, ::openPopup)
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:47:22 +01:00
|
|
|
private val navHost by lazy {
|
|
|
|
supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:31:40 +02:00
|
|
|
private val externalSourceIntentProcessors by lazy {
|
|
|
|
listOf(
|
2019-12-18 16:09:12 +01:00
|
|
|
SpeechProcessingIntentProcessor(this, components.analytics.metrics),
|
2019-08-22 20:31:40 +02:00
|
|
|
StartSearchIntentProcessor(components.analytics.metrics),
|
|
|
|
DeepLinkIntentProcessor(this),
|
|
|
|
OpenBrowserIntentProcessor(this, ::getIntentSessionId)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-01-27 14:33:57 +01:00
|
|
|
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
|
|
|
|
if (overrideConfiguration != null) {
|
|
|
|
val uiMode = overrideConfiguration.uiMode
|
|
|
|
overrideConfiguration.setTo(baseContext.resources.configuration)
|
|
|
|
overrideConfiguration.uiMode = uiMode
|
|
|
|
}
|
|
|
|
super.applyOverrideConfiguration(overrideConfiguration)
|
|
|
|
}
|
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
final override fun onCreate(savedInstanceState: Bundle?) {
|
2018-12-07 21:11:50 +01:00
|
|
|
super.onCreate(savedInstanceState)
|
2019-06-10 22:46:55 +02:00
|
|
|
|
2019-08-01 01:20:34 +02:00
|
|
|
components.publicSuffixList.prefetch()
|
2019-06-14 19:08:46 +02:00
|
|
|
|
2020-01-09 20:28:21 +01:00
|
|
|
setupThemeAndBrowsingMode(getModeFromIntentOrLastKnown(intent))
|
2019-06-14 19:08:46 +02:00
|
|
|
setContentView(R.layout.activity_home)
|
2020-01-17 01:58:12 +01:00
|
|
|
Performance.instrumentColdStartupToHomescreenTime(this)
|
2020-01-16 19:03:18 +01:00
|
|
|
|
|
|
|
externalSourceIntentProcessors.any { it.process(intent, navHost.navController, this.intent) }
|
2019-06-14 19:08:46 +02:00
|
|
|
|
2020-02-11 17:12:39 +01:00
|
|
|
Performance.processIntentIfPerformanceTest(intent, this)
|
2019-12-12 22:23:02 +01:00
|
|
|
|
2019-09-24 19:33:46 +02:00
|
|
|
if (settings().isTelemetryEnabled) {
|
2019-09-03 23:47:43 +02:00
|
|
|
lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter,
|
|
|
|
navHost.navController, ::getBreadcrumbMessage))
|
2019-06-14 19:08:46 +02:00
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
intent
|
|
|
|
?.toSafeIntent()
|
|
|
|
?.let(::getIntentSource)
|
|
|
|
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
|
2019-06-04 17:08:06 +02:00
|
|
|
}
|
2019-05-23 22:05:30 +02:00
|
|
|
supportActionBar?.hide()
|
2020-02-04 07:41:52 +01:00
|
|
|
|
|
|
|
lifecycle.addObserver(webExtensionPopupFeature)
|
2019-03-04 23:32:10 +01:00
|
|
|
}
|
2019-03-22 07:05:28 +01:00
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
@CallSuper
|
2019-05-29 00:26:36 +02:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2019-10-03 21:43:33 +02:00
|
|
|
|
2019-06-13 02:13:24 +02:00
|
|
|
lifecycleScope.launch {
|
|
|
|
with(components.backgroundServices) {
|
|
|
|
// Make sure accountManager is initialized.
|
|
|
|
accountManager.initAsync().await()
|
|
|
|
// If we're authenticated, kick-off a sync and a device state refresh.
|
|
|
|
accountManager.authenticatedAccount()?.let {
|
2019-08-23 01:56:13 +02:00
|
|
|
accountManager.syncNowAsync(SyncReason.Startup, debounce = true)
|
2019-06-13 02:13:24 +02:00
|
|
|
}
|
2019-05-29 00:26:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:46:17 +01:00
|
|
|
final override fun onRestart() {
|
|
|
|
hotStartMonitor.onRestartFirstMethodCall()
|
|
|
|
super.onRestart()
|
|
|
|
}
|
|
|
|
|
|
|
|
final override fun onPostResume() {
|
|
|
|
super.onPostResume()
|
|
|
|
hotStartMonitor.onPostResumeFinalMethodCall()
|
|
|
|
}
|
|
|
|
|
2020-01-04 10:35:46 +01:00
|
|
|
final override fun onPause() {
|
|
|
|
super.onPause()
|
|
|
|
|
|
|
|
// Every time the application goes into the background, it is possible that the user
|
|
|
|
// is about to change the browsers installed on their system. Therefore, we reset the cache of
|
|
|
|
// all the installed browsers.
|
|
|
|
//
|
|
|
|
// NB: There are ways for the user to install new products without leaving the browser.
|
|
|
|
BrowsersCache.resetAll()
|
|
|
|
}
|
2020-01-22 21:53:26 +01:00
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
/**
|
|
|
|
* Handles intents received when the activity is open.
|
|
|
|
*/
|
|
|
|
final override fun onNewIntent(intent: Intent?) {
|
|
|
|
super.onNewIntent(intent)
|
2019-08-22 20:31:40 +02:00
|
|
|
intent ?: return
|
|
|
|
|
|
|
|
val intentProcessors = listOf(CrashReporterIntentProcessor()) + externalSourceIntentProcessors
|
|
|
|
intentProcessors.any { it.process(intent, navHost.navController, this.intent) }
|
2020-01-09 20:28:21 +01:00
|
|
|
browsingModeManager.mode = getModeFromIntentOrLastKnown(intent)
|
2019-08-20 19:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides view inflation to inject a custom [EngineView] from [components].
|
|
|
|
*/
|
|
|
|
final override fun onCreateView(
|
2019-01-31 20:33:56 +01:00
|
|
|
parent: View?,
|
|
|
|
name: String,
|
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet
|
2019-08-20 19:00:49 +02:00
|
|
|
): View? = when (name) {
|
|
|
|
EngineView::class.java.name -> components.core.engine.createView(context, attrs).asView()
|
|
|
|
else -> super.onCreateView(parent, name, context, attrs)
|
|
|
|
}
|
2019-02-01 06:52:26 +01:00
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
final override fun onBackPressed() {
|
2019-02-01 06:52:26 +01:00
|
|
|
supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach {
|
2019-11-28 00:02:47 +01:00
|
|
|
if (it is UserInteractionHandler && it.onBackPressed()) {
|
2019-02-01 06:52:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
2019-02-06 23:31:39 +01:00
|
|
|
|
2019-09-03 23:47:43 +02:00
|
|
|
protected open fun getBreadcrumbMessage(destination: NavDestination): String {
|
2019-08-20 19:00:49 +02:00
|
|
|
val fragmentName = resources.getResourceEntryName(destination.id)
|
|
|
|
return "Changing to fragment $fragmentName, isCustomTab: false"
|
|
|
|
}
|
|
|
|
|
|
|
|
@VisibleForTesting(otherwise = PROTECTED)
|
|
|
|
internal open fun getIntentSource(intent: SafeIntent): Event.OpenedApp.Source? {
|
|
|
|
return when {
|
|
|
|
intent.isLauncherIntent -> Event.OpenedApp.Source.APP_ICON
|
|
|
|
intent.action == Intent.ACTION_VIEW -> Event.OpenedApp.Source.LINK
|
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 19:52:33 +02:00
|
|
|
/**
|
|
|
|
* External sources such as 3rd party links and shortcuts use this function to enter
|
2020-01-09 20:28:21 +01:00
|
|
|
* private mode directly before the content view is created. Returns the mode set by the intent
|
|
|
|
* otherwise falls back to the last known mode.
|
2019-09-11 19:52:33 +02:00
|
|
|
*/
|
2020-01-09 20:28:21 +01:00
|
|
|
internal fun getModeFromIntentOrLastKnown(intent: Intent?): BrowsingMode {
|
2019-09-11 19:52:33 +02:00
|
|
|
intent?.toSafeIntent()?.let {
|
|
|
|
if (it.hasExtra(PRIVATE_BROWSING_MODE)) {
|
|
|
|
val startPrivateMode = it.getBooleanExtra(PRIVATE_BROWSING_MODE, false)
|
2019-10-07 19:51:09 +02:00
|
|
|
return BrowsingMode.fromBoolean(isPrivate = startPrivateMode)
|
2019-09-11 19:52:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-09 20:28:21 +01:00
|
|
|
return settings().lastKnownMode
|
2019-09-11 19:52:33 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:09 +02:00
|
|
|
private fun setupThemeAndBrowsingMode(mode: BrowsingMode) {
|
2020-01-09 20:28:21 +01:00
|
|
|
settings().lastKnownMode = mode
|
2019-10-07 19:51:09 +02:00
|
|
|
browsingModeManager = createBrowsingModeManager(mode)
|
2019-08-20 19:00:49 +02:00
|
|
|
themeManager = createThemeManager()
|
|
|
|
themeManager.setActivityTheme(this)
|
|
|
|
themeManager.applyStatusBarTheme(this)
|
|
|
|
}
|
|
|
|
|
2020-01-16 19:03:18 +01:00
|
|
|
/**
|
|
|
|
* Returns the [supportActionBar], inflating it if necessary.
|
|
|
|
* Everyone should call this instead of supportActionBar.
|
|
|
|
*/
|
|
|
|
fun getSupportActionBarAndInflateIfNecessary(): ActionBar {
|
2019-08-20 19:00:49 +02:00
|
|
|
// Add ids to this that we don't want to have a toolbar back button
|
2020-01-16 19:03:18 +01:00
|
|
|
if (!isToolbarInflated) {
|
|
|
|
val navigationToolbar = navigationToolbarStub.inflate() as Toolbar
|
|
|
|
|
|
|
|
setSupportActionBar(navigationToolbar)
|
|
|
|
|
|
|
|
NavigationUI.setupWithNavController(
|
|
|
|
navigationToolbar,
|
|
|
|
navHost.navController,
|
|
|
|
AppBarConfiguration.Builder().build()
|
|
|
|
)
|
|
|
|
navigationToolbar.setNavigationOnClickListener {
|
|
|
|
onBackPressed()
|
|
|
|
}
|
2019-08-20 19:00:49 +02:00
|
|
|
|
2020-01-16 19:03:18 +01:00
|
|
|
isToolbarInflated = true
|
|
|
|
}
|
|
|
|
return supportActionBar!!
|
2019-08-14 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
protected open fun getIntentSessionId(intent: SafeIntent): String? = null
|
|
|
|
|
2019-05-09 23:21:33 +02:00
|
|
|
@Suppress("LongParameterList")
|
2019-03-29 21:49:50 +01:00
|
|
|
fun openToBrowserAndLoad(
|
2019-04-25 22:00:09 +02:00
|
|
|
searchTermOrURL: String,
|
2019-04-29 21:32:30 +02:00
|
|
|
newTab: Boolean,
|
|
|
|
from: BrowserDirection,
|
2019-04-29 17:30:32 +02:00
|
|
|
customTabSessionId: String? = null,
|
2019-05-09 23:21:33 +02:00
|
|
|
engine: SearchEngine? = null,
|
|
|
|
forceSearch: Boolean = false
|
2019-03-29 21:49:50 +01:00
|
|
|
) {
|
2019-04-29 17:30:32 +02:00
|
|
|
openToBrowser(from, customTabSessionId)
|
2019-05-09 23:21:33 +02:00
|
|
|
load(searchTermOrURL, newTab, engine, forceSearch)
|
2019-02-28 18:25:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-29 17:30:32 +02:00
|
|
|
fun openToBrowser(from: BrowserDirection, customTabSessionId: String? = null) {
|
2020-01-04 03:15:35 +01:00
|
|
|
if (sessionObserver == null) {
|
2019-09-24 04:23:12 +02:00
|
|
|
sessionObserver = UriOpenedObserver(this)
|
2020-01-04 03:15:35 +01:00
|
|
|
}
|
2019-06-06 21:16:31 +02:00
|
|
|
|
2019-08-22 01:29:45 +02:00
|
|
|
if (navHost.navController.alreadyOnDestination(R.id.browserFragment)) return
|
|
|
|
@IdRes val fragmentId = if (from.fragmentId != 0) from.fragmentId else null
|
2019-08-12 18:31:59 +02:00
|
|
|
val directions = getNavDirections(from, customTabSessionId)
|
2019-10-25 23:25:09 +02:00
|
|
|
if (directions != null) {
|
|
|
|
navHost.navController.nav(fragmentId, directions)
|
|
|
|
}
|
2019-02-06 23:31:39 +01:00
|
|
|
}
|
|
|
|
|
2019-08-12 18:31:59 +02:00
|
|
|
protected open fun getNavDirections(
|
|
|
|
from: BrowserDirection,
|
|
|
|
customTabSessionId: String?
|
2019-10-25 23:25:09 +02:00
|
|
|
): NavDirections? = when (from) {
|
2019-08-12 18:31:59 +02:00
|
|
|
BrowserDirection.FromGlobal ->
|
|
|
|
NavGraphDirections.actionGlobalBrowser(customTabSessionId)
|
|
|
|
BrowserDirection.FromHome ->
|
|
|
|
HomeFragmentDirections.actionHomeFragmentToBrowserFragment(customTabSessionId)
|
|
|
|
BrowserDirection.FromSearch ->
|
|
|
|
SearchFragmentDirections.actionSearchFragmentToBrowserFragment(customTabSessionId)
|
|
|
|
BrowserDirection.FromSettings ->
|
|
|
|
SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(customTabSessionId)
|
|
|
|
BrowserDirection.FromBookmarks ->
|
|
|
|
BookmarkFragmentDirections.actionBookmarkFragmentToBrowserFragment(customTabSessionId)
|
|
|
|
BrowserDirection.FromHistory ->
|
|
|
|
HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(customTabSessionId)
|
|
|
|
BrowserDirection.FromExceptions ->
|
|
|
|
ExceptionsFragmentDirections.actionExceptionsFragmentToBrowserFragment(
|
|
|
|
customTabSessionId
|
|
|
|
)
|
2019-09-03 22:16:29 +02:00
|
|
|
BrowserDirection.FromAbout ->
|
|
|
|
AboutFragmentDirections.actionAboutFragmentToBrowserFragment(customTabSessionId)
|
2019-09-10 22:29:21 +02:00
|
|
|
BrowserDirection.FromTrackingProtection ->
|
|
|
|
TrackingProtectionFragmentDirections.actionTrackingProtectionFragmentToBrowserFragment(
|
2019-10-03 21:43:33 +02:00
|
|
|
customTabSessionId
|
|
|
|
)
|
2019-10-10 20:16:21 +02:00
|
|
|
BrowserDirection.FromDefaultBrowserSettingsFragment ->
|
|
|
|
DefaultBrowserSettingsFragmentDirections.actionDefaultBrowserSettingsFragmentToBrowserFragment(
|
|
|
|
customTabSessionId
|
|
|
|
)
|
2020-01-25 03:13:44 +01:00
|
|
|
BrowserDirection.FromSavedLoginsFragment ->
|
|
|
|
SavedLoginsFragmentDirections.actionSavedLoginsFragmentToBrowserFragment(
|
|
|
|
customTabSessionId
|
|
|
|
)
|
2019-08-12 18:31:59 +02:00
|
|
|
}
|
|
|
|
|
2019-07-19 00:15:24 +02:00
|
|
|
private fun load(
|
|
|
|
searchTermOrURL: String,
|
|
|
|
newTab: Boolean,
|
|
|
|
engine: SearchEngine?,
|
|
|
|
forceSearch: Boolean
|
|
|
|
) {
|
2019-08-07 22:02:08 +02:00
|
|
|
val mode = browsingModeManager.mode
|
2019-02-28 18:25:37 +01:00
|
|
|
|
2019-04-29 21:32:30 +02:00
|
|
|
val loadUrlUseCase = if (newTab) {
|
2019-08-07 22:02:08 +02:00
|
|
|
when (mode) {
|
|
|
|
BrowsingMode.Private -> components.useCases.tabsUseCases.addPrivateTab
|
|
|
|
BrowsingMode.Normal -> components.useCases.tabsUseCases.addTab
|
2019-02-28 18:25:37 +01:00
|
|
|
}
|
|
|
|
} else components.useCases.sessionUseCases.loadUrl
|
|
|
|
|
|
|
|
val searchUseCase: (String) -> Unit = { searchTerms ->
|
2019-04-29 21:32:30 +02:00
|
|
|
if (newTab) {
|
2019-02-28 18:25:37 +01:00
|
|
|
components.useCases.searchUseCases.newTabSearch
|
2019-07-19 00:15:24 +02:00
|
|
|
.invoke(
|
|
|
|
searchTerms,
|
|
|
|
Session.Source.USER_ENTERED,
|
|
|
|
true,
|
2019-08-07 22:02:08 +02:00
|
|
|
mode.isPrivate,
|
2019-07-19 00:15:24 +02:00
|
|
|
searchEngine = engine
|
|
|
|
)
|
2019-03-29 21:49:50 +01:00
|
|
|
} else components.useCases.searchUseCases.defaultSearch.invoke(searchTerms, engine)
|
2019-02-28 18:25:37 +01:00
|
|
|
}
|
|
|
|
|
2019-05-09 23:21:33 +02:00
|
|
|
if (!forceSearch && searchTermOrURL.isUrl()) {
|
2019-04-25 22:00:09 +02:00
|
|
|
loadUrlUseCase.invoke(searchTermOrURL.toNormalizedUrl())
|
2019-02-28 18:25:37 +01:00
|
|
|
} else {
|
2019-04-25 22:00:09 +02:00
|
|
|
searchUseCase.invoke(searchTermOrURL)
|
2019-02-28 18:25:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 07:00:22 +02:00
|
|
|
fun updateThemeForSession(session: Session) {
|
2019-08-07 22:02:08 +02:00
|
|
|
val sessionMode = BrowsingMode.fromBoolean(session.private)
|
|
|
|
if (sessionMode != browsingModeManager.mode) {
|
|
|
|
browsingModeManager.mode = sessionMode
|
2019-04-27 07:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:09 +02:00
|
|
|
protected open fun createBrowsingModeManager(initialMode: BrowsingMode): BrowsingModeManager {
|
|
|
|
return DefaultBrowsingModeManager(initialMode) { newMode ->
|
|
|
|
themeManager.currentTheme = newMode
|
2019-05-31 01:13:06 +02:00
|
|
|
}
|
2019-05-31 00:49:58 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 19:00:49 +02:00
|
|
|
protected open fun createThemeManager(): ThemeManager {
|
|
|
|
return DefaultThemeManager(browsingModeManager.mode, this)
|
2019-05-31 00:49:58 +02:00
|
|
|
}
|
|
|
|
|
2020-02-04 07:41:52 +01:00
|
|
|
private fun openPopup(webExtensionState: WebExtensionState) {
|
|
|
|
val action = NavGraphDirections.actionGlobalWebExtensionActionPopupFragment(
|
|
|
|
webExtensionId = webExtensionState.id,
|
|
|
|
webExtensionTitle = webExtensionState.name
|
|
|
|
)
|
|
|
|
navHost.navController.navigate(action)
|
|
|
|
}
|
|
|
|
|
2019-02-06 23:31:39 +01:00
|
|
|
companion object {
|
|
|
|
const val OPEN_TO_BROWSER = "open_to_browser"
|
2019-07-11 19:24:58 +02:00
|
|
|
const val OPEN_TO_BROWSER_AND_LOAD = "open_to_browser_and_load"
|
|
|
|
const val OPEN_TO_SEARCH = "open_to_search"
|
2019-09-11 19:52:33 +02:00
|
|
|
const val PRIVATE_BROWSING_MODE = "private_browsing_mode"
|
2019-08-28 23:41:37 +02:00
|
|
|
const val EXTRA_DELETE_PRIVATE_TABS = "notification_delete_and_open"
|
|
|
|
const val EXTRA_OPENED_FROM_NOTIFICATION = "notification_open"
|
2019-02-06 23:31:39 +01:00
|
|
|
}
|
2018-12-07 21:11:50 +01:00
|
|
|
}
|