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
|
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
|
2019-01-07 22:47:47 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
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
|
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
|
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
|
2019-10-03 21:43:33 +02:00
|
|
|
import mozilla.components.support.utils.Browsers
|
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
|
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
|
2019-08-22 01:29:45 +02:00
|
|
|
import org.mozilla.fenix.search.SearchFragmentDirections
|
2019-11-22 09:45:41 +01:00
|
|
|
import org.mozilla.fenix.settings.about.AboutFragmentDirections
|
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
|
2019-08-21 17:33:59 +02:00
|
|
|
import org.mozilla.fenix.theme.DefaultThemeManager
|
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
2019-10-03 21:43:33 +02:00
|
|
|
import java.lang.ref.WeakReference
|
2018-12-07 21:11:50 +01:00
|
|
|
|
2019-06-15 01:46:40 +02:00
|
|
|
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
2019-09-26 21:30:28 +02:00
|
|
|
open class HomeActivity : AppCompatActivity() {
|
2019-03-18 22:32:03 +01:00
|
|
|
|
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()
|
|
|
|
|
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(
|
|
|
|
SpeechProcessingIntentProcessor(this),
|
|
|
|
StartSearchIntentProcessor(components.analytics.metrics),
|
|
|
|
DeepLinkIntentProcessor(this),
|
|
|
|
OpenBrowserIntentProcessor(this, ::getIntentSessionId)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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-10-26 06:41:31 +02:00
|
|
|
val mode = getPrivateModeFromIntent(intent)
|
2019-09-11 19:52:33 +02:00
|
|
|
|
2019-08-01 01:20:34 +02:00
|
|
|
components.publicSuffixList.prefetch()
|
2019-10-07 19:51:09 +02:00
|
|
|
setupThemeAndBrowsingMode(mode)
|
2019-06-14 19:08:46 +02:00
|
|
|
|
|
|
|
setContentView(R.layout.activity_home)
|
|
|
|
|
|
|
|
setupToolbarAndNavigation()
|
|
|
|
|
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()
|
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-10-08 17:40:28 +02:00
|
|
|
unsetOpenLinksInAPrivateTabIfNecessary()
|
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-08-21 15:38:37 +02:00
|
|
|
it.deviceConstellation().pollForEventsAsync().await()
|
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()
|
|
|
|
}
|
|
|
|
|
2019-10-08 17:40:28 +02:00
|
|
|
private fun unsetOpenLinksInAPrivateTabIfNecessary() {
|
2019-10-03 21:43:33 +02:00
|
|
|
// Toggle off the open_link_in_private_tab pref if we are no longer set as the default browser
|
|
|
|
// We do this on a separate thread to alleviate performance issues
|
|
|
|
val weakReferenceContext = WeakReference(this)
|
|
|
|
lifecycleScope.launch {
|
|
|
|
val context = weakReferenceContext.get() ?: return@launch
|
|
|
|
if (!Browsers.all(context).isDefaultBrowser) {
|
|
|
|
context.settings().preferences
|
|
|
|
.edit()
|
|
|
|
.putBoolean(context.getString(R.string.pref_key_open_links_in_a_private_tab), false)
|
|
|
|
.apply()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) }
|
2019-10-26 06:41:31 +02:00
|
|
|
browsingModeManager.mode = getPrivateModeFromIntent(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
|
|
|
|
* private mode directly before the content view is created.
|
|
|
|
*/
|
2019-10-26 06:41:31 +02:00
|
|
|
private fun getPrivateModeFromIntent(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)
|
|
|
|
intent.removeExtra(PRIVATE_BROWSING_MODE)
|
2019-10-07 19:51:09 +02:00
|
|
|
|
|
|
|
return BrowsingMode.fromBoolean(isPrivate = startPrivateMode)
|
2019-09-11 19:52:33 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-07 19:51:09 +02:00
|
|
|
return BrowsingMode.Normal
|
2019-09-11 19:52:33 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:09 +02:00
|
|
|
private fun setupThemeAndBrowsingMode(mode: BrowsingMode) {
|
|
|
|
browsingModeManager = createBrowsingModeManager(mode)
|
2019-08-20 19:00:49 +02:00
|
|
|
themeManager = createThemeManager()
|
|
|
|
themeManager.setActivityTheme(this)
|
|
|
|
themeManager.applyStatusBarTheme(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setupToolbarAndNavigation() {
|
|
|
|
// Add ids to this that we don't want to have a toolbar back button
|
|
|
|
val appBarConfiguration = AppBarConfiguration.Builder().build()
|
|
|
|
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar)
|
|
|
|
setSupportActionBar(navigationToolbar)
|
|
|
|
NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration)
|
|
|
|
navigationToolbar.setNavigationOnClickListener {
|
|
|
|
onBackPressed()
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:31:40 +02:00
|
|
|
externalSourceIntentProcessors.any { it.process(intent, navHost.navController, this.intent) }
|
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) {
|
2019-06-06 21:16:31 +02:00
|
|
|
if (sessionObserver == null)
|
2019-09-24 04:23:12 +02:00
|
|
|
sessionObserver = UriOpenedObserver(this)
|
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
|
|
|
|
)
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|