You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't prevent dropped file from opening in Window #908
Dropping a filetype that the browser recognizes (my test file is an MP4 file) will always result in the file being opened and my app page being unloaded
So, I'm able to stop this in the renderer via document.drop, I think this is a bug around WebView and event propagation
In my WebView contents, I'm handling the drop event and preventing default. When I drop a file onto the WebView, the WebView gets the 'drop', but the renderer page (i.e. the WebView's host) also gets the 'drop' and proceeds to open the file.
If I prevent default in the renderer page, that stops the file from being opened, but it also stops the WebView from receiving the event too.
So, one thing that might make sense is, a way to pass Event objects to the WebView, so I can write something like:
The open-url and open-file events are emitted when you drag file to the dock icon or user opens your application from Finder, not related to drop-drag here.
To solve your problem, I think you can prevent host page to handle dragover event when dragging over <webview>:
Getting closer - this prevents the renderer from navigating to the movie and results in the webview getting the dragover event, but not the drop event. If you want an easy test, throw https://reactivex.slack.com/messages into a WebView then drop a movie into it (or other content that a browser would open directly)
@zcbenz I can do that, but I can't recreate the DataTransfer object in the WebView because the constructor is protected. I suppose I could read the files in the renderer via node.js then transfer them via IPC to the WebView, but that's potentially a lot of data to read up into memory and send over IPC since we allow uploading of arbitrarily large files.
The entire operation works if the file is not a MIME type that the browser can open inline (i.e. a zip file) and I allow everything (i.e. no preventDefault anywhere). Maybe we could rig Atom Shell to just never inline load files that are dropped onto the window?
This is something we should probably be doing anyways, or else every renderer process has to hook the drop event because you could accidentally drop a JPEG on the window and break the app. For apps that (for whatever reason) do want to directly inline load the file, they can hook drop and do the navigation themselves
The entire operation works if the file is not a MIME type that the browser can open inline (i.e. a zip file) and I allow everything (i.e. no preventDefault anywhere). Maybe we could rig Atom Shell to just never inline load files that are dropped onto the window?
I'm 👍 on this, I'll see if I can find a way to do it.
Activity
anaisbetts commentedon Dec 10, 2014
So, I'm able to stop this in the renderer via
document.drop, I think this is a bug around WebView and event propagationIn my WebView contents, I'm handling the
dropevent and preventing default. When I drop a file onto the WebView, the WebView gets the 'drop', but the renderer page (i.e. the WebView's host) also gets the 'drop' and proceeds to open the file.If I prevent default in the renderer page, that stops the file from being opened, but it also stops the WebView from receiving the event too.
So, one thing that might make sense is, a way to pass Event objects to the WebView, so I can write something like:
zcbenz commentedon Dec 10, 2014
The
open-urlandopen-fileevents are emitted when you drag file to the dock icon or user opens your application from Finder, not related to drop-drag here.To solve your problem, I think you can prevent host page to handle
dragoverevent when dragging over<webview>:anaisbetts commentedon Dec 10, 2014
Getting closer - this prevents the renderer from navigating to the movie and results in the
webviewgetting the dragover event, but not thedropevent. If you want an easy test, throwhttps://reactivex.slack.com/messagesinto a WebView then drop a movie into it (or other content that a browser would open directly)zcbenz commentedon Dec 10, 2014
There is also a bug of Chromium that
dropnever firing: https://code.google.com/p/chromium/issues/detail?id=412373It is not exactly the same with our case but I think they are the same bug.
I think you can work around this bug by sending a message to webview when the host page received
dropevent.anaisbetts commentedon Dec 10, 2014
@zcbenz I can do that, but I can't recreate the
DataTransferobject in the WebView because the constructor is protected. I suppose I could read the files in the renderer via node.js then transfer them via IPC to the WebView, but that's potentially a lot of data to read up into memory and send over IPC since we allow uploading of arbitrarily large files.The entire operation works if the file is not a MIME type that the browser can open inline (i.e. a zip file) and I allow everything (i.e. no
preventDefaultanywhere). Maybe we could rig Atom Shell to just never inline load files that are dropped onto the window?This is something we should probably be doing anyways, or else every renderer process has to hook the
dropevent because you could accidentally drop a JPEG on the window and break the app. For apps that (for whatever reason) do want to directly inline load the file, they can hookdropand do the navigation themselveszcbenz commentedon Dec 11, 2014
I'm 👍 on this, I'll see if I can find a way to do it.