browser export

This commit is contained in:
yves committed 2026-11-07 19:49:09 +01:00
1 parent 1d974b42a1
commit 0966c6de17
13 files changed
+640 -207

No files matched your search

@@ -79,13 +79,16 @@ class CesiumjsPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityA
when (call.method) {
"create" -> {
val html = call.argument<String>("html")
if (id == null || html == null) {
result.error("bad_args", "create requires id and html", null)
// A url makes a browser view: loaded from the network, links
// stay in the view.
val url = call.argument<String>("url")
if (id == null || (html == null && url == null)) {
result.error("bad_args", "create requires id and html or url", null)
} else if (views.containsKey(id)) {
result.error("exists", "a view with this id already exists", null)
} else {
val baseUrl = call.argument<String>("baseUrl") ?: BASE_URL
views[id] = createWebView(id, html, baseUrl)
views[id] = createWebView(id, html, baseUrl, url)
result.success(null)
}
}
@@ -101,6 +104,27 @@ class CesiumjsPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityA
}
}
}
"loadUrl" -> {
val view = views[id]
val url = call.argument<String>("url")
when {
view == null -> result.error("not_found", "unknown view id", null)
url == null -> result.error("bad_args", "url missing", null)
else -> {
view.loadUrl(url)
result.success(null)
}
}
}
"reload" -> {
val view = views[id]
if (view == null) {
result.error("not_found", "unknown view id", null)
} else {
view.reload()
result.success(null)
}
}
// No in-app inspector on Android: use chrome://inspect (debug builds).
"openInspector" -> result.success(null)
"dispose" -> {
@@ -116,9 +140,10 @@ class CesiumjsPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityA
}
@SuppressLint("SetJavaScriptEnabled")
private fun createWebView(id: Int, html: String, baseUrl: String): WebView {
private fun createWebView(id: Int, html: String?, baseUrl: String, url: String?): WebView {
val browser = url != null
val view = WebView(activityContext ?: appContext)
view.setBackgroundColor(Color.BLACK)
if (!browser) view.setBackgroundColor(Color.BLACK)
view.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
@@ -138,7 +163,7 @@ class CesiumjsPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityA
v: WebView,
request: WebResourceRequest,
): Boolean {
if (!request.isForMainFrame) return false
if (browser || !request.isForMainFrame) return false
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(request.url.toString()))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -168,7 +193,11 @@ class CesiumjsPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityA
return true // keep the app alive
}
}
view.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8", null)
if (url != null) {
view.loadUrl(url)
} else {
view.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8", null)
}
return view
}