diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/core/api/qwebenginepage.cpp | 14 | ||||
-rw-r--r-- | src/core/api/qwebenginepage_p.h | 7 | ||||
-rw-r--r-- | src/core/autofill_client_qt.cpp | 162 | ||||
-rw-r--r-- | src/core/autofill_client_qt.h | 108 | ||||
-rw-r--r-- | src/core/autofill_popup_controller.cpp | 150 | ||||
-rw-r--r-- | src/core/autofill_popup_controller.h | 98 | ||||
-rw-r--r-- | src/core/autofill_popup_controller_p.h | 76 | ||||
-rw-r--r-- | src/core/configure/BUILD.root.gn.in | 3 | ||||
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 11 | ||||
-rw-r--r-- | src/core/pref_service_adapter.cpp | 9 | ||||
-rw-r--r-- | src/core/renderer/content_renderer_client_qt.cpp | 19 | ||||
-rw-r--r-- | src/core/web_contents_adapter.cpp | 8 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 4 |
14 files changed, 670 insertions, 1 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 18078ba5a..904baf7d2 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -76,6 +76,8 @@ foreach(arch ${archs}) accessibility_activation_observer.cpp accessibility_activation_observer.h accessibility_tree_formatter_qt.cpp authentication_dialog_controller.cpp authentication_dialog_controller.h authentication_dialog_controller_p.h + autofill_client_qt.cpp autofill_client_qt.h + autofill_popup_controller.cpp autofill_popup_controller.h autofill_popup_controller_p.h browser_accessibility_manager_qt.cpp browser_accessibility_manager_qt.h browser_accessibility_qt.cpp browser_accessibility_qt.h browser_main_parts_qt.cpp browser_main_parts_qt.h diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index 8a49e6577..332a612fc 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -59,6 +59,7 @@ #include "qwebenginesettings.h" #include "authentication_dialog_controller.h" +#include "autofill_popup_controller.h" #include "color_chooser_controller.h" #include "find_text_helper.h" #include "file_picker_controller.h" @@ -692,6 +693,19 @@ void QWebEnginePagePrivate::findTextFinished(const QWebEngineFindTextResult &res Q_EMIT q->findTextFinished(result); } +void QWebEnginePagePrivate::showAutofillPopup(QtWebEngineCore::AutofillPopupController *controller, + const QRect &bounds, bool autoselectFirstSuggestion) +{ + if (view) + view->showAutofillPopup(controller, bounds, autoselectFirstSuggestion); +} + +void QWebEnginePagePrivate::hideAutofillPopup() +{ + if (view) + view->hideAutofillPopup(); +} + void QWebEnginePagePrivate::ensureInitialized() const { if (!adapter->isInitialized()) diff --git a/src/core/api/qwebenginepage_p.h b/src/core/api/qwebenginepage_p.h index 2b76795b5..68203ba76 100644 --- a/src/core/api/qwebenginepage_p.h +++ b/src/core/api/qwebenginepage_p.h @@ -61,6 +61,7 @@ #include <QtCore/QTimer> namespace QtWebEngineCore { +class AutofillPopupController; class RenderWidgetHostViewQtDelegate; class RenderWidgetHostViewQtDelegateClient; class RenderWidgetHostViewQtDelegateItem; @@ -109,6 +110,9 @@ public: virtual void didPrintPage(QPrinter *&printer, QSharedPointer<QByteArray> result) = 0; virtual void didPrintPageToPdf(const QString &filePath, bool success) = 0; virtual void printRequested() = 0; + virtual void showAutofillPopup(QtWebEngineCore::AutofillPopupController *controller, + const QRect &bounds, bool autoselectFirstSuggestion) = 0; + virtual void hideAutofillPopup() = 0; }; class Q_WEBENGINECORE_PRIVATE_EXPORT QWebEnginePagePrivate : public QtWebEngineCore::WebContentsAdapterClient @@ -195,6 +199,9 @@ public: const QObject *holdingQObject() const override; ClientType clientType() override { return QtWebEngineCore::WebContentsAdapterClient::WidgetsClient; } void findTextFinished(const QWebEngineFindTextResult &result) override; + void showAutofillPopup(QtWebEngineCore::AutofillPopupController *controller, + const QRect &bounds, bool autoselectFirstSuggestion) override; + void hideAutofillPopup() override; QtWebEngineCore::ProfileAdapter *profileAdapter() override; QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override; diff --git a/src/core/autofill_client_qt.cpp b/src/core/autofill_client_qt.cpp new file mode 100644 index 000000000..b599560d1 --- /dev/null +++ b/src/core/autofill_client_qt.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "autofill_client_qt.h" + +#include "autofill_popup_controller.h" +#include "autofill_popup_controller_p.h" +#include "render_widget_host_view_qt.h" +#include "type_conversion.h" +#include "web_contents_adapter_client.h" +#include "web_contents_view_qt.h" + +#include "base/task/thread_pool.h" +#include "base/threading/thread_task_runner_handle.h" +#include "chrome/browser/profiles/profile.h" +#include "components/autofill/core/common/autofill_prefs.h" +#include "content/browser/web_contents/web_contents_impl.h" + +namespace QtWebEngineCore { + +AutofillClientQt::AutofillClientQt(content::WebContents *webContents) + : content::WebContentsObserver(webContents) + , m_popupController(new AutofillPopupController(new AutofillPopupControllerPrivate)) +{ +} + +AutofillClientQt::~AutofillClientQt() { } + +autofill::PersonalDataManager *AutofillClientQt::GetPersonalDataManager() +{ + return nullptr; +} + +autofill::AutocompleteHistoryManager *AutofillClientQt::GetAutocompleteHistoryManager() +{ + return nullptr; +} + +PrefService *AutofillClientQt::GetPrefs() +{ + return const_cast<PrefService *>(base::as_const(*this).GetPrefs()); +} + +const PrefService *AutofillClientQt::GetPrefs() const +{ + Profile *profile = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); + return profile->GetPrefs(); +} + +void AutofillClientQt::ShowAutofillPopup(const autofill::AutofillClient::PopupOpenArgs &open_args, + base::WeakPtr<autofill::AutofillPopupDelegate> delegate) +{ + // Specific popups (personal, address, credit card, password) are not supported. + DCHECK(open_args.popup_type == autofill::PopupType::kUnspecified); + + m_popupController->d->delegate = delegate; + m_popupController->d->suggestions = open_args.suggestions; + m_popupController->updateModel(); + + adapterClient()->showAutofillPopup(m_popupController.data(), + QRect(toQt(gfx::ToEnclosingRect(open_args.element_bounds))), + open_args.autoselect_first_suggestion.value()); +} + +void AutofillClientQt::UpdateAutofillPopupDataListValues(const std::vector<std::u16string> &values, + const std::vector<std::u16string> &labels) +{ + Q_UNUSED(labels); + + if (values.empty()) + HideAutofillPopup(autofill::PopupHidingReason::kNoSuggestions); +} + +void AutofillClientQt::PinPopupView() +{ + // Called by password_manager component only. + NOTIMPLEMENTED(); +} + +autofill::AutofillClient::PopupOpenArgs AutofillClientQt::GetReopenPopupArgs() const +{ + // Called by password_manager component only. + NOTIMPLEMENTED(); + return autofill::AutofillClient::PopupOpenArgs(); +} + +base::span<const autofill::Suggestion> AutofillClientQt::GetPopupSuggestions() const +{ + // Called by password_manager component only. + NOTIMPLEMENTED(); + return base::span<const autofill::Suggestion>(); +} + +void AutofillClientQt::UpdatePopup(const std::vector<autofill::Suggestion> &, autofill::PopupType) +{ + // Called by password_manager component only. + NOTIMPLEMENTED(); +} + +void AutofillClientQt::HideAutofillPopup(autofill::PopupHidingReason) +{ + adapterClient()->hideAutofillPopup(); +} + +bool AutofillClientQt::IsAutocompleteEnabled() +{ + return autofill::prefs::IsAutocompleteEnabled(GetPrefs()); +} + +void AutofillClientQt::PropagateAutofillPredictions(content::RenderFrameHost *, + const std::vector<autofill::FormStructure *> &) +{ + // For testing purposes only. + NOTIMPLEMENTED(); +} + +WebContentsAdapterClient *AutofillClientQt::adapterClient() +{ + return WebContentsViewQt::from( + static_cast<content::WebContentsImpl *>(web_contents())->GetView()) + ->client(); +} + +WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillClientQt); + +} // namespace QtWebEngineCore diff --git a/src/core/autofill_client_qt.h b/src/core/autofill_client_qt.h new file mode 100644 index 000000000..762ff1109 --- /dev/null +++ b/src/core/autofill_client_qt.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef AUTOFILL_CLIENT_QT_H +#define AUTOFILL_CLIENT_QT_H + +#include <string> +#include <vector> + +#include "base/memory/weak_ptr.h" +#include "components/autofill/core/browser/autofill_client.h" +#include "content/public/browser/web_contents_observer.h" +#include "content/public/browser/web_contents_user_data.h" + +#include <QScopedPointer> + +namespace QtWebEngineCore { + +class AutofillPopupController; +class WebContentsAdapterClient; + +class AutofillClientQt : public autofill::AutofillClient, + public content::WebContentsUserData<AutofillClientQt>, + public content::WebContentsObserver +{ +public: + ~AutofillClientQt() override; + + // autofill::AutofillClient overrides: + autofill::PersonalDataManager *GetPersonalDataManager() override; + autofill::AutocompleteHistoryManager *GetAutocompleteHistoryManager() override; + PrefService *GetPrefs() override; + const PrefService *GetPrefs() const override; + + void ShowAutofillPopup(const autofill::AutofillClient::PopupOpenArgs &open_args, + base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override; + void UpdateAutofillPopupDataListValues(const std::vector<std::u16string> &values, + const std::vector<std::u16string> &labels) override; + void PinPopupView() override; + autofill::AutofillClient::PopupOpenArgs GetReopenPopupArgs() const override; + base::span<const autofill::Suggestion> GetPopupSuggestions() const override; + void UpdatePopup(const std::vector<autofill::Suggestion> &, autofill::PopupType) override; + void HideAutofillPopup(autofill::PopupHidingReason reason) override; + bool IsAutocompleteEnabled() override; + void PropagateAutofillPredictions(content::RenderFrameHost *, + const std::vector<autofill::FormStructure *> &) override; + +private: + explicit AutofillClientQt(content::WebContents *webContents); + + WebContentsAdapterClient *adapterClient(); + + QScopedPointer<AutofillPopupController> m_popupController; + + WEB_CONTENTS_USER_DATA_KEY_DECL(); + friend class content::WebContentsUserData<AutofillClientQt>; +}; + +} // namespace QtWebEngineCore + +#endif // AUTOFILL_CLIENT_QT_H diff --git a/src/core/autofill_popup_controller.cpp b/src/core/autofill_popup_controller.cpp new file mode 100644 index 000000000..e42f5a4f6 --- /dev/null +++ b/src/core/autofill_popup_controller.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "autofill_popup_controller.h" +#include "autofill_popup_controller_p.h" + +#include "components/autofill/core/browser/ui/autofill_popup_delegate.h" +#include "components/autofill/core/browser/ui/suggestion.h" + +namespace QtWebEngineCore { + +AutofillPopupController::AutofillPopupController(AutofillPopupControllerPrivate *dd) +{ + Q_ASSERT(dd); + d.reset(dd); +} + +AutofillPopupController::~AutofillPopupController() { } + +void AutofillPopupController::setCurrentIndex(const QModelIndex &index) +{ + if (m_currentIndex == index) + return; + + m_currentIndex = index; + + if (m_currentIndex.isValid()) { + const autofill::Suggestion &suggestion = d->suggestions[m_currentIndex.row()]; + d->delegate->DidSelectSuggestion(suggestion.value, suggestion.frontend_id); + } + + Q_EMIT currentIndexChanged(index); +} + +void AutofillPopupController::selectPreviousSuggestion() +{ + if (!m_currentIndex.isValid()) { + setCurrentIndex(m_model.index(m_model.rowCount() - 1, 0)); + return; + } + + if (m_currentIndex.row() == 0) { + selectLastSuggestion(); + return; + } + + setCurrentIndex(m_model.index(m_currentIndex.row() - 1, 0)); +} + +void AutofillPopupController::selectNextSuggestion() +{ + if (!m_currentIndex.isValid()) { + setCurrentIndex(m_model.index(0, 0)); + return; + } + + if (m_currentIndex.row() == m_model.rowCount() - 1) { + selectFirstSuggestion(); + return; + } + + setCurrentIndex(m_model.index(m_currentIndex.row() + 1, 0)); +} + +void AutofillPopupController::selectFirstSuggestion() +{ + setCurrentIndex(m_model.index(0, 0)); +} + +void AutofillPopupController::selectLastSuggestion() +{ + setCurrentIndex(m_model.index(m_model.rowCount() - 1, 0)); +} + +void AutofillPopupController::acceptSuggestion() +{ + if (!m_currentIndex.isValid()) + return; + + const int index = m_currentIndex.row(); + const autofill::Suggestion &suggestion = d->suggestions[index]; + d->delegate->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, + suggestion.backend_id, index); +} + +void AutofillPopupController::notifyPopupShown() +{ + d->delegate->OnPopupShown(); +} + +void AutofillPopupController::notifyPopupHidden() +{ + d->delegate->OnPopupHidden(); +} + +void AutofillPopupController::selectSuggestion(int index) +{ + if (index < 0) + setCurrentIndex(QModelIndex()); + else + setCurrentIndex(m_model.index(index, 0)); +} + +void AutofillPopupController::updateModel() +{ + QStringList values; + for (size_t i = 0; i < d->suggestions.size(); ++i) { + values.append(QString::fromStdU16String(d->suggestions[i].value)); + } + m_model.setStringList(values); + setCurrentIndex(QModelIndex()); +} + +} // namespace QtWebEngineCore diff --git a/src/core/autofill_popup_controller.h b/src/core/autofill_popup_controller.h new file mode 100644 index 000000000..5432123f1 --- /dev/null +++ b/src/core/autofill_popup_controller.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AUTOFILL_POPUP_CONTROLLER_H +#define AUTOFILL_POPUP_CONTROLLER_H + +#include <QtWebEngineCore/private/qtwebenginecoreglobal_p.h> + +#include <QModelIndex> +#include <QObject> +#include <QScopedPointer> +#include <QStringListModel> + +namespace QtWebEngineCore { + +class AutofillPopupControllerPrivate; + +class Q_WEBENGINECORE_PRIVATE_EXPORT AutofillPopupController : public QObject +{ + Q_OBJECT + Q_PROPERTY(QStringListModel *model READ model CONSTANT FINAL) + +public: + ~AutofillPopupController(); + + QStringListModel *model() { return &m_model; } + + void selectPreviousSuggestion(); + void selectNextSuggestion(); + void selectFirstSuggestion(); + void selectLastSuggestion(); + + void notifyPopupShown(); + void notifyPopupHidden(); + +public Q_SLOTS: + void selectSuggestion(int index); + void acceptSuggestion(); + +Q_SIGNALS: + void currentIndexChanged(const QModelIndex &index); + +private: + AutofillPopupController(AutofillPopupControllerPrivate *); + QScopedPointer<AutofillPopupControllerPrivate> d; + + void setCurrentIndex(const QModelIndex &index); + + // Only called by AutofillClientQt: + void updateModel(); + + QStringListModel m_model; + QModelIndex m_currentIndex; + + friend class AutofillClientQt; +}; + +} // namespace QtWebEngineCore + +Q_DECLARE_METATYPE(QtWebEngineCore::AutofillPopupController *) + +#endif // AUTOFILL_POPUP_CONTROLLER_H diff --git a/src/core/autofill_popup_controller_p.h b/src/core/autofill_popup_controller_p.h new file mode 100644 index 000000000..880eec86e --- /dev/null +++ b/src/core/autofill_popup_controller_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AUTOFILL_POPUP_CONTROLLER_P_H +#define AUTOFILL_POPUP_CONTROLLER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <vector> + +#include "base/memory/weak_ptr.h" +#include "components/autofill/core/browser/ui/suggestion.h" + +namespace autofill { +class AutofillPopupDelegate; +} + +namespace QtWebEngineCore { + +class AutofillPopupControllerPrivate +{ +public: + AutofillPopupControllerPrivate() = default; + + base::WeakPtr<autofill::AutofillPopupDelegate> delegate = nullptr; + std::vector<autofill::Suggestion> suggestions; +}; + +} // namespace QtWebEngineCore + +#endif // AUTOFILL_POPUP_CONTROLLER_P_H diff --git a/src/core/configure/BUILD.root.gn.in b/src/core/configure/BUILD.root.gn.in index 35fe32476..f1fa1eaa3 100644 --- a/src/core/configure/BUILD.root.gn.in +++ b/src/core/configure/BUILD.root.gn.in @@ -104,6 +104,9 @@ shared_library("QtWebEngineCore") { defines = [ "CHROMIUM_VERSION=\"" + chromium_version[0] + "\"" ] deps = [ "//base", + "//components/autofill/content/browser", + "//components/autofill/content/renderer", + "//components/autofill/core/browser", "//components/cdm/renderer", "//components/error_page/common", "//components/favicon/content", diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 1bbac4439..0fdf1f397 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -42,6 +42,7 @@ #include "base/files/file_util.h" #include "base/task/post_task.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h" +#include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/custom_handlers/protocol_handler_registry.h" #include "components/error_page/common/error.h" #include "components/error_page/common/localized_error.h" @@ -502,6 +503,8 @@ void ContentBrowserClientQt::ExposeInterfacesToRenderer(service_manager::BinderR #endif } +// TODO: BindAssociatedReceiverForFrame -> RegisterAssociatedInterfaceBindersForRenderFrameHost +// https://chromium-review.googlesource.com/c/chromium/src/+/3281481 bool ContentBrowserClientQt::BindAssociatedReceiverFromFrame(content::RenderFrameHost *rfh, const std::string &interface_name, mojo::ScopedInterfaceEndpointHandle *handle) @@ -529,6 +532,14 @@ bool ContentBrowserClientQt::BindAssociatedReceiverFromFrame(content::RenderFram return true; } #endif + + if (interface_name == autofill::mojom::AutofillDriver::Name_) { + mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver> receiver( + std::move(*handle)); + autofill::ContentAutofillDriverFactory::BindAutofillDriver(std::move(receiver), rfh); + return true; + } + DCHECK(!ContentBrowserClient::BindAssociatedReceiverFromFrame(rfh, interface_name, handle)); return false; } diff --git a/src/core/pref_service_adapter.cpp b/src/core/pref_service_adapter.cpp index d7795c7e9..f3a99c3e2 100644 --- a/src/core/pref_service_adapter.cpp +++ b/src/core/pref_service_adapter.cpp @@ -46,6 +46,7 @@ #include "base/threading/thread_restrictions.h" #include "chrome/browser/prefs/chrome_command_line_pref_store.h" #include "content/public/browser/browser_thread.h" +#include "components/autofill/core/common/autofill_prefs.h" #include "components/language/core/browser/pref_names.h" #include "components/prefs/pref_member.h" #include "components/prefs/in_memory_pref_store.h" @@ -131,6 +132,14 @@ void PrefServiceAdapter::setup(const ProfileAdapter &profileAdapter) // default value will be different. We'll need to initialize it later. registry->RegisterStringPref(kPrefMediaDeviceIDSalt, std::string()); + registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabledDeprecated, false); + registry->RegisterBooleanPref(autofill::prefs::kAutofillProfileEnabled, false); + registry->RegisterBooleanPref(autofill::prefs::kAutofillCreditCardEnabled, false); + registry->RegisterBooleanPref(autofill::prefs::kAutofillCreditCardFidoAuthEnabled, false); + registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, false); + registry->RegisterBooleanPref(autofill::prefs::kAutofillJapanCityFieldMigratedDeprecated, + false); + { base::ScopedAllowBlocking allowBlock; m_prefService = factory.Create(registry); diff --git a/src/core/renderer/content_renderer_client_qt.cpp b/src/core/renderer/content_renderer_client_qt.cpp index b410ad377..ffb5178e7 100644 --- a/src/core/renderer/content_renderer_client_qt.cpp +++ b/src/core/renderer/content_renderer_client_qt.cpp @@ -47,6 +47,10 @@ #include "components/spellcheck/renderer/spellcheck.h" #include "components/spellcheck/renderer/spellcheck_provider.h" #endif +#include "components/autofill/content/renderer/autofill_agent.h" +#include "components/autofill/content/renderer/autofill_assistant_agent.h" +#include "components/autofill/content/renderer/password_autofill_agent.h" +#include "components/autofill/content/renderer/password_generation_agent.h" #include "components/cdm/renderer/external_clear_key_key_system_properties.h" #include "components/cdm/renderer/widevine_key_system_properties.h" #include "components/error_page/common/error.h" @@ -210,8 +214,10 @@ void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame *render_fr #if QT_CONFIG(webengine_printing_and_pdf) new printing::PrintRenderFrameHelper(render_frame, base::WrapUnique(new PrintWebViewHelperDelegateQt())); #endif // QT_CONFIG(webengine_printing_and_pdf) -#if BUILDFLAG(ENABLE_EXTENSIONS) + blink::AssociatedInterfaceRegistry *associated_interfaces = render_frame_observer->associatedInterfaces(); + +#if BUILDFLAG(ENABLE_EXTENSIONS) associated_interfaces->AddInterface(base::BindRepeating( &extensions::MimeHandlerViewContainerManager::BindReceiver, render_frame->GetRoutingID())); @@ -219,6 +225,17 @@ void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame *render_fr auto registry = std::make_unique<service_manager::BinderRegistry>(); ExtensionsRendererClientQt::GetInstance()->RenderFrameCreated(render_frame, render_frame_observer->registry()); #endif + + autofill::AutofillAssistantAgent *autofill_assistant_agent = + new autofill::AutofillAssistantAgent(render_frame); + autofill::PasswordAutofillAgent *password_autofill_agent = + new autofill::PasswordAutofillAgent(render_frame, associated_interfaces); + autofill::PasswordGenerationAgent *password_generation_agent = + new autofill::PasswordGenerationAgent(render_frame, password_autofill_agent, + associated_interfaces); + + new autofill::AutofillAgent(render_frame, password_autofill_agent, password_generation_agent, + autofill_assistant_agent, associated_interfaces); } void ContentRendererClientQt::RunScriptsAtDocumentStart(content::RenderFrame *render_frame) diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 45dfd1017..525ee728d 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -43,6 +43,7 @@ #include "web_contents_adapter.h" +#include "autofill_client_qt.h" #include "devtools_frontend_qt.h" #include "download_manager_delegate_qt.h" #include "favicon_driver_qt.h" @@ -66,6 +67,8 @@ #include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h" #include "base/values.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h" +#include "components/autofill/core/browser/autofill_manager.h" +#include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/favicon/core/favicon_service.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/text_input_manager.h" @@ -517,6 +520,11 @@ void WebContentsAdapter::initialize(content::SiteInstance *site) FaviconDriverQt::CreateForWebContents( webContents(), FaviconServiceFactoryQt::GetForBrowserContext(context), m_adapterClient); + AutofillClientQt::CreateForWebContents(webContents()); + autofill::ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( + webContents(), AutofillClientQt::FromWebContents(webContents()), + /* app_locale = */ "", autofill::AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER); + // Create an instance of WebEngineVisitedLinksManager to catch the first // content::NOTIFICATION_RENDERER_PROCESS_CREATED event. This event will // force to initialize visited links in VisitedLinkSlave. diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 2729e7beb..0ad91e92e 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -80,6 +80,7 @@ struct DropData; namespace QtWebEngineCore { +class AutofillPopupController; class CertificateErrorController; class ClientCertSelectController; class AuthenticationDialogController; @@ -245,6 +246,9 @@ public: virtual void showTouchSelectionMenu(TouchSelectionMenuController *menuController, const QRect &bounds, const QSize &handleSize) = 0; virtual void hideTouchSelectionMenu() = 0; virtual void findTextFinished(const QWebEngineFindTextResult &result) = 0; + virtual void showAutofillPopup(AutofillPopupController *controller, const QRect &bounds, + bool autoselectFirstSuggestion) = 0; + virtual void hideAutofillPopup() = 0; virtual ProfileAdapter *profileAdapter() = 0; virtual WebContentsAdapter* webContentsAdapter() = 0; |