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#ifndef EXTENSIONS_CLIENT_QT_H
45#define EXTENSIONS_CLIENT_QT_H
46
47#include "extensions/common/extensions_client.h"
48
49#include "base/compiler_specific.h"
50#include "base/lazy_instance.h"
51#include "base/macros.h"
52#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
53#include "extensions/common/features/feature_provider.h"
54#include "extensions/common/features/json_feature_provider_source.h"
55#include "extensions/common/permissions/extensions_api_permissions.h"
56#include "url/gurl.h"
57
58namespace extensions {
59
60// Sets up global state for the extensions system. Should be Set() once in each
61// process. This should be implemented by the client of the extensions system.
62class ExtensionsClientQt : public ExtensionsClient
63{
64public:
65 ExtensionsClientQt();
66 virtual ~ExtensionsClientQt() {}
67
68 // Initializes global state. Not done in the constructor because unit tests
69 // can create additional ExtensionsClients because the utility thread runs
70 // in-process.
71 void Initialize() override;
72 void InitializeWebStoreUrls(base::CommandLine *command_line) override;
73
74 // Returns the global PermissionMessageProvider to use to provide permission
75 // warning strings.
76 const PermissionMessageProvider &GetPermissionMessageProvider() const override;
77
78 // Returns the application name. For example, "Chromium" or "app_shell".
79 const std::string GetProductName() override;
80
81 // Takes the list of all hosts and filters out those with special
82 // permission strings. Adds the regular hosts to |new_hosts|,
83 // and adds any additional permissions to |permissions|.
84 // TODO(sashab): Split this function in two: One to filter out ignored host
85 // permissions, and one to get permissions for the given hosts.
86 void FilterHostPermissions(const URLPatternSet &hosts,
87 URLPatternSet *new_hosts,
88 PermissionIDSet *permissions) const override;
89
90 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
91 // only used for testing in the browser process.
92 void SetScriptingWhitelist(const ScriptingWhitelist &whitelist) override;
93
94 // Return the whitelist of extensions that can run content scripts on
95 // any origin.
96 const ScriptingWhitelist &GetScriptingWhitelist() const override;
97
98 // Get the set of chrome:// hosts that |extension| can run content scripts on.
99 URLPatternSet GetPermittedChromeSchemeHosts(const Extension *extension,
100 const APIPermissionSet &api_permissions) const override;
101
102 // Returns false if content scripts are forbidden from running on |url|.
103 bool IsScriptableURL(const GURL &url, std::string *error) const override;
104
105 // Determines if certain fatal extensions errors should be surpressed
106 // (i.e., only logged) or allowed (i.e., logged before crashing).
107 bool ShouldSuppressFatalErrors() const override;
108
109 // Records that a fatal error was caught and suppressed. It is expected that
110 // embedders will only do so if ShouldSuppressFatalErrors at some point
111 // returned true.
112 void RecordDidSuppressFatalError() override;
113
114 // Returns the base webstore URL prefix.
115 const GURL &GetWebstoreBaseURL() const override;
116
117 // Returns the URL to use for update manifest queries.
118 const GURL &GetWebstoreUpdateURL() const override;
119
120 // Returns a flag indicating whether or not a given URL is a valid
121 // extension blacklist URL.
122 bool IsBlacklistUpdateURL(const GURL &url) const override;
123
124 // Returns the set of file paths corresponding to any images within an
125 // extension's contents that may be displayed directly within the browser UI
126 // or WebUI, such as icons or theme images. This set of paths is used by the
127 // extension unpacker to determine which assets should be transcoded safely
128 // within the utility sandbox.
129 //
130 // The default implementation returns the images used as icons for the
131 // extension itself, so implementors of ExtensionsClient overriding this may
132 // want to call the base class version and then add additional paths to that
133 // result.
134 std::set<base::FilePath> GetBrowserImagePaths(const Extension *extension) override;
135 // Get the LazyInstance for ChromeExtensionsClient.
136 static ExtensionsClientQt *GetInstance();
137
138private:
139 ScriptingWhitelist scripting_whitelist_;
140 const ChromePermissionMessageProvider permission_message_provider_;
141 mutable GURL update_url_;
142 mutable GURL base_url_;
143 DISALLOW_COPY_AND_ASSIGN(ExtensionsClientQt);
144};
145
146} // namespace extensions
147
148#endif // EXTENSIONS_CLIENT_QT_H
149