chromium/extensions/browser/api/declarative_net_request/constants.h

// Copyright 2017 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_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_

#include <cstddef>
#include <cstdint>
#include <string_view>

#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "extensions/common/api/declarative_net_request/constants.h"

namespace extensions::declarative_net_request {

// The result of parsing JSON rules provided by an extension. Corresponds to a
// single rule.
enum class ParseResult {};

// Describes the ways in which updating dynamic rules can fail.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UpdateDynamicRulesStatus {};

// Describes the result of loading a single JSON Ruleset.
// This is logged as part of UMA. Hence existing values should not be re-
// numbered or deleted.
enum class LoadRulesetResult {};

// Specifies whether and how extensions require host permissions to modify the
// request.
enum class HostPermissionsAlwaysRequired {};

// Specifies the request stage for which rulesets are to be matched.
enum class RulesetMatchingStage {};

// Schemes which can be used as part of url transforms.
extern const char* const kAllowedTransformSchemes[4];

// Rule parsing errors.
extern const char kErrorRequestMethodDuplicated[];
extern const char kErrorResourceTypeDuplicated[];
extern const char kErrorInvalidRuleKey[];
extern const char kErrorNoApplicableResourceTypes[];
extern const char kErrorEmptyList[];
extern const char kErrorEmptyKey[];
extern const char kErrorInvalidRedirectUrl[];
extern const char kErrorDuplicateIDs[];
extern const char kErrorPersisting[];
extern const char kErrorNonAscii[];
extern const char kErrorInvalidKey[];
extern const char kErrorInvalidTransformScheme[];
extern const char kErrorQueryAndTransformBothSpecified[];
extern const char kErrorDomainsAndInitiatorDomainsBothSpecified[];
extern const char kErrorJavascriptRedirect[];
extern const char kErrorMultipleFilters[];
extern const char kErrorRegexSubstitutionWithoutFilter[];
extern const char kErrorInvalidAllowAllRequestsResourceType[];
extern const char kErrorRegexTooLarge[];
extern const char kErrorNoHeaderListsSpecified[];
extern const char kErrorInvalidModifyHeaderName[];
extern const char kErrorInvalidModifyHeaderValue[];
extern const char kErrorNoHeaderValueSpecified[];
extern const char kErrorHeaderValuePresent[];
extern const char kErrorAppendInvalidRequestHeader[];
extern const char kErrorTabIdsOnNonSessionRule[];
extern const char kErrorTabIdDuplicated[];
extern const char kErrorInvalidMatchingHeaderName[];
extern const char kErrorInvalidMatchingHeaderValue[];
extern const char kErrorResponseHeaderDuplicated[];
extern const char kErrorResponseHeaderRuleCannotModifyRequestHeaders[];

extern const char kErrorListNotPassed[];

// Rule indexing install warnings.
extern const char kRuleCountExceeded[];
extern const char kRegexRuleCountExceeded[];
extern const char kEnabledRuleCountExceeded[];
extern const char kEnabledRegexRuleCountExceeded[];
extern const char kRuleNotParsedWarning[];
extern const char kTooManyParseFailuresWarning[];
extern const char kIndexingRuleLimitExceeded[];

// Dynamic rules API errors.
extern const char kInternalErrorUpdatingDynamicRules[];
extern const char kInternalErrorGettingDynamicRules[];
extern const char kDynamicRuleCountExceeded[];
extern const char kDynamicUnsafeRuleCountExceeded[];
extern const char kDynamicRegexRuleCountExceeded[];

// Session-scoped rules API errors.
extern const char kSessionRuleCountExceeded[];
extern const char kSessionUnsafeRuleCountExceeded[];
extern const char kSessionRegexRuleCountExceeded[];

// Static ruleset toggling API errors.
extern const char kInvalidRulesetIDError[];
extern const char kEnabledRulesetsRuleCountExceeded[];
extern const char kEnabledRulesetsRegexRuleCountExceeded[];
extern const char kInternalErrorUpdatingEnabledRulesets[];
extern const char kEnabledRulesetCountExceeded[];

// Static rule toggling API errors.
extern const char kDisabledStaticRuleCountExceeded[];

// setExtensionActionOptions API errors.
extern const char kTabNotFoundError[];
extern const char kIncrementActionCountWithoutUseAsBadgeTextError[];

// testMatchOutcome API errors.
extern const char kInvalidTestURLError[];
extern const char kInvalidTestInitiatorError[];
extern const char kInvalidTestTabIdError[];
extern const char kInvalidResponseHeaderObjectError[];
extern const char kInvalidResponseHeaderNameError[];
extern const char kInvalidResponseHeaderValueError[];

// Histogram names.
extern const char kIndexAndPersistRulesTimeHistogram[];
extern const char kManifestEnabledRulesCountHistogram[];
extern const char kUpdateDynamicRulesStatusHistogram[];
extern const char kReadDynamicRulesJSONStatusHistogram[];
extern const char kIsLargeRegexHistogram[];
extern const char kRegexRuleSizeHistogram[];
extern const char kLoadRulesetResultHistogram[];

// Placeholder text to use for getBadgeText extension function call, when the
// badge text is set to the DNR action count.
extern const char kActionCountPlaceholderBadgeText[];

// Error returned for the getMatchedRules extension function call, if the
// extension does not have sufficient permissions to make the call.
extern const char kErrorGetMatchedRulesMissingPermissions[];

// The maximum amount of static rules in the global rule pool for a single
// profile.
inline constexpr int kMaxStaticRulesPerProfile =;

// The per-extension maximum amount of disabled static rules.
inline constexpr int kMaxDisabledStaticRules =;

// Maximum size of a compiled RegEx rule in KB. Limited to 2 KB which means
// that given 1024 rules, the total usage would be 2 MB.
inline constexpr int kRegexMaxMemKb =;

// Identifier for a Flatbuffer containing `flat::EmbedderConditions` as the
// root.
extern const char kEmbedderConditionsBufferIdentifier[];

// An allowlist of request headers that can be appended onto, in the form of
// (header name, header delimiter). Currently, this list contains all standard
// HTTP request headers that support multiple values in a single entry. This
// list may be extended in the future to support custom headers.
inline constexpr auto kDNRRequestHeaderAppendAllowList =;

}  // namespace extensions::declarative_net_request

#endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_