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

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

Issue 1011383005: Percent-encode illegal characters in Android page info popup URL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change unicode representation Created 5 years, 9 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
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/WebsiteSettingsPopupTest.java » ('j') | 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;
11 import android.graphics.drawable.ColorDrawable; 11 import android.graphics.drawable.ColorDrawable;
12 import android.net.Uri;
12 import android.text.Layout; 13 import android.text.Layout;
13 import android.text.Spannable; 14 import android.text.Spannable;
14 import android.text.SpannableStringBuilder; 15 import android.text.SpannableStringBuilder;
15 import android.text.style.ForegroundColorSpan; 16 import android.text.style.ForegroundColorSpan;
16 import android.text.style.StyleSpan; 17 import android.text.style.StyleSpan;
17 import android.util.AttributeSet; 18 import android.util.AttributeSet;
18 import android.view.Gravity; 19 import android.view.Gravity;
19 import android.view.LayoutInflater; 20 import android.view.LayoutInflater;
20 import android.view.View; 21 import android.view.View;
21 import android.view.View.OnClickListener; 22 import android.view.View.OnClickListener;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (maxLines != mCurrentMaxLines) { 158 if (maxLines != mCurrentMaxLines) {
158 setMaxLines(maxLines); 159 setMaxLines(maxLines);
159 return true; 160 return true;
160 } 161 }
161 return false; 162 return false;
162 } 163 }
163 } 164 }
164 165
165 private static final int MAX_TABLET_DIALOG_WIDTH_DP = 400; 166 private static final int MAX_TABLET_DIALOG_WIDTH_DP = 400;
166 167
168 private static final char FIRST_UNICODE_WHITESPACE = '\u2000';
169 private static final char FINAL_UNICODE_WHITESPACE = '\u200F';
170 private static final char UNICODE_NBSP = '\u00A0';
171
167 private final Context mContext; 172 private final Context mContext;
168 private final Profile mProfile; 173 private final Profile mProfile;
169 private final WebContents mWebContents; 174 private final WebContents mWebContents;
170 175
171 // A pointer to the C++ object for this UI. 176 // A pointer to the C++ object for this UI.
172 private final long mNativeWebsiteSettingsPopup; 177 private final long mNativeWebsiteSettingsPopup;
173 178
174 // The outer container, filled with the layout from website_settings.xml. 179 // The outer container, filled with the layout from website_settings.xml.
175 private final LinearLayout mContainer; 180 private final LinearLayout mContainer;
176 181
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 mFullUrl = mWebContents.getVisibleUrl(); 287 mFullUrl = mWebContents.getVisibleUrl();
283 try { 288 try {
284 mParsedUrl = new URI(mFullUrl); 289 mParsedUrl = new URI(mFullUrl);
285 mIsInternalPage = UrlUtilities.isInternalScheme(mParsedUrl); 290 mIsInternalPage = UrlUtilities.isInternalScheme(mParsedUrl);
286 } catch (URISyntaxException e) { 291 } catch (URISyntaxException e) {
287 mParsedUrl = null; 292 mParsedUrl = null;
288 mIsInternalPage = false; 293 mIsInternalPage = false;
289 } 294 }
290 mSecurityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebContent s); 295 mSecurityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebContent s);
291 296
292 SpannableStringBuilder urlBuilder = new SpannableStringBuilder(mFullUrl) ; 297 String displayUrl = prepareUrlForDisplay(mFullUrl);
298 SpannableStringBuilder urlBuilder = new SpannableStringBuilder(displayUr l);
293 OmniboxUrlEmphasizer.emphasizeUrl(urlBuilder, mContext.getResources(), m Profile, 299 OmniboxUrlEmphasizer.emphasizeUrl(urlBuilder, mContext.getResources(), m Profile,
294 mSecurityLevel, mIsInternalPage, true); 300 mSecurityLevel, mIsInternalPage, true);
295 mUrlTitle.setText(urlBuilder); 301 mUrlTitle.setText(urlBuilder);
296 302
297 // Set the URL connection message now, and the URL after layout (so it 303 // Set the URL connection message now, and the URL after layout (so it
298 // can calculate its ideal height). 304 // can calculate its ideal height).
299 mUrlConnectionMessage.setText(getUrlConnectionMessage()); 305 mUrlConnectionMessage.setText(getUrlConnectionMessage());
300 } 306 }
301 307
302 /** 308 /**
309 * Percent-encodes suspicious Unicode whitespace characters in a URL so that it can be safely
310 * displayed.
311 */
312 public static String prepareUrlForDisplay(String urlStr) {
313 StringBuilder urlBuilder = new StringBuilder();
314 for (int i = 0; i < urlStr.length(); i++) {
315 char c = urlStr.charAt(i);
316 if ((c >= FIRST_UNICODE_WHITESPACE
317 && c <= FINAL_UNICODE_WHITESPACE)
318 || c == ' '
319 || c == UNICODE_NBSP) {
320 urlBuilder.append(Uri.encode(Character.toString(c)));
321 } else {
322 urlBuilder.append(c);
323 }
324 }
325 return urlBuilder.toString();
326 }
327
328 /**
303 * Sets the visibility of the lower area of the dialog (containing the permi ssions and 'Site 329 * Sets the visibility of the lower area of the dialog (containing the permi ssions and 'Site
304 * Settings' button). 330 * Settings' button).
305 * 331 *
306 * @param isVisible Whether to show or hide the dialog area. 332 * @param isVisible Whether to show or hide the dialog area.
307 */ 333 */
308 private void setVisibilityOfLowerDialogArea(boolean isVisible) { 334 private void setVisibilityOfLowerDialogArea(boolean isVisible) {
309 mHorizontalSeparator.setVisibility(isVisible ? View.VISIBLE : View.GONE) ; 335 mHorizontalSeparator.setVisibility(isVisible ? View.VISIBLE : View.GONE) ;
310 mLowerDialogArea.setVisibility(isVisible ? View.VISIBLE : View.GONE); 336 mLowerDialogArea.setVisibility(isVisible ? View.VISIBLE : View.GONE);
311 } 337 }
312 338
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 new WebsiteSettingsPopup(context, profile, webContents); 562 new WebsiteSettingsPopup(context, profile, webContents);
537 } 563 }
538 564
539 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); 565 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents);
540 566
541 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); 567 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid);
542 568
543 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid, 569 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid,
544 int type, int setting); 570 int type, int setting);
545 } 571 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/WebsiteSettingsPopupTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698