Skip to content

windows: report OS file drops to the host - #7

Merged
Y-PLONI merged 1 commit into
Otzaria:masterfrom
palmoni5:feat/windows-file-drop
Aug 13, 2026
Merged

windows: report OS file drops to the host#7
Y-PLONI merged 1 commit into
Otzaria:masterfrom
palmoni5:feat/windows-file-drop

Conversation

@palmoni5

Copy link
Copy Markdown
Member

Why

In visual (composition) hosting, WebViewDropTarget registers the Flutter view's only IDropTarget. Windows permits one per HWND, so a host app that wants OS file drops cannot add its own: whichever registers first wins, and a general-purpose drop package registers at plugin-registration time — before any webview exists. The webview's own RegisterDragDrop then fails with DRAGDROP_S_ALREADYREGISTERED and HTML5 drag and drop inside plugin webviews silently breaks again (the regression #5237 this target was written to fix).

What

Route file drags through the existing target instead of adding a second owner.

  • Registration is decoupled from webview lifetime (acquire / releaseIfUnused), so the target can exist for a host with no webview and is torn down when neither needs it.
  • New FileDropManager (channel …_filedrop): setEnabled opts in, and onFileDrop reports enter / over / leave / drop with the dragged paths (CF_HDROP) and client coordinates.
  • setAccepted carries the host's answer back and drives the drag cursor, so the effect is DROPEFFECT_COPY only where the host would actually take the drop, and the plain DROPEFFECT_NONE refusal everywhere else. The answer is asynchronous and therefore lags by one drag event, which the continuous DragOver stream absorbs.

Coordinates reuse the existing two-corner mapping, so they stay correct on RTL-mirrored windows (WS_EX_LAYOUTRTL).

Security

Unchanged: files still never reach WebView2. reportFileDrag calls forwardLeave() before reporting, so a file dropped on browser UI (e.g. print preview) still cannot bypass page-level and navigation guards. With no host opted in, behaviour is byte-for-byte the previous flat refusal.

Verification

  • Compiles and links in a real Flutter Windows app.
  • Verified by hand on Windows: drag cursor is COPY only over the host's drop region and the X elsewhere; dropping a file delivers its path to the host; a non-matching file is refused everywhere.
  • HTML5 drag and drop inside a plugin webview (draggable + dragover/drop) still works — the non-file path is untouched apart from the currentDragHasFiles_ early return, which is false for such drags.

palmoni5 added a commit to palmoni5/otzaria that referenced this pull request Aug 13, 2026
גרירת \u200E.otzplugin\u200E אל חלונית התוספים או אל משגר הכלים מתקינה אותו,
דרך אותו אירוע ואותו דיאלוג הרשאות שבורר הקבצים משתמש בהם.

ב-Windows יש \u200EIDropTarget\u200E אחד לכל חלון והוא בבעלות הפורק של
flutter_inappwebview, ולכן הגרירה מגיעה משם ולא מחבילת גרירה נפרדת —
חבילה כזו הייתה גוזלת את הרישום ושוברת בשקט את ה-HTML5 drag בתוספים.

הקליטה דולקת רק כשמותקן אזור קליטה, וה-Dart מחזיר ל-native החלטת
accept/reject כדי שסמן הגרירה יופיע רק מעל אזור שבאמת יקלוט את הקובץ.

תלוי ב-Otzaria/flutter_inappwebview#7; עד למיזוג ועדכון ה-ref הקוד רדום
(הערוץ אינו קיים, והחריגה נתפסת).
In visual hosting the webview drop target owns the Flutter view's only
IDropTarget, so a host that needs OS file drops cannot register its own
alongside it - RegisterDragDrop would fail with DRAGDROP_S_ALREADYREGISTERED
and silently disable HTML5 drag and drop inside webviews.

Route file drags through the existing target instead. Registration is no
longer tied to webview lifetime, and a host that opts in via the new
filedrop channel receives enter/over/leave/drop with the dragged paths.
Its setAccepted answer drives the drag cursor, so the effect is COPY only
where the host would actually take the drop.

Files still never reach WebView2: dropping one on browser UI bypasses
every page-level and navigation guard.
@palmoni5
palmoni5 force-pushed the feat/windows-file-drop branch from 9554913 to 5773ba0 Compare August 13, 2026 11:59
@palmoni5
palmoni5 changed the base branch from fix/windows-creation-failure-and-null-view to master August 13, 2026 11:59
@Y-PLONI
Y-PLONI merged commit 5773ba0 into Otzaria:master Aug 13, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants