Changeset 94979 in webkit


Ignore:
Timestamp:
Sep 12, 2011 2:41:06 PM (13 years ago)
Author:
igor.oliveira@openbossa.org
Message:

2011-09-12 Igor Oliveira <igor.oliveira@openbossa.org>

[Qt] [WK2] implement support to upload files in Qt WebKit2
https://bugs.webkit.org/show_bug.cgi?id=67228

This patch implements support to upload files in the Desktop Qt WebKit2 implementation.

Reviewed by Andreas Kling.

  • Shared/WebOpenPanelParameters.h: (WebKit::WebOpenPanelParameters::selectedFileNames):
  • UIProcess/API/qt/qdesktopwebview.cpp: (QDesktopWebViewPrivate::chooseFiles): (QDesktopWebViewPrivate::onOpenPanelFilesSelected): (QDesktopWebViewPrivate::onOpenPanelFinished):
  • UIProcess/API/qt/qdesktopwebview_p.h:
  • UIProcess/qt/ClientImpl.cpp:

qt_wk_runOpenPanel supports single and multiple files selection.

(qt_wk_runOpenPanel):

  • UIProcess/qt/ClientImpl.h:
  • UIProcess/qt/QtWebPageProxy.cpp: (QtWebPageProxy::init):
  • UIProcess/qt/TouchViewInterface.h: (WebKit::TouchViewInterface::chooseFiles):
  • UIProcess/qt/ViewInterface.h:
Location:
trunk/Source/WebKit2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r94960 r94979  
     12011-09-12  Igor Oliveira  <igor.oliveira@openbossa.org>
     2
     3        [Qt] [WK2] implement support to upload files in Qt WebKit2
     4        https://bugs.webkit.org/show_bug.cgi?id=67228
     5
     6        This patch implements support to upload files in the Desktop Qt WebKit2 implementation.
     7
     8        Reviewed by Andreas Kling.
     9
     10        * Shared/WebOpenPanelParameters.h:
     11        (WebKit::WebOpenPanelParameters::selectedFileNames):
     12        * UIProcess/API/qt/qdesktopwebview.cpp:
     13        (QDesktopWebViewPrivate::chooseFiles):
     14        (QDesktopWebViewPrivate::onOpenPanelFilesSelected):
     15        (QDesktopWebViewPrivate::onOpenPanelFinished):
     16        * UIProcess/API/qt/qdesktopwebview_p.h:
     17        * UIProcess/qt/ClientImpl.cpp:
     18
     19        qt_wk_runOpenPanel supports single and multiple files selection.
     20
     21        (qt_wk_runOpenPanel):
     22        * UIProcess/qt/ClientImpl.h:
     23        * UIProcess/qt/QtWebPageProxy.cpp:
     24        (QtWebPageProxy::init):
     25        * UIProcess/qt/TouchViewInterface.h:
     26        (WebKit::TouchViewInterface::chooseFiles):
     27        * UIProcess/qt/ViewInterface.h:
     28
    1292011-09-12  Alexis Menard  <alexis.menard@openbossa.org>
    230
  • trunk/Source/WebKit2/Shared/WebOpenPanelParameters.h

    r74139 r94979  
    5656
    5757    bool allowMultipleFiles() const { return m_data.allowMultipleFiles; }
     58    Vector<String> selectedFileNames() const { return m_data.filenames; }
    5859
    5960private:
  • trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp

    r93784 r94979  
    2929#include <QtDeclarative/qsgitem.h>
    3030#include <QtGui/QCursor>
     31#include <QtGui/QFileDialog>
    3132#include <QtGui/QFocusEvent>
    3233#include <QtGui/QGraphicsSceneEvent>
     
    3637#include <QtGui/QTouchEvent>
    3738#include <QtGui/QWheelEvent>
     39#include <WKOpenPanelResultListener.h>
    3840
    3941QDesktopWebViewPrivate::QDesktopWebViewPrivate(QDesktopWebView* q, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     
    381383}
    382384
     385void QDesktopWebViewPrivate::chooseFiles(WKOpenPanelResultListenerRef listenerRef, const QStringList& selectedFileNames, ViewInterface::FileChooserType type)
     386{
     387#ifndef QT_NO_FILEDIALOG
     388    openPanelResultListener = listenerRef;
     389
     390    // Qt does not support multiple files suggestion, so we get just the first suggestion.
     391    QString selectedFileName;
     392    if (!selectedFileNames.isEmpty())
     393        selectedFileName = selectedFileNames.at(0);
     394
     395    QWidget* widget = q->canvas();
     396    fileDialog = new QFileDialog(widget, QString(), selectedFileName);
     397    fileDialog->open(this, SLOT(onOpenPanelFilesSelected()));
     398
     399    connect(fileDialog, SIGNAL(finished(int)), this, SLOT(onOpenPanelFinished(int)));
     400#endif
     401}
     402
     403void QDesktopWebViewPrivate::onOpenPanelFilesSelected()
     404{
     405    const QStringList fileList = fileDialog->selectedFiles();
     406    Vector<RefPtr<APIObject> > wkFiles(fileList.size());
     407
     408    for (unsigned i = 0; i < fileList.size(); ++i)
     409        wkFiles[i] = WebURL::create(QUrl::fromLocalFile(fileList.at(i)).toString());
     410
     411    WKOpenPanelResultListenerChooseFiles(openPanelResultListener, toAPI(ImmutableArray::adopt(wkFiles).leakRef()));
     412}
     413
     414void QDesktopWebViewPrivate::onOpenPanelFinished(int result)
     415{
     416    if (result == QDialog::Rejected)
     417        WKOpenPanelResultListenerCancel(openPanelResultListener);
     418
     419    fileDialog->deleteLater();
     420    fileDialog = 0;
     421}
     422
    383423static PolicyInterface::PolicyAction toPolicyAction(QDesktopWebView::NavigationPolicy policy)
    384424{
  • trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h

    r93427 r94979  
    2626#include "ViewInterface.h"
    2727
     28#include <QtCore/QObject>
     29
    2830class QDesktopWebView;
     31class QFileDialog;
    2932
    30 class QDesktopWebViewPrivate : public WebKit::ViewInterface, public WebKit::PolicyInterface
     33class QDesktopWebViewPrivate : public QObject, public WebKit::ViewInterface, public WebKit::PolicyInterface
    3134{
     35    Q_OBJECT
    3236public:
    3337    QDesktopWebViewPrivate(QDesktopWebView*, WKContextRef = 0, WKPageGroupRef = 0);
     
    4044    bool isCrashed;
    4145    QWebNavigationController* navigationController;
     46
     47private Q_SLOTS:
     48    void onOpenPanelFilesSelected();
     49    void onOpenPanelFinished(int result);
    4250
    4351private:
     
    7381    virtual void didRelaunchProcess();
    7482
     83    virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, ViewInterface::FileChooserType);
     84
    7585    // PolicyInterface.
    7686    virtual PolicyInterface::PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
    7787
    7888    QSharedPointer<QMenu> activeMenu;
     89
     90    QFileDialog* fileDialog;
     91    WKOpenPanelResultListenerRef openPanelResultListener;
    7992};
    8093
  • trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp

    r93784 r94979  
    3030#include <QtWebPageProxy.h>
    3131#include <ViewInterface.h>
     32#include <WKArray.h>
    3233#include <WKFrame.h>
    3334#include <WKFramePolicyListener.h>
     35#include <WKOpenPanelParameters.h>
     36#include <WKOpenPanelResultListener.h>
    3437#include <WKType.h>
    3538#include <WKURLRequest.h>
     
    146149    QString qText = WKStringCopyQString(text);
    147150    toViewInterface(clientInfo)->didChangeStatusText(qText);
     151}
     152
     153void qt_wk_runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo)
     154{
     155    Vector<String> wkSelectedFileNames = toImpl(parameters)->selectedFileNames();
     156
     157    QStringList selectedFileNames;
     158    if (!wkSelectedFileNames.isEmpty())
     159        for (unsigned i = 0; wkSelectedFileNames.size(); ++i)
     160            selectedFileNames += wkSelectedFileNames.at(i);
     161
     162    ViewInterface::FileChooserType allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? ViewInterface::MultipleFilesSelection : ViewInterface::SingleFileSelection;
     163    toViewInterface(clientInfo)->chooseFiles(listener, selectedFileNames, allowMultipleFiles);
    148164}
    149165
  • trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h

    r93784 r94979  
    4141// ui client
    4242void qt_wk_setStatusText(WKPageRef page, WKStringRef text, const void *clientInfo);
     43void qt_wk_runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef, WKOpenPanelResultListenerRef, const void* clientInfo);
    4344
    4445// Policy client.
  • trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp

    r94960 r94979  
    141141    uiClient.clientInfo = m_viewInterface;
    142142    uiClient.setStatusText = qt_wk_setStatusText;
     143    uiClient.runOpenPanel = qt_wk_runOpenPanel;
    143144    WKPageSetPageUIClient(toAPI(m_webPageProxy.get()), &uiClient);
    144145
  • trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h

    r94672 r94979  
    7676    virtual void didRelaunchProcess();
    7777
     78    virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList&, FileChooserType) { }
     79
    7880private:
    7981    QTouchWebView* const m_viewportView;
  • trunk/Source/WebKit2/UIProcess/qt/ViewInterface.h

    r93407 r94979  
    2525#include <QtCore/QSize>
    2626#include <QtGui/QMenu>
     27#include <WebKit2/WKBase.h>
    2728
    2829class QWebError;
     
    4849{
    4950public:
     51    enum FileChooserType {
     52        SingleFileSelection,
     53        MultipleFilesSelection
     54    };
     55
    5056    virtual void setViewNeedsDisplay(const QRect&) = 0;
    5157
     
    7884    virtual void processDidCrash() = 0;
    7985    virtual void didRelaunchProcess() = 0;
     86
     87    virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, FileChooserType) = 0;
    8088};
    8189
Note: See TracChangeset for help on using the changeset viewer.