Fix: Refactor Collabora iframe creation for improved readability and maintainability

This commit is contained in:
Leon Bösche
2026-01-12 15:44:57 +01:00
parent 0ee3b32ef3
commit 64690231c2

View File

@@ -451,10 +451,11 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
Widget _buildCollaboraIframe(String wopisrc) {
// For Collabora Online, we need to POST the WOPISrc, not GET it
// Create an HTML page with auto-submitting form and set as iframe src
final String viewType = 'collabora-form-${DateTime.now().millisecondsSinceEpoch}';
final String viewType =
'collabora-form-${DateTime.now().millisecondsSinceEpoch}';
ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) {
// Create the iframe
// Create the iframe
final iframe = html.IFrameElement()
..style.border = 'none'
..style.width = '100%'
@@ -467,11 +468,12 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
)
..setAttribute(
'sandbox',
'allow-scripts allow-popups allow-forms allow-pointer-lock allow-presentation allow-modals allow-downloads allow-popups-to-escape-sandbox',
'allow-same-origin allow-scripts allow-popups allow-forms',
);
// Create an HTML page with an auto-submitting form
final htmlContent = '''
final htmlContent =
'''
<!DOCTYPE html>
<html>
<head>
@@ -489,7 +491,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
''';
// Set iframe src to a data URL with the form
final dataUrl = 'data:text/html;charset=utf-8,${Uri.encodeComponent(htmlContent)}';
final dataUrl =
'data:text/html;charset=utf-8,${Uri.encodeComponent(htmlContent)}';
iframe.src = dataUrl;
// Create a container