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 Oct 8, 2019
1 parent 47f952a commit b6ad443
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 18 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
12 changes: 12 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ object FeatureFlags {
* Gives option in Settings to disable auto play media
*/
val autoPlayMedia = nightly or debug

val granularDataDeletion = nightly or debug

/**
* 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 @@ -32,12 +32,12 @@ class FindInPageIntegration(
}

override fun onLaunch(view: View, feature: LifecycleAwareFeature) {
store.state.findCustomTabOrSelectedTab(sessionId)?.let { session ->
if (session !is CustomTabSessionState) {
store.state.findCustomTabOrSelectedTab(sessionId)?.let { tab ->
if (tab is CustomTabSessionState) {
toolbar.visibility = View.GONE
}
view.visibility = View.VISIBLE
(feature as FindInPageFeature).bind(session)
(feature as FindInPageFeature).bind(tab)
view.layoutParams.height = toolbar.height
}
}
Expand Down
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 @@ -18,6 +18,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 @@ -55,7 +56,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(store) }

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.BrowserMenuImageSwitch
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,13 +6,20 @@ 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
Expand All @@ -32,6 +39,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 +49,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 +73,31 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
requireComponents.core.sessionManager,
toolbar,
customTabSessionId,
emptyList()
trustedScopes
) { toolbarVisible ->
updateLayoutMargins(inFullScreen = !toolbarVisible)
},
owner = this,
view = toolbar)

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

consumeFrom(browserStore) {
Expand Down Expand Up @@ -121,8 +154,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 @@ -198,10 +198,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

0 comments on commit b6ad443

Please sign in to comment.