File: connection_info_view_android.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 (132 lines) | stat: -rw-r--r-- 4,981 bytes parent folder | download | duplicates (6)
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
127
128
129
130
131
132
// 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.

#include "components/page_info/android/connection_info_view_android.h"

#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "components/page_info/android/page_info_client.h"
#include "components/page_info/page_info.h"
#include "components/page_info/page_info_delegate.h"
#include "components/page_info/page_info_ui_delegate.h"
#include "components/security_state/core/security_state.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/web_contents.h"
#include "net/cert/x509_certificate.h"
#include "ui/base/l10n/l10n_util.h"

// Must come after all headers that specialize FromJniType() / ToJniType().
#include "components/page_info/android/jni_headers/ConnectionInfoView_jni.h"

using base::android::CheckException;
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
using base::android::GetClass;
using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef;
using content::WebContents;

// static
static jlong JNI_ConnectionInfoView_Init(
    JNIEnv* env,
    const JavaParamRef<jobject>& obj,
    const JavaParamRef<jobject>& java_web_contents) {
  content::WebContents* web_contents =
      content::WebContents::FromJavaWebContents(java_web_contents);
  DCHECK(web_contents);

  return reinterpret_cast<intptr_t>(
      new ConnectionInfoViewAndroid(env, obj, web_contents));
}

ConnectionInfoViewAndroid::ConnectionInfoViewAndroid(
    JNIEnv* env,
    jobject java_page_info_pop,
    WebContents* web_contents) {
  page_info_client_ = page_info::GetPageInfoClient();
  DCHECK(page_info_client_);

  // Important to use GetVisibleEntry to match what's showing in the omnibox.
  content::NavigationEntry* nav_entry =
      web_contents->GetController().GetVisibleEntry();
  if (nav_entry->IsInitialEntry())
    return;

  popup_jobject_.Reset(env, java_page_info_pop);

  presenter_ = std::make_unique<PageInfo>(
      page_info_client_->CreatePageInfoDelegate(web_contents), web_contents,
      nav_entry->GetURL());
  presenter_->InitializeUiState(this, base::DoNothing());
}

ConnectionInfoViewAndroid::~ConnectionInfoViewAndroid() = default;

void ConnectionInfoViewAndroid::Destroy(JNIEnv* env,
                                        const JavaParamRef<jobject>& obj) {
  delete this;
}

void ConnectionInfoViewAndroid::ResetCertDecisions(
    JNIEnv* env,
    const JavaParamRef<jobject>& obj,
    const JavaParamRef<jobject>& java_web_contents) {
  presenter_->OnRevokeSSLErrorBypassButtonPressed();
}

void ConnectionInfoViewAndroid::SetIdentityInfo(
    const IdentityInfo& identity_info) {
  JNIEnv* env = base::android::AttachCurrentThread();

  {
    int icon_id = page_info_client_->GetJavaResourceId(
        PageInfoUI::GetIdentityIconID(identity_info.identity_status));
    int icon_color_id = page_info_client_->GetJavaResourceId(
        PageInfoUI::GetIdentityIconColorID(identity_info.identity_status));

    // The certificate dialog link of the site's identity
    // section is displayed only if the site's identity was verified.
    ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
        env, identity_info.identity_status_description_android);
    std::u16string certificate_label;

    // Only show the certificate viewer link if the connection actually used a
    // certificate.
    if (identity_info.identity_status !=
        PageInfo::SITE_IDENTITY_STATUS_NO_CERT) {
      certificate_label =
          l10n_util::GetStringUTF16(IDS_PAGE_INFO_CERT_INFO_BUTTON);
    }

    Java_ConnectionInfoView_addCertificateSection(
        env, popup_jobject_, icon_id, description,
        ConvertUTF16ToJavaString(env, certificate_label), icon_color_id);

    if (identity_info.show_ssl_decision_revoke_button) {
      std::u16string reset_button_label = l10n_util::GetStringUTF16(
          IDS_PAGE_INFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON);
      Java_ConnectionInfoView_addResetCertDecisionsButton(
          env, popup_jobject_,
          ConvertUTF16ToJavaString(env, reset_button_label));
    }
  }

  {
    ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
        env, identity_info.connection_status_description);
    Java_ConnectionInfoView_addDescriptionSection(
        env, popup_jobject_, /*iconId=*/0, description, /*iconColorId=*/0);
  }

  Java_ConnectionInfoView_addMoreInfoLink(
      env, popup_jobject_,
      ConvertUTF8ToJavaString(
          env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)));
  Java_ConnectionInfoView_onReady(env, popup_jobject_);
}