diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index d918c2570..4e3f046b5 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -135,45 +135,42 @@ open class HomeActivity : AppCompatActivity() { } private fun handleOpenedFromExternalSourceIfNecessary(intent: Intent?) { - if (intent?.extras?.getBoolean(OPEN_TO_BROWSER) == true) { - handleOpenedFromExternalSource() - } - } + this.intent.putExtra(OPEN_TO_BROWSER, false) + var customTabSessionId: String? = null - private fun handleOpenedFromExternalSource() { - intent?.putExtra(OPEN_TO_BROWSER, false) - openToBrowser( - BrowserDirection.FromGlobal, - SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID) - ?: components.core.sessionManager.selectedSession?.id - ) + intent?.let { + if (isCustomTab) { + customTabSessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID) + } + openToBrowser(BrowserDirection.FromGlobal, customTabSessionId) + } } fun openToBrowserAndLoad( searchTermOrURL: String, - externalSessionId: String? = null, + customTabSessionId: String? = null, engine: SearchEngine? = null, from: BrowserDirection ) { - openToBrowser(from, externalSessionId) - load(searchTermOrURL, externalSessionId, engine) + openToBrowser(from, customTabSessionId) + load(searchTermOrURL, customTabSessionId, engine) } - fun openToBrowser(from: BrowserDirection, externalSessionId: String? = null) { + fun openToBrowser(from: BrowserDirection, customTabSessionId: String? = null) { val directions = when (from) { - BrowserDirection.FromGlobal -> NavGraphDirections.actionGlobalBrowser(externalSessionId) - BrowserDirection.FromHome -> HomeFragmentDirections.actionHomeFragmentToBrowserFragment(externalSessionId) + BrowserDirection.FromGlobal -> NavGraphDirections.actionGlobalBrowser(customTabSessionId) + BrowserDirection.FromHome -> HomeFragmentDirections.actionHomeFragmentToBrowserFragment(customTabSessionId) BrowserDirection.FromSearch -> - SearchFragmentDirections.actionSearchFragmentToBrowserFragment(externalSessionId) + SearchFragmentDirections.actionSearchFragmentToBrowserFragment(customTabSessionId) BrowserDirection.FromSettings -> - SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(externalSessionId) + SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(customTabSessionId) BrowserDirection.FromBookmarks -> - BookmarkFragmentDirections.actionBookmarkFragmentToBrowserFragment(externalSessionId) + BookmarkFragmentDirections.actionBookmarkFragmentToBrowserFragment(customTabSessionId) BrowserDirection.FromBookmarksFolderSelect -> SelectBookmarkFolderFragmentDirections - .actionBookmarkSelectFolderFragmentToBrowserFragment(externalSessionId) + .actionBookmarkSelectFolderFragmentToBrowserFragment(customTabSessionId) BrowserDirection.FromHistory -> - HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(externalSessionId) + HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(customTabSessionId) } if (sessionObserver == null) sessionObserver = subscribeToSessions() diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 63d4b2b33..c1dc66093 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -97,8 +97,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, private val customTabsIntegration = ViewBoundFeatureWrapper() private lateinit var job: Job - // Session id for custom tab or opened from external intent - var externalSessionId: String? = null + var customTabSessionId: String? = null override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job @@ -113,13 +112,13 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, savedInstanceState: Bundle? ): View? { require(arguments != null) - externalSessionId = BrowserFragmentArgs.fromBundle(arguments!!).externalSessionId + customTabSessionId = BrowserFragmentArgs.fromBundle(arguments!!).customTabSessionId val view = inflater.inflate(R.layout.fragment_browser, container, false) toolbarComponent = ToolbarComponent( view.browserLayout, - ActionBusFactory.get(this), externalSessionId, + ActionBusFactory.get(this), customTabSessionId, (activity as HomeActivity).browsingModeManager.isPrivate, SearchState("", getSessionById()?.searchTerms ?: "", isEditing = false), search_engine_icon @@ -150,7 +149,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } private fun getAppropriateLayoutGravity(): Int { - if (getSessionById()?.isCustomTabSession() == true) { + if (customTabSessionId != null) { return Gravity.TOP } @@ -206,7 +205,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, sessionManager, SessionUseCases(sessionManager), view.engineView, - externalSessionId + customTabSessionId ), owner = this, view = view @@ -241,7 +240,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, feature = FullScreenFeature( sessionManager, SessionUseCases(sessionManager), - externalSessionId + customTabSessionId ) { if (it) { 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) - if (getSessionById()?.isCustomTabSession() == true) { - externalSessionId?.let { - customTabsIntegration.set( - feature = CustomTabsIntegration( - requireContext(), - requireComponents.core.sessionManager, - toolbar, - it, - activity, - onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) } - ), - owner = this, - view = view) - } + customTabSessionId?.let { + customTabsIntegration.set( + feature = CustomTabsIntegration( + requireContext(), + requireComponents.core.sessionManager, + toolbar, + it, + activity, + onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) } + ), + owner = this, + view = view) } toolbarComponent.getView().setOnSiteSecurityClickedListener { @@ -508,8 +505,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, val directions = BrowserFragmentDirections .actionBrowserFragmentToSearchFragment(null) Navigation.findNavController(view!!).navigate(directions) - (activity as HomeActivity).browsingModeManager.mode = - BrowsingModeManager.Mode.Private + (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Private } ToolbarMenu.Item.FindInPage -> { FindInPageIntegration.launch?.invoke() @@ -529,8 +525,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, val directions = BrowserFragmentDirections .actionBrowserFragmentToSearchFragment(null) Navigation.findNavController(view!!).navigate(directions) - (activity as HomeActivity).browsingModeManager.mode = - BrowsingModeManager.Mode.Normal + (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal } ToolbarMenu.Item.OpenInFenix -> { val intent = Intent(context, IntentReceiverActivity::class.java) @@ -576,10 +571,10 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } private fun getSessionById(): Session? { - return if (externalSessionId != null) { + return if (customTabSessionId != null) { requireNotNull( requireContext().components.core.sessionManager.findSessionById( - externalSessionId!! + customTabSessionId!! ) ) } else { @@ -628,7 +623,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } private fun setToolbarBehavior(loading: Boolean) { - if (getSessionById()?.isCustomTabSession() == true) { + if (customTabSessionId != null) { return } diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index d6253c7db..eae61a3e2 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -104,7 +104,7 @@ android:id="@+id/action_browserFragment_to_searchFragment" app:destination="@id/searchFragment" />