summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
commit2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch)
tree988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp
parentdd91e772430dc294e3bf478c119ef8d43c0a3358 (diff)
downloadqtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp')
-rw-r--r--Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp197
1 files changed, 159 insertions, 38 deletions
diff --git a/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp b/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp
index 16c642934..6e41c8b39 100644
--- a/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp
@@ -21,12 +21,17 @@
#include "config.h"
#include "QtDialogRunner.h"
-#include <QtDeclarative/QDeclarativeComponent>
-#include <QtDeclarative/QDeclarativeContext>
-#include <QtDeclarative/QDeclarativeEngine>
+#include "WKRetainPtr.h"
+#include "WKStringQt.h"
+#include "qwebpermissionrequest_p.h"
+#include <QtQml/QQmlComponent>
+#include <QtQml/QQmlContext>
+#include <QtQml/QQmlEngine>
#include <QtQuick/QQuickItem>
#include <wtf/PassOwnPtr.h>
+namespace WebKit {
+
QtDialogRunner::QtDialogRunner()
: QEventLoop()
, m_wasAccepted(false)
@@ -69,23 +74,20 @@ private:
QString m_defaultValue;
};
-class AuthenticationDialogContextObject : public QObject {
+class BaseAuthenticationContextObject : public QObject {
Q_OBJECT
Q_PROPERTY(QString hostname READ hostname CONSTANT)
- Q_PROPERTY(QString realm READ realm CONSTANT)
Q_PROPERTY(QString prefilledUsername READ prefilledUsername CONSTANT)
public:
- AuthenticationDialogContextObject(const QString& hostname, const QString& realm, const QString& prefilledUsername)
+ BaseAuthenticationContextObject(const QString& hostname, const QString& prefilledUsername)
: QObject()
, m_hostname(hostname)
- , m_realm(realm)
, m_prefilledUsername(prefilledUsername)
{
}
QString hostname() const { return m_hostname; }
- QString realm() const { return m_realm; }
QString prefilledUsername() const { return m_prefilledUsername; }
public slots:
@@ -98,41 +100,41 @@ signals:
private:
QString m_hostname;
- QString m_realm;
QString m_prefilledUsername;
};
-class ProxyAuthenticationDialogContextObject : public QObject {
+class HttpAuthenticationDialogContextObject : public BaseAuthenticationContextObject {
+ Q_OBJECT
+ Q_PROPERTY(QString realm READ realm CONSTANT)
+
+public:
+ HttpAuthenticationDialogContextObject(const QString& hostname, const QString& realm, const QString& prefilledUsername)
+ : BaseAuthenticationContextObject(hostname, prefilledUsername)
+ , m_realm(realm)
+ {
+ }
+
+ QString realm() const { return m_realm; }
+
+private:
+ QString m_realm;
+};
+
+class ProxyAuthenticationDialogContextObject : public BaseAuthenticationContextObject {
Q_OBJECT
- Q_PROPERTY(QString hostname READ hostname CONSTANT)
Q_PROPERTY(quint16 port READ port CONSTANT)
- Q_PROPERTY(QString prefilledUsername READ prefilledUsername CONSTANT)
public:
ProxyAuthenticationDialogContextObject(const QString& hostname, quint16 port, const QString& prefilledUsername)
- : QObject()
- , m_hostname(hostname)
+ : BaseAuthenticationContextObject(hostname, prefilledUsername)
, m_port(port)
- , m_prefilledUsername(prefilledUsername)
{
}
- QString hostname() const { return m_hostname; }
quint16 port() const { return m_port; }
- QString prefilledUsername() const { return m_prefilledUsername; }
-
-public slots:
- void accept(const QString& username, const QString& password) { emit accepted(username, password); }
- void reject() { emit rejected(); }
-
-signals:
- void accepted(const QString& username, const QString& password);
- void rejected();
private:
- QString m_hostname;
quint16 m_port;
- QString m_prefilledUsername;
};
class CertificateVerificationDialogContextObject : public QObject {
@@ -160,7 +162,97 @@ private:
QString m_hostname;
};
-bool QtDialogRunner::initForAlert(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& message)
+class FilePickerContextObject : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QStringList fileList READ fileList CONSTANT)
+ Q_PROPERTY(bool allowMultipleFiles READ allowMultipleFiles CONSTANT)
+
+public:
+ FilePickerContextObject(const QStringList& selectedFiles, bool allowMultiple)
+ : QObject()
+ , m_allowMultiple(allowMultiple)
+ , m_fileList(selectedFiles)
+ {
+ }
+
+ QStringList fileList() const { return m_fileList; }
+ bool allowMultipleFiles() const { return m_allowMultiple;}
+
+public slots:
+ void reject() { emit rejected();}
+ void accept(const QVariant& path)
+ {
+ QStringList filesPath = path.toStringList();
+ // For single file upload, send only the first element if there are more than one file paths
+ if (!m_allowMultiple && filesPath.count() > 1)
+ filesPath = QStringList(filesPath.at(0));
+ emit fileSelected(filesPath);
+ }
+
+signals:
+ void rejected();
+ void fileSelected(const QStringList&);
+
+private:
+ bool m_allowMultiple;
+ QStringList m_fileList;
+};
+
+class DatabaseQuotaDialogContextObject : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString databaseName READ databaseName CONSTANT)
+ Q_PROPERTY(QString displayName READ displayName CONSTANT)
+ Q_PROPERTY(quint64 currentQuota READ currentQuota CONSTANT)
+ Q_PROPERTY(quint64 currentOriginUsage READ currentOriginUsage CONSTANT)
+ Q_PROPERTY(quint64 currentDatabaseUsage READ currentDatabaseUsage CONSTANT)
+ Q_PROPERTY(quint64 expectedUsage READ expectedUsage CONSTANT)
+ Q_PROPERTY(QtWebSecurityOrigin* origin READ securityOrigin CONSTANT)
+
+public:
+ DatabaseQuotaDialogContextObject(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage)
+ : QObject()
+ , m_databaseName(databaseName)
+ , m_displayName(displayName)
+ , m_currentQuota(currentQuota)
+ , m_currentOriginUsage(currentOriginUsage)
+ , m_currentDatabaseUsage(currentDatabaseUsage)
+ , m_expectedUsage(expectedUsage)
+ {
+ WKRetainPtr<WKStringRef> scheme = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin));
+ WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(securityOrigin));
+
+ m_securityOrigin.setScheme(WKStringCopyQString(scheme.get()));
+ m_securityOrigin.setHost(WKStringCopyQString(host.get()));
+ m_securityOrigin.setPort(static_cast<int>(WKSecurityOriginGetPort(securityOrigin)));
+ }
+
+ QString databaseName() const { return m_databaseName; }
+ QString displayName() const { return m_displayName; }
+ quint64 currentQuota() const { return m_currentQuota; }
+ quint64 currentOriginUsage() const { return m_currentOriginUsage; }
+ quint64 currentDatabaseUsage() const { return m_currentDatabaseUsage; }
+ quint64 expectedUsage() const { return m_expectedUsage; }
+ QtWebSecurityOrigin* securityOrigin() { return &m_securityOrigin; }
+
+public slots:
+ void accept(quint64 size) { emit accepted(size); }
+ void reject() { emit rejected(); }
+
+signals:
+ void accepted(quint64 size);
+ void rejected();
+
+private:
+ QString m_databaseName;
+ QString m_displayName;
+ quint64 m_currentQuota;
+ quint64 m_currentOriginUsage;
+ quint64 m_currentDatabaseUsage;
+ quint64 m_expectedUsage;
+ QtWebSecurityOrigin m_securityOrigin;
+};
+
+bool QtDialogRunner::initForAlert(QQmlComponent* component, QQuickItem* dialogParent, const QString& message)
{
DialogContextObject* contextObject = new DialogContextObject(message);
if (!createDialog(component, dialogParent, contextObject))
@@ -170,7 +262,7 @@ bool QtDialogRunner::initForAlert(QDeclarativeComponent* component, QQuickItem*
return true;
}
-bool QtDialogRunner::initForConfirm(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& message)
+bool QtDialogRunner::initForConfirm(QQmlComponent* component, QQuickItem* dialogParent, const QString& message)
{
DialogContextObject* contextObject = new DialogContextObject(message);
if (!createDialog(component, dialogParent, contextObject))
@@ -182,7 +274,7 @@ bool QtDialogRunner::initForConfirm(QDeclarativeComponent* component, QQuickItem
return true;
}
-bool QtDialogRunner::initForPrompt(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& message, const QString& defaultValue)
+bool QtDialogRunner::initForPrompt(QQmlComponent* component, QQuickItem* dialogParent, const QString& message, const QString& defaultValue)
{
DialogContextObject* contextObject = new DialogContextObject(message, defaultValue);
if (!createDialog(component, dialogParent, contextObject))
@@ -194,9 +286,9 @@ bool QtDialogRunner::initForPrompt(QDeclarativeComponent* component, QQuickItem*
return true;
}
-bool QtDialogRunner::initForAuthentication(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& hostname, const QString& realm, const QString& prefilledUsername)
+bool QtDialogRunner::initForAuthentication(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname, const QString& realm, const QString& prefilledUsername)
{
- AuthenticationDialogContextObject* contextObject = new AuthenticationDialogContextObject(hostname, realm, prefilledUsername);
+ HttpAuthenticationDialogContextObject* contextObject = new HttpAuthenticationDialogContextObject(hostname, realm, prefilledUsername);
if (!createDialog(component, dialogParent, contextObject))
return false;
@@ -207,7 +299,7 @@ bool QtDialogRunner::initForAuthentication(QDeclarativeComponent* component, QQu
return true;
}
-bool QtDialogRunner::initForProxyAuthentication(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& hostname, uint16_t port, const QString& prefilledUsername)
+bool QtDialogRunner::initForProxyAuthentication(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname, uint16_t port, const QString& prefilledUsername)
{
ProxyAuthenticationDialogContextObject* contextObject = new ProxyAuthenticationDialogContextObject(hostname, port, prefilledUsername);
if (!createDialog(component, dialogParent, contextObject))
@@ -220,7 +312,7 @@ bool QtDialogRunner::initForProxyAuthentication(QDeclarativeComponent* component
return true;
}
-bool QtDialogRunner::initForCertificateVerification(QDeclarativeComponent* component, QQuickItem* dialogParent, const QString& hostname)
+bool QtDialogRunner::initForCertificateVerification(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname)
{
CertificateVerificationDialogContextObject* contextObject = new CertificateVerificationDialogContextObject(hostname);
if (!createDialog(component, dialogParent, contextObject))
@@ -233,12 +325,38 @@ bool QtDialogRunner::initForCertificateVerification(QDeclarativeComponent* compo
return true;
}
-bool QtDialogRunner::createDialog(QDeclarativeComponent* component, QQuickItem* dialogParent, QObject* contextObject)
+bool QtDialogRunner::initForFilePicker(QQmlComponent* component, QQuickItem* dialogParent, const QStringList& selectedFiles, bool allowMultiple)
+{
+ FilePickerContextObject* contextObject = new FilePickerContextObject(selectedFiles, allowMultiple);
+ if (!createDialog(component, dialogParent, contextObject))
+ return false;
+
+ connect(contextObject, SIGNAL(fileSelected(QStringList)), SLOT(onFileSelected(QStringList)));
+ connect(contextObject, SIGNAL(fileSelected(QStringList)), SLOT(quit()));
+ connect(contextObject, SIGNAL(rejected()), SLOT(quit()));
+
+ return true;
+}
+
+bool QtDialogRunner::initForDatabaseQuotaDialog(QQmlComponent* component, QQuickItem* dialogParent, const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage)
{
- QDeclarativeContext* baseContext = component->creationContext();
+ DatabaseQuotaDialogContextObject* contextObject = new DatabaseQuotaDialogContextObject(databaseName, displayName, securityOrigin, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
+ if (!createDialog(component, dialogParent, contextObject))
+ return false;
+
+ connect(contextObject, SIGNAL(accepted(quint64)), SLOT(onDatabaseQuotaAccepted(quint64)));
+ connect(contextObject, SIGNAL(accepted(quint64)), SLOT(quit()));
+ connect(contextObject, SIGNAL(rejected()), SLOT(quit()));
+
+ return true;
+}
+
+bool QtDialogRunner::createDialog(QQmlComponent* component, QQuickItem* dialogParent, QObject* contextObject)
+{
+ QQmlContext* baseContext = component->creationContext();
if (!baseContext)
- baseContext = QDeclarativeEngine::contextForObject(dialogParent);
- m_dialogContext = adoptPtr(new QDeclarativeContext(baseContext));
+ baseContext = QQmlEngine::contextForObject(dialogParent);
+ m_dialogContext = adoptPtr(new QQmlContext(baseContext));
// This makes both "message" and "model.message" work for the dialog, just like QtQuick's ListView delegates.
contextObject->setParent(m_dialogContext.get());
@@ -262,5 +380,8 @@ bool QtDialogRunner::createDialog(QDeclarativeComponent* component, QQuickItem*
return true;
}
+} // namespace WebKit
+
#include "QtDialogRunner.moc"
#include "moc_QtDialogRunner.cpp"
+