// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ #include <stddef.h> #include <set> #include <string> #include <vector> #include "base/values.h" #include "extensions/common/mojom/api_permission_id.mojom-shared.h" #include "extensions/common/permissions/api_permission.h" #include "extensions/common/permissions/base_set_operators.h" namespace extensions { class APIPermissionSet; template<> struct BaseSetOperatorsTraits<APIPermissionSet> { … }; class APIPermissionSet : public BaseSetOperators<APIPermissionSet> { … }; // An ID representing a single permission that belongs to an app or extension. // // Each PermissionID has a required ID to identify the permission. For most // permissions, this is all they have. // // Some more complex permissions have a parameter, which acts like an argument // for the permission. For example, host permissions might have the ID // kReadOnlyHost and the argument 'www.google.com' (the host which is // read-only). Parameters are passed to the permission message rules for this // permission, so they can affect the displayed message. // // Note: Inheriting from std::pair automatically gives us an operator< // (required for putting these into an std::set). // // TODO(sashab): Move this to the same file as PermissionIDSet once that moves // to its own file. class PermissionID : public std::pair<mojom::APIPermissionID, std::u16string> { … }; // A set of permissions for an app or extension. Used for passing around groups // of permissions, such as required or optional permissions. // // Each permission can also store a string, such as a hostname or device number, // as a parameter that helps identify the permission. This parameter can then // be used when the permission message is generated. For example, the permission // kHostReadOnly might have the parameter "google.com", which means that the app // or extension has the permission to read the host google.com. This parameter // may then be included in the permission message when it is generated later. // // Example: // // Create an empty PermissionIDSet. // PermissionIDSet p; // // Add a permission to the set. // p.insert(mojom::APIPermissionID::kNetworkState); // // Add a permission with a parameter to the set. // p.insert(mojom::APIPermissionID::kHostReadOnly, // u"http://www.google.com"); // // TODO(sashab): Move this to its own file and rename it to PermissionSet after // APIPermission is removed, the current PermissionSet is no longer used, and // mojom::APIPermissionID is the only type of Permission ID. class PermissionIDSet { … }; } // namespace extensions #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_