Created
May 11, 2012 14:47
-
-
Save torarnv/2660217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp w/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | |
index 6723558..42927da 100644 | |
--- i/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | |
+++ w/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | |
@@ -495,47 +495,36 @@ void QQuickWebViewPrivate::_q_onReceivedResponseFromDownload(QWebDownloadItem* d | |
void QQuickWebViewPrivate::runJavaScriptAlert(const QString& alertText) | |
{ | |
- if (!alertDialog) | |
- return; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForAlert(alertDialog, q, alertText)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForAlert(alertText)) | |
return; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
} | |
bool QQuickWebViewPrivate::runJavaScriptConfirm(const QString& message) | |
{ | |
- if (!confirmDialog) | |
- return true; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForConfirm(confirmDialog, q, message)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForConfirm(message)) | |
return true; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
return dialogRunner.wasAccepted(); | |
} | |
QString QQuickWebViewPrivate::runJavaScriptPrompt(const QString& message, const QString& defaultValue, bool& ok) | |
{ | |
- if (!promptDialog) { | |
- ok = true; | |
- return defaultValue; | |
- } | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForPrompt(promptDialog, q, message, defaultValue)) { | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForPrompt(message, defaultValue)) { | |
ok = true; | |
return defaultValue; | |
} | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
ok = dialogRunner.wasAccepted(); | |
return dialogRunner.result(); | |
@@ -543,15 +532,12 @@ QString QQuickWebViewPrivate::runJavaScriptPrompt(const QString& message, const | |
void QQuickWebViewPrivate::handleAuthenticationRequiredRequest(const QString& hostname, const QString& realm, const QString& prefilledUsername, QString& username, QString& password) | |
{ | |
- if (!authenticationDialog) | |
- return; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForAuthentication(authenticationDialog, q, hostname, realm, prefilledUsername)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForAuthentication(hostname, realm, prefilledUsername)) | |
return; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
username = dialogRunner.username(); | |
password = dialogRunner.password(); | |
@@ -559,15 +545,12 @@ void QQuickWebViewPrivate::handleAuthenticationRequiredRequest(const QString& ho | |
void QQuickWebViewPrivate::handleProxyAuthenticationRequiredRequest(const QString& hostname, uint16_t port, const QString& prefilledUsername, QString& username, QString& password) | |
{ | |
- if (!proxyAuthenticationDialog) | |
- return; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForProxyAuthentication(proxyAuthenticationDialog, q, hostname, port, prefilledUsername)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForProxyAuthentication(hostname, port, prefilledUsername)) | |
return; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
username = dialogRunner.username(); | |
password = dialogRunner.password(); | |
@@ -575,43 +558,25 @@ void QQuickWebViewPrivate::handleProxyAuthenticationRequiredRequest(const QStrin | |
bool QQuickWebViewPrivate::handleCertificateVerificationRequest(const QString& hostname) | |
{ | |
- if (!certificateVerificationDialog) | |
- return false; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForCertificateVerification(certificateVerificationDialog, q, hostname)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForCertificateVerification(hostname)) | |
return false; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
return dialogRunner.wasAccepted(); | |
} | |
-void QQuickWebViewPrivate::execDialogRunner(QtDialogRunner& dialogRunner) | |
-{ | |
- setViewInAttachedProperties(dialogRunner.dialog()); | |
- | |
- disableMouseEvents(); | |
- m_dialogActive = true; | |
- | |
- dialogRunner.exec(); | |
- m_dialogActive = false; | |
- enableMouseEvents(); | |
-} | |
- | |
void QQuickWebViewPrivate::chooseFiles(WKOpenPanelResultListenerRef listenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType type) | |
{ | |
Q_Q(QQuickWebView); | |
- if (!filePicker) | |
- return; | |
- | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForFilePicker(filePicker, q, selectedFileNames, (type == QtWebPageUIClient::MultipleFilesSelection))) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForFilePicker(selectedFileNames, (type == QtWebPageUIClient::MultipleFilesSelection))) | |
return; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
if (dialogRunner.wasAccepted()) { | |
QStringList selectedPaths = dialogRunner.filePaths(); | |
@@ -628,20 +593,41 @@ void QQuickWebViewPrivate::chooseFiles(WKOpenPanelResultListenerRef listenerRef, | |
quint64 QQuickWebViewPrivate::exceededDatabaseQuota(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) | |
{ | |
- if (!databaseQuotaDialog) | |
- return 0; | |
- | |
Q_Q(QQuickWebView); | |
- QtDialogRunner dialogRunner; | |
- if (!dialogRunner.initForDatabaseQuotaDialog(databaseQuotaDialog, q, databaseName, displayName, securityOrigin, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage)) | |
+ QtDialogRunner dialogRunner(q); | |
+ if (!dialogRunner.initForDatabaseQuotaDialog(databaseName, displayName, securityOrigin, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage)) | |
return 0; | |
- execDialogRunner(dialogRunner); | |
+ dialogRunner.waitForDismiss(); | |
return dialogRunner.wasAccepted() ? dialogRunner.databaseQuota() : 0; | |
} | |
-void QQuickWebViewPrivate::setViewInAttachedProperties(QObject* object) | |
+/* The 'WebView' attached property allows items spawned by the webView to | |
+ refer back to the originating webView through 'WebView.view', similar | |
+ to how ListView.view and GridView.view is exposed to items. */ | |
+QQuickWebViewAttached::QQuickWebViewAttached(QObject* object) | |
+ : QObject(object) | |
+ , m_view(0) | |
+{ | |
+} | |
+ | |
+void QQuickWebViewAttached::setView(QQuickWebView* view) | |
+{ | |
+ if (m_view == view) | |
+ return; | |
+ m_view = view; | |
+ emit viewChanged(); | |
+} | |
+ | |
+QQuickWebViewAttached* QQuickWebView::qmlAttachedProperties(QObject* object) | |
+{ | |
+ return new QQuickWebViewAttached(object); | |
+} | |
+ | |
+ | |
+ | |
+void QQuickWebViewPrivate::addAttachedPropertyTo(QObject* object) | |
{ | |
Q_Q(QQuickWebView); | |
QQuickWebViewAttached* attached = static_cast<QQuickWebViewAttached*>(qmlAttachedPropertiesObject<QQuickWebView>(object)); | |
@@ -969,21 +955,6 @@ void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize) | |
\sa WebNavigationRequest | |
*/ | |
-QQuickWebViewAttached::QQuickWebViewAttached(QObject* object) | |
- : QObject(object) | |
- , m_view(0) | |
-{ | |
- | |
-} | |
- | |
-void QQuickWebViewAttached::setView(QQuickWebView* view) | |
-{ | |
- if (m_view == view) | |
- return; | |
- m_view = view; | |
- emit viewChanged(); | |
-} | |
- | |
QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView) | |
: QObject(webView) | |
, q_ptr(webView) | |
@@ -1624,11 +1595,6 @@ QQuickWebViewExperimental* QQuickWebView::experimental() const | |
return m_experimental; | |
} | |
-QQuickWebViewAttached* QQuickWebView::qmlAttachedProperties(QObject* object) | |
-{ | |
- return new QQuickWebViewAttached(object); | |
-} | |
- | |
/*! | |
\internal | |
*/ | |
diff --git i/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h w/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h | |
index c6956e0..24ffc58 100644 | |
--- i/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h | |
+++ w/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h | |
@@ -219,9 +219,9 @@ private: | |
friend class WebKit::QtViewportInteractionEngine; | |
friend class WebKit::QtWebPageLoadClient; | |
friend class WebKit::QtWebPagePolicyClient; | |
- friend class WebKit::QtWebPageUIClient; | |
+ friend class WebKit::QtWebPageUIClient; | |
friend class WTR::PlatformWebView; | |
- friend class QQuickWebViewExperimental; | |
+ friend class QQuickWebViewExperimental; | |
}; | |
QML_DECLARE_TYPE(QQuickWebView) | |
diff --git i/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h w/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h | |
index 6dd2e7a..659c59e 100644 | |
--- i/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h | |
+++ w/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h | |
@@ -56,6 +56,7 @@ QT_END_NAMESPACE | |
class QQuickWebViewPrivate { | |
Q_DECLARE_PUBLIC(QQuickWebView) | |
+ friend class WebKit::QtDialogRunner; | |
friend class QQuickWebViewExperimental; | |
friend class QQuickWebPage; | |
friend class QWebPreferencesPrivate; | |
@@ -116,11 +117,9 @@ public: | |
bool handleCertificateVerificationRequest(const QString& hostname); | |
void handleProxyAuthenticationRequiredRequest(const QString& hostname, uint16_t port, const QString& prefilledUsername, QString& username, QString& password); | |
- void execDialogRunner(WebKit::QtDialogRunner&); | |
- | |
void setRenderToOffscreenBuffer(bool enable) { m_renderToOffscreenBuffer = enable; } | |
void setTransparentBackground(bool); | |
- void setViewInAttachedProperties(QObject*); | |
+ void addAttachedPropertyTo(QObject*); | |
void setIcon(const QUrl&); | |
bool navigatorQtObjectEnabled() const; | |
diff --git i/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml w/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml | |
index 4e15c23..1c97929 100644 | |
--- i/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml | |
+++ w/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml | |
@@ -13,45 +13,35 @@ TestWebView { | |
property int promptCount: 0 | |
experimental.alertDialog: Item { | |
- Timer { | |
- running: true | |
- interval: 1 | |
- onTriggered: { | |
- // Testing both attached property and id defined in the Component context. | |
- parent.WebView.view.messageFromAlertDialog = message | |
- webView.modelMessageEqualsMessage = Boolean(model.message == message) | |
- model.dismiss() | |
- } | |
+ Component.onCompleted: { | |
+ // Testing both attached property and id defined in the Component context. | |
+ WebView.view.messageFromAlertDialog = message | |
+ parent.modelMessageEqualsMessage = Boolean(model.message == message) | |
+ model.dismiss() | |
} | |
} | |
experimental.confirmDialog: Item { | |
- Timer { | |
- running: true | |
- interval: 1 | |
- onTriggered: { | |
- parent.WebView.view.confirmCount += 1 | |
- if (message == "ACCEPT") | |
- model.accept() | |
- else | |
- model.reject() | |
- } | |
+ Component.onCompleted: { | |
+ WebView.view.confirmCount += 1 | |
+ if (message == "ACCEPT") | |
+ model.accept() | |
+ else | |
+ model.reject() | |
} | |
} | |
experimental.promptDialog: Item { | |
- Timer { | |
- running: true | |
- interval: 1 | |
- onTriggered: { | |
- parent.WebView.view.promptCount += 1 | |
- if (message == "REJECT") | |
- model.reject() | |
- else { | |
- var reversedDefaultValue = defaultValue.split("").reverse().join("") | |
- model.accept(reversedDefaultValue) | |
- } | |
+ Component.onCompleted: { | |
+ WebView.view.promptCount += 1 | |
+ if (message == "REJECT") | |
+ model.reject() | |
+ else { | |
+ var reversedDefaultValue = defaultValue.split("").reverse().join("") | |
+ model.accept(reversedDefaultValue) | |
} | |
+ | |
+ console.log("yepp") | |
} | |
} | |
@@ -96,6 +86,7 @@ TestWebView { | |
} | |
function test_prompt() { | |
+ console.log("faen") | |
webView.url = Qt.resolvedUrl("../common/prompt.html") | |
verify(webView.waitForLoadSucceeded()) | |
compare(webView.promptCount, 2) | |
diff --git i/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp w/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp | |
index 6e41c8b..4601752 100644 | |
--- i/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp | |
+++ w/Source/WebKit2/UIProcess/qt/QtDialogRunner.cpp | |
@@ -23,6 +23,7 @@ | |
#include "WKRetainPtr.h" | |
#include "WKStringQt.h" | |
+#include "qquickwebview_p_p.h" | |
#include "qwebpermissionrequest_p.h" | |
#include <QtQml/QQmlComponent> | |
#include <QtQml/QQmlContext> | |
@@ -30,10 +31,13 @@ | |
#include <QtQuick/QQuickItem> | |
#include <wtf/PassOwnPtr.h> | |
+#include <QDebug> | |
+ | |
namespace WebKit { | |
-QtDialogRunner::QtDialogRunner() | |
+QtDialogRunner::QtDialogRunner(QQuickWebView* webView) | |
: QEventLoop() | |
+ , m_webView(webView) | |
, m_wasAccepted(false) | |
{ | |
} | |
@@ -42,30 +46,81 @@ QtDialogRunner::~QtDialogRunner() | |
{ | |
} | |
-class DialogContextObject : public QObject { | |
+// All dialogs need a way to support the state of the | |
+// dialog being done/finished/dismissed. This is handled | |
+// in the dialog base context. | |
+class DialogContextBase : public QObject { | |
+ Q_OBJECT | |
+ | |
+public: | |
+ DialogContextBase() | |
+ : QObject() | |
+ , m_dismissed(false) | |
+ { | |
+ } | |
+ | |
+public slots: | |
+ // Allows clients to call dismiss() directly, while also | |
+ // being able to hook up signals to automatically also | |
+ // dismiss the dialog since it's a slot. | |
+ | |
+ void dismiss() { | |
+ m_dismissed = true; | |
+ emit dismissed(); | |
+ } | |
+ | |
+signals: | |
+ void dismissed(); | |
+ | |
+private: | |
+ // We store the dismissed state so that waitForDismiss can check | |
+ // to see if a dialog has already been dismissed before spinning | |
+ // an event loop. | |
+ bool m_dismissed; | |
+ friend void QtDialogRunner::waitForDismiss(); | |
+}; | |
+ | |
+class DialogMessageContext : public DialogContextBase | |
+{ | |
+ Q_OBJECT | |
+ Q_PROPERTY(QString message READ message CONSTANT) | |
+ | |
+public: | |
+ DialogMessageContext(const QString& message) | |
+ : DialogContextBase() | |
+ , m_message(message) | |
+ { | |
+ } | |
+ | |
+ QString message() const { return m_message; } | |
+ | |
+private: | |
+ QString m_message; | |
+}; | |
+ | |
+ | |
+class DialogContextObject : public DialogContextBase { | |
Q_OBJECT | |
Q_PROPERTY(QString message READ message CONSTANT) | |
Q_PROPERTY(QString defaultValue READ defaultValue CONSTANT) | |
public: | |
DialogContextObject(const QString& message, const QString& defaultValue = QString()) | |
- : QObject() | |
+ : DialogContextBase() | |
, m_message(message) | |
, m_defaultValue(defaultValue) | |
{ | |
+ connect(this, SIGNAL(accepted(QString)), SLOT(dismiss())); | |
+ connect(this, SIGNAL(rejected()), SLOT(dismiss())); | |
} | |
QString message() const { return m_message; } | |
QString defaultValue() const { return m_defaultValue; } | |
public slots: | |
- void dismiss() { emit dismissed(); } | |
- void accept() { emit accepted(); } | |
- void accept(const QString& result) { emit accepted(result); } | |
+ void accept(const QString& result = QString()) { emit accepted(result); } | |
void reject() { emit rejected(); } | |
signals: | |
- void dismissed(); | |
- void accepted(); | |
void accepted(const QString& result); | |
void rejected(); | |
@@ -74,17 +129,19 @@ private: | |
QString m_defaultValue; | |
}; | |
-class BaseAuthenticationContextObject : public QObject { | |
+class BaseAuthenticationContextObject : public DialogContextBase { | |
Q_OBJECT | |
Q_PROPERTY(QString hostname READ hostname CONSTANT) | |
Q_PROPERTY(QString prefilledUsername READ prefilledUsername CONSTANT) | |
public: | |
BaseAuthenticationContextObject(const QString& hostname, const QString& prefilledUsername) | |
- : QObject() | |
+ : DialogContextBase() | |
, m_hostname(hostname) | |
, m_prefilledUsername(prefilledUsername) | |
{ | |
+ connect(this, SIGNAL(accepted(QString, QString)), SLOT(dismiss())); | |
+ connect(this, SIGNAL(rejected()), SLOT(dismiss())); | |
} | |
QString hostname() const { return m_hostname; } | |
@@ -137,15 +194,17 @@ private: | |
quint16 m_port; | |
}; | |
-class CertificateVerificationDialogContextObject : public QObject { | |
+class CertificateVerificationDialogContextObject : public DialogContextBase { | |
Q_OBJECT | |
Q_PROPERTY(QString hostname READ hostname CONSTANT) | |
public: | |
CertificateVerificationDialogContextObject(const QString& hostname) | |
- : QObject() | |
+ : DialogContextBase() | |
, m_hostname(hostname) | |
{ | |
+ connect(this, SIGNAL(accepted()), SLOT(dismiss())); | |
+ connect(this, SIGNAL(rejected()), SLOT(dismiss())); | |
} | |
QString hostname() const { return m_hostname; } | |
@@ -162,17 +221,19 @@ private: | |
QString m_hostname; | |
}; | |
-class FilePickerContextObject : public QObject { | |
+class FilePickerContextObject : public DialogContextBase { | |
Q_OBJECT | |
Q_PROPERTY(QStringList fileList READ fileList CONSTANT) | |
Q_PROPERTY(bool allowMultipleFiles READ allowMultipleFiles CONSTANT) | |
public: | |
FilePickerContextObject(const QStringList& selectedFiles, bool allowMultiple) | |
- : QObject() | |
+ : DialogContextBase() | |
, m_allowMultiple(allowMultiple) | |
, m_fileList(selectedFiles) | |
{ | |
+ connect(this, SIGNAL(fileSelected(QStringList)), SLOT(dismiss())); | |
+ connect(this, SIGNAL(rejected()), SLOT(dismiss())); | |
} | |
QStringList fileList() const { return m_fileList; } | |
@@ -198,7 +259,7 @@ private: | |
QStringList m_fileList; | |
}; | |
-class DatabaseQuotaDialogContextObject : public QObject { | |
+class DatabaseQuotaDialogContextObject : public DialogContextBase { | |
Q_OBJECT | |
Q_PROPERTY(QString databaseName READ databaseName CONSTANT) | |
Q_PROPERTY(QString displayName READ displayName CONSTANT) | |
@@ -210,7 +271,7 @@ class DatabaseQuotaDialogContextObject : public QObject { | |
public: | |
DatabaseQuotaDialogContextObject(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) | |
- : QObject() | |
+ : DialogContextBase() | |
, m_databaseName(databaseName) | |
, m_displayName(displayName) | |
, m_currentQuota(currentQuota) | |
@@ -224,6 +285,9 @@ public: | |
m_securityOrigin.setScheme(WKStringCopyQString(scheme.get())); | |
m_securityOrigin.setHost(WKStringCopyQString(host.get())); | |
m_securityOrigin.setPort(static_cast<int>(WKSecurityOriginGetPort(securityOrigin))); | |
+ | |
+ connect(this, SIGNAL(accepted(quint64)), SLOT(dismiss())); | |
+ connect(this, SIGNAL(rejected()), SLOT(dismiss())); | |
} | |
QString databaseName() const { return m_databaseName; } | |
@@ -252,118 +316,144 @@ private: | |
QtWebSecurityOrigin m_securityOrigin; | |
}; | |
-bool QtDialogRunner::initForAlert(QQmlComponent* component, QQuickItem* dialogParent, const QString& message) | |
+void QtDialogRunner::waitForDismiss() | |
{ | |
- DialogContextObject* contextObject = new DialogContextObject(message); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
- return false; | |
- connect(contextObject, SIGNAL(dismissed()), SLOT(quit())); | |
- return true; | |
+ /*disableMouseEvents(); | |
+ m_dialogActive = true; | |
+ | |
+ dialogRunner.exec(); | |
+ m_dialogActive = false; | |
+ enableMouseEvents();*/ | |
+ | |
+ DialogContextBase* context = static_cast<DialogContextBase*>(m_dialogContext->contextObject()); | |
+ | |
+ // We may have already been dismissed as part of Component.onCompleted() | |
+ if (context->m_dismissed) | |
+ return; | |
+ | |
+ connect(context, SIGNAL(dismissed()), SLOT(quit())); | |
+ | |
+ QQuickWebViewPrivate* webViewPrivate = QQuickWebViewPrivate::get(m_webView); | |
+ | |
+ // FIXME: Change the way we disable mouse and touch events to use the | |
+ // concept of suspending instead (in this case event processing). | |
+ webViewPrivate->disableMouseEvents(); | |
+ webViewPrivate->m_dialogActive = true; | |
+ exec(); // Spin the event loop | |
+ webViewPrivate->m_dialogActive = false; | |
+ webViewPrivate->enableMouseEvents(); | |
} | |
-bool QtDialogRunner::initForConfirm(QQmlComponent* component, QQuickItem* dialogParent, const QString& message) | |
+bool QtDialogRunner::initForAlert(const QString& message) | |
{ | |
+ QDeclarativeComponent* component = m_webView->experimental()->alertDialog(); | |
+ if (!component) | |
+ return false; | |
+ | |
DialogContextObject* contextObject = new DialogContextObject(message); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ | |
+ return createDialog(component, contextObject); | |
+} | |
+ | |
+bool QtDialogRunner::initForConfirm(const QString& message) | |
+{ | |
+ QDeclarativeComponent* component = m_webView->experimental()->confirmDialog(); | |
+ if (!component) | |
return false; | |
- connect(contextObject, SIGNAL(accepted()), SLOT(onAccepted())); | |
- connect(contextObject, SIGNAL(accepted()), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ DialogContextObject* contextObject = new DialogContextObject(message); | |
+ connect(contextObject, SIGNAL(accepted(QString)), SLOT(onAccepted())); | |
+ | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForPrompt(QQmlComponent* component, QQuickItem* dialogParent, const QString& message, const QString& defaultValue) | |
+bool QtDialogRunner::initForPrompt(const QString& message, const QString& defaultValue) | |
{ | |
- DialogContextObject* contextObject = new DialogContextObject(message, defaultValue); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->promptDialog(); | |
+ if (!component) | |
return false; | |
+ DialogContextObject* contextObject = new DialogContextObject(message, defaultValue); | |
connect(contextObject, SIGNAL(accepted(QString)), SLOT(onAccepted(QString))); | |
- connect(contextObject, SIGNAL(accepted(QString)), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForAuthentication(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname, const QString& realm, const QString& prefilledUsername) | |
+bool QtDialogRunner::initForAuthentication(const QString& hostname, const QString& realm, const QString& prefilledUsername) | |
{ | |
- HttpAuthenticationDialogContextObject* contextObject = new HttpAuthenticationDialogContextObject(hostname, realm, prefilledUsername); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->authenticationDialog(); | |
+ if (!component) | |
return false; | |
+ HttpAuthenticationDialogContextObject* contextObject = new HttpAuthenticationDialogContextObject(hostname, realm, prefilledUsername); | |
connect(contextObject, SIGNAL(accepted(QString, QString)), SLOT(onAuthenticationAccepted(QString, QString))); | |
- connect(contextObject, SIGNAL(accepted(QString, QString)), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForProxyAuthentication(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname, uint16_t port, const QString& prefilledUsername) | |
+bool QtDialogRunner::initForProxyAuthentication(const QString& hostname, uint16_t port, const QString& prefilledUsername) | |
{ | |
- ProxyAuthenticationDialogContextObject* contextObject = new ProxyAuthenticationDialogContextObject(hostname, port, prefilledUsername); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->proxyAuthenticationDialog(); | |
+ if (!component) | |
return false; | |
+ ProxyAuthenticationDialogContextObject* contextObject = new ProxyAuthenticationDialogContextObject(hostname, port, prefilledUsername); | |
connect(contextObject, SIGNAL(accepted(QString, QString)), SLOT(onAuthenticationAccepted(QString, QString))); | |
- connect(contextObject, SIGNAL(accepted(QString, QString)), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForCertificateVerification(QQmlComponent* component, QQuickItem* dialogParent, const QString& hostname) | |
+bool QtDialogRunner::initForCertificateVerification(const QString& hostname) | |
{ | |
- CertificateVerificationDialogContextObject* contextObject = new CertificateVerificationDialogContextObject(hostname); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->certificateVerificationDialog(); | |
+ if (!component) | |
return false; | |
+ CertificateVerificationDialogContextObject* contextObject = new CertificateVerificationDialogContextObject(hostname); | |
connect(contextObject, SIGNAL(accepted()), SLOT(onAccepted())); | |
- connect(contextObject, SIGNAL(accepted()), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForFilePicker(QQmlComponent* component, QQuickItem* dialogParent, const QStringList& selectedFiles, bool allowMultiple) | |
+bool QtDialogRunner::initForFilePicker(const QStringList& selectedFiles, bool allowMultiple) | |
{ | |
- FilePickerContextObject* contextObject = new FilePickerContextObject(selectedFiles, allowMultiple); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->filePicker(); | |
+ if (!component) | |
return false; | |
+ FilePickerContextObject* contextObject = new FilePickerContextObject(selectedFiles, allowMultiple); | |
connect(contextObject, SIGNAL(fileSelected(QStringList)), SLOT(onFileSelected(QStringList))); | |
- connect(contextObject, SIGNAL(fileSelected(QStringList)), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::initForDatabaseQuotaDialog(QQmlComponent* component, QQuickItem* dialogParent, const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) | |
+bool QtDialogRunner::initForDatabaseQuotaDialog(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage) | |
{ | |
- DatabaseQuotaDialogContextObject* contextObject = new DatabaseQuotaDialogContextObject(databaseName, displayName, securityOrigin, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage); | |
- if (!createDialog(component, dialogParent, contextObject)) | |
+ QDeclarativeComponent* component = m_webView->experimental()->databaseQuotaDialog(); | |
+ if (!component) | |
return false; | |
+ DatabaseQuotaDialogContextObject* contextObject = new DatabaseQuotaDialogContextObject(databaseName, displayName, securityOrigin, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage); | |
connect(contextObject, SIGNAL(accepted(quint64)), SLOT(onDatabaseQuotaAccepted(quint64))); | |
- connect(contextObject, SIGNAL(accepted(quint64)), SLOT(quit())); | |
- connect(contextObject, SIGNAL(rejected()), SLOT(quit())); | |
- return true; | |
+ return createDialog(component, contextObject); | |
} | |
-bool QtDialogRunner::createDialog(QQmlComponent* component, QQuickItem* dialogParent, QObject* contextObject) | |
+bool QtDialogRunner::createDialog(QQmlComponent* component, QObject* contextObject) | |
{ | |
QQmlContext* baseContext = component->creationContext(); | |
if (!baseContext) | |
- baseContext = QQmlEngine::contextForObject(dialogParent); | |
+ baseContext = QQmlEngine::contextForObject(m_webView); | |
m_dialogContext = adoptPtr(new QQmlContext(baseContext)); | |
- // This makes both "message" and "model.message" work for the dialog, just like QtQuick's ListView delegates. | |
+ // This makes both "message" and "model.message" work for the dialog, | |
+ // just like QtQuick's ListView delegates. | |
contextObject->setParent(m_dialogContext.get()); | |
m_dialogContext->setContextProperty(QLatin1String("model"), contextObject); | |
m_dialogContext->setContextObject(contextObject); | |
- QObject* object = component->create(m_dialogContext.get()); | |
+ QObject* object = component->beginCreate(m_dialogContext.get()); | |
if (!object) { | |
m_dialogContext.clear(); | |
return false; | |
@@ -376,10 +466,41 @@ bool QtDialogRunner::createDialog(QQmlComponent* component, QQuickItem* dialogPa | |
return false; | |
} | |
- m_dialog->setParentItem(dialogParent); | |
+ QQuickWebViewPrivate::get(m_webView)->addAttachedPropertyTo(m_dialog.get()); | |
+ m_dialog->setParentItem(m_webView); | |
+ | |
+ // Only fully create the component once we've set both a parent | |
+ // and the needed context and attached properties, so that dialogs | |
+ // can do useful stuff in their Component.onCompleted() method. | |
+ component->completeCreate(); | |
+ | |
return true; | |
} | |
+void QtDialogRunner::onAccepted(const QString& result) | |
+{ | |
+ m_wasAccepted = true; | |
+ m_result = result; | |
+} | |
+ | |
+void QtDialogRunner::onAuthenticationAccepted(const QString& username, const QString& password) | |
+{ | |
+ m_username = username; | |
+ m_password = password; | |
+} | |
+ | |
+void QtDialogRunner::onFileSelected(const QStringList& filePaths) | |
+{ | |
+ m_wasAccepted = true; | |
+ m_filepaths = filePaths; | |
+} | |
+ | |
+void QtDialogRunner::onDatabaseQuotaAccepted(quint64 quota) | |
+{ | |
+ m_wasAccepted = true; | |
+ m_databaseQuota = quota; | |
+} | |
+ | |
} // namespace WebKit | |
#include "QtDialogRunner.moc" | |
diff --git i/Source/WebKit2/UIProcess/qt/QtDialogRunner.h w/Source/WebKit2/UIProcess/qt/QtDialogRunner.h | |
index f53fc92..069a3a1 100644 | |
--- i/Source/WebKit2/UIProcess/qt/QtDialogRunner.h | |
+++ w/Source/WebKit2/UIProcess/qt/QtDialogRunner.h | |
@@ -22,6 +22,7 @@ | |
#define QtDialogRunner_h | |
#include "WKSecurityOrigin.h" | |
+#include "qquickwebview_p.h" | |
#include <QtCore/QEventLoop> | |
#include <QtCore/QStringList> | |
#include <wtf/OwnPtr.h> | |
@@ -38,17 +39,19 @@ class QtDialogRunner : public QEventLoop { | |
Q_OBJECT | |
public: | |
- QtDialogRunner(); | |
+ QtDialogRunner(QQuickWebView* webView); | |
virtual ~QtDialogRunner(); | |
- bool initForAlert(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& message); | |
- bool initForConfirm(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& message); | |
- bool initForPrompt(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& message, const QString& defaultValue); | |
- bool initForAuthentication(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& hostname, const QString& realm, const QString& prefilledUsername); | |
- bool initForCertificateVerification(QDeclarativeComponent*, QQuickItem*, const QString& hostname); | |
- bool initForProxyAuthentication(QDeclarativeComponent*, QQuickItem*, const QString& hostname, uint16_t port, const QString& prefilledUsername); | |
- bool initForFilePicker(QDeclarativeComponent*, QQuickItem*, const QStringList& selectedFiles, bool allowMultiple); | |
- bool initForDatabaseQuotaDialog(QDeclarativeComponent*, QQuickItem*, const QString& databaseName, const QString& displayName, WKSecurityOriginRef, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage); | |
+ bool initForAlert(const QString& message); | |
+ bool initForConfirm(const QString& message); | |
+ bool initForPrompt(const QString& message, const QString& defaultValue); | |
+ bool initForAuthentication(const QString& hostname, const QString& realm, const QString& prefilledUsername); | |
+ bool initForCertificateVerification(const QString& hostname); | |
+ bool initForProxyAuthentication(const QString& hostname, uint16_t port, const QString& prefilledUsername); | |
+ bool initForFilePicker(const QStringList& selectedFiles, bool allowMultiple); | |
+ bool initForDatabaseQuotaDialog(const QString& databaseName, const QString& displayName, WKSecurityOriginRef, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage); | |
+ | |
+ void waitForDismiss(); | |
QQuickItem* dialog() const { return m_dialog.get(); } | |
@@ -63,33 +66,15 @@ public: | |
QStringList filePaths() const { return m_filepaths; } | |
public slots: | |
- void onAccepted(const QString& result = QString()) | |
- { | |
- m_wasAccepted = true; | |
- m_result = result; | |
- } | |
- | |
- void onAuthenticationAccepted(const QString& username, const QString& password) | |
- { | |
- m_username = username; | |
- m_password = password; | |
- } | |
- | |
- void onFileSelected(const QStringList& filePaths) | |
- { | |
- m_wasAccepted = true; | |
- m_filepaths = filePaths; | |
- } | |
- | |
- void onDatabaseQuotaAccepted(quint64 quota) | |
- { | |
- m_wasAccepted = true; | |
- m_databaseQuota = quota; | |
- } | |
+ void onAccepted(const QString& result = QString()); | |
+ void onAuthenticationAccepted(const QString& username, const QString& password); | |
+ void onFileSelected(const QStringList& filePaths); | |
+ void onDatabaseQuotaAccepted(quint64 quota); | |
private: | |
- bool createDialog(QDeclarativeComponent*, QQuickItem* dialogParent, QObject* contextObject); | |
+ bool createDialog(QDeclarativeComponent* component, QObject* contextObject); | |
+ QQuickWebView* m_webView; | |
OwnPtr<QDeclarativeContext> m_dialogContext; | |
OwnPtr<QQuickItem> m_dialog; | |
QString m_result; | |
diff --git i/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp w/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp | |
index 9f9100a..648394b 100644 | |
--- i/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp | |
+++ w/Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp | |
@@ -283,10 +283,13 @@ void WebPopupMenuProxyQt::createItem(QObject* contextObject) | |
connect(contextObject, SIGNAL(acceptedWithOriginalIndex(int)), SLOT(hidePopupMenu()), Qt::QueuedConnection); | |
connect(contextObject, SIGNAL(rejected()), SLOT(hidePopupMenu()), Qt::QueuedConnection); | |
- QQuickWebViewPrivate::get(m_webView)->setViewInAttachedProperties(m_itemSelector.get()); | |
- component->completeCreate(); | |
- | |
+ QQuickWebViewPrivate::get(m_webView)->addAttachedPropertyTo(m_itemSelector.get()); | |
m_itemSelector->setParentItem(m_webView); | |
+ | |
+ // Only fully create the component once we've set both a parent | |
+ // and the needed context and attached properties, so that the | |
+ // dialog can do useful stuff in Component.onCompleted(). | |
+ component->completeCreate(); | |
} | |
void WebPopupMenuProxyQt::createContext(QQmlComponent* component, QObject* contextObject) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment