forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes mozilla-mobile#2293 - Open custom tabs when leaving scope
Refactors PWA code so that it uses a BrowserFragment subclass.
- Loading branch information
Showing
32 changed files
with
727 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
...s/feature/pwa/src/main/java/mozilla/components/feature/pwa/AbstractWebAppShellActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
components/feature/pwa/src/main/java/mozilla/components/feature/pwa/ext/Bundle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* 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 mozilla.components.feature.pwa.ext | ||
|
||
import android.os.Bundle | ||
import mozilla.components.concept.engine.manifest.WebAppManifest | ||
import mozilla.components.concept.engine.manifest.WebAppManifestParser | ||
import mozilla.components.concept.engine.manifest.getOrNull | ||
|
||
internal const val EXTRA_WEB_APP_MANIFEST = "mozilla.components.feature.pwa.EXTRA_WEB_APP_MANIFEST" | ||
|
||
/** | ||
* Serializes and inserts a [WebAppManifest] value into the mapping of this [Bundle], | ||
* replacing any existing web app manifest. | ||
*/ | ||
fun Bundle.putWebAppManifest(webAppManifest: WebAppManifest?) { | ||
val json = webAppManifest?.let { WebAppManifestParser().serialize(it).toString() } | ||
putString(EXTRA_WEB_APP_MANIFEST, json) | ||
} | ||
|
||
/** | ||
* Parses and returns the [WebAppManifest] associated with this [Bundle], | ||
* or null if no mapping of the desired type exists. | ||
*/ | ||
fun Bundle.getWebAppManifest(): WebAppManifest? { | ||
return getString(EXTRA_WEB_APP_MANIFEST)?.let { json -> | ||
WebAppManifestParser().parse(json).getOrNull() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
components/feature/pwa/src/main/java/mozilla/components/feature/pwa/ext/Intent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* 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 mozilla.components.feature.pwa.ext | ||
|
||
import android.content.Intent | ||
import mozilla.components.concept.engine.manifest.WebAppManifest | ||
import mozilla.components.concept.engine.manifest.WebAppManifestParser | ||
|
||
/** | ||
* Add extended [WebAppManifest] data to the intent. | ||
*/ | ||
fun Intent.putWebAppManifest(webAppManifest: WebAppManifest) { | ||
val json = WebAppManifestParser().serialize(webAppManifest) | ||
putExtra(EXTRA_WEB_APP_MANIFEST, json.toString()) | ||
} | ||
|
||
/** | ||
* Retrieve extended [WebAppManifest] data from the intent. | ||
*/ | ||
fun Intent.getWebAppManifest(): WebAppManifest? { | ||
return extras?.getWebAppManifest() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...feature/pwa/src/main/java/mozilla/components/feature/pwa/feature/WebAppActivityFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* 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 mozilla.components.feature.pwa.feature | ||
|
||
import android.app.Activity | ||
import androidx.annotation.VisibleForTesting | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleObserver | ||
import androidx.lifecycle.OnLifecycleEvent | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.browser.icons.BrowserIcons | ||
import mozilla.components.browser.icons.extension.toIconRequest | ||
import mozilla.components.concept.engine.manifest.WebAppManifest | ||
import mozilla.components.feature.pwa.ext.applyOrientation | ||
import mozilla.components.feature.pwa.ext.toTaskDescription | ||
import mozilla.components.support.ktx.android.view.enterToImmersiveMode | ||
|
||
/** | ||
* Feature used to handle window effects for "standalone" and "fullscreen" web apps. | ||
*/ | ||
class WebAppActivityFeature( | ||
private val activity: Activity, | ||
private val icons: BrowserIcons, | ||
private val manifest: WebAppManifest | ||
) : LifecycleObserver { | ||
|
||
private val scope = MainScope() | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) | ||
fun onResume() { | ||
if (manifest.display == WebAppManifest.DisplayMode.FULLSCREEN) { | ||
activity.enterToImmersiveMode() | ||
} | ||
|
||
activity.applyOrientation(manifest) | ||
|
||
scope.launch { | ||
updateRecentEntry() | ||
} | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | ||
fun onDestroy() { | ||
scope.cancel() | ||
} | ||
|
||
@VisibleForTesting | ||
internal suspend fun updateRecentEntry() { | ||
val icon = icons.loadIcon(manifest.toIconRequest()).await() | ||
|
||
activity.setTaskDescription(manifest.toTaskDescription(icon.bitmap)) | ||
} | ||
} |
Oops, something went wrong.