Bug 109308 - Web Inspector: Add command for selecting files for file input element
Summary: Web Inspector: Add command for selecting files for file input element
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Ken Kania
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-08 09:28 PST by Ken Kania
Modified: 2013-02-21 01:20 PST (History)
16 users (show)

See Also:


Attachments
Patch (22.71 KB, patch)
2013-02-08 09:54 PST, Ken Kania
no flags Details | Formatted Diff | Diff
Patch (7.79 KB, patch)
2013-02-11 10:45 PST, Ken Kania
no flags Details | Formatted Diff | Diff
Patch (14.70 KB, patch)
2013-02-11 16:17 PST, Ken Kania
no flags Details | Formatted Diff | Diff
Patch (15.45 KB, patch)
2013-02-12 09:39 PST, Ken Kania
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Kania 2013-02-08 09:28:44 PST
We'd like to support choosing files for a file input element for automation. Proposal:

DOM.setFileInputFiles
nodeId: <NodeId>
files: Array<string>

For the chromium port, we'd have to allow the renderer to access these files in the browser process.
Comment 1 Ken Kania 2013-02-08 09:54:58 PST
Created attachment 187334 [details]
Patch
Comment 2 Pavel Feldman 2013-02-09 02:03:44 PST
Comment on attachment 187334 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=187334&action=review

> Source/WebCore/inspector/Inspector.json:2106
> +                "name": "setFileInputFiles",

I am not sure this fits DOM domain well, but I have no better idea.

> LayoutTests/inspector-protocol/dom-focus.html:-6
> -window.addEventListener("load", function() {

Please move these in a separate change.
Comment 3 Ken Kania 2013-02-11 10:45:32 PST
Created attachment 187613 [details]
Patch
Comment 4 Joseph Pecoraro 2013-02-11 11:23:24 PST
Neat. Is this intended to be protocol only (automating interaction with a page through the inspector protocol), or will there be UI for this in the frontend?

Setting arbitrary file paths on an <input type="file"> through the protocol sounds like it could be dangerous. I'm thinking of remotely inspecting a mobile device where often the file system is obscured to users. Take iOS for instance, setting arbitrary paths through <input type="file"> is not possible, but if exposed through the protocol here, it would be. Maybe it should just be up to the port to protect against this?
Comment 5 Ken Kania 2013-02-11 12:03:01 PST
(In reply to comment #4)
> Neat. Is this intended to be protocol only (automating interaction with a page through the inspector protocol), or will there be UI for this in the frontend?
> 
> Setting arbitrary file paths on an <input type="file"> through the protocol sounds like it could be dangerous. I'm thinking of remotely inspecting a mobile device where often the file system is obscured to users. Take iOS for instance, setting arbitrary paths through <input type="file"> is not possible, but if exposed through the protocol here, it would be. Maybe it should just be up to the port to protect against this?

My intention is only for automation. I think handling the validity/security of the file upload could be done at the port level. Is this feasible for iOS with the current design?
Comment 6 Joseph Pecoraro 2013-02-11 13:50:38 PST
(In reply to comment #5)
> (In reply to comment #4)
> > Neat. Is this intended to be protocol only (automating interaction with a page through the inspector protocol), or will there be UI for this in the frontend?
> > 
> > Setting arbitrary file paths on an <input type="file"> through the protocol sounds like it could be dangerous. I'm thinking of remotely inspecting a mobile device where often the file system is obscured to users. Take iOS for instance, setting arbitrary paths through <input type="file"> is not possible, but if exposed through the protocol here, it would be. Maybe it should just be up to the port to protect against this?
> 
> My intention is only for automation. I think handling the validity/security of the file upload could be done at the port level. Is this feasible for iOS with the current design?

That sounds reasonable. The port should be security conscious if it needs to be.

However, it would still be nice to opt out of this if needed. This could be done in the same way "canClearBrowserCache" and friends are done. An InspectorClient method, like:

    virtual bool canSetFileInputFiles() { return false; }

And an optional protocol method to see if the feature is enabled. If not a protocol method, then an error string with your new method to let the that the front-end, or automated front-end, to know whether or not the feature is supported. This would let the front-end know immediately that things are not supported, instead of failing later attempting the upload.
Comment 7 Joseph Pecoraro 2013-02-11 13:52:36 PST
> If not a protocol method, then an error string with your new method to let the that the front-end, or automated front-end, to know whether or not the feature is supported.

Correction: If not a protocol method, then an error result when your new protocol method is called. This would let the front-end, or automated front-end, know whether or not the feature is supported. [...]

Sorry for my poor grammar!
Comment 8 Ken Kania 2013-02-11 16:17:49 PST
Created attachment 187711 [details]
Patch
Comment 9 Build Bot 2013-02-11 18:49:39 PST
Comment on attachment 187711 [details]
Patch

Attachment 187711 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/16504359

New failing tests:
inspector-protocol/dom/setFileInputFiles.html
Comment 10 Yury Semikhatsky 2013-02-12 01:58:01 PST
Comment on attachment 187711 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=187711&action=review

> LayoutTests/inspector-protocol/dom/setFileInputFiles.html:6
> +window.addEventListener("load", onLoad);

To make it clear that onLoad is executed before runtTest I'd put runtTest() call at the end of onLoad and set onLoad as onload handler for <body>

> LayoutTests/inspector-protocol/dom/setFileInputFiles.html:24
> +    function abortOnError(msg)

WebKit style guide discourages using abbreviations.
Comment 11 Yury Semikhatsky 2013-02-12 01:58:51 PST
(In reply to comment #6)
> However, it would still be nice to opt out of this if needed. This could be done in the same way "canClearBrowserCache" and friends are done. An InspectorClient method, like:
> 
>     virtual bool canSetFileInputFiles() { return false; }
> 
Why not opt-in by default an have some ports to opt-out when needed?
Comment 12 Timothy Hatcher 2013-02-12 07:34:03 PST
(In reply to comment #11)
> (In reply to comment #6)
> > However, it would still be nice to opt out of this if needed. This could be done in the same way "canClearBrowserCache" and friends are done. An InspectorClient method, like:
> > 
> >     virtual bool canSetFileInputFiles() { return false; }
> > 
> Why not opt-in by default an have some ports to opt-out when needed?

I think opt-in makes more sense. This feature is only needed for automation, and that is not the focus for most ports. And as Joe mentioned this can be a security concern that would just be sitting there waiting to be exploited when it isn't needed by the port.
Comment 13 Ken Kania 2013-02-12 09:39:48 PST
Created attachment 187887 [details]
Patch
Comment 14 Ken Kania 2013-02-12 09:42:36 PST
(In reply to comment #13)
> Created an attachment (id=187887) [details]
> Patch

Addressed comments. Made default be to not allow setFileInputFiles. Enabled for chromium and added chromium-specific expectation.
Comment 15 WebKit Review Bot 2013-02-21 01:20:03 PST
Comment on attachment 187887 [details]
Patch

Clearing flags on attachment: 187887

Committed r143574: <http://trac.webkit.org/changeset/143574>
Comment 16 WebKit Review Bot 2013-02-21 01:20:08 PST
All reviewed patches have been landed.  Closing bug.