mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 20:06:10 +00:00
fix(mobile): say which WebView to install when Android's is too old to open a workspace (#40907)
* fix(mobile): tell Android users which WebView to update when it is too old The page shell needs androidx's DOCUMENT_START_SCRIPT:1, which stable WebView only reports from Chromium 101; the comments claimed 83/88. Name the required WebView and the one installed, and how to switch it. * fix(mobile): read the WebView provider through the shell module index Tests stub the module index; a direct file import loaded expo-modules-core unstubbed.
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ internal enum class MobileWebShellBridgeInstall {
|
||||
/** The prop is false, so nothing is registered and Phase B behaviour is byte-identical. */
|
||||
SKIP,
|
||||
INSTALL,
|
||||
/** The WebView provider is older than `WEB_MESSAGE_LISTENER` (Chromium 88). Terminal. */
|
||||
/** The WebView provider is older than `WEB_MESSAGE_LISTENER` (Chromium 83). Terminal. */
|
||||
UNAVAILABLE
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ internal class MobileWebShellDocument(private val context: Context) {
|
||||
view.destroy()
|
||||
}
|
||||
|
||||
// Keep explicit settings for the Chromium 83 floor, even where newer WebViews ignore deprecated options.
|
||||
// Keep explicit settings even where newer WebViews ignore deprecated options; the floor is Chromium 101.
|
||||
// B4 requires device proofs: no network, persistent state, file/content access, cleartext or navigation escape.
|
||||
@Suppress("DEPRECATION")
|
||||
private fun createWebView(): WebView {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ internal val MOBILE_WEB_SHELL_NETWORK_API_BLOCKER = """
|
||||
})();
|
||||
""".trimIndent()
|
||||
|
||||
/** Query document-start-script capability (Chromium 83 floor), not version strings. */
|
||||
/** Query capability, not version strings; stable WebView has it from Chromium 101. */
|
||||
internal fun installMobileWebShellNetworkApiBlocker(
|
||||
webView: WebView,
|
||||
allowedOrigin: String
|
||||
|
||||
+13
@@ -8,6 +8,8 @@ import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.webkit.WebViewCompat
|
||||
import androidx.webkit.WebViewFeature
|
||||
import expo.modules.kotlin.exception.CodedException
|
||||
import expo.modules.kotlin.exception.Exceptions
|
||||
import expo.modules.kotlin.functions.Queues
|
||||
@@ -68,6 +70,17 @@ class OrcaMobileWebShellModule : Module() {
|
||||
Uri.fromFile(directory).toString()
|
||||
}
|
||||
|
||||
// Lets isolation-unavailable name the WebView to update.
|
||||
Function("currentWebViewProvider") {
|
||||
val context = appContext.reactContext ?: return@Function null
|
||||
val info = WebViewCompat.getCurrentWebViewPackage(context) ?: return@Function null
|
||||
val version = info.versionName ?: return@Function null
|
||||
val name = info.applicationInfo?.loadLabel(context.packageManager)?.toString() ?: info.packageName
|
||||
val hasShellFeatures = WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT) &&
|
||||
WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)
|
||||
mapOf("name" to name, "version" to version, "hasShellFeatures" to hasShellFeatures)
|
||||
}
|
||||
|
||||
AsyncFunction("prepareSpareDocument") { directory: String, sessionId: String ->
|
||||
val activity = appContext.currentActivity ?: return@AsyncFunction false
|
||||
MobileWebShellSparePool.prepare(activity, directory, sessionId)
|
||||
|
||||
@@ -18,7 +18,7 @@ export type OrcaMobileWebShellViewProps = ViewProps & {
|
||||
generationDirectory: string
|
||||
/** `[A-Za-z0-9_-]{1,128}`. Scopes the private origin, so every mount must mint a fresh one. */
|
||||
sessionId: string
|
||||
// Bridge is off by default with nothing registered. Opt-in on Android below WEB_MESSAGE_LISTENER/Chromium 88 fails isolation-unavailable instead of loading unfenced.
|
||||
// Bridge is off by default with nothing registered. Opt-in on Android below WEB_MESSAGE_LISTENER/Chromium 83 fails isolation-unavailable instead of loading unfenced.
|
||||
bridgeEnabled?: boolean
|
||||
onLoadState?: (event: NativeSyntheticEvent<MobileWebShellLoadStatePayload>) => void
|
||||
// Raw JSON from window.orcaBridge; native silently rejects other origins/frames/WebViews and envelopes above 640 KiB (MobileWebShellBridge.maxMessageByteCount).
|
||||
@@ -82,6 +82,23 @@ export function warmUpWebShell(): void {
|
||||
}
|
||||
}
|
||||
|
||||
export type WebViewProvider = { name: string; version: string; hasShellFeatures: boolean }
|
||||
|
||||
// Android only: the WebView provider and whether it has the shell's fences. Null when unknown.
|
||||
export function currentWebViewProvider(): WebViewProvider | null {
|
||||
if (Platform.OS !== 'android') {
|
||||
return null
|
||||
}
|
||||
const shell = requireOptionalNativeModule<{
|
||||
currentWebViewProvider?: () => WebViewProvider | null
|
||||
}>('OrcaMobileWebShell')
|
||||
try {
|
||||
return shell?.currentWebViewProvider?.() ?? null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
MOBILE_WEB_SHELL_FAILURE_REASONS,
|
||||
parseMobileWebShellLoadState,
|
||||
|
||||
@@ -820,6 +820,8 @@
|
||||
"webShell": {
|
||||
"shellStateScreen": {
|
||||
"isolationUnavailable": "This device's WebView is too old to open the workspace safely.",
|
||||
"isolationUnavailableAndroid": "Orca needs Android System WebView or Chrome 101 or newer. Update it from the Play Store, or pick a newer one in Developer options > WebView implementation.",
|
||||
"webViewInUse": "This device has {{name}} {{version}}.",
|
||||
"downloadFailed": "The latest app could not be downloaded from this host.",
|
||||
"hostProfileUnreadable": "Could not read this host on your device. Try again.",
|
||||
"statusUnreadable": "Could not read this host's status. Go back and reopen it.",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { Pressable, Text, View } from 'react-native'
|
||||
import { Platform, Pressable, Text, View } from 'react-native'
|
||||
import { currentWebViewProvider } from '../../modules/orca-mobile-web-shell/src'
|
||||
import { ProtocolBlockScreen } from '../components/ProtocolBlockScreen'
|
||||
import { colors, radii, spacing, typography } from '../theme/mobile-theme'
|
||||
import { themedStyleSheet } from '../theme/themed-styles'
|
||||
@@ -65,11 +66,30 @@ function Failed({
|
||||
useMobileColorScheme()
|
||||
// Retry cannot change a settled isolation gate or give an unsupported WebView the missing fence.
|
||||
const retryable = state.reason !== 'isolation-unavailable' && state.reason !== 'status-unreadable'
|
||||
const provider = state.reason === 'isolation-unavailable' ? currentWebViewProvider() : null
|
||||
// Unknown provider (older binary): a missing feature is still the likely cause.
|
||||
const webViewTooOld =
|
||||
Platform.OS === 'android' &&
|
||||
state.reason === 'isolation-unavailable' &&
|
||||
provider?.hasShellFeatures !== true
|
||||
return (
|
||||
<Centered>
|
||||
<Text style={styles.failedMessage} testID="mobile-web-shell-failed">
|
||||
{failureMessage(state.reason, t)}
|
||||
{webViewTooOld
|
||||
? t(
|
||||
'webShell.shellStateScreen.isolationUnavailableAndroid',
|
||||
'Orca needs Android System WebView or Chrome 101 or newer. Update it from the Play Store, or pick a newer one in Developer options > WebView implementation.'
|
||||
)
|
||||
: failureMessage(state.reason, t)}
|
||||
</Text>
|
||||
{webViewTooOld && provider ? (
|
||||
<Text style={styles.failedDetail}>
|
||||
{t('webShell.shellStateScreen.webViewInUse', 'This device has {{name}} {{version}}.', {
|
||||
name: provider.name,
|
||||
version: provider.version
|
||||
})}
|
||||
</Text>
|
||||
) : null}
|
||||
{retryable ? (
|
||||
<Pressable
|
||||
style={({ pressed }) => [styles.retryButton, pressed && styles.pressed]}
|
||||
@@ -160,6 +180,12 @@ const styles = themedStyleSheet(() => ({
|
||||
textAlign: 'center',
|
||||
marginBottom: spacing.lg
|
||||
},
|
||||
failedDetail: {
|
||||
fontSize: typography.metaSize,
|
||||
color: colors.textSecondary,
|
||||
textAlign: 'center',
|
||||
marginBottom: spacing.lg
|
||||
},
|
||||
retryButton: {
|
||||
backgroundColor: colors.bgRaised,
|
||||
paddingVertical: spacing.sm + 2,
|
||||
|
||||
Reference in New Issue
Block a user