[fenix] No issue: Sets BrowserFragment sessionId only in custom tabs

pull/600/head
Sawyer Blatz 6 years ago committed by Emily Kager
parent 257e0ed550
commit 72485cbd45

@ -135,45 +135,42 @@ open class HomeActivity : AppCompatActivity() {
} }
private fun handleOpenedFromExternalSourceIfNecessary(intent: Intent?) { private fun handleOpenedFromExternalSourceIfNecessary(intent: Intent?) {
if (intent?.extras?.getBoolean(OPEN_TO_BROWSER) == true) { this.intent.putExtra(OPEN_TO_BROWSER, false)
handleOpenedFromExternalSource() var customTabSessionId: String? = null
}
}
private fun handleOpenedFromExternalSource() { intent?.let {
intent?.putExtra(OPEN_TO_BROWSER, false) if (isCustomTab) {
openToBrowser( customTabSessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
BrowserDirection.FromGlobal, }
SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID) openToBrowser(BrowserDirection.FromGlobal, customTabSessionId)
?: components.core.sessionManager.selectedSession?.id }
)
} }
fun openToBrowserAndLoad( fun openToBrowserAndLoad(
searchTermOrURL: String, searchTermOrURL: String,
externalSessionId: String? = null, customTabSessionId: String? = null,
engine: SearchEngine? = null, engine: SearchEngine? = null,
from: BrowserDirection from: BrowserDirection
) { ) {
openToBrowser(from, externalSessionId) openToBrowser(from, customTabSessionId)
load(searchTermOrURL, externalSessionId, engine) load(searchTermOrURL, customTabSessionId, engine)
} }
fun openToBrowser(from: BrowserDirection, externalSessionId: String? = null) { fun openToBrowser(from: BrowserDirection, customTabSessionId: String? = null) {
val directions = when (from) { val directions = when (from) {
BrowserDirection.FromGlobal -> NavGraphDirections.actionGlobalBrowser(externalSessionId) BrowserDirection.FromGlobal -> NavGraphDirections.actionGlobalBrowser(customTabSessionId)
BrowserDirection.FromHome -> HomeFragmentDirections.actionHomeFragmentToBrowserFragment(externalSessionId) BrowserDirection.FromHome -> HomeFragmentDirections.actionHomeFragmentToBrowserFragment(customTabSessionId)
BrowserDirection.FromSearch -> BrowserDirection.FromSearch ->
SearchFragmentDirections.actionSearchFragmentToBrowserFragment(externalSessionId) SearchFragmentDirections.actionSearchFragmentToBrowserFragment(customTabSessionId)
BrowserDirection.FromSettings -> BrowserDirection.FromSettings ->
SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(externalSessionId) SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(customTabSessionId)
BrowserDirection.FromBookmarks -> BrowserDirection.FromBookmarks ->
BookmarkFragmentDirections.actionBookmarkFragmentToBrowserFragment(externalSessionId) BookmarkFragmentDirections.actionBookmarkFragmentToBrowserFragment(customTabSessionId)
BrowserDirection.FromBookmarksFolderSelect -> BrowserDirection.FromBookmarksFolderSelect ->
SelectBookmarkFolderFragmentDirections SelectBookmarkFolderFragmentDirections
.actionBookmarkSelectFolderFragmentToBrowserFragment(externalSessionId) .actionBookmarkSelectFolderFragmentToBrowserFragment(customTabSessionId)
BrowserDirection.FromHistory -> BrowserDirection.FromHistory ->
HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(externalSessionId) HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(customTabSessionId)
} }
if (sessionObserver == null) if (sessionObserver == null)
sessionObserver = subscribeToSessions() sessionObserver = subscribeToSessions()

@ -97,8 +97,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>() private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()
private lateinit var job: Job private lateinit var job: Job
// Session id for custom tab or opened from external intent var customTabSessionId: String? = null
var externalSessionId: String? = null
override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job
@ -113,13 +112,13 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
require(arguments != null) require(arguments != null)
externalSessionId = BrowserFragmentArgs.fromBundle(arguments!!).externalSessionId customTabSessionId = BrowserFragmentArgs.fromBundle(arguments!!).customTabSessionId
val view = inflater.inflate(R.layout.fragment_browser, container, false) val view = inflater.inflate(R.layout.fragment_browser, container, false)
toolbarComponent = ToolbarComponent( toolbarComponent = ToolbarComponent(
view.browserLayout, view.browserLayout,
ActionBusFactory.get(this), externalSessionId, ActionBusFactory.get(this), customTabSessionId,
(activity as HomeActivity).browsingModeManager.isPrivate, (activity as HomeActivity).browsingModeManager.isPrivate,
SearchState("", getSessionById()?.searchTerms ?: "", isEditing = false), SearchState("", getSessionById()?.searchTerms ?: "", isEditing = false),
search_engine_icon search_engine_icon
@ -150,7 +149,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
} }
private fun getAppropriateLayoutGravity(): Int { private fun getAppropriateLayoutGravity(): Int {
if (getSessionById()?.isCustomTabSession() == true) { if (customTabSessionId != null) {
return Gravity.TOP return Gravity.TOP
} }
@ -206,7 +205,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
sessionManager, sessionManager,
SessionUseCases(sessionManager), SessionUseCases(sessionManager),
view.engineView, view.engineView,
externalSessionId customTabSessionId
), ),
owner = this, owner = this,
view = view view = view
@ -241,7 +240,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
feature = FullScreenFeature( feature = FullScreenFeature(
sessionManager, sessionManager,
SessionUseCases(sessionManager), SessionUseCases(sessionManager),
externalSessionId customTabSessionId
) { ) {
if (it) { if (it) {
FenixSnackbar.make(view.rootView, Snackbar.LENGTH_LONG) FenixSnackbar.make(view.rootView, Snackbar.LENGTH_LONG)
@ -279,20 +278,18 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java) val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java)
if (getSessionById()?.isCustomTabSession() == true) { customTabSessionId?.let {
externalSessionId?.let { customTabsIntegration.set(
customTabsIntegration.set( feature = CustomTabsIntegration(
feature = CustomTabsIntegration( requireContext(),
requireContext(), requireComponents.core.sessionManager,
requireComponents.core.sessionManager, toolbar,
toolbar, it,
it, activity,
activity, onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) } ),
), owner = this,
owner = this, view = view)
view = view)
}
} }
toolbarComponent.getView().setOnSiteSecurityClickedListener { toolbarComponent.getView().setOnSiteSecurityClickedListener {
@ -508,8 +505,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
val directions = BrowserFragmentDirections val directions = BrowserFragmentDirections
.actionBrowserFragmentToSearchFragment(null) .actionBrowserFragmentToSearchFragment(null)
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
(activity as HomeActivity).browsingModeManager.mode = (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Private
BrowsingModeManager.Mode.Private
} }
ToolbarMenu.Item.FindInPage -> { ToolbarMenu.Item.FindInPage -> {
FindInPageIntegration.launch?.invoke() FindInPageIntegration.launch?.invoke()
@ -529,8 +525,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
val directions = BrowserFragmentDirections val directions = BrowserFragmentDirections
.actionBrowserFragmentToSearchFragment(null) .actionBrowserFragmentToSearchFragment(null)
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
(activity as HomeActivity).browsingModeManager.mode = (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal
BrowsingModeManager.Mode.Normal
} }
ToolbarMenu.Item.OpenInFenix -> { ToolbarMenu.Item.OpenInFenix -> {
val intent = Intent(context, IntentReceiverActivity::class.java) val intent = Intent(context, IntentReceiverActivity::class.java)
@ -576,10 +571,10 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
} }
private fun getSessionById(): Session? { private fun getSessionById(): Session? {
return if (externalSessionId != null) { return if (customTabSessionId != null) {
requireNotNull( requireNotNull(
requireContext().components.core.sessionManager.findSessionById( requireContext().components.core.sessionManager.findSessionById(
externalSessionId!! customTabSessionId!!
) )
) )
} else { } else {
@ -628,7 +623,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
} }
private fun setToolbarBehavior(loading: Boolean) { private fun setToolbarBehavior(loading: Boolean) {
if (getSessionById()?.isCustomTabSession() == true) { if (customTabSessionId != null) {
return return
} }

@ -104,7 +104,7 @@
android:id="@+id/action_browserFragment_to_searchFragment" android:id="@+id/action_browserFragment_to_searchFragment"
app:destination="@id/searchFragment" /> app:destination="@id/searchFragment" />
<argument <argument
android:name="external_session_id" android:name="custom_tab_session_id"
app:argType="string" app:argType="string"
app:nullable="true" /> app:nullable="true" />
<action <action

Loading…
Cancel
Save