Changeset 275050 in webkit


Ignore:
Timestamp:
Mar 25, 2021 11:54:45 AM (16 months ago)
Author:
BJ Burg
Message:

SendKeys on Input of type=file returns element not found in some cases
https://bugs.webkit.org/show_bug.cgi?id=223028
<rdar://problem/75526126>

Reviewed by Devin Rousso.

This bizarre behavior is triggered by removing the <input type=file> element inside an onclick() handler
for the input element. This confuses safaridriver, which expects to be able to query the file input's .value
via JavaScript after setting the files.

As part of the fix, provide the list of selected filenames in the Automation.fileChooserDismissed event.
On the safaridriver side, just use the list of filenames provided in this event to avoid an extra JS evaluation
that may race with page content.

  • UIProcess/Automation/Automation.json:
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::handleRunOpenPanel):

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r275047 r275050  
     12021-03-25  BJ Burg  <bburg@apple.com>
     2
     3        SendKeys on Input of type=file returns element not found in some cases
     4        https://bugs.webkit.org/show_bug.cgi?id=223028
     5        <rdar://problem/75526126>
     6
     7        Reviewed by Devin Rousso.
     8
     9        This bizarre behavior is triggered by removing the <input type=file> element inside an onclick() handler
     10        for the input element. This confuses safaridriver, which expects to be able to query the file input's .value
     11        via JavaScript after setting the files.
     12
     13        As part of the fix, provide the list of selected filenames in the Automation.fileChooserDismissed event.
     14        On the safaridriver side, just use the list of filenames provided in this event to avoid an extra JS evaluation
     15        that may race with page content.
     16
     17        * UIProcess/Automation/Automation.json:
     18        * UIProcess/Automation/WebAutomationSession.cpp:
     19        (WebKit::WebAutomationSession::handleRunOpenPanel):
     20
    1212021-03-25  Alex Christensen  <achristensen@webkit.org>
    222
  • trunk/Source/WebKit/UIProcess/Automation/Automation.json

    r270582 r275050  
    722722            "parameters": [
    723723                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
    724                 { "name": "selectionCancelled", "type": "boolean", "description": "If true, the chooser was dismissed because file selection was cancelled." }
     724                { "name": "selectionCancelled", "type": "boolean", "description": "If true, file selection was cancelled due to an error. For example, this could occur if a file's MIME type cannot be handled by WebKit." },
     725                { "name": "selectedFiles", "type": "array", "items": { "type": "string" }, "optional": true, "description": "A list of file names that were successfully selected for upload." }
    725726            ]
    726727        },
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r274815 r275050  
    901901    if (!m_filesToSelectForFileUpload.size()) {
    902902        resultListener.cancel();
    903         m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
     903        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
    904904        return;
    905905    }
     
    907907    if (m_filesToSelectForFileUpload.size() > 1 && !parameters.allowMultipleFiles()) {
    908908        resultListener.cancel();
    909         m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
     909        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
    910910        return;
    911911    }
     
    926926
    927927    // Per §14.3.10.5 in the W3C spec, if at least one file cannot be accepted, the command should fail.
    928     // The REST API service can tell that this failed by checking the "files" attribute of the input element.
    929928    for (const String& filename : m_filesToSelectForFileUpload) {
    930929        if (!fileCanBeAcceptedForUpload(filename, allowedMIMETypes, allowedFileExtensions)) {
    931930            resultListener.cancel();
    932             m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
     931            m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
    933932            return;
    934933        }
    935934    }
    936935
     936    // Copy the file list we used before calling out to the open panel listener.
     937    Ref<JSON::ArrayOf<String>> selectedFiles = JSON::ArrayOf<String>::create();
     938    for (const String& filename : m_filesToSelectForFileUpload)
     939        selectedFiles->addItem(filename);
     940
    937941    resultListener.chooseFiles(m_filesToSelectForFileUpload);
    938     m_domainNotifier->fileChooserDismissed(browsingContextHandle, false);
     942
     943    m_domainNotifier->fileChooserDismissed(browsingContextHandle, false, WTFMove(selectedFiles));
    939944}
    940945
Note: See TracChangeset for help on using the changeset viewer.