Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ConnectionInfoPopup.java

Issue 1100283002: Add connection info popup within Page Info on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser;
6
7 import android.app.Dialog;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.content.Intent;
11 import android.graphics.Color;
12 import android.provider.Browser;
13 import android.text.TextUtils;
14 import android.view.LayoutInflater;
15 import android.view.View;
16 import android.view.View.OnClickListener;
17 import android.view.ViewGroup;
18 import android.view.Window;
19 import android.widget.Button;
20 import android.widget.ImageView;
21 import android.widget.LinearLayout;
22 import android.widget.ScrollView;
23 import android.widget.TextView;
24
25 import org.chromium.base.CalledByNative;
26 import org.chromium.chrome.R;
27 import org.chromium.content_public.browser.WebContents;
28 import org.chromium.content_public.browser.WebContentsObserver;
29
30 import java.net.URISyntaxException;
31
32 /**
33 * Java side of Android implementation of the website settings UI.
34 */
35 public class ConnectionInfoPopup implements OnClickListener {
36 private static final String HELP_URL =
37 "http://www.google.com/support/chrome/bin/answer.py?answer=95617";
38 private static final int DESCRIPTION_TEXT_SIZE_SP = 12;
39 private final Context mContext;
40 private final Dialog mDialog;
41 private final LinearLayout mContainer;
42 private final WebContents mWebContents;
43 private final int mPaddingWide, mPaddingThin;
44 private final long mNativeConnectionInfoPopup;
45 private TextView mCertificateViewer, mMoreInfoLink;
46 private ViewGroup mCertificateLayout, mDescriptionLayout;
47 private Button mResetCertDecisionsButton;
48 private String mLinkUrl;
49
50 private ConnectionInfoPopup(Context context, WebContents webContents) {
51 mContext = context;
52 mWebContents = webContents;
53
54 mContainer = new LinearLayout(mContext);
55 mContainer.setOrientation(LinearLayout.VERTICAL);
56 mContainer.setBackgroundColor(Color.WHITE);
57 mPaddingWide = (int) context.getResources().getDimension(
58 R.dimen.connection_info_padding_wide);
59 mPaddingThin = (int) context.getResources().getDimension(
60 R.dimen.connection_info_padding_thin);
61 mContainer.setPadding(mPaddingWide, mPaddingWide, mPaddingWide,
62 mPaddingWide - mPaddingThin);
63
64 mDialog = new Dialog(mContext);
65 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
66 mDialog.setCanceledOnTouchOutside(true);
67 // This needs to come after other member initialization.
68 mNativeConnectionInfoPopup = nativeInit(this, webContents);
69 final WebContentsObserver webContentsObserver =
70 new WebContentsObserver(mWebContents) {
71 @Override
72 public void navigationEntryCommitted() {
73 // If a navigation is committed (e.g. from in-page redirect), th e data we're
74 // showing is stale so dismiss the dialog.
75 mDialog.dismiss();
76 }
77 };
78 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
79 @Override
80 public void onDismiss(DialogInterface dialog) {
81 assert mNativeConnectionInfoPopup != 0;
82 webContentsObserver.destroy();
83 nativeDestroy(mNativeConnectionInfoPopup);
84 }
85 });
86 }
87
88 /**
89 * Adds certificate section, which contains an icon, a headline, a
90 * description and a label for certificate info link.
91 */
92 @CalledByNative
93 private void addCertificateSection(int enumeratedIconId, String headline, St ring description,
94 String label) {
95 View section = addSection(enumeratedIconId, headline, description);
96 assert mCertificateLayout == null;
97 mCertificateLayout = (ViewGroup) section.findViewById(R.id.connection_in fo_text_layout);
98 if (label != null && !label.isEmpty()) {
99 setCertificateViewer(label);
100 }
101 }
102
103 /**
104 * Adds Description section, which contains an icon, a headline, and a
105 * description. Most likely headline for description is empty
106 */
107 @CalledByNative
108 private void addDescriptionSection(int enumeratedIconId, String headline, St ring description) {
109 View section = addSection(enumeratedIconId, headline, description);
110 assert mDescriptionLayout == null;
111 mDescriptionLayout = (ViewGroup) section.findViewById(R.id.connection_in fo_text_layout);
112 }
113
114 private View addSection(int enumeratedIconId, String headline, String descri ption) {
115 View section = LayoutInflater.from(mContext).inflate(R.layout.connection _info,
116 null);
117 ImageView i = (ImageView) section.findViewById(R.id.connection_info_icon );
118 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
119 i.setImageResource(drawableId);
120
121 TextView h = (TextView) section.findViewById(R.id.connection_info_headli ne);
122 h.setText(headline);
123 if (TextUtils.isEmpty(headline)) h.setVisibility(View.GONE);
124
125 TextView d = (TextView) section.findViewById(R.id.connection_info_descri ption);
126 d.setText(description);
127 d.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
128 if (TextUtils.isEmpty(description)) d.setVisibility(View.GONE);
129
130 mContainer.addView(section);
131 return section;
132 }
133
134 private void setCertificateViewer(String label) {
135 assert mCertificateViewer == null;
136 mCertificateViewer = new TextView(mContext);
137 mCertificateViewer.setText(label);
138 mCertificateViewer.setTextColor(
139 mContext.getResources().getColor(R.color.website_settings_popup_ text_link));
140 mCertificateViewer.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
141 mCertificateViewer.setOnClickListener(this);
142 mCertificateViewer.setPadding(0, mPaddingThin, 0, mPaddingThin);
143 mCertificateLayout.addView(mCertificateViewer);
144 }
145
146 @CalledByNative
147 private void addResetCertDecisionsButton(String label) {
148 assert mNativeConnectionInfoPopup != 0;
149 assert mResetCertDecisionsButton == null;
150
151 mResetCertDecisionsButton = new Button(mContext);
152 mResetCertDecisionsButton.setText(label);
153 mResetCertDecisionsButton.setBackground(mContext.getResources().getDrawa ble(
154 R.drawable.connection_info_reset_cert_decisions));
155 mResetCertDecisionsButton.setTextColor(
156 mContext.getResources().getColor(
157 R.color.connection_info_popup_reset_cert_decisions_button));
158 mResetCertDecisionsButton.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
159 mResetCertDecisionsButton.setOnClickListener(this);
160
161 LinearLayout container = new LinearLayout(mContext);
162 container.setOrientation(LinearLayout.VERTICAL);
163 container.addView(mResetCertDecisionsButton);
164 container.setPadding(0, 0, 0, mPaddingWide);
165 mContainer.addView(container);
166 }
167
168 @CalledByNative
169 private void addMoreInfoLink(String linkText) {
170 mMoreInfoLink = new TextView(mContext);
171 mLinkUrl = HELP_URL;
172 mMoreInfoLink.setText(linkText);
173 mMoreInfoLink.setTextColor(
174 mContext.getResources().getColor(R.color.website_settings_popup_ text_link));
175 mMoreInfoLink.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
176 mMoreInfoLink.setPadding(0, mPaddingThin, 0, mPaddingThin);
177 mMoreInfoLink.setOnClickListener(this);
178 mDescriptionLayout.addView(mMoreInfoLink);
179 }
180
181 /** Displays the ConnectionInfoPopup. */
182 @CalledByNative
183 private void showDialog() {
184 ScrollView scrollView = new ScrollView(mContext);
185 scrollView.addView(mContainer);
186 mDialog.addContentView(scrollView,
187 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA RENT,
188 LinearLayout.LayoutParams.MATCH_PARENT));
189
190 mDialog.getWindow().setLayout(
191 ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.W RAP_CONTENT);
192 mDialog.show();
193 }
194
195 @Override
196 public void onClick(View v) {
197 if (mResetCertDecisionsButton == v) {
198 nativeResetCertDecisions(mNativeConnectionInfoPopup, mWebContents);
199 mDialog.dismiss();
200 } else if (mCertificateViewer == v) {
201 byte[][] certChain = nativeGetCertificateChain(mWebContents);
202 if (certChain == null) {
203 // The WebContents may have been destroyed/invalidated. If so,
204 // ignore this request.
205 return;
206 }
207 CertificateViewer.showCertificateChain(mContext, certChain);
208 } else if (mMoreInfoLink == v) {
209 mDialog.dismiss();
210 try {
211 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
212 i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
213 i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName ());
214 mContext.startActivity(i);
215 } catch (URISyntaxException ex) {
216 // Do nothing intentionally.
217 }
218 }
219 }
220
221 /**
222 * Shows a connection info dialog for the provided WebContents.
223 *
224 * The popup adds itself to the view hierarchy which owns the reference whil e it's
225 * visible.
226 *
227 * @param context Context which is used for launching a dialog.
228 * @param webContents The WebContents for which to show Website information. This
229 * information is retrieved for the visible entry.
230 */
231 public static void show(Context context, WebContents webContents) {
232 new ConnectionInfoPopup(context, webContents);
233 }
234
235 private static native long nativeInit(ConnectionInfoPopup popup,
236 WebContents webContents);
237 private native void nativeDestroy(long nativeConnectionInfoPopupAndroid);
238 private native void nativeResetCertDecisions(
239 long nativeConnectionInfoPopupAndroid, WebContents webContents);
240 private native byte[][] nativeGetCertificateChain(WebContents webContents);
241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698