summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ssl/security_state_model_android.cc
blob: c7eea4395b154dcbaad14b2f31e3a1b88bcfaf14 (plain)
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ssl/security_state_model_android.h"

#include "base/logging.h"
#include "chrome/browser/ssl/chrome_security_state_model_client.h"
#include "content/public/browser/web_contents.h"
#include "jni/SecurityStateModel_jni.h"

// static
bool RegisterSecurityStateModelAndroid(JNIEnv* env) {
  return RegisterNativesImpl(env);
}

// static
jint GetSecurityLevelForWebContents(
    JNIEnv* env,
    const JavaParamRef<jclass>& jcaller,
    const JavaParamRef<jobject>& jweb_contents) {
  content::WebContents* web_contents =
      content::WebContents::FromJavaWebContents(jweb_contents);
  DCHECK(web_contents);
  ChromeSecurityStateModelClient::CreateForWebContents(web_contents);
  ChromeSecurityStateModelClient* model_client =
      ChromeSecurityStateModelClient::FromWebContents(web_contents);
  DCHECK(model_client);
  return model_client->GetSecurityInfo().security_level;
}

// static
jboolean IsDeprecatedSHA1Present(JNIEnv* env,
                                 const JavaParamRef<jclass>& jcaller,
                                 const JavaParamRef<jobject>& jweb_contents) {
  content::WebContents* web_contents =
      content::WebContents::FromJavaWebContents(jweb_contents);
  DCHECK(web_contents);
  ChromeSecurityStateModelClient::CreateForWebContents(web_contents);
  ChromeSecurityStateModelClient* model_client =
      ChromeSecurityStateModelClient::FromWebContents(web_contents);
  DCHECK(model_client);
  return model_client->GetSecurityInfo().sha1_deprecation_status !=
         security_state::SecurityStateModel::NO_DEPRECATED_SHA1;
}

// static
jboolean IsPassiveMixedContentPresent(
    JNIEnv* env,
    const JavaParamRef<jclass>& jcaller,
    const JavaParamRef<jobject>& jweb_contents) {
  content::WebContents* web_contents =
      content::WebContents::FromJavaWebContents(jweb_contents);
  DCHECK(web_contents);
  ChromeSecurityStateModelClient::CreateForWebContents(web_contents);
  ChromeSecurityStateModelClient* model_client =
      ChromeSecurityStateModelClient::FromWebContents(web_contents);
  DCHECK(model_client);
  return model_client->GetSecurityInfo().mixed_content_status ==
             security_state::SecurityStateModel::DISPLAYED_MIXED_CONTENT ||
         model_client->GetSecurityInfo().mixed_content_status ==
             security_state::SecurityStateModel::
                 RAN_AND_DISPLAYED_MIXED_CONTENT;
}