diff --git a/app/build.gradle b/app/build.gradle
index de6df0948..e79765528 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -118,6 +118,7 @@ dependencies {
implementation Deps.mozilla_feature_awesomebar
implementation Deps.mozilla_feature_contextmenu
+ implementation Deps.mozilla_feature_customtabs
implementation Deps.mozilla_feature_downloads
implementation Deps.mozilla_feature_intent
implementation Deps.mozilla_feature_prompts
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7200b00bd..d38e807c7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,6 +25,15 @@
+
+
@@ -47,6 +56,15 @@
+
+
+
+
+
+
components.core.engine.createView(
- context,
- attrs
- ).asView()
+ EngineView::class.java.name -> components.core.engine.createView(context, attrs).asView()
else -> super.onCreateView(parent, name, context, attrs)
}
diff --git a/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt b/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
index 5a4ab787e..d703a9102 100644
--- a/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
+++ b/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
@@ -9,6 +9,7 @@ import android.content.Intent
import android.os.Bundle
import mozilla.components.browser.session.tab.CustomTabConfig
import mozilla.components.support.utils.SafeIntent
+import org.mozilla.fenix.customtabs.CustomTabActivity
import org.mozilla.fenix.ext.components
class IntentReceiverActivity : Activity() {
@@ -20,7 +21,7 @@ class IntentReceiverActivity : Activity() {
val intent = Intent(intent)
if (CustomTabConfig.isCustomTabIntent(SafeIntent(intent))) {
- // TODO Enter CustomTabActivity here.
+ intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
} else {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
}
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 988cbe4bc..94eae4346 100644
--- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
+++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
@@ -23,6 +23,7 @@ import kotlinx.android.synthetic.main.fragment_browser.view.*
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.contextmenu.ContextMenuFeature
+import mozilla.components.feature.customtabs.CustomTabsToolbarFeature
import mozilla.components.feature.downloads.DownloadsFeature
import mozilla.components.feature.session.SessionFeature
import mozilla.components.feature.session.SessionUseCases
@@ -47,6 +48,7 @@ class BrowserFragment : Fragment(), BackHandler {
private lateinit var promptsFeature: PromptFeature
private lateinit var sessionFeature: SessionFeature
private lateinit var toolbarComponent: ToolbarComponent
+ private lateinit var customTabsToolbarFeature: CustomTabsToolbarFeature
override fun onCreateView(
inflater: LayoutInflater,
@@ -90,6 +92,8 @@ class BrowserFragment : Fragment(), BackHandler {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
+ val sessionId = arguments?.getString(SESSION_ID)
+
val sessionManager = requireComponents.core.sessionManager
contextMenuFeature = ContextMenuFeature(
@@ -122,18 +126,28 @@ class BrowserFragment : Fragment(), BackHandler {
sessionFeature = SessionFeature(
sessionManager,
SessionUseCases(sessionManager),
- view.engineView
+ view.engineView,
+ sessionId
)
findInPageIntegration = FindInPageIntegration(requireComponents.core.sessionManager, view.findInPageView)
+ customTabsToolbarFeature = CustomTabsToolbarFeature(
+ sessionManager,
+ toolbar,
+ sessionId,
+ requireComponents.toolbar.menuBuilder
+ ) { requireActivity().finish() }
+
+
lifecycle.addObservers(
contextMenuFeature,
downloadsFeature,
findInPageIntegration,
promptsFeature,
sessionFeature,
- (toolbarComponent.uiView as ToolbarUIView).toolbarIntegration
+ (toolbarComponent.uiView as ToolbarUIView).toolbarIntegration,
+ customTabsToolbarFeature
)
getSafeManagedObservable()
@@ -176,8 +190,15 @@ class BrowserFragment : Fragment(), BackHandler {
}
companion object {
+ private const val SESSION_ID = "session_id"
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
private const val TOOLBAR_HEIGHT = 56f
+
+ fun create(sessionId: String? = null): BrowserFragment = BrowserFragment().apply {
+ arguments = Bundle().apply {
+ putString(SESSION_ID, sessionId)
+ }
+ }
}
}
diff --git a/app/src/main/java/org/mozilla/fenix/components/Components.kt b/app/src/main/java/org/mozilla/fenix/components/Components.kt
index 53a44537f..f7d6a6b9f 100644
--- a/app/src/main/java/org/mozilla/fenix/components/Components.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/Components.kt
@@ -14,13 +14,7 @@ class Components(private val context: Context) {
val core by lazy { Core(context) }
val search by lazy { Search(context) }
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
- val toolbar by lazy {
- Toolbar(
- context,
- useCases.sessionUseCases,
- core.sessionManager
- )
- }
+ val toolbar by lazy { Toolbar(context, useCases.sessionUseCases, core.sessionManager) }
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
val analytics by lazy { Analytics(context) }
}
diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/Toolbar.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/Toolbar.kt
index add4d1181..9ebcdcaf7 100644
--- a/app/src/main/java/org/mozilla/fenix/components/toolbar/Toolbar.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/Toolbar.kt
@@ -40,7 +40,7 @@ class Toolbar(
ShippedDomainsProvider().also { it.initialize(context) }
}
- private val menuToolbar by lazy {
+ val menuToolbar by lazy {
val back = BrowserMenuItemToolbar.Button(
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
iconTintColorResource = R.color.icons,
diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt
index 14c25cfa0..931c83d73 100644
--- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt
@@ -10,6 +10,8 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.navigation.Navigation
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider
+import mozilla.components.browser.session.SessionManager
+import mozilla.components.browser.session.runWithSession
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
@@ -23,16 +25,16 @@ class ToolbarIntegration(
toolbar: BrowserToolbar,
domainAutocompleteProvider: DomainAutocompleteProvider,
historyStorage: HistoryStorage,
+ sessionManager: SessionManager,
sessionId: String? = null
) : LifecycleObserver {
init {
toolbar.setMenuBuilder(context.components.toolbar.menuBuilder)
val home = BrowserToolbar.Button(
- context.resources.getDrawable(
- R.drawable.ic_home,
- context.application.theme
- ), context.getString(R.string.browser_home_button)
+ context.resources.getDrawable(R.drawable.ic_home, context.application.theme),
+ context.getString(R.string.browser_home_button),
+ visible = { sessionManager.runWithSession(sessionId) { it.isCustomTabSession().not() } }
) {
Navigation.findNavController(toolbar).navigate(R.id.action_browserFragment_to_homeFragment)
}
diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt
new file mode 100644
index 000000000..d42a1c4f2
--- /dev/null
+++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ 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/. */
+
+package org.mozilla.fenix.customtabs
+
+import org.mozilla.fenix.HomeActivity
+
+class CustomTabActivity : HomeActivity()
diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt
new file mode 100644
index 000000000..1afa63bcf
--- /dev/null
+++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt
@@ -0,0 +1,15 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/.
+ */
+
+package org.mozilla.fenix.customtabs
+
+import mozilla.components.concept.engine.Engine
+import mozilla.components.feature.customtabs.AbstractCustomTabsService
+import org.mozilla.fenix.ext.components
+
+class CustomTabsService : AbstractCustomTabsService() {
+ override val engine: Engine by lazy { applicationContext.components.core.engine }
+}
diff --git a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarUIView.kt b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarUIView.kt
index 8eef786fc..33de9ca64 100644
--- a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarUIView.kt
+++ b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarUIView.kt
@@ -66,7 +66,8 @@ class ToolbarUIView(
this,
view,
ShippedDomainsProvider().also { it.initialize(this) },
- components.core.historyStorage
+ components.core.historyStorage,
+ components.core.sessionManager
)
}
}
diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml
index e1aba2210..f2a8a4144 100644
--- a/app/src/main/res/navigation/nav_graph.xml
+++ b/app/src/main/res/navigation/nav_graph.xml
@@ -46,6 +46,7 @@
+