summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2014-01-13 15:01:54 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-15 21:35:29 +0100
commit6f5850dd4f6c4cc253c48f41f59130aee5415591 (patch)
tree9f92f25e0e297cdc51e5dd8aed3b942413e6c917 /src/core
parente46886912858e9b233fb099bb211e288dd7d57b5 (diff)
JS dialogs in QtQuick
Refactor JavaScriptDialogManagerQt to support a Qt Quick dialogs friendly approach. Qt Quick dialogs are still missing a prompt, so we use a "handmade" one. This should be solved before 5.3 though. Change-Id: I965df66837b2e81d6e4618a8da1167a37661c26e Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_gyp_generator.pro3
-rw-r--r--src/core/javascript_dialog_controller.cpp104
-rw-r--r--src/core/javascript_dialog_controller.h74
-rw-r--r--src/core/javascript_dialog_controller_p.h68
-rw-r--r--src/core/javascript_dialog_manager_qt.cpp31
-rw-r--r--src/core/javascript_dialog_manager_qt.h12
-rw-r--r--src/core/web_contents_adapter.cpp3
-rw-r--r--src/core/web_contents_adapter_client.h4
-rw-r--r--src/core/web_contents_delegate_qt.cpp1
9 files changed, 290 insertions, 10 deletions
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro
index 4064324d0..a22b9126a 100644
--- a/src/core/core_gyp_generator.pro
+++ b/src/core/core_gyp_generator.pro
@@ -41,6 +41,7 @@ SOURCES = \
dev_tools_http_handler_delegate_qt.cpp \
download_manager_delegate_qt.cpp \
chromium_gpu_helper.cpp \
+ javascript_dialog_controller.cpp \
javascript_dialog_manager_qt.cpp \
process_main.cpp \
render_widget_host_view_qt.cpp \
@@ -69,6 +70,8 @@ HEADERS = \
dev_tools_http_handler_delegate_qt.h \
download_manager_delegate_qt.h \
chromium_gpu_helper.h \
+ javascript_dialog_controller_p.h \
+ javascript_dialog_controller.h \
javascript_dialog_manager_qt.h \
process_main.h \
render_widget_host_view_qt.h \
diff --git a/src/core/javascript_dialog_controller.cpp b/src/core/javascript_dialog_controller.cpp
new file mode 100644
index 000000000..ed0431084
--- /dev/null
+++ b/src/core/javascript_dialog_controller.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "javascript_dialog_controller.h"
+#include "javascript_dialog_controller_p.h"
+
+#include"javascript_dialog_manager_qt.h"
+#include "type_conversion.h"
+
+void JavaScriptDialogControllerPrivate::dialogFinished(bool accepted, const base::string16 &promptValue)
+{
+ // Clear the queue first as this could result in the engine asking us to run another dialog.
+ JavaScriptDialogManagerQt::GetInstance()->removeDialogForContents(contents);
+
+ callback.Run(accepted, promptValue);
+}
+
+JavaScriptDialogControllerPrivate::JavaScriptDialogControllerPrivate(WebContentsAdapterClient::JavascriptDialogType t, const QString &msg, const QString &prompt
+ , const content::JavaScriptDialogManager::DialogClosedCallback &cb, content::WebContents *c)
+ : type(t)
+ , message(msg)
+ , defaultPrompt(prompt)
+ , callback(cb)
+ , contents(c)
+{
+}
+
+JavaScriptDialogController::~JavaScriptDialogController()
+{
+}
+
+QString JavaScriptDialogController::message() const
+{
+ return d->message;
+}
+
+QString JavaScriptDialogController::defaultPrompt() const
+{
+ return d->defaultPrompt;
+}
+
+WebContentsAdapterClient::JavascriptDialogType JavaScriptDialogController::type() const
+{
+ return d->type;
+}
+
+void JavaScriptDialogController::textProvided(const QString &text)
+{
+ d->userInput = text;
+}
+
+void JavaScriptDialogController::accept()
+{
+ d->dialogFinished(true, toString16(d->userInput));
+}
+
+void JavaScriptDialogController::reject()
+{
+ d->dialogFinished(false, toString16(d->defaultPrompt));
+}
+
+JavaScriptDialogController::JavaScriptDialogController(JavaScriptDialogControllerPrivate *dd)
+{
+ Q_ASSERT(dd);
+ d.reset(dd);
+}
diff --git a/src/core/javascript_dialog_controller.h b/src/core/javascript_dialog_controller.h
new file mode 100644
index 000000000..e92bc8067
--- /dev/null
+++ b/src/core/javascript_dialog_controller.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef JAVASCRIPT_DIALOG_CONTROLLER_H
+#define JAVASCRIPT_DIALOG_CONTROLLER_H
+
+#include "web_contents_adapter_client.h"
+
+QT_FORWARD_DECLARE_CLASS(QString)
+
+struct JavaScriptDialogControllerPrivate;
+
+class QWEBENGINE_EXPORT JavaScriptDialogController : public QObject {
+ Q_OBJECT
+public:
+ ~JavaScriptDialogController();
+ QString message() const;
+ QString defaultPrompt() const;
+ WebContentsAdapterClient::JavascriptDialogType type() const;
+
+public Q_SLOTS:
+ void textProvided(const QString &text);
+ void accept();
+ void reject();
+
+Q_SIGNALS:
+ void dialogCloseRequested();
+
+private:
+ JavaScriptDialogController(JavaScriptDialogControllerPrivate *);
+
+ QScopedPointer<JavaScriptDialogControllerPrivate> d;
+ friend class JavaScriptDialogManagerQt;
+};
+
+#endif // JAVASCRIPT_DIALOG_CONTROLLER_H
diff --git a/src/core/javascript_dialog_controller_p.h b/src/core/javascript_dialog_controller_p.h
new file mode 100644
index 000000000..9e84b31a0
--- /dev/null
+++ b/src/core/javascript_dialog_controller_p.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef JAVASCRIPT_DIALOG_CONTROLLER_P_H
+#define JAVASCRIPT_DIALOG_CONTROLLER_P_H
+
+#include "content/public/browser/javascript_dialog_manager.h"
+#include "web_contents_adapter_client.h"
+#include <QString>
+
+namespace content {
+class WebContents;
+}
+
+class JavaScriptDialogControllerPrivate {
+
+public:
+ void dialogFinished(bool accepted, const base::string16 &promptValue);
+ JavaScriptDialogControllerPrivate(WebContentsAdapterClient::JavascriptDialogType, const QString &message, const QString &prompt
+ , const content::JavaScriptDialogManager::DialogClosedCallback &, content::WebContents *);
+
+ WebContentsAdapterClient::JavascriptDialogType type;
+ QString message;
+ QString defaultPrompt;
+ QString userInput;
+ content::JavaScriptDialogManager::DialogClosedCallback callback;
+ content::WebContents *contents;
+};
+
+#endif // JAVASCRIPT_DIALOG_CONTROLLER_P_H
diff --git a/src/core/javascript_dialog_manager_qt.cpp b/src/core/javascript_dialog_manager_qt.cpp
index b2f6d86bc..f0b8c5485 100644
--- a/src/core/javascript_dialog_manager_qt.cpp
+++ b/src/core/javascript_dialog_manager_qt.cpp
@@ -41,6 +41,8 @@
#include "javascript_dialog_manager_qt.h"
+#include "javascript_dialog_controller.h"
+#include "javascript_dialog_controller_p.h"
#include "web_contents_adapter_client.h"
#include "web_contents_view_qt.h"
#include "type_conversion.h"
@@ -65,14 +67,31 @@ void JavaScriptDialogManagerQt::RunJavaScriptDialog(content::WebContents *webCon
return;
}
- QString promptInput;
WebContentsAdapterClient::JavascriptDialogType dialogType = static_cast<WebContentsAdapterClient::JavascriptDialogType>(javascriptMessageType);
- bool res = client->javascriptDialog(dialogType, toQt(messageText).toHtmlEscaped(), toQt(defaultPromptText).toHtmlEscaped(), &promptInput);
- callback.Run(res, toString16(promptInput));
+ JavaScriptDialogControllerPrivate *dialogData = new JavaScriptDialogControllerPrivate(dialogType, toQt(messageText).toHtmlEscaped()
+ , toQt(defaultPromptText).toHtmlEscaped(), callback, webContents);
+ QSharedPointer<JavaScriptDialogController> dialog(new JavaScriptDialogController(dialogData));
+
+ // We shouldn't get new dialogs for a given WebContents until we gave back a result.
+ Q_ASSERT(!m_activeDialogs.contains(webContents));
+ m_activeDialogs.insert(webContents, dialog);
+
+ client->javascriptDialog(dialog);
+}
+
+bool JavaScriptDialogManagerQt::HandleJavaScriptDialog(content::WebContents *contents, bool accept, const base::string16 *promptOverride)
+{
+ if (!m_activeDialogs.contains(contents))
+ return false;
+ QSharedPointer<JavaScriptDialogController> dialog = m_activeDialogs.value(contents);
+ Q_EMIT dialog->dialogCloseRequested();
+ dialog->d->dialogFinished(accept, promptOverride ? *promptOverride : base::string16());
+ return true;
}
-bool JavaScriptDialogManagerQt::HandleJavaScriptDialog(content::WebContents *, bool accept, const base::string16 *promptOverride)
+
+void JavaScriptDialogManagerQt::removeDialogForContents(content::WebContents *contents)
{
- // FIXME: We might need to keep a queue of modal dialogs in there and unqueue them...
- return false;
+ QSharedPointer<JavaScriptDialogController> dialog = m_activeDialogs.take(contents);
+ Q_EMIT dialog->dialogCloseRequested();
}
diff --git a/src/core/javascript_dialog_manager_qt.h b/src/core/javascript_dialog_manager_qt.h
index de416e03e..69eaf94b1 100644
--- a/src/core/javascript_dialog_manager_qt.h
+++ b/src/core/javascript_dialog_manager_qt.h
@@ -45,7 +45,10 @@
#include "content/public/common/javascript_message_type.h"
#include "qglobal.h"
+#include <QMap>
+#include <QSharedPointer>
+class JavaScriptDialogController;
namespace content {
class WebContents;
}
@@ -62,8 +65,13 @@ public:
virtual void RunBeforeUnloadDialog(content::WebContents *, const base::string16 &messageText, bool isReload,
const content::JavaScriptDialogManager::DialogClosedCallback &callback) Q_DECL_OVERRIDE { Q_UNUSED(messageText); Q_UNUSED(isReload); Q_UNUSED(callback); }
virtual bool HandleJavaScriptDialog(content::WebContents *, bool accept, const base::string16 *promptOverride) Q_DECL_OVERRIDE;
- virtual void CancelActiveAndPendingDialogs(content::WebContents *) Q_DECL_OVERRIDE {}
- virtual void WebContentsDestroyed(content::WebContents *) Q_DECL_OVERRIDE {}
+ virtual void CancelActiveAndPendingDialogs(content::WebContents *contents) Q_DECL_OVERRIDE { removeDialogForContents(contents); }
+ virtual void WebContentsDestroyed(content::WebContents *contents) Q_DECL_OVERRIDE { removeDialogForContents(contents); }
+
+ void removeDialogForContents(content::WebContents *);
+
+private:
+ QMap<content::WebContents *, QSharedPointer<JavaScriptDialogController> > m_activeDialogs;
};
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 7542f35bd..bb2ac36f4 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -40,8 +40,9 @@
****************************************************************************/
#include "web_contents_adapter.h"
-#include "content_browser_client_qt.h"
#include "browser_context_qt.h"
+#include "content_browser_client_qt.h"
+#include "javascript_dialog_manager_qt.h"
#include "type_conversion.h"
#include "web_contents_adapter_client.h"
#include "web_contents_delegate_qt.h"
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 2231fd46b..28cd3c4d8 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -44,10 +44,12 @@
#include "qtwebenginecoreglobal.h"
#include <QRect>
+#include <QSharedPointer>
#include <QString>
#include <QStringList>
#include <QUrl>
+class JavaScriptDialogController;
class RenderWidgetHostViewQt;
class RenderWidgetHostViewQtDelegate;
class RenderWidgetHostViewQtDelegateClient;
@@ -123,7 +125,7 @@ public:
virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect & initialGeometry) = 0;
virtual void close() = 0;
virtual bool contextMenuRequested(const WebEngineContextMenuData&) = 0;
- virtual bool javascriptDialog(JavascriptDialogType type, const QString &message, const QString &defaultValue = QString(), QString *result = 0) = 0;
+ virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) = 0;
virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) = 0;
};
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 6dd8121dd..c3648bccf 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -86,6 +86,7 @@ void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content
void WebContentsDelegateQt::CloseContents(content::WebContents *source)
{
m_viewClient->close();
+ GetJavaScriptDialogManager()->CancelActiveAndPendingDialogs(source);
}
void WebContentsDelegateQt::LoadingStateChanged(content::WebContents* source)