Devlin Cronin | c9be99a | 2022-09-15 03:01:38 | [diff] [blame^] | 1 | // Copyright 2022 The Chromium Authors. All rights reserved. |
| 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. |
| 31 | extensions::manifest_keys::kSettingsOverride, |
| 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, |
| 38 | extensions::manifest_keys::kManifestVersion, |
| 39 | extensions::manifest_keys::kMinimumChromeVersion, |
| 40 | extensions::manifest_keys::kName, |
| 41 | extensions::manifest_keys::kOfflineEnabled, |
| 42 | extensions::manifest_keys::kOptionsPage, |
| 43 | extensions::manifest_keys::kOptionsUI, |
| 44 | extensions::manifest_keys::kShortName, |
| 45 | extensions::manifest_keys::kUpdateURL, |
| 46 | extensions::manifest_keys::kVersion, |
| 47 | extensions::api::incognito::ManifestKeys::kIncognito, |
| 48 | }; |
| 49 | |
| 50 | } // namespace |
| 51 | |
| 52 | namespace simple_overrides { |
| 53 | |
| 54 | bool IsSimpleOverrideExtension(const extensions::Extension& extension) { |
| 55 | // Return true only if the extension has exclusively allowlisted keys in the |
| 56 | // manifest. |
| 57 | for (const auto [key, value] : |
| 58 | extension.manifest()->available_values().GetDict()) { |
| 59 | if (base::ranges::find(kAllowlistedManifestKeys, key) == |
| 60 | std::end(kAllowlistedManifestKeys)) { |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | std::vector<std::string> GetAllowlistedManifestKeysForTesting() { |
| 69 | return std::vector<std::string>(std::begin(kAllowlistedManifestKeys), |
| 70 | std::end(kAllowlistedManifestKeys)); |
| 71 | } |
| 72 | |
| 73 | } // namespace simple_overrides |