File: permissions_api_helpers.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 3,841 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_HELPERS_H_
#define CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_HELPERS_H_

#include <memory>
#include <string>

#include "extensions/common/permissions/api_permission_set.h"
#include "extensions/common/url_pattern_set.h"

namespace extensions {

class PermissionSet;

namespace api {
namespace permissions {
struct Permissions;
}
}  // namespace api

namespace permissions_api_helpers {

// Converts the permission `set` to a permissions object.
std::unique_ptr<api::permissions::Permissions> PackPermissionSet(
    const PermissionSet& set);

// The result of unpacking the API permissions object.
struct UnpackPermissionSetResult {
  UnpackPermissionSetResult();
  ~UnpackPermissionSetResult();

  // API permissions that are in the extension's "required" permission set.
  APIPermissionSet required_apis;
  // Explicit hosts that are in the extension's "required" permission set.
  URLPatternSet required_explicit_hosts;
  // Scriptable hosts that are in the extension's "required" permission set.
  URLPatternSet required_scriptable_hosts;

  // API permissions that are in the extension's "optional" permission set.
  APIPermissionSet optional_apis;
  // Explicit hosts that are in the extension's "optional" permission set.
  URLPatternSet optional_explicit_hosts;

  // API permissions that were not listed in the extension's permissions.
  APIPermissionSet unlisted_apis;
  // Host permissions that were not listed in the extension's permissions.
  URLPatternSet unlisted_hosts;

  // Special case: restricted file:-scheme patterns. These are populated with
  // the patterns that are explicitly related to file:-schemes if the extension
  // does *not* have file access.
  // Consider unpacking ["<all_urls>", "file:///*"]:
  // - If the extension does *not* have file access:
  //   * <all_urls> will be unpacked normally, but will not include
  //     URLPattern::SCHEME_FILE as a valid scheme.
  //   * file:///* will be included in restricted_file_scheme_patterns, because
  //     it is restricted and cannot be granted without explicit access from the
  //     chrome://extensions page.
  // - If the extension *has* file access:
  //   * <all_urls> will be unpacked normally, and will include
  //     URLPattern::SCHEME_FILE as a valid scheme.
  //   * file:///* will be unpacked normally (`restricted_file_scheme_patterns`
  //     will be empty).
  URLPatternSet restricted_file_scheme_patterns;
};

// Parses the `permissions_input` object, and partitions permissions into the
// result. `required_permissions` and `optional_permissions` are the required
// and optional permissions specified in the extension's manifest, used for
// separating permissions. `has_file_access` is used to determine whether the
// file:-scheme is valid for host permissions. If file access is allowed,
// <all_urls> will match the file:-scheme (otherwise, it will not). Patterns
// that specifically specify "file:" will be parsed regardless (and placed into
// restricted_file_scheme_patterns if file access is disallowed). If an error is
// detected (e.g., an unknown API permission, invalid URL pattern, or API that
// doesn't support being optional), `error` is populated and null is returned.
std::unique_ptr<UnpackPermissionSetResult> UnpackPermissionSet(
    const api::permissions::Permissions& permissions_input,
    const PermissionSet& required_permissions,
    const PermissionSet& optional_permissions,
    bool has_file_access,
    std::string* error);

}  // namespace permissions_api_helpers
}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_HELPERS_H_