blob: 280b42e6c08eae6764bcbb59cbccd301a5b1c588 [file] [log] [blame]
mark a. foltz0c6ee392023-08-30 19:45:181// Copyright 2022 The Chromium Authors
Devlin Croninc9be99a2022-09-15 03:01:382// 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
11namespace {
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.
29const char* kAllowlistedManifestKeys[] = {
30 "author", // "author" is a recognized key, but never used as a constant.
Devlin Cronin83636982022-09-15 20:32:2231 extensions::manifest_keys::kAboutPage,
Devlin Croninc9be99a2022-09-15 03:01:3832 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 Kinard1e1099172024-05-24 21:45:2738 extensions::manifest_keys::kIconVariants,
Devlin Cronin83636982022-09-15 20:32:2239 extensions::manifest_keys::kKey,
Devlin Croninc9be99a2022-09-15 03:01:3840 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 Cronin83636982022-09-15 20:32:2246 extensions::manifest_keys::kSettingsOverride,
Devlin Croninc9be99a2022-09-15 03:01:3847 extensions::manifest_keys::kShortName,
48 extensions::manifest_keys::kUpdateURL,
49 extensions::manifest_keys::kVersion,
Devlin Cronin83636982022-09-15 20:32:2250 extensions::manifest_keys::kVersionName,
Devlin Croninc9be99a2022-09-15 03:01:3851 extensions::api::incognito::ManifestKeys::kIncognito,
52};
53
54} // namespace
55
56namespace simple_overrides {
57
58bool IsSimpleOverrideExtension(const extensions::Extension& extension) {
59 // Return true only if the extension has exclusively allowlisted keys in the
60 // manifest.
Alex Turnercc15203c2022-12-21 01:54:0661 for (const auto [key, value] : extension.manifest()->available_values()) {
Peter Kastingaaeff702025-01-27 16:43:0462 if (std::ranges::find(kAllowlistedManifestKeys, key) ==
Devlin Croninc9be99a2022-09-15 03:01:3863 std::end(kAllowlistedManifestKeys)) {
64 return false;
65 }