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

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

Issue 690343003: Fixed crash caused from invalid URLs in the PageInfo dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.graphics.Color; 10 import android.graphics.Color;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 private final Button mCopyUrlButton; 92 private final Button mCopyUrlButton;
93 private final Button mSiteSettingsButton; 93 private final Button mSiteSettingsButton;
94 private final Button mDoneButton; 94 private final Button mDoneButton;
95 95
96 // The dialog the container is placed in. 96 // The dialog the container is placed in.
97 private final Dialog mDialog; 97 private final Dialog mDialog;
98 98
99 // The full URL from the URL bar, which is copied to the user's clipboard wh en they select 'Copy 99 // The full URL from the URL bar, which is copied to the user's clipboard wh en they select 'Copy
100 // URL'. 100 // URL'.
101 private String mFullUrl; 101 private String mFullUrl;
102 private URI mUrl;
103 102
104 /** 103 /**
105 * Creates the WebsiteSettingsPopup, but does not display it. Also initializ es the corresponding 104 * Creates the WebsiteSettingsPopup, but does not display it. Also initializ es the corresponding
106 * C++ object and saves a pointer to it. 105 * C++ object and saves a pointer to it.
107 * 106 *
108 * @param context Context which is used for launching a dialog. 107 * @param context Context which is used for launching a dialog.
109 * @param webContents The WebContents for which to show Website information. This information is 108 * @param webContents The WebContents for which to show Website information. This information is
110 * retrieved for the visible entry. 109 * retrieved for the visible entry.
111 */ 110 */
112 private WebsiteSettingsPopup(Context context, WebContents webContents) { 111 private WebsiteSettingsPopup(Context context, WebContents webContents) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 188 case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
190 return R.drawable.permission_push_notification; 189 return R.drawable.permission_push_notification;
191 case ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS: 190 case ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS:
192 return R.drawable.permission_popups; 191 return R.drawable.permission_popups;
193 default: 192 default:
194 assert false : "Icon requested for invalid permission: " + permi ssion; 193 assert false : "Icon requested for invalid permission: " + permi ssion;
195 return -1; 194 return -1;
196 } 195 }
197 } 196 }
198 197
198 /**
199 * Gets the color to use for the scheme in the URL title for the given secur ity level. Does not
200 * apply to internal pages.
201 *
202 * @param toolbarModelSecurityLevel A valid ToolbarModelSecurityLevel, which is the security
203 * level of the page.
204 * @return The color ID to color the scheme in the URL title.
205 */
206 private int getSchemeColorId(int toolbarModelSecurityLevel) {
207 switch (toolbarModelSecurityLevel) {
208 case ToolbarModelSecurityLevel.NONE:
209 return R.color.website_settings_popup_url_scheme_http;
210 case ToolbarModelSecurityLevel.SECURE:
211 case ToolbarModelSecurityLevel.EV_SECURE:
212 return R.color.website_settings_popup_url_scheme_https;
213 case ToolbarModelSecurityLevel.SECURITY_WARNING:
214 case ToolbarModelSecurityLevel.SECURITY_POLICY_WARNING:
215 return R.color.website_settings_popup_url_scheme_mixed;
216 case ToolbarModelSecurityLevel.SECURITY_ERROR:
217 return R.color.website_settings_popup_url_scheme_broken;
218 default:
219 assert false : "Invalid security level specified: " + toolbarMod elSecurityLevel;
220 return R.color.website_settings_popup_url_scheme_http;
221 }
222 }
223
224 /**
225 * Gets the message to display in the connection message box for the given s ecurity level. Does
226 * not apply to SECURITY_ERROR pages, since these have their own coloured/fo rmatted message.
227 *
228 * @param toolbarModelSecurityLevel A valid ToolbarModelSecurityLevel, which is the security
229 * level of the page.
230 * @return The ID of the message to display in the connection message box.
231 */
232 private int getConnectionMessageId(int toolbarModelSecurityLevel) {
233 switch (toolbarModelSecurityLevel) {
234 case ToolbarModelSecurityLevel.NONE:
235 return R.string.page_info_connection_http;
236 case ToolbarModelSecurityLevel.SECURE:
237 case ToolbarModelSecurityLevel.EV_SECURE:
238 return R.string.page_info_connection_https;
239 case ToolbarModelSecurityLevel.SECURITY_WARNING:
240 case ToolbarModelSecurityLevel.SECURITY_POLICY_WARNING:
241 return R.string.page_info_connection_mixed;
242 default:
243 assert false : "Invalid security level specified: " + toolbarMod elSecurityLevel;
244 return R.string.page_info_connection_http;
245 }
246 }
247
248 /**
249 * Updates the details (URL title and connection message) displayed in the p opup.
250 *
251 * @param isInternalPage Whether or not this page is an internal chrome page (e.g. the
252 * chrome://settings page).
253 */
199 @CalledByNative 254 @CalledByNative
200 private void updatePageDetails(boolean isInternalPage) { 255 private void updatePageDetails(boolean isInternalPage) {
201 mFullUrl = mWebContents.getVisibleUrl(); 256 mFullUrl = mWebContents.getVisibleUrl();
202 int securityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebCont ents); 257 int securityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebCont ents);
203 258
259 URI parsedUrl;
204 try { 260 try {
205 mUrl = new URI(mFullUrl); 261 parsedUrl = new URI(mFullUrl);
206 } catch (URISyntaxException e) { 262 } catch (URISyntaxException e) {
207 assert false : "Invalid URL specified: " + mFullUrl; 263 parsedUrl = null;
208 } 264 }
209 265
210 int schemeColorId = -1; 266 if (parsedUrl != null) {
211 if (securityLevel == ToolbarModelSecurityLevel.SECURITY_ERROR) { 267 // The URL is valid - color the scheme (and other components) for th e security level.
212 schemeColorId = R.color.website_settings_popup_url_scheme_broken; 268 SpannableStringBuilder sb = new SpannableStringBuilder();
269
270 int schemeColorId = R.color.website_settings_popup_url_scheme_http;
271 if (!isInternalPage) {
272 schemeColorId = getSchemeColorId(securityLevel);
273 }
274
275 sb.append(parsedUrl.toString());
276 final ForegroundColorSpan schemeColorSpan = new ForegroundColorSpan(
277 mContext.getResources().getColor(schemeColorId));
278 sb.setSpan(schemeColorSpan, 0, parsedUrl.getScheme().length(),
279 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
280 if (securityLevel == ToolbarModelSecurityLevel.SECURITY_ERROR) {
281 sb.setSpan(new StrikethroughSpan(), 0, parsedUrl.getScheme().len gth(),
282 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
283 }
284
285 // The domain is everything after the scheme until the end of the or igin.
286 final ForegroundColorSpan domainColorSpan = new ForegroundColorSpan(
287 mContext.getResources().getColor(R.color.website_settings_po pup_url_domain));
288 sb.setSpan(domainColorSpan, parsedUrl.getScheme().length(),
289 UrlUtilities.getOriginForDisplay(parsedUrl, true).length(),
290 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
291
292 mUrlTitle.setText(sb);
293 } else {
294 // The URL is invalid - still display it in the title, but don't app ly any coloring.
295 mUrlTitle.setText(mFullUrl);
296 }
297
298 // Display the appropriate connection message.
299 SpannableStringBuilder messageBuilder = new SpannableStringBuilder();
300 if (securityLevel != ToolbarModelSecurityLevel.SECURITY_ERROR) {
301 messageBuilder.append(mContext.getResources().getString(
302 getConnectionMessageId(securityLevel)));
303 } else {
304 String originToDisplay;
305 if (parsedUrl != null) {
306 originToDisplay = UrlUtilities.getOriginForDisplay(parsedUrl, fa lse);
307 } else {
308 // The URL is invalid - just display the full URL.
309 originToDisplay = mFullUrl;
310 }
213 311
214 String leadingText = mContext.getResources().getString( 312 String leadingText = mContext.getResources().getString(
215 R.string.page_info_connection_broken_leading_text); 313 R.string.page_info_connection_broken_leading_text);
216 String followingText = mContext.getResources().getString( 314 String followingText = mContext.getResources().getString(
217 R.string.page_info_connection_broken_following_text, 315 R.string.page_info_connection_broken_following_text, originT oDisplay);
218 UrlUtilities.getOriginForDisplay(mUrl, false)); 316 messageBuilder.append(leadingText + " " + followingText);
219 SpannableStringBuilder sb = new SpannableStringBuilder(leadingText + " "
220 + followingText);
221 final ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext .getResources() 317 final ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext .getResources()
222 .getColor(R.color.website_settings_popup_url_scheme_broken)) ; 318 .getColor(R.color.website_settings_popup_url_scheme_broken)) ;
223 final StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.B OLD); 319 final StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.B OLD);
224 sb.setSpan(redSpan, 0, leadingText.length(), Spannable.SPAN_INCLUSIV E_EXCLUSIVE); 320 messageBuilder.setSpan(redSpan, 0, leadingText.length(),
225 sb.setSpan(boldSpan, 0, leadingText.length(), Spannable.SPAN_INCLUSI VE_EXCLUSIVE); 321 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
226 mUrlConnectionMessage.setText(sb); 322 messageBuilder.setSpan(boldSpan, 0, leadingText.length(),
227 } else {
228 int connectionMessageId = 0;
229 if (isInternalPage) {
230 schemeColorId = R.color.website_settings_popup_url_scheme_http;
231 connectionMessageId = R.string.page_info_connection_internal_pag e;
232 } else {
233 switch (securityLevel) {
234 case ToolbarModelSecurityLevel.NONE:
235 schemeColorId = R.color.website_settings_popup_url_schem e_http;
236 connectionMessageId = R.string.page_info_connection_http ;
237 break;
238 case ToolbarModelSecurityLevel.SECURE:
239 case ToolbarModelSecurityLevel.EV_SECURE:
240 schemeColorId = R.color.website_settings_popup_url_schem e_https;
241 connectionMessageId = R.string.page_info_connection_http s;
242 break;
243 case ToolbarModelSecurityLevel.SECURITY_WARNING:
244 case ToolbarModelSecurityLevel.SECURITY_POLICY_WARNING:
245 schemeColorId = R.color.website_settings_popup_url_schem e_mixed;
246 connectionMessageId = R.string.page_info_connection_mixe d;
247 break;
248 default:
249 assert false : "Invalid security level specified: " + se curityLevel;
250 schemeColorId = R.color.website_settings_popup_url_schem e_http;
251 connectionMessageId = R.string.page_info_connection_http ;
252 }
253 }
254 mUrlConnectionMessage.setText(mContext.getResources().getString(conn ectionMessageId));
255 }
256
257 // Color the URI-parsed version of the URL.
258 SpannableStringBuilder sb = new SpannableStringBuilder(mUrl.toString());
259 final ForegroundColorSpan schemeColorSpan = new ForegroundColorSpan(mCon text.getResources()
260 .getColor(schemeColorId));
261 sb.setSpan(schemeColorSpan, 0, mUrl.getScheme().length(),
262 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
263 if (securityLevel == ToolbarModelSecurityLevel.SECURITY_ERROR) {
264 sb.setSpan(new StrikethroughSpan(), 0, mUrl.getScheme().length(),
265 Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 323 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
266 } 324 }
267 325 mUrlConnectionMessage.setText(messageBuilder);
268 // The domain is everything after the scheme until the end of the
269 // origin.
270 final ForegroundColorSpan domainColorSpan = new ForegroundColorSpan(
271 mContext.getResources().getColor(R.color.website_settings_popup_ url_domain));
272 sb.setSpan(domainColorSpan, mUrl.getScheme().length(),
273 UrlUtilities.getOriginForDisplay(mUrl, true).length(),
274 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
275 mUrlTitle.setText(sb);
276 } 326 }
277 327
278 /** 328 /**
279 * Adds a new row for the given permission. 329 * Adds a new row for the given permission.
280 * 330 *
281 * @param name The title of the permission to display to the user. 331 * @param name The title of the permission to display to the user.
282 * @param type The ContentSettingsType of the permission. 332 * @param type The ContentSettingsType of the permission.
283 * @param currentSetting The ContentSetting of the currently selected settin g. 333 * @param currentSetting The ContentSetting of the currently selected settin g.
284 */ 334 */
285 @CalledByNative 335 @CalledByNative
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 459 }
410 } 460 }
411 461
412 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); 462 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents);
413 463
414 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); 464 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid);
415 465
416 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid, 466 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid,
417 int type, int setting); 467 int type, int setting);
418 } 468 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698