File: simple_overrides.cc

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (76 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/extensions/extensions_overrides/simple_overrides.h"

#include "extensions/common/api/incognito.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"

namespace {

// Only the following manifest keys are allowed in an extension for it to be
// considered a simple override extension.
// --- When to add to this list ---
// The features in this list should be those that do not give the extension
// *any* additional capability beyond what the corresponding site would have if
// the user manually changed the search. This means these fields can be:
//   a) required (e.g. "name") and internal (e.g. "differential_fingerprint")
//      fields
//   b) trivial appearance (e.g. "icons") and metadata (e.g. "short_name")
//      fields
//   c) localization (e.g. "default_locale") and customization (e.g.
//      "options_page") fields
//   d) the search engine override fields (we don't consider any other overrides
//      to be simple overrides).
// If the field controls anything else, it should be disallowed, and added to
// this file's corresponding unittest.cc.
const char* kAllowlistedManifestKeys[] = {
    "author",  // "author" is a recognized key, but never used as a constant.
    extensions::manifest_keys::kAboutPage,
    extensions::manifest_keys::kCurrentLocale,
    extensions::manifest_keys::kDefaultLocale,
    extensions::manifest_keys::kDescription,
    extensions::manifest_keys::kDifferentialFingerprint,
    extensions::manifest_keys::kHomepageURL,
    extensions::manifest_keys::kIcons,
    extensions::manifest_keys::kIconVariants,
    extensions::manifest_keys::kKey,
    extensions::manifest_keys::kManifestVersion,
    extensions::manifest_keys::kMinimumChromeVersion,
    extensions::manifest_keys::kName,
    extensions::manifest_keys::kOfflineEnabled,
    extensions::manifest_keys::kOptionsPage,
    extensions::manifest_keys::kOptionsUI,
    extensions::manifest_keys::kSettingsOverride,
    extensions::manifest_keys::kShortName,
    extensions::manifest_keys::kUpdateURL,
    extensions::manifest_keys::kVersion,
    extensions::manifest_keys::kVersionName,
    extensions::api::incognito::ManifestKeys::kIncognito,
};

}  // namespace

namespace simple_overrides {

bool IsSimpleOverrideExtension(const extensions::Extension& extension) {
  // Return true only if the extension has exclusively allowlisted keys in the
  // manifest.
  for (const auto [key, value] : extension.manifest()->available_values()) {
    if (std::ranges::find(kAllowlistedManifestKeys, key) ==
        std::end(kAllowlistedManifestKeys)) {
      return false;
    }
  }

  return true;
}

std::vector<std::string> GetAllowlistedManifestKeysForTesting() {
  return std::vector<std::string>(std::begin(kAllowlistedManifestKeys),
                                  std::end(kAllowlistedManifestKeys));
}

}  // namespace simple_overrides