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,7 +451,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
Widget _buildCollaboraIframe(String wopisrc) { Widget _buildCollaboraIframe(String wopisrc) {
// For Collabora Online, we need to POST the WOPISrc, not GET it // 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 // 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) { ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) {
// Create the iframe // Create the iframe
@@ -467,11 +468,12 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
) )
..setAttribute( ..setAttribute(
'sandbox', '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 // Create an HTML page with an auto-submitting form
final htmlContent = ''' final htmlContent =
'''
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@@ -489,7 +491,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
'''; ''';
// Set iframe src to a data URL with the form // 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; iframe.src = dataUrl;
// Create a container // Create a container