Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91489

Missing FileSelectionMode::FileSelectUploadFolder member

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.15.2
    • WebEngine
    • None
    • e648cd13290973ce30c5ff48574cb0f37f47c495

    Description

      In https://codereview.qt-project.org/c/qt/qtwebengine/+/74325, in the QWebEnginePage::chooseFiles implementation, WebContentsAdapterClient::UploadFolder is commented as Chromium extension, not exposed as part of the public API for now..

      However, despite being nonstandard, the webkitdirectory attribute triggering such an upload is widely supported and used by sites like Google Drive or OneDrive to let users upload an entire folder.

      When it gets triggered (such as via this example), QtWebEngine's default chooseFiles implementation handles it correctly - but if a subclass wants to override the behavior, it needs to handle a hardcoded enum value "2" because it's not exposed via FileSelectionMode.

      This can be observed by e.g. patching simplebrowser to log those values and then using the example above:

      diff --git i/examples/webenginewidgets/simplebrowser/webpage.cpp w/examples/webenginewidgets/simplebrowser/webpage.cpp
      index 9f7038cd..1a6c8280 100644
      --- i/examples/webenginewidgets/simplebrowser/webpage.cpp
      +++ w/examples/webenginewidgets/simplebrowser/webpage.cpp
      @@ -59,6 +59,7 @@
       #include <QStyle>
       #include <QTimer>
       #include <QWebEngineCertificateError>
      +#include <QDebug>
       
       WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
           : QWebEnginePage(profile, parent)
      @@ -116,6 +117,12 @@ bool WebPage::certificateError(const QWebEngineCertificateError &error)
       #endif
       }
       
      +QStringList WebPage::chooseFiles(QWebEnginePage::FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes)
      +{
      +    qDebug() << "chooseFiles: " << mode;
      +    return QWebEnginePage::chooseFiles(mode, oldFiles, acceptedMimeTypes);
      +}
      +
       void WebPage::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth)
       {
           QWidget *mainWindow = view()->window();
      diff --git i/examples/webenginewidgets/simplebrowser/webpage.h w/examples/webenginewidgets/simplebrowser/webpage.h
      index 90829589..78366334 100644
      --- i/examples/webenginewidgets/simplebrowser/webpage.h
      +++ w/examples/webenginewidgets/simplebrowser/webpage.h
      @@ -63,6 +63,7 @@ class WebPage : public QWebEnginePage
       
       protected:
           bool certificateError(const QWebEngineCertificateError &error) override;
      +    QStringList chooseFiles(QWebEnginePage::FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) override;
       
       private slots:
           void handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            egedi Balazs Egedi
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes