diff options
author | Michal Klocek <michal.klocek@qt.io> | 2020-09-12 17:22:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-04 10:20:01 +0200 |
commit | c5826a63e1da9aee119c0b7d4c797bb8d13390f9 (patch) | |
tree | 634e82466e1868359cb1df12261b56ca2fcde58e | |
parent | 3a3d9fd97ddad29153baf87a7baa63b81352fd13 (diff) | |
download | qtwebengine-chromium-c5826a63e1da9aee119c0b7d4c797bb8d13390f9.tar.gz |
Add user script data mojo interface and traits
Change-Id: I13e2d365fd7c13e7aa18c2a5882fb71267fdcd60
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
5 files changed, 294 insertions, 0 deletions
diff --git a/chromium/qtwebengine/userscript/BUILD.gn b/chromium/qtwebengine/userscript/BUILD.gn new file mode 100644 index 00000000000..09992acfa70 --- /dev/null +++ b/chromium/qtwebengine/userscript/BUILD.gn @@ -0,0 +1,38 @@ +import("//mojo/public/tools/bindings/mojom.gni") +import("//chrome/common/features.gni") +import("//tools/grit/grit_rule.gni") + +mojom("interfaces") { + sources = [ + "userscript.mojom", + ] + + deps = [ + "//mojo/public/mojom/base", + "//url/mojom:url_mojom_gurl", + ] + + cpp_typemaps = [ + { + types = [ + { + mojom = "qtwebengine.mojom.UserScriptData" + cpp = "QtWebEngineCore::UserScriptData" + }, + ] + traits_headers = ["//qtwebengine/userscript/user_script_data_mojom_traits.h" ] + traits_sources = ["//qtwebengine/userscript/user_script_data_mojom_traits.cc" ] + }, + ] +} + +source_set("mojom_traits") { + sources = [ "user_script_data_mojom_traits.h", + "user_script_data_mojom_traits.cc", + ] +} + +source_set("userscript") { + sources = [ "user_script_data.h" ] + deps = [ ":interfaces" ] +} diff --git a/chromium/qtwebengine/userscript/user_script_data.h b/chromium/qtwebengine/userscript/user_script_data.h new file mode 100644 index 00000000000..39706acfe3b --- /dev/null +++ b/chromium/qtwebengine/userscript/user_script_data.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 USER_SCRIPT_DATA_H +#define USER_SCRIPT_DATA_H + +#include <string> +#include "url/gurl.h" + +namespace QtWebEngineCore { + +struct UserScriptData { + enum InjectionPoint { + AfterLoad, + DocumentLoadFinished, + DocumentElementCreation + }; + + UserScriptData() = default; + + std::string source; + GURL url; + uint8_t injectionPoint = 0; + bool injectForSubframes = false; + uint8_t worldId = 1; + uint64_t scriptId = 0; + std::vector<std::string> globs; + std::vector<std::string> excludeGlobs; + std::vector<std::string> urlPatterns; +}; +} // namespace QtWebEngineCore +#endif // USER_SCRIPT_DATA_H diff --git a/chromium/qtwebengine/userscript/user_script_data_mojom_traits.cc b/chromium/qtwebengine/userscript/user_script_data_mojom_traits.cc new file mode 100644 index 00000000000..f20a72fb11c --- /dev/null +++ b/chromium/qtwebengine/userscript/user_script_data_mojom_traits.cc @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 "qtwebengine/userscript/user_script_data_mojom_traits.h" + +namespace mojo { + +bool StructTraits<qtwebengine::mojom::UserScriptDataDataView, + QtWebEngineCore::UserScriptData>:: + Read(qtwebengine::mojom::UserScriptDataDataView data, + QtWebEngineCore::UserScriptData* out_data) { + if (!data.ReadSource(&out_data->source)) + return false; + if (!data.ReadUrl(&out_data->url)) + return false; + out_data->injectionPoint = data.injectionPoint(); + out_data->injectForSubframes = data.injectForSubframes(); + out_data->worldId = data.worldId(); + out_data->scriptId = data.scriptId(); + if (!data.ReadGlobs(&out_data->globs)) + return false; + if (!data.ReadExcludeGlobs(&out_data->excludeGlobs)) + return false; + if (!data.ReadUrlPatterns(&out_data->urlPatterns)) + return false; + return true; +}; + +} // namespace mojo diff --git a/chromium/qtwebengine/userscript/user_script_data_mojom_traits.h b/chromium/qtwebengine/userscript/user_script_data_mojom_traits.h new file mode 100644 index 00000000000..ef41ad1ca40 --- /dev/null +++ b/chromium/qtwebengine/userscript/user_script_data_mojom_traits.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 USER_SCRIPT_DATA_MOJOM_TRAITS_H_ +#define USER_SCRIPT_DATA_MOJOM_TRAITS_H_ + +#include <string> +#include "mojo/public/cpp/bindings/struct_traits.h" +#include "qtwebengine/userscript/user_script_data.h" +#include "qtwebengine/userscript/userscript.mojom.h" +#include "url/gurl.h" + +namespace mojo { + +template <> +class StructTraits<qtwebengine::mojom::UserScriptDataDataView, + QtWebEngineCore::UserScriptData> { + public: + static std::string source(const QtWebEngineCore::UserScriptData& d) { + return d.source; + } + static GURL url(const QtWebEngineCore::UserScriptData& d) { return d.url; } + static uint8_t injectionPoint(const QtWebEngineCore::UserScriptData& d) { + return d.injectionPoint; + } + static bool injectForSubframes(const QtWebEngineCore::UserScriptData& d) { + return d.injectForSubframes; + } + static uint64_t worldId(const QtWebEngineCore::UserScriptData& d) { + return d.worldId; + } + static uint8_t scriptId(const QtWebEngineCore::UserScriptData& d) { + return d.scriptId; + } + static std::vector<std::string> globs( + const QtWebEngineCore::UserScriptData& d) { + return d.globs; + } + static std::vector<std::string> excludeGlobs( + const QtWebEngineCore::UserScriptData& d) { + return d.excludeGlobs; + } + static std::vector<std::string> urlPatterns( + const QtWebEngineCore::UserScriptData& d) { + return d.urlPatterns; + } + static bool Read(qtwebengine::mojom::UserScriptDataDataView data, + QtWebEngineCore::UserScriptData* out_data); +}; + +} // namespace mojo +#endif diff --git a/chromium/qtwebengine/userscript/userscript.mojom b/chromium/qtwebengine/userscript/userscript.mojom new file mode 100644 index 00000000000..6fa0e24895b --- /dev/null +++ b/chromium/qtwebengine/userscript/userscript.mojom @@ -0,0 +1,35 @@ +module qtwebengine.mojom; + +import "url/mojom/url.mojom"; + +enum InjectionPoint { + AfterLoad, + DocumentLoadFinished, + DocumentElementCreation +}; + +struct UserScriptData { + string source; + url.mojom.Url url; + uint8 injectionPoint = 0; // fixme : use InjectionPoint Enum + bool injectForSubframes = false; + uint8 worldId = 1; + uint64 scriptId = 0; + array<string> globs; + array<string> excludeGlobs; + array<string> urlPatterns; +}; + +// per frame +interface UserResourceControllerRenderFrame { + AddScript(UserScriptData data); + RemoveScript(UserScriptData data); + ClearScripts(); +}; + +// global +interface UserResourceController { + AddScript(UserScriptData data); + RemoveScript(UserScriptData data); + ClearScripts(); +}; |