File: safe_browsing_bridge.cc

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 (113 lines) | stat: -rw-r--r-- 4,191 bytes parent folder | download | duplicates (5)
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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/android/jni_string.h"
#include "base/files/file_path.h"
// NOTE: This target is transitively depended on by //chrome/browser and thus
// can't depend on it.
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"  // nogncheck
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/safe_browsing_service_interface.h"
#include "components/safe_browsing/content/common/file_type_policies.h"
#include "components/safe_browsing/core/common/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "content/public/browser/web_contents.h"

// Must come after all headers that specialize FromJniType() / ToJniType().
#include "chrome/browser/safe_browsing/android/jni_headers/SafeBrowsingBridge_jni.h"

using base::android::JavaParamRef;

namespace {

PrefService* GetPrefService(const base::android::JavaRef<jobject>& j_profile) {
  return Profile::FromJavaObject(j_profile)->GetPrefs();
}

}  // namespace

namespace safe_browsing {

static jint JNI_SafeBrowsingBridge_UmaValueForFile(
    JNIEnv* env,
    const JavaParamRef<jstring>& path) {
  base::FilePath file_path(base::android::ConvertJavaStringToUTF8(env, path));
  return safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile(
      file_path);
}

static jboolean JNI_SafeBrowsingBridge_GetSafeBrowsingExtendedReportingEnabled(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile) {
  return safe_browsing::IsExtendedReportingEnabled(*GetPrefService(j_profile));
}

static void JNI_SafeBrowsingBridge_SetSafeBrowsingExtendedReportingEnabled(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile,
    jboolean enabled) {
  safe_browsing::SetExtendedReportingPrefAndMetric(
      GetPrefService(j_profile), enabled,
      safe_browsing::SBER_OPTIN_SITE_ANDROID_SETTINGS);
}

static jboolean JNI_SafeBrowsingBridge_GetSafeBrowsingExtendedReportingManaged(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile) {
  PrefService* pref_service = GetPrefService(j_profile);
  return pref_service->IsManagedPreference(
      prefs::kSafeBrowsingScoutReportingEnabled);
}

static jint JNI_SafeBrowsingBridge_GetSafeBrowsingState(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile) {
  return static_cast<jint>(
      safe_browsing::GetSafeBrowsingState(*GetPrefService(j_profile)));
}

static void JNI_SafeBrowsingBridge_SetSafeBrowsingState(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile,
    jint state) {
  return safe_browsing::SetSafeBrowsingState(
      GetPrefService(j_profile), static_cast<SafeBrowsingState>(state),
      /*is_esb_enabled_by_account_integration=*/false);
}

static void JNI_SafeBrowsingBridge_EnableSafeBrowsingSettingSetLocallyPref(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile) {
  return safe_browsing::EnableSafeBrowsingSettingSetLocallyPref(
      GetPrefService(j_profile));
}

static jboolean JNI_SafeBrowsingBridge_IsSafeBrowsingManaged(
    JNIEnv* env,
    const JavaParamRef<jobject>& j_profile) {
  return safe_browsing::IsSafeBrowsingPolicyManaged(*GetPrefService(j_profile));
}

static jboolean JNI_SafeBrowsingBridge_IsHashRealTimeLookupEligibleInSession(
    JNIEnv* env) {
  return safe_browsing::hash_realtime_utils::
      IsHashRealTimeLookupEligibleInSession();
}

static void JNI_SafeBrowsingBridge_ReportIntent(
    JNIEnv* env,
    content::WebContents* web_contents,
    std::string& package_name,
    std::string& uri) {
  reinterpret_cast<SafeBrowsingServiceInterface*>(
      g_browser_process->safe_browsing_service())
      ->ReportExternalAppRedirect(web_contents, package_name, uri);
}

}  // namespace safe_browsing