For #9056: Search from custom tab

pull/35/head
Tiger Oakes 4 years ago committed by Jonathan Almeida
parent 0cc1d32e56
commit 0b333fe48a

@ -40,13 +40,11 @@ import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.state.SessionState import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.state.WebExtensionState import mozilla.components.browser.state.state.WebExtensionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.contextmenu.DefaultSelectionActionDelegate import mozilla.components.feature.contextmenu.DefaultSelectionActionDelegate
import mozilla.components.feature.privatemode.notification.PrivateNotificationFeature import mozilla.components.feature.privatemode.notification.PrivateNotificationFeature
import mozilla.components.feature.search.BrowserStoreSearchAdapter import mozilla.components.feature.search.BrowserStoreSearchAdapter
import mozilla.components.feature.search.SearchAdapter
import mozilla.components.service.fxa.sync.SyncReason import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
@ -414,7 +412,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
): View? = when (name) { ): View? = when (name) {
EngineView::class.java.name -> components.core.engine.createView(context, attrs).apply { EngineView::class.java.name -> components.core.engine.createView(context, attrs).apply {
selectionActionDelegate = DefaultSelectionActionDelegate( selectionActionDelegate = DefaultSelectionActionDelegate(
getSearchAdapter(components.core.store), BrowserStoreSearchAdapter(
components.core.store,
tabId = getIntentSessionId(intent.toSafeIntent())
),
resources = context.resources, resources = context.resources,
shareTextClicked = { share(it) }, shareTextClicked = { share(it) },
emailTextClicked = { email(it) }, emailTextClicked = { email(it) },
@ -507,9 +508,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
super.onUserLeaveHint() super.onUserLeaveHint()
} }
protected open fun getSearchAdapter(store: BrowserStore): SearchAdapter =
BrowserStoreSearchAdapter(store)
protected open fun getBreadcrumbMessage(destination: NavDestination): String { protected open fun getBreadcrumbMessage(destination: NavDestination): String {
val fragmentName = resources.getResourceEntryName(destination.id) val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: false" return "Changing to fragment $fragmentName, isCustomTab: false"

@ -57,6 +57,7 @@ import mozilla.components.feature.privatemode.feature.SecureWindowFeature
import mozilla.components.feature.prompts.PromptFeature import mozilla.components.feature.prompts.PromptFeature
import mozilla.components.feature.prompts.share.ShareDelegate import mozilla.components.feature.prompts.share.ShareDelegate
import mozilla.components.feature.readerview.ReaderViewFeature import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.search.SearchFeature
import mozilla.components.feature.session.FullScreenFeature import mozilla.components.feature.session.FullScreenFeature
import mozilla.components.feature.session.PictureInPictureFeature import mozilla.components.feature.session.PictureInPictureFeature
import mozilla.components.feature.session.SessionFeature import mozilla.components.feature.session.SessionFeature
@ -152,6 +153,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
private val secureWindowFeature = ViewBoundFeatureWrapper<SecureWindowFeature>() private val secureWindowFeature = ViewBoundFeatureWrapper<SecureWindowFeature>()
private var fullScreenMediaFeature = private var fullScreenMediaFeature =
ViewBoundFeatureWrapper<MediaFullscreenOrientationFeature>() ViewBoundFeatureWrapper<MediaFullscreenOrientationFeature>()
private val searchFeature = ViewBoundFeatureWrapper<SearchFeature>()
private var pipFeature: PictureInPictureFeature? = null private var pipFeature: PictureInPictureFeature? = null
var customTabSessionId: String? = null var customTabSessionId: String? = null
@ -219,6 +221,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
} }
return getSessionById()?.also { session -> return getSessionById()?.also { session ->
val openInFenixIntent = Intent(context, IntentReceiverActivity::class.java).apply {
action = Intent.ACTION_VIEW
putExtra(HomeActivity.OPEN_TO_BROWSER, true)
}
val browserToolbarController = DefaultBrowserToolbarController( val browserToolbarController = DefaultBrowserToolbarController(
activity = requireActivity() as HomeActivity, activity = requireActivity() as HomeActivity,
navController = findNavController(), navController = findNavController(),
@ -234,10 +241,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
swipeRefresh = swipeRefresh, swipeRefresh = swipeRefresh,
browserAnimator = browserAnimator, browserAnimator = browserAnimator,
customTabSession = customTabSessionId?.let { sessionManager.findSessionById(it) }, customTabSession = customTabSessionId?.let { sessionManager.findSessionById(it) },
openInFenixIntent = Intent(context, IntentReceiverActivity::class.java).apply { openInFenixIntent = openInFenixIntent,
action = Intent.ACTION_VIEW
putExtra(HomeActivity.OPEN_TO_BROWSER, true)
},
bookmarkTapped = { viewLifecycleOwner.lifecycleScope.launch { bookmarkTapped(it) } }, bookmarkTapped = { viewLifecycleOwner.lifecycleScope.launch { bookmarkTapped(it) } },
scope = viewLifecycleOwner.lifecycleScope, scope = viewLifecycleOwner.lifecycleScope,
tabCollectionStorage = requireComponents.core.tabCollectionStorage, tabCollectionStorage = requireComponents.core.tabCollectionStorage,
@ -501,6 +505,26 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
view = view view = view
) )
searchFeature.set(
feature = SearchFeature(store, customTabSessionId) { request, tabId ->
val parentSession = sessionManager.findSessionById(tabId)
val useCase = if (request.isPrivate) {
requireComponents.useCases.searchUseCases.newPrivateTabSearch
} else {
requireComponents.useCases.searchUseCases.newTabSearch
}
if (parentSession?.isCustomTabSession() == true) {
useCase.invoke(request.query)
requireActivity().startActivity(openInFenixIntent)
} else {
useCase.invoke(request.query, parentSession = parentSession)
}
},
owner = this,
view = view
)
val accentHighContrastColor = val accentHighContrastColor =
ThemeManager.resolveAttribute(R.attr.accentHighContrast, context) ThemeManager.resolveAttribute(R.attr.accentHighContrast, context)

@ -25,7 +25,6 @@ import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.feature.app.links.AppLinksUseCases import mozilla.components.feature.app.links.AppLinksUseCases
import mozilla.components.feature.contextmenu.ContextMenuCandidate import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.readerview.ReaderViewFeature import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.search.SearchFeature
import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tabs.WindowFeature import mozilla.components.feature.tabs.WindowFeature
@ -53,7 +52,6 @@ import org.mozilla.fenix.trackingprotection.TrackingProtectionOverlay
class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
private val windowFeature = ViewBoundFeatureWrapper<WindowFeature>() private val windowFeature = ViewBoundFeatureWrapper<WindowFeature>()
private val searchFeature = ViewBoundFeatureWrapper<SearchFeature>()
private var readerModeAvailable = false private var readerModeAvailable = false
@ -141,23 +139,6 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
owner = this, owner = this,
view = view view = view
) )
searchFeature.set(
feature = SearchFeature(components.core.store) {
if (it.isPrivate) {
components.useCases.searchUseCases.newPrivateTabSearch.invoke(
it.query,
parentSession = getSessionById()
)
} else {
components.useCases.searchUseCases.newTabSearch.invoke(
it.query,
parentSession = getSessionById()
)
}
},
owner = this,
view = view
)
} }
} }

@ -4,19 +4,15 @@
package org.mozilla.fenix.customtabs package org.mozilla.fenix.customtabs
import android.content.Intent
import androidx.navigation.NavDestination import androidx.navigation.NavDestination
import androidx.navigation.NavDirections import androidx.navigation.NavDirections
import mozilla.components.browser.session.runWithSession import mozilla.components.browser.session.runWithSession
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.manifest.WebAppManifestParser import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.feature.intent.ext.getSessionId import mozilla.components.feature.intent.ext.getSessionId
import mozilla.components.feature.pwa.ext.getWebAppManifest import mozilla.components.feature.pwa.ext.getWebAppManifest
import mozilla.components.feature.search.SearchAdapter
import mozilla.components.support.utils.SafeIntent import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -28,12 +24,6 @@ import java.security.InvalidParameterException
*/ */
open class ExternalAppBrowserActivity : HomeActivity() { open class ExternalAppBrowserActivity : HomeActivity() {
private val openInFenixIntent by lazy {
Intent(this, IntentReceiverActivity::class.java).apply {
action = Intent.ACTION_VIEW
}
}
final override fun getBreadcrumbMessage(destination: NavDestination): String { final override fun getBreadcrumbMessage(destination: NavDestination): String {
val fragmentName = resources.getResourceEntryName(destination.id) val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: true" return "Changing to fragment $fragmentName, isCustomTab: true"
@ -73,19 +63,6 @@ open class ExternalAppBrowserActivity : HomeActivity() {
} }
} }
override fun getSearchAdapter(store: BrowserStore): SearchAdapter {
val baseAdapter = super.getSearchAdapter(store)
return object : SearchAdapter {
override fun sendSearch(isPrivate: Boolean, text: String) {
baseAdapter.sendSearch(isPrivate, text)
startActivity(openInFenixIntent)
}
override fun isPrivateSession() = baseAdapter.isPrivateSession()
}
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()

Loading…
Cancel
Save