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.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 Loading... | |
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 Loading... | |
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 = encodeSuspiciousUrl(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. | |
310 * This only affects the fragment, as all other URL components will already be encoded. | |
311 */ | |
312 public static String encodeSuspiciousUrl(String urlStr) { | |
Ted C
2015/03/25 19:55:38
This name to me implies that the URL is suspicious
tsergeant
2015/03/25 23:44:47
Done.
| |
313 StringBuilder urlBuilder = new StringBuilder(); | |
314 for (int i = 0; i < urlStr.length(); i++) { | |
315 char fragmentChar = urlStr.charAt(i); | |
Matt Giuca
2015/03/25 03:23:24
nit: Rename fragmentChar to something else (maybe
tsergeant
2015/03/25 23:44:47
Done.
| |
316 if ((fragmentChar >= FIRST_UNICODE_WHITESPACE | |
317 && fragmentChar <= FINAL_UNICODE_WHITESPACE) | |
318 || fragmentChar == ' ' | |
319 || fragmentChar == UNICODE_NBSP) | |
Ted C
2015/03/25 19:55:38
braces are required in java unless the statement a
tsergeant
2015/03/25 23:44:47
Done.
| |
320 urlBuilder.append(Uri.encode(Character.toString(fragmentChar))); | |
321 else | |
322 urlBuilder.append(fragmentChar); | |
323 } | |
324 return urlBuilder.toString(); | |
325 } | |
326 | |
327 /** | |
303 * Sets the visibility of the lower area of the dialog (containing the permi ssions and 'Site | 328 * Sets the visibility of the lower area of the dialog (containing the permi ssions and 'Site |
304 * Settings' button). | 329 * Settings' button). |
305 * | 330 * |
306 * @param isVisible Whether to show or hide the dialog area. | 331 * @param isVisible Whether to show or hide the dialog area. |
307 */ | 332 */ |
308 private void setVisibilityOfLowerDialogArea(boolean isVisible) { | 333 private void setVisibilityOfLowerDialogArea(boolean isVisible) { |
309 mHorizontalSeparator.setVisibility(isVisible ? View.VISIBLE : View.GONE) ; | 334 mHorizontalSeparator.setVisibility(isVisible ? View.VISIBLE : View.GONE) ; |
310 mLowerDialogArea.setVisibility(isVisible ? View.VISIBLE : View.GONE); | 335 mLowerDialogArea.setVisibility(isVisible ? View.VISIBLE : View.GONE); |
311 } | 336 } |
312 | 337 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 new WebsiteSettingsPopup(context, profile, webContents); | 561 new WebsiteSettingsPopup(context, profile, webContents); |
537 } | 562 } |
538 | 563 |
539 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); | 564 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); |
540 | 565 |
541 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); | 566 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); |
542 | 567 |
543 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid, | 568 private native void nativeOnPermissionSettingChanged(long nativeWebsiteSetti ngsPopupAndroid, |
544 int type, int setting); | 569 int type, int setting); |
545 } | 570 } |
OLD | NEW |