OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.app.Dialog; | 7 import android.app.Dialog; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.graphics.Color; | 11 import android.graphics.Color; |
12 import android.provider.Browser; | 12 import android.provider.Browser; |
13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.view.View.OnClickListener; | 16 import android.view.View.OnClickListener; |
17 import android.view.ViewGroup; | 17 import android.view.ViewGroup; |
18 import android.view.Window; | 18 import android.view.Window; |
| 19 import android.widget.Button; |
19 import android.widget.ImageView; | 20 import android.widget.ImageView; |
20 import android.widget.LinearLayout; | 21 import android.widget.LinearLayout; |
21 import android.widget.ScrollView; | 22 import android.widget.ScrollView; |
22 import android.widget.TextView; | 23 import android.widget.TextView; |
23 | 24 |
| 25 import org.chromium.base.ApiCompatibilityUtils; |
24 import org.chromium.base.CalledByNative; | 26 import org.chromium.base.CalledByNative; |
25 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
26 import org.chromium.content.browser.WebContentsObserverAndroid; | 28 import org.chromium.content.browser.WebContentsObserverAndroid; |
27 import org.chromium.content_public.browser.WebContents; | 29 import org.chromium.content_public.browser.WebContents; |
28 | 30 |
29 import java.net.URISyntaxException; | 31 import java.net.URISyntaxException; |
30 | 32 |
31 /** | 33 /** |
32 * Java side of Android implementation of the website settings UI. | 34 * Java side of Android implementation of the website settings UI. |
33 */ | 35 */ |
34 public class WebsiteSettingsPopup implements OnClickListener { | 36 public class WebsiteSettingsPopup implements OnClickListener { |
35 private static final String HELP_URL = | 37 private static final String HELP_URL = |
36 "http://www.google.com/support/chrome/bin/answer.py?answer=95617"; | 38 "http://www.google.com/support/chrome/bin/answer.py?answer=95617"; |
37 private static final int DESCRIPTION_TEXT_SIZE_SP = 12; | 39 private static final int DESCRIPTION_TEXT_SIZE_SP = 12; |
38 private final Context mContext; | 40 private final Context mContext; |
39 private final Dialog mDialog; | 41 private final Dialog mDialog; |
40 private final LinearLayout mContainer; | 42 private final LinearLayout mContainer; |
41 private final WebContents mWebContents; | 43 private final WebContents mWebContents; |
42 private final int mPaddingWide, mPaddingThin; | 44 private final int mPaddingWide, mPaddingThin; |
| 45 private final long mNativeWebsiteSettingsPopup; |
43 private TextView mCertificateViewer, mMoreInfoLink; | 46 private TextView mCertificateViewer, mMoreInfoLink; |
44 private ViewGroup mCertificateLayout, mDescriptionLayout; | 47 private ViewGroup mCertificateLayout, mDescriptionLayout; |
| 48 private Button mResetCertDecisionsButton; |
45 private String mLinkUrl; | 49 private String mLinkUrl; |
46 | 50 |
47 private WebsiteSettingsPopup(Context context, WebContents webContents) { | 51 private WebsiteSettingsPopup(Context context, WebContents webContents) { |
48 mContext = context; | 52 mContext = context; |
49 mWebContents = webContents; | 53 mWebContents = webContents; |
50 | 54 |
51 mContainer = new LinearLayout(mContext); | 55 mContainer = new LinearLayout(mContext); |
52 mContainer.setOrientation(LinearLayout.VERTICAL); | 56 mContainer.setOrientation(LinearLayout.VERTICAL); |
53 mContainer.setBackgroundColor(Color.WHITE); | 57 mContainer.setBackgroundColor(Color.WHITE); |
54 mPaddingWide = (int) context.getResources().getDimension( | 58 mPaddingWide = (int) context.getResources().getDimension( |
55 R.dimen.certificate_viewer_padding_wide); | 59 R.dimen.certificate_viewer_padding_wide); |
56 mPaddingThin = (int) context.getResources().getDimension( | 60 mPaddingThin = (int) context.getResources().getDimension( |
57 R.dimen.certificate_viewer_padding_thin); | 61 R.dimen.certificate_viewer_padding_thin); |
58 mContainer.setPadding(mPaddingWide, mPaddingWide + mPaddingThin, mPaddin
gWide, | 62 mContainer.setPadding(mPaddingWide, mPaddingWide + mPaddingThin, mPaddin
gWide, |
59 mPaddingWide); | 63 mPaddingWide); |
60 | 64 |
61 mDialog = new Dialog(mContext); | 65 mDialog = new Dialog(mContext); |
62 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | 66 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); |
63 mDialog.setCanceledOnTouchOutside(true); | 67 mDialog.setCanceledOnTouchOutside(true); |
64 // This needs to come after other member initialization. | 68 // This needs to come after other member initialization. |
65 final long nativeWebsiteSettingsPopup = nativeInit(this, webContents); | 69 mNativeWebsiteSettingsPopup = nativeInit(this, webContents); |
66 final WebContentsObserverAndroid webContentsObserver = | 70 final WebContentsObserverAndroid webContentsObserver = |
67 new WebContentsObserverAndroid(mWebContents) { | 71 new WebContentsObserverAndroid(mWebContents) { |
68 @Override | 72 @Override |
69 public void navigationEntryCommitted() { | 73 public void navigationEntryCommitted() { |
70 // If a navigation is committed (e.g. from in-page redirect), th
e data we're | 74 // If a navigation is committed (e.g. from in-page redirect), th
e data we're |
71 // showing is stale so dismiss the dialog. | 75 // showing is stale so dismiss the dialog. |
72 mDialog.dismiss(); | 76 mDialog.dismiss(); |
73 } | 77 } |
74 }; | 78 }; |
75 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | 79 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
76 @Override | 80 @Override |
77 public void onDismiss(DialogInterface dialog) { | 81 public void onDismiss(DialogInterface dialog) { |
78 assert nativeWebsiteSettingsPopup != 0; | 82 assert mNativeWebsiteSettingsPopup != 0; |
79 webContentsObserver.detachFromWebContents(); | 83 webContentsObserver.detachFromWebContents(); |
80 nativeDestroy(nativeWebsiteSettingsPopup); | 84 nativeDestroy(mNativeWebsiteSettingsPopup); |
81 } | 85 } |
82 }); | 86 }); |
83 } | 87 } |
84 | 88 |
85 /** | 89 /** |
86 * Adds certificate section, which contains an icon, a headline, a | 90 * Adds certificate section, which contains an icon, a headline, a |
87 * description and a label for certificate info link. | 91 * description and a label for certificate info link. |
88 */ | 92 */ |
89 @CalledByNative | 93 @CalledByNative |
90 private void addCertificateSection(int enumeratedIconId, String headline, St
ring description, | 94 private void addCertificateSection(int enumeratedIconId, String headline, St
ring description, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 mCertificateViewer.setText(label); | 137 mCertificateViewer.setText(label); |
134 mCertificateViewer.setTextColor( | 138 mCertificateViewer.setTextColor( |
135 mContext.getResources().getColor(R.color.website_settings_popup_
text_link)); | 139 mContext.getResources().getColor(R.color.website_settings_popup_
text_link)); |
136 mCertificateViewer.setTextSize(DESCRIPTION_TEXT_SIZE_SP); | 140 mCertificateViewer.setTextSize(DESCRIPTION_TEXT_SIZE_SP); |
137 mCertificateViewer.setOnClickListener(this); | 141 mCertificateViewer.setOnClickListener(this); |
138 mCertificateViewer.setPadding(0, mPaddingWide, 0, mPaddingWide); | 142 mCertificateViewer.setPadding(0, mPaddingWide, 0, mPaddingWide); |
139 mCertificateLayout.addView(mCertificateViewer); | 143 mCertificateLayout.addView(mCertificateViewer); |
140 } | 144 } |
141 | 145 |
142 @CalledByNative | 146 @CalledByNative |
| 147 private void addResetCertDecisionsButton(String label) { |
| 148 assert mNativeWebsiteSettingsPopup != 0; |
| 149 assert mResetCertDecisionsButton == null; |
| 150 |
| 151 mResetCertDecisionsButton = new Button(mContext); |
| 152 mResetCertDecisionsButton.setText(label); |
| 153 ApiCompatibilityUtils.setBackgroundForView(mResetCertDecisionsButton, |
| 154 mContext.getResources().getDrawable( |
| 155 R.drawable.website_settings_reset_cert_decisions)); |
| 156 mResetCertDecisionsButton.setTextColor( |
| 157 mContext.getResources().getColor( |
| 158 R.color.website_settings_popup_reset_cert_decisions_button)); |
| 159 mResetCertDecisionsButton.setTextSize(DESCRIPTION_TEXT_SIZE_SP); |
| 160 mResetCertDecisionsButton.setOnClickListener(this); |
| 161 |
| 162 LinearLayout container = new LinearLayout(mContext); |
| 163 container.setOrientation(LinearLayout.VERTICAL); |
| 164 container.addView(mResetCertDecisionsButton); |
| 165 container.setPadding(0, 0, 0, mPaddingWide); |
| 166 mContainer.addView(container); |
| 167 } |
| 168 |
| 169 @CalledByNative |
143 private void addMoreInfoLink(String linkText) { | 170 private void addMoreInfoLink(String linkText) { |
144 addUrl(linkText, HELP_URL); | 171 addUrl(linkText, HELP_URL); |
145 } | 172 } |
146 | 173 |
147 /** Adds a section containing a description and a hyperlink. */ | 174 /** Adds a section containing a description and a hyperlink. */ |
148 private void addUrl(String label, String url) { | 175 private void addUrl(String label, String url) { |
149 mMoreInfoLink = new TextView(mContext); | 176 mMoreInfoLink = new TextView(mContext); |
150 mLinkUrl = url; | 177 mLinkUrl = url; |
151 mMoreInfoLink.setText(label); | 178 mMoreInfoLink.setText(label); |
152 mMoreInfoLink.setTextColor( | 179 mMoreInfoLink.setTextColor( |
(...skipping 11 matching lines...) Expand all Loading... |
164 scrollView.addView(mContainer); | 191 scrollView.addView(mContainer); |
165 mDialog.addContentView(scrollView, | 192 mDialog.addContentView(scrollView, |
166 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA
RENT, | 193 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA
RENT, |
167 LinearLayout.LayoutParams.MATCH_PARENT)); | 194 LinearLayout.LayoutParams.MATCH_PARENT)); |
168 mDialog.show(); | 195 mDialog.show(); |
169 } | 196 } |
170 | 197 |
171 @Override | 198 @Override |
172 public void onClick(View v) { | 199 public void onClick(View v) { |
173 mDialog.dismiss(); | 200 mDialog.dismiss(); |
174 if (mCertificateViewer == v) { | 201 if (mResetCertDecisionsButton == v) { |
| 202 nativeResetCertDecisions(mNativeWebsiteSettingsPopup, mWebContents); |
| 203 } else if (mCertificateViewer == v) { |
175 byte[][] certChain = nativeGetCertificateChain(mWebContents); | 204 byte[][] certChain = nativeGetCertificateChain(mWebContents); |
176 if (certChain == null) { | 205 if (certChain == null) { |
177 // The WebContents may have been destroyed/invalidated. If so, | 206 // The WebContents may have been destroyed/invalidated. If so, |
178 // ignore this request. | 207 // ignore this request. |
179 return; | 208 return; |
180 } | 209 } |
181 CertificateViewer.showCertificateChain(mContext, certChain); | 210 CertificateViewer.showCertificateChain(mContext, certChain); |
182 } else if (mMoreInfoLink == v) { | 211 } else if (mMoreInfoLink == v) { |
183 try { | 212 try { |
184 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME); | 213 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME); |
(...skipping 14 matching lines...) Expand all Loading... |
199 * @param webContents The WebContents for which to show Website information.
This | 228 * @param webContents The WebContents for which to show Website information.
This |
200 * information is retrieved for the visible entry. | 229 * information is retrieved for the visible entry. |
201 */ | 230 */ |
202 @SuppressWarnings("unused") | 231 @SuppressWarnings("unused") |
203 public static void show(Context context, WebContents webContents) { | 232 public static void show(Context context, WebContents webContents) { |
204 new WebsiteSettingsPopup(context, webContents); | 233 new WebsiteSettingsPopup(context, webContents); |
205 } | 234 } |
206 | 235 |
207 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent
s webContents); | 236 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent
s webContents); |
208 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); | 237 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); |
| 238 private native void nativeResetCertDecisions( |
| 239 long nativeWebsiteSettingsPopupAndroid, WebContents webContents); |
209 private native byte[][] nativeGetCertificateChain(WebContents webContents); | 240 private native byte[][] nativeGetCertificateChain(WebContents webContents); |
210 } | 241 } |
OLD | NEW |