mark a. foltz | 0c6ee39 | 2023-08-30 19:45:18 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/ui/extensions/extensions_overrides/simple_overrides.h" |
| 6 | |
| 7 | #include "extensions/common/api/incognito.h" |
| 8 | #include "extensions/common/extension.h" |
| 9 | #include "extensions/common/manifest_constants.h" |
| 10 | |
| 11 | namespace { |
| 12 | |
| 13 | // Only the following manifest keys are allowed in an extension for it to be |
| 14 | // considered a simple override extension. |
| 15 | // --- When to add to this list --- |
| 16 | // The features in this list should be those that do not give the extension |
| 17 | // *any* additional capability beyond what the corresponding site would have if |
| 18 | // the user manually changed the search. This means these fields can be: |
| 19 | // a) required (e.g. "name") and internal (e.g. "differential_fingerprint") |
| 20 | // fields |
| 21 | // b) trivial appearance (e.g. "icons") and metadata (e.g. "short_name") |
| 22 | // fields |
| 23 | // c) localization (e.g. "default_locale") and customization (e.g. |
| 24 | // "options_page") fields |
| 25 | // d) the search engine override fields (we don't consider any other overrides |
| 26 | // to be simple overrides). |
| 27 | // If the field controls anything else, it should be disallowed, and added to |
| 28 | // this file's corresponding unittest.cc. |
| 29 | const char* kAllowlistedManifestKeys[] = { |
| 30 | "author", // "author" is a recognized key, but never used as a constant. |
Devlin Cronin | 8363698 | 2022-09-15 20:32:22 | [diff] [blame] | 31 | extensions::manifest_keys::kAboutPage, |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 32 | extensions::manifest_keys::kCurrentLocale, |
| 33 | extensions::manifest_keys::kDefaultLocale, |
| 34 | extensions::manifest_keys::kDescription, |
| 35 | extensions::manifest_keys::kDifferentialFingerprint, |
| 36 | extensions::manifest_keys::kHomepageURL, |
| 37 | extensions::manifest_keys::kIcons, |
Solomon Kinard | 1e109917 | 2024-05-24 21:45:27 | [diff] [blame] | 38 | extensions::manifest_keys::kIconVariants, |
Devlin Cronin | 8363698 | 2022-09-15 20:32:22 | [diff] [blame] | 39 | extensions::manifest_keys::kKey, |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 40 | extensions::manifest_keys::kManifestVersion, |
| 41 | extensions::manifest_keys::kMinimumChromeVersion, |
| 42 | extensions::manifest_keys::kName, |
| 43 | extensions::manifest_keys::kOfflineEnabled, |
| 44 | extensions::manifest_keys::kOptionsPage, |
| 45 | extensions::manifest_keys::kOptionsUI, |
Devlin Cronin | 8363698 | 2022-09-15 20:32:22 | [diff] [blame] | 46 | extensions::manifest_keys::kSettingsOverride, |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 47 | extensions::manifest_keys::kShortName, |
| 48 | extensions::manifest_keys::kUpdateURL, |
| 49 | extensions::manifest_keys::kVersion, |
Devlin Cronin | 8363698 | 2022-09-15 20:32:22 | [diff] [blame] | 50 | extensions::manifest_keys::kVersionName, |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 51 | extensions::api::incognito::ManifestKeys::kIncognito, |
| 52 | }; |
| 53 | |
| 54 | } // namespace |
| 55 | |
| 56 | namespace simple_overrides { |
| 57 | |
| 58 | bool IsSimpleOverrideExtension(const extensions::Extension& extension) { |
| 59 | // Return true only if the extension has exclusively allowlisted keys in the |
| 60 | // manifest. |
Alex Turner | cc15203c | 2022-12-21 01:54:06 | [diff] [blame] | 61 | for (const auto [key, value] : extension.manifest()->available_values()) { |
Peter Kasting | aaeff70 | 2025-01-27 16:43:04 | [diff] [blame] | 62 | if (std::ranges::find(kAllowlistedManifestKeys, key) == |
Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame] | 63 | std::end(kAllowlistedManifestKeys)) { |
| 64 | return false; |
| 65 | } |
|
|