summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebengineview.cpp6
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h2
-rw-r--r--src/webengine/ui/AlertDialog.qml46
-rw-r--r--src/webengine/ui/ConfirmDialog.qml47
-rw-r--r--src/webengine/ui/PromptDialog.qml96
-rw-r--r--src/webengine/ui/qmldir3
-rw-r--r--src/webengine/ui/ui.pro5
-rw-r--r--src/webengine/ui_delegates_manager.cpp77
-rw-r--r--src/webengine/ui_delegates_manager.h12
9 files changed, 286 insertions, 8 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 1dcc2acd0..c06a4af48 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -43,6 +43,7 @@
#include "qquickwebengineview_p_p.h"
#include "net/base/net_errors.h"
+#include "javascript_dialog_controller.h"
#include "qquickwebengineloadrequest_p.h"
#include "render_widget_host_view_qt_delegate_quick.h"
#include "ui_delegates_manager.h"
@@ -171,10 +172,9 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu
return true;
}
-bool QQuickWebEngineViewPrivate::javascriptDialog(JavascriptDialogType type, const QString &message, const QString &defaultValue, QString *result)
+void QQuickWebEngineViewPrivate::javascriptDialog(QSharedPointer<JavaScriptDialogController> dialog)
{
- Q_UNUSED(message); Q_UNUSED(defaultValue); Q_UNUSED(result);
- return false;
+ ui()->showDialog(dialog);
}
void QQuickWebEngineViewPrivate::titleChanged(const QString &title)
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 67337baeb..45622d308 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -136,7 +136,7 @@ public:
virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect &) Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
virtual bool contextMenuRequested(const WebEngineContextMenuData &) Q_DECL_OVERRIDE;
- virtual bool javascriptDialog(JavascriptDialogType, const QString &message, const QString &defaultValue = QString(), QString *result = 0) Q_DECL_OVERRIDE { Q_UNUSED(message); Q_UNUSED(defaultValue); Q_UNUSED(result); return false; }
+ virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) Q_DECL_OVERRIDE;
virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) { Q_UNUSED(defaultFileName); Q_UNUSED(acceptedMimeTypes);}
void setDevicePixelRatio(qreal);
diff --git a/src/webengine/ui/AlertDialog.qml b/src/webengine/ui/AlertDialog.qml
new file mode 100644
index 000000000..bc494a080
--- /dev/null
+++ b/src/webengine/ui/AlertDialog.qml
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the demonstration applications 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$
+**
+****************************************************************************/
+
+import QtQuick.Dialogs 1.1
+
+MessageDialog {
+ icon: StandardIcon.Information
+}
diff --git a/src/webengine/ui/ConfirmDialog.qml b/src/webengine/ui/ConfirmDialog.qml
new file mode 100644
index 000000000..108497d3d
--- /dev/null
+++ b/src/webengine/ui/ConfirmDialog.qml
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the demonstration applications 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$
+**
+****************************************************************************/
+
+import QtQuick.Dialogs 1.1
+
+MessageDialog {
+ icon: StandardIcon.Question
+ standardButtons: StandardButton.Ok | StandardButton.Cancel
+}
diff --git a/src/webengine/ui/PromptDialog.qml b/src/webengine/ui/PromptDialog.qml
new file mode 100644
index 000000000..534c9dd9b
--- /dev/null
+++ b/src/webengine/ui/PromptDialog.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the demonstration applications 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$
+**
+****************************************************************************/
+
+// FIXME: prompt missing in Qt Quick Dialogs atm. Make our own for now.
+import QtQuick.Controls 1.1
+import QtQuick.Layouts 1.0
+import QtQuick 2.0
+
+ApplicationWindow {
+ signal input(string text);
+ signal accepted;
+ signal rejected;
+ property alias text: message.text;
+ property alias prompt: field.text;
+
+ width: 350
+ height: 100
+ flags: Qt.Dialog
+
+ function open() {
+ show();
+ }
+
+ ColumnLayout {
+ anchors.fill: parent;
+ anchors.margins: 4;
+ Text {
+ id: message;
+ Layout.fillWidth: true;
+ }
+ TextField {
+ id:field;
+ Layout.fillWidth: true;
+ }
+ RowLayout {
+ Layout.alignment: Qt.AlignRight
+ spacing: 8;
+ Button {
+ text: "OK"
+ onClicked: {
+ input(field.text)
+ accepted();
+ close();
+ destroy();
+ }
+ }
+ Button {
+ text: "Cancel"
+ onClicked: {
+ rejected();
+ close();
+ destroy();
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/webengine/ui/qmldir b/src/webengine/ui/qmldir
index bc0e2e300..bb942a81a 100644
--- a/src/webengine/ui/qmldir
+++ b/src/webengine/ui/qmldir
@@ -1,4 +1,7 @@
module QtWebEngine.UIDelegates
+AlertDialog 1.0 AlertDialog.qml
+ConfirmDialog 1.0 ConfirmDialog.qml
+PromptDialog 1.0 PromptDialog.qml
Menu 1.0 Menu.qml
MenuItem 1.0 MenuItem.qml
MenuSeparator 1.0 MenuSeparator.qml
diff --git a/src/webengine/ui/ui.pro b/src/webengine/ui/ui.pro
index 42a5777dc..049b428f5 100644
--- a/src/webengine/ui/ui.pro
+++ b/src/webengine/ui/ui.pro
@@ -1,6 +1,11 @@
TARGETPATH = QtWebEngine/UIDelegates
QML_FILES += \
+ # JS Dialogs
+ AlertDialog.qml \
+ ConfirmDialog.qml \
+ PromptDialog.qml \
+ # Menus. Based on Qt Quick Controls
Menu.qml \
MenuItem.qml \
MenuSeparator.qml
diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp
index 34edbd479..6ee3ea360 100644
--- a/src/webengine/ui_delegates_manager.cpp
+++ b/src/webengine/ui_delegates_manager.cpp
@@ -40,7 +40,9 @@
****************************************************************************/
#include "ui_delegates_manager.h"
+
#include "api/qquickwebengineview_p.h"
+#include "javascript_dialog_controller.h"
#include <QAbstractListModel>
#include <QClipboard>
@@ -158,9 +160,9 @@ QQmlContext *UIDelegatesManager::creationContextForComponent(QQmlComponent *comp
return baseContext;
}
-#define CHECK_QML_SIGNAL_PROPERTY(prop, type, location) \
+#define CHECK_QML_SIGNAL_PROPERTY(prop, location) \
if (!prop.isSignalProperty()) \
- qWarning(#type "component (Loaded from %s) is missing %s signal property.\n", qPrintable(location.toString()), qPrintable(prop.name()));
+ qWarning("%s is missing %s signal property.\n", qPrintable(location.toString()), qPrintable(prop.name()));
void UIDelegatesManager::addMenuItem(MenuItemHandler *menuItemHandler, const QString &text, const QString &iconName, bool enabled)
{
@@ -231,3 +233,74 @@ QObject *UIDelegatesManager::addMenu(QObject *parentMenu, const QString &title,
return menu;
}
+#define ASSIGN_DIALOG_COMPONENT_DATA_CASE_STATEMENT(TYPE, COMPONENT) \
+ case TYPE:\
+ dialogComponent = COMPONENT##Component.data(); \
+ break;
+
+
+void UIDelegatesManager::showDialog(QSharedPointer<JavaScriptDialogController> dialogController)
+{
+ Q_ASSERT(!dialogController.isNull());
+ ComponentType dialogComponentType = Invalid;
+ QString title;
+ switch (dialogController->type()) {
+ case WebContentsAdapterClient::AlertDialog:
+ dialogComponentType = AlertDialog;
+ title = QObject::tr("Javascript Alert - %1");
+ break;
+ case WebContentsAdapterClient::ConfirmDialog:
+ dialogComponentType = ConfirmDialog;
+ title = QObject::tr("Javascript Confirm - %1");
+ break;
+ case WebContentsAdapterClient::PromptDialog:
+ dialogComponentType = PromptDialog;
+ title = QObject::tr("Javascript Prompt - %1");
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
+
+ if (!ensureComponentLoaded(dialogComponentType))
+ return;
+
+ QQmlComponent *dialogComponent = Q_NULLPTR;
+ switch (dialogComponentType) {
+ FOR_EACH_COMPONENT_TYPE(ASSIGN_DIALOG_COMPONENT_DATA_CASE_STATEMENT, NO_SEPARATOR)
+ default:
+ Q_UNREACHABLE();
+ }
+
+ QQmlContext *context(creationContextForComponent(dialogComponent));
+ QObject *dialog = dialogComponent->beginCreate(context);
+ dialog->setParent(m_view);
+ QQmlProperty textProp(dialog, QStringLiteral("text"));
+ textProp.write(dialogController->message());
+
+ QQmlProperty titleProp(dialog, QStringLiteral("title"));
+ titleProp.write(title.arg(m_view->url().toString()));
+
+ if (dialogComponentType == PromptDialog) {
+ QQmlProperty promptProp(dialog, QStringLiteral("prompt"));
+ promptProp.write(dialogController->defaultPrompt());
+ QQmlProperty inputSignal(dialog, QStringLiteral("onInput"));
+ CHECK_QML_SIGNAL_PROPERTY(inputSignal, dialogComponent->url());
+ static int setTextIndex = dialogController->metaObject()->indexOfSlot("textProvided(QString)");
+ QObject::connect(dialog, inputSignal.method(), dialogController.data(), dialogController->metaObject()->method(setTextIndex));
+ }
+
+ QQmlProperty acceptSignal(dialog, QStringLiteral("onAccepted"));
+ QQmlProperty rejectSignal(dialog, QStringLiteral("onRejected"));
+ CHECK_QML_SIGNAL_PROPERTY(acceptSignal, dialogComponent->url());
+ CHECK_QML_SIGNAL_PROPERTY(rejectSignal, dialogComponent->url());
+
+ static int acceptIndex = dialogController->metaObject()->indexOfSlot("accept()");
+ QObject::connect(dialog, acceptSignal.method(), dialogController.data(), dialogController->metaObject()->method(acceptIndex));
+ static int rejectIndex = dialogController->metaObject()->indexOfSlot("reject()");
+ QObject::connect(dialog, rejectSignal.method(), dialogController.data(), dialogController->metaObject()->method(rejectIndex));
+ dialogComponent->completeCreate();
+
+ QObject::connect(dialogController.data(), &JavaScriptDialogController::dialogCloseRequested, dialog, &QObject::deleteLater);
+
+ QMetaObject::invokeMethod(dialog, "open");
+}
diff --git a/src/webengine/ui_delegates_manager.h b/src/webengine/ui_delegates_manager.h
index 65f994b93..eeece895c 100644
--- a/src/webengine/ui_delegates_manager.h
+++ b/src/webengine/ui_delegates_manager.h
@@ -47,14 +47,18 @@
#include <QExplicitlySharedDataPointer>
#include <QPoint>
-#include <QPointer>
#include <QQmlComponent>
+#include <QScopedPointer>
+#include <QSharedPointer>
#include <QUrl>
#define FOR_EACH_COMPONENT_TYPE(F, SEPARATOR) \
F(Menu, menu) SEPARATOR \
F(MenuItem, menuItem) SEPARATOR \
- F(MenuSeparator, menuSeparator) SEPARATOR
+ F(MenuSeparator, menuSeparator) SEPARATOR \
+ F(AlertDialog, alertDialog) SEPARATOR \
+ F(ConfirmDialog, confirmDialog) SEPARATOR \
+ F(PromptDialog, promptDialog) SEPARATOR
#define COMMA_SEPARATOR ,
#define SEMICOLON_SEPARATOR ;
@@ -63,6 +67,7 @@
#define MEMBER_DECLARATION(TYPE, COMPONENT) \
QScopedPointer<QQmlComponent> COMPONENT##Component
+class JavaScriptDialogController;
QT_BEGIN_NAMESPACE
class QObject;
class QQmlContext;
@@ -106,7 +111,9 @@ class UIDelegatesManager {
public:
enum ComponentType {
+ Invalid = -1,
FOR_EACH_COMPONENT_TYPE(ENUM_DECLARATION, COMMA_SEPARATOR)
+ ComponentTypeCount
};
UIDelegatesManager(QQuickWebEngineView *);
@@ -115,6 +122,7 @@ public:
void addMenuSeparator(QObject *menu);
QObject *addMenu(QObject *parentMenu, const QString &title, const QPoint &pos = QPoint());
QQmlContext *creationContextForComponent(QQmlComponent *);
+ void showDialog(QSharedPointer<JavaScriptDialogController>);
private:
bool ensureComponentLoaded(ComponentType);