diff --git a/b0esche_cloud/lib/pages/document_viewer.dart b/b0esche_cloud/lib/pages/document_viewer.dart index 05ab0d1..48b4700 100644 --- a/b0esche_cloud/lib/pages/document_viewer.dart +++ b/b0esche_cloud/lib/pages/document_viewer.dart @@ -457,15 +457,28 @@ class _DocumentViewerModalState extends State { } Widget _buildCollaboraIframe(String collaboraUrl) { - // For Collabora Online, create an iframe that loads the editor directly - const String viewType = 'collabora-iframe'; + // For Collabora Online, we need to POST the WOPISrc, not GET it + // Create an iframe and submit a form to load the document + const String viewType = 'collabora-form'; ui.platformViewRegistry.registerViewFactory( viewType, (int viewId) { - // Create the iframe with the properly encoded Collabora URL + // Extract the WOPISrc from the URL + final uri = Uri.parse(collaboraUrl); + final wopisrc = uri.queryParameters['WOPISrc'] ?? ''; + + // Create a container for the form and iframe + final container = html.DivElement() + ..style.width = '100%' + ..style.height = '100%' + ..style.margin = '0' + ..style.padding = '0' + ..style.overflow = 'hidden'; + + // Create the iframe first final iframe = html.IFrameElement() - ..src = collaboraUrl + ..name = 'collabora-iframe' ..style.border = 'none' ..style.width = '100%' ..style.height = '100%' @@ -475,13 +488,35 @@ class _DocumentViewerModalState extends State { 'allow', 'microphone; camera; usb; autoplay; clipboard-read; clipboard-write', ) - // Remove allow-same-origin for security, add allow-popups-to-escape-sandbox ..setAttribute( 'sandbox', 'allow-scripts allow-popups allow-forms allow-pointer-lock allow-presentation allow-modals allow-downloads allow-popups-to-escape-sandbox', ); - return iframe; + container.append(iframe); + + // Create a hidden form that will POST to Collabora + final form = html.FormElement() + ..method = 'POST' + ..action = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html' + ..target = 'collabora-iframe' + ..style.display = 'none'; + + // Add WOPISrc as a hidden input + final wopisrcInput = html.InputElement() + ..type = 'hidden' + ..name = 'WOPISrc' + ..value = wopisrc; + + form.append(wopisrcInput); + container.append(form); + + // Use a timer to submit the form after the iframe is fully loaded + Future.delayed(const Duration(milliseconds: 100), () { + form.submit(); + }); + + return container; }, );