feat: add WebView Plugin API#2525
Conversation
Add cordova-plugin-acode-webview allowing plugins to create and manage isolated WebView instances with fullscreen, window, panel, and hidden modes. Features: - Create independent WebView instances via acode.webview.create() - Load URLs, HTML content, and execute JavaScript - Bidirectional messaging between plugin and WebView - Lifecycle management: show, hide, reload, destroy - Lifecycle events: pageFinished, titleChanged, closed
Fullscreen mode is now a clean full-screen WebView with no chrome. Back button handles navigation and closing.
Greptile SummaryThis PR introduces
Confidence Score: 5/5The Java and JS implementation is solid — URL sandboxing, bridge re-injection, and fullscreen lifecycle management are all handled correctly. The remaining comments are non-blocking quality improvements. The core correctness issues flagged in earlier review rounds (null plugin singleton, lifecycle listeners not firing, navigation removing the message bridge, file-origin access) have all been fixed. The findings in this pass are a deprecated API, a potential double-fire of the closed event on explicit destroy, and use of a plain HashMap across threads — none of which cause data loss or broken functionality in normal use. Files Needing Attention: WebViewActivity.java and WebViewPlugin.java are worth a second glance for the unconditional closed event dispatch and the HashMap threading model. Important Files Changed
Sequence DiagramsequenceDiagram
participant Plugin as Plugin JS
participant WebviewJS as src/lib/webview.js
participant Bridge as www/webview.js (Cordova)
participant WVPlugin as WebViewPlugin.java
participant WVInstance as WebViewInstance.java
participant WVActivity as WebViewActivity.java
Plugin->>WebviewJS: "acode.webview.create({ mode, visible })"
WebviewJS->>Bridge: setMessageCallback (once, ensureInit)
WebviewJS->>Bridge: create(options)
Bridge->>WVPlugin: execute(create, options)
WVPlugin->>WVInstance: new WebViewInstance(id, mode, ...)
alt "mode === fullscreen && visible"
WVPlugin->>WVActivity: startActivity(intent + webviewId)
WVActivity->>WVInstance: createWebView(activity)
WVInstance->>WVInstance: injectBridge()
else "mode === hidden"
WVPlugin->>WVInstance: createWebView(activity)
WVInstance->>WVInstance: injectBridge()
end
WVPlugin-->>Bridge: callbackContext.success(id)
Bridge-->>WebviewJS: Promise resolves with id
WebviewJS-->>Plugin: new WebView(id) instance
Plugin->>WebviewJS: wv.loadURL(url)
WebviewJS->>Bridge: loadURL(id, url)
Bridge->>WVPlugin: execute(loadURL, ...)
WVPlugin->>WVInstance: loadURL(safeUrl)
WVInstance->>WVInstance: sanitizeUrl - http/https only
WVInstance-->>Bridge: callbackContext.success()
WVInstance->>WVPlugin: sendEventToCordova(id, pageFinished, data)
WVPlugin-->>Bridge: PluginResult keepCallback
Bridge-->>WebviewJS: message callback fires
WebviewJS-->>Plugin: on pageFinished listeners
Plugin->>WebviewJS: wv.destroy()
WebviewJS->>Bridge: destroy(id)
Bridge->>WVPlugin: execute(destroy, id)
WVPlugin->>WVInstance: instance.destroy()
WVInstance->>WVActivity: hosting.finish()
WVActivity->>WVPlugin: sendEventToCordova(webviewId, closed, null)
WVActivity-->>WVPlugin: onDestroy complete
WVPlugin-->>Bridge: callbackContext.success()
Bridge-->>WebviewJS: destroy() resolves
Reviews (4): Last reviewed commit: "fix: lock" | Re-trigger Greptile |
- Fix event dispatch: filter callbacks by event name instead of
calling {event,callback} objects as functions (webview.js)
- Make hidden WebViews showable: attachToActivity() on first show()
- Remove universal file access (setAllowFileAccessFromFileURLs,
setAllowUniversalAccessFromFileURLs) for untrusted content
- Clean up fullscreen path: remove throwaway WebView in Activity,
register instance cleanup in onDestroy
- Add deprecated shouldOverrideUrlLoading(String) for compat
- Use Handler(Looper.getMainLooper()) instead of View.post()
so hidden WebViews can process loadURL/evaluate without a window
- Remove unused constructor params (title, x, y, initiallyVisible)
|
@greptile ai |
Add cordova-plugin-acode-webview allowing plugins to create and manage isolated WebView instances with fullscreen, window, panel, and hidden modes.
Features:
Pre/Post Merge To-do:
Closes #2281