File: safe_browsing_api_handler_util.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; 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 (126 lines) | stat: -rw-r--r-- 4,837 bytes parent folder | download | duplicates (3)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Helper functions for SafeBrowsingApiHandlerImpl.  Separated out for tests.

#ifndef COMPONENTS_SAFE_BROWSING_ANDROID_SAFE_BROWSING_API_HANDLER_UTIL_H_
#define COMPONENTS_SAFE_BROWSING_ANDROID_SAFE_BROWSING_API_HANDLER_UTIL_H_

#include <string>

#include "components/safe_browsing/core/browser/db/util.h"

namespace safe_browsing {

// Threat types as per the Java code.
// Threat type values must be consistent with values in SafeBrowsingThreat.java
// in GMS's SafetyNet API.
enum class SafetyNetJavaThreatType {
  // Below listed entries are magic numbers for allowlists. These are not
  // actually threat types used by GMSCore.
  CSD_DOWNLOAD_ALLOWLIST = 9,
  CSD_ALLOWLIST = 16,
  MAX_VALUE
};

// Must match what SafeBrowsingApiHandler.java uses for |lookupResult|.
// This is self-defined enum in Chromium. The difference between this enum and
// the |SafeBrowsingJavaResponseStatus| enum is that this enum represents the
// call result to the API (e.g. not able to connect, timed out, invalid input)
// while |SafeBrowsingJavaResponseStatus| is obtained directly from the API
// response in a successful call. In other words, ResponseStatus is valid only
// when LookupResult is SUCCESS.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SafeBrowsingApiLookupResult {
  SUCCESS = 0,
  // General failure bucket. This is set if none of the more granular failure
  // buckets fits.
  FAILURE = 1,
  // The API call to the Safe Browsing API timed out.
  FAILURE_API_CALL_TIMEOUT = 2,
  // The API throws an UnsupportedApiCallException.
  FAILURE_API_UNSUPPORTED = 3,
  // The API throws an ApiException with API_UNAVAILABLE status code.
  FAILURE_API_NOT_AVAILABLE = 4,
  // The API handler is null. Should never happen in production.
  FAILURE_HANDLER_NULL = 5
};

// Must match the definition in SafeBrowsing::ThreatType in SafeBrowsing API.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// Note: Please update the hard coded value in MockSafeBrowsingApiHandler if
// values are changed.
enum class SafeBrowsingJavaThreatType {
  NO_THREAT = 0,
  SOCIAL_ENGINEERING = 2,
  UNWANTED_SOFTWARE = 3,
  POTENTIALLY_HARMFUL_APPLICATION = 4,
  BILLING = 15,
  ABUSIVE_EXPERIENCE_VIOLATION = 20,
  BETTER_ADS_VIOLATION = 21
};

// Must match the definition in SafeBrowsing::ThreatAttribute in SafeBrowsing
// API.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SafeBrowsingJavaThreatAttribute { CANARY = 1, FRAME_ONLY = 2 };

// Must match the definition in SafeBrowsing::Protocol in the SafeBrowsing
// API.
enum class SafeBrowsingJavaProtocol { LOCAL_BLOCK_LIST = 4, REAL_TIME = 5 };

// Must match the definition in SafeBrowsingResponse::SafeBrowsingResponseStatus
// in SafeBrowsing API. This enum is converted directly from the API response.
// See the comment above |SafeBrowsingApiLookupResult| for the difference
// between the two enums.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SafeBrowsingJavaResponseStatus {
  SUCCESS_WITH_LOCAL_BLOCKLIST = 0,
  SUCCESS_WITH_REAL_TIME = 1,
  SUCCESS_FALLBACK_REAL_TIME_TIMEOUT = 2,
  SUCCESS_FALLBACK_REAL_TIME_THROTTLED = 3,
  FAILURE_NETWORK_UNAVAILABLE = 4,
  FAILURE_BLOCK_LIST_UNAVAILABLE = 5,
  FAILURE_INVALID_URL = 6
};

// The result logged when validating the response from SafeBrowsing API.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SafeBrowsingJavaValidationResult {
  VALID = 0,
  VALID_WITH_UNRECOGNIZED_RESPONSE_STATUS = 1,
  INVALID_LOOKUP_RESULT = 2,
  INVALID_THREAT_TYPE = 3,
  INVALID_THREAT_ATTRIBUTE = 4,

  kMaxValue = INVALID_THREAT_ATTRIBUTE
};

// The result of either SafetyNet.isVerifyAppsEnabled or
// SafetyNet.enableVerifyApps.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.safe_browsing
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: VerifyAppsResult
enum class VerifyAppsEnabledResult {
  SUCCESS_ENABLED = 0,
  SUCCESS_NOT_ENABLED = 1,
  TIMEOUT = 2,
  FAILED = 3,
  SUCCESS_ALREADY_ENABLED = 4,
  kMaxValue = SUCCESS_ALREADY_ENABLED,
};

// Translates |threat_type| and |threat_attributes| from the Safe Browsing API
// into ThreatMetadata.
ThreatMetadata GetThreatMetadataFromSafeBrowsingApi(
    SafeBrowsingJavaThreatType threat_type,
    const std::vector<int>& threat_attributes);

}  // namespace safe_browsing

#endif  // COMPONENTS_SAFE_BROWSING_ANDROID_SAFE_BROWSING_API_HANDLER_UTIL_H_