Skip to content

Commit

Permalink
Closes mozilla-mobile#778 - Progressive Web Apps!
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Sep 25, 2019
1 parent b6e6e36 commit a64d8da
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 16 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
<data android:mimeType="text/plain" />
</intent-filter>

<intent-filter>
<action android:name="mozilla.components.feature.pwa.VIEW_PWA" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="https" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ object FeatureFlags {
* Gives option in Settings to Delete Browsing Data on new menu option Quit
*/
val deleteDataOnQuit = nightly or debug

/**
* Allows Progressive Web Apps to be installed to the device home screen.
*/
val progressiveWebApps = nightly or debug
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.content.Context
import mozilla.components.browser.session.SessionManager
import mozilla.components.feature.customtabs.CustomTabIntentProcessor
import mozilla.components.feature.intent.processing.TabIntentProcessor
import mozilla.components.feature.pwa.ManifestStorage
import mozilla.components.feature.pwa.intent.WebAppIntentProcessor
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import org.mozilla.fenix.test.Mockable
Expand Down Expand Up @@ -38,6 +40,7 @@ class IntentProcessors(

val externalAppIntentProcessors by lazy {
listOf(
WebAppIntentProcessor(sessionManager, sessionUseCases.loadUrl, ManifestStorage(context)),
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
)
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/UseCases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.session.SettingsUseCases
import mozilla.components.feature.tabs.TabsUseCases
import org.mozilla.fenix.FeatureFlags.progressiveWebApps
import org.mozilla.fenix.test.Mockable

/**
Expand Down Expand Up @@ -53,7 +54,9 @@ class UseCases(

val appLinksUseCases by lazy { AppLinksUseCases(context.applicationContext) }

val webAppUseCases by lazy { WebAppUseCases(context, sessionManager, httpClient, supportWebApps = false) }
val webAppUseCases by lazy {
WebAppUseCases(context, sessionManager, httpClient, supportWebApps = progressiveWebApps)
}

val downloadUseCases by lazy { DownloadsUseCases(sessionManager) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import mozilla.components.browser.menu.item.BrowserMenuHighlightableItem
import mozilla.components.browser.menu.item.BrowserMenuImageText
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
import mozilla.components.browser.menu.item.BrowserMenuSwitch
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.ext.asActivity
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.theme.ThemeManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
package org.mozilla.fenix.customtabs

import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
import mozilla.components.browser.session.runWithSession
import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.feature.intent.ext.getSessionId
import mozilla.components.feature.pwa.ext.getWebAppManifest
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
Expand All @@ -22,6 +25,7 @@ import java.security.InvalidParameterException
* such as custom tabs and progressive web apps.
*/
open class ExternalAppBrowserActivity : HomeActivity() {

final override fun getBreadcrumbMessage(destination: NavDestination): String {
val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: true"
Expand All @@ -34,12 +38,20 @@ open class ExternalAppBrowserActivity : HomeActivity() {
override fun getNavDirections(
from: BrowserDirection,
customTabSessionId: String?
) = when (from) {
BrowserDirection.FromGlobal ->
NavGraphDirections.actionGlobalExternalAppBrowser(customTabSessionId)
else -> throw InvalidParameterException(
"Tried to navigate to ExternalAppBrowserFragment from $from"
)
): NavDirections {
val manifest = intent
.getWebAppManifest()
?.let { WebAppManifestParser().serialize(it).toString() }
return when (from) {
BrowserDirection.FromGlobal ->
NavGraphDirections.actionGlobalExternalAppBrowser(
activeSessionId = customTabSessionId,
webAppManifest = manifest
)
else -> throw InvalidParameterException(
"Tried to navigate to ExternalAppBrowserFragment from $from"
)
}
}

final override fun createBrowsingModeManager() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ package org.mozilla.fenix.customtabs

import android.view.Gravity
import android.view.View
import androidx.core.view.isGone
import androidx.navigation.fragment.navArgs
import kotlinx.android.synthetic.main.component_search.*
import kotlinx.android.synthetic.main.fragment_browser.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import mozilla.components.browser.session.Session
import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.concept.engine.manifest.getOrNull
import mozilla.components.feature.pwa.ext.getTrustedScope
import mozilla.components.feature.pwa.ext.trustedOrigins
import mozilla.components.feature.pwa.feature.WebAppActivityFeature
import mozilla.components.feature.pwa.feature.WebAppHideToolbarFeature
import mozilla.components.feature.pwa.feature.WebAppSiteControlsFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BaseBrowserFragment
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
Expand All @@ -32,6 +40,8 @@ import org.mozilla.fenix.ext.requireComponents
@ExperimentalCoroutinesApi
class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {

private val args by navArgs<ExternalAppBrowserFragmentArgs>()

private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()
private val hideToolbarFeature = ViewBoundFeatureWrapper<WebAppHideToolbarFeature>()

Expand All @@ -40,6 +50,11 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
val activity = requireActivity()
val components = activity.components

val manifest = args.webAppManifest?.let { json ->
WebAppManifestParser().parse(json).getOrNull()
}
val trustedScopes = listOfNotNull(manifest?.getTrustedScope())

customTabSessionId?.let { customTabSessionId ->
customTabsIntegration.set(
feature = CustomTabsIntegration(
Expand All @@ -59,12 +74,29 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
requireComponents.core.sessionManager,
toolbar,
customTabSessionId,
emptyList()
trustedScopes
) { toolbarVisible ->
updateLayoutMargins(inFullScreen = !toolbarVisible)
},
owner = this,
view = toolbar)

if (manifest != null) {
activity.lifecycle.addObservers(
WebAppActivityFeature(
activity,
components.core.icons,
manifest
),
WebAppSiteControlsFeature(
activity.applicationContext,
requireComponents.core.sessionManager,
requireComponents.useCases.sessionUseCases.reload,
customTabSessionId,
manifest
)
)
}
}

consumeFrom(browserStore) {
Expand Down Expand Up @@ -121,8 +153,13 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
}

override fun getEngineMargins(): Pair<Int, Int> {
val toolbarSize = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height)
return toolbarSize to 0
val toolbarHidden = toolbar.isGone
return if (toolbarHidden) {
0 to 0
} else {
val toolbarSize = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height)
toolbarSize to 0
}
}

override fun getAppropriateLayoutGravity() = Gravity.TOP
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@
android:id="@+id/externalAppBrowserFragment"
android:name="org.mozilla.fenix.customtabs.ExternalAppBrowserFragment"
tools:layout="@layout/fragment_browser">
<argument
android:name="activeSessionId"
app:argType="string"
app:nullable="true" />
<argument android:name="activeSessionId" app:argType="string" app:nullable="true" />
<argument android:name="webAppManifest" app:argType="string" app:nullable="true"/>
<action
android:id="@+id/action_externalAppBrowserFragment_to_shareFragment"
app:destination="@id/shareFragment" />
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Versions {
const val androidx_work = "2.0.1"
const val google_material = "1.1.0-alpha10"

const val mozilla_android_components = "14.0.1"
const val mozilla_android_components = "15.0.0-SNAPSHOT"
// Note that android-components also depends on application-services,
// and in fact is our main source of appservices-related functionality.
// The version number below tracks the application-services version
Expand Down

0 comments on commit a64d8da

Please sign in to comment.