1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWebEngine module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40// Portions copyright 2013 The Chromium Authors. All rights reserved.
41// Use of this source code is governed by a BSD-style license that can be
42// found in the LICENSE file.
43
44#include "extensions_client_qt.h"
45
46#include "extensions/common/alias.h"
47#include "extensions/common/core_extensions_api_provider.h"
48#include "extensions/common/extension_urls.h"
49
50#include "extensions/common/features/simple_feature.h"
51#include "extensions/common/permissions/permissions_info.h"
52
53#include "extensions_api_provider_qt.h"
54
55
56namespace extensions {
57
58template<class FeatureClass> SimpleFeature *CreateFeature()
59{
60 return new FeatureClass;
61}
62
63static base::LazyInstance<ExtensionsClientQt>::Leaky g_client = LAZY_INSTANCE_INITIALIZER;
64
65ExtensionsClientQt *ExtensionsClientQt::GetInstance()
66{
67 return g_client.Pointer();
68}
69
70ExtensionsClientQt::ExtensionsClientQt() : ExtensionsClient()
71{
72 AddAPIProvider(std::make_unique<CoreExtensionsAPIProvider>());
73 AddAPIProvider(std::make_unique<ExtensionsAPIProviderQt>());
74}
75
76// Initializes global state. Not done in the constructor because unit tests
77// can create additional ExtensionsClients because the utility thread runs
78// in-process.
79void ExtensionsClientQt::Initialize()
80{
81}
82
83void ExtensionsClientQt::InitializeWebStoreUrls(base::CommandLine *command_line)
84{
85}
86
87// Returns the global PermissionMessageProvider to use to provide permission
88// warning strings.
89const PermissionMessageProvider &ExtensionsClientQt::GetPermissionMessageProvider() const
90{
91 return permission_message_provider_;
92}
93
94// Returns the application name. For example, "Chromium" or "app_shell".
95const std::string ExtensionsClientQt::GetProductName()
96{
97 return "Qt WebEngine"; // return Qt WebEngine for now, consider returning the application name if possible.
98}
99
100// Takes the list of all hosts and filters out those with special
101// permission strings. Adds the regular hosts to |new_hosts|,
102// and adds any additional permissions to |permissions|.
103// TODO(sashab): Split this function in two: One to filter out ignored host
104// permissions, and one to get permissions for the given hosts.
105void ExtensionsClientQt::FilterHostPermissions(const URLPatternSet &hosts,
106 URLPatternSet *new_hosts,
107 PermissionIDSet *permissions) const
108{
109}
110
111// Replaces the scripting whitelist with |whitelist|. Used in the renderer{}
112// only used for testing in the browser process.
113void ExtensionsClientQt::SetScriptingWhitelist(const ExtensionsClient::ScriptingWhitelist &whitelist)
114{
115 scripting_whitelist_ = whitelist;
116}
117
118// Return the whitelist of extensions that can run content scripts on
119// any origin.
120const ExtensionsClient::ScriptingWhitelist &ExtensionsClientQt::GetScriptingWhitelist() const
121{
122 return scripting_whitelist_;
123}
124
125// Get the set of chrome:// hosts that |extension| can run content scripts on.
126URLPatternSet ExtensionsClientQt::GetPermittedChromeSchemeHosts(const Extension *extension,
127 const APIPermissionSet &api_permissions) const
128{
129 return URLPatternSet();
130}
131
132// Returns false if content scripts are forbidden from running on |url|.
133bool ExtensionsClientQt::IsScriptableURL(const GURL &url, std::string *error) const
134{
135 return true;
136}
137
138// Determines if certain fatal extensions errors should be surpressed
139// (i.e., only logged) or allowed (i.e., logged before crashing).
140bool ExtensionsClientQt::ShouldSuppressFatalErrors() const
141{
142 return true;
143}
144
145// Records that a fatal error was caught and suppressed. It is expected that
146// embedders will only do so if ShouldSuppressFatalErrors at some point
147// returned true.
148void ExtensionsClientQt::RecordDidSuppressFatalError()
149{
150}
151
152// Returns the base webstore URL prefix.
153const GURL &ExtensionsClientQt::GetWebstoreBaseURL() const
154{
155 if (base_url_.is_empty())
156 base_url_ = GURL(extension_urls::kChromeWebstoreBaseURL);
157 return base_url_;
158}
159
160// Returns the URL to use for update manifest queries.
161const GURL &ExtensionsClientQt::GetWebstoreUpdateURL() const
162{
163 if (update_url_.is_empty())
164 update_url_ = GURL(extension_urls::GetWebstoreUpdateUrl());
165 return update_url_;
166}
167
168// Returns a flag indicating whether or not a given URL is a valid
169// extension blacklist URL.
170bool ExtensionsClientQt::IsBlacklistUpdateURL(const GURL &url) const
171{
172 return true;
173}
174
175// Returns the set of file paths corresponding to any images within an
176// extension's contents that may be displayed directly within the browser UI
177// or WebUI, such as icons or theme images. This set of paths is used by the
178// extension unpacker to determine which assets should be transcoded safely
179// within the utility sandbox.
180//
181// The default implementation returns the images used as icons for the
182// extension itself, so implementors of ExtensionsClient overriding this may
183// want to call the base class version and then add additional paths to that
184// result.
185std::set<base::FilePath> ExtensionsClientQt::GetBrowserImagePaths(const Extension *extension)
186{
187 return ExtensionsClient::GetBrowserImagePaths(extension);
188}
189
190} // namespace extensions
191