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

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

Issue 2901023002: Disable learning text suggestions if in incognito. (Closed)
Patch Set: Created 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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.omnibox; 5 package org.chromium.chrome.browser.omnibox;
6 6
7 import android.content.ClipData; 7 import android.content.ClipData;
8 import android.content.ClipboardManager; 8 import android.content.ClipboardManager;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.res.Resources; 10 import android.content.res.Resources;
11 import android.graphics.Canvas; 11 import android.graphics.Canvas;
12 import android.graphics.Paint; 12 import android.graphics.Paint;
13 import android.graphics.Rect; 13 import android.graphics.Rect;
14 import android.net.Uri; 14 import android.net.Uri;
15 import android.os.Build; 15 import android.os.Build;
16 import android.os.StrictMode; 16 import android.os.StrictMode;
17 import android.os.SystemClock; 17 import android.os.SystemClock;
18 import android.text.Editable; 18 import android.text.Editable;
19 import android.text.Layout; 19 import android.text.Layout;
20 import android.text.Selection; 20 import android.text.Selection;
21 import android.text.TextUtils; 21 import android.text.TextUtils;
22 import android.text.style.ReplacementSpan; 22 import android.text.style.ReplacementSpan;
23 import android.util.AttributeSet; 23 import android.util.AttributeSet;
24 import android.util.Pair; 24 import android.util.Pair;
25 import android.view.GestureDetector; 25 import android.view.GestureDetector;
26 import android.view.KeyEvent; 26 import android.view.KeyEvent;
27 import android.view.MotionEvent; 27 import android.view.MotionEvent;
28 import android.view.View; 28 import android.view.View;
29 import android.view.accessibility.AccessibilityNodeInfo; 29 import android.view.accessibility.AccessibilityNodeInfo;
30 import android.view.inputmethod.EditorInfo;
31 import android.view.inputmethod.InputConnection;
30 import android.widget.TextView; 32 import android.widget.TextView;
31 33
32 import org.chromium.base.ApiCompatibilityUtils; 34 import org.chromium.base.ApiCompatibilityUtils;
33 import org.chromium.base.Log; 35 import org.chromium.base.Log;
34 import org.chromium.base.SysUtils; 36 import org.chromium.base.SysUtils;
35 import org.chromium.base.VisibleForTesting; 37 import org.chromium.base.VisibleForTesting;
36 import org.chromium.chrome.R; 38 import org.chromium.chrome.R;
37 import org.chromium.chrome.browser.WindowDelegate; 39 import org.chromium.chrome.browser.WindowDelegate;
38 import org.chromium.chrome.browser.metrics.StartupMetrics; 40 import org.chromium.chrome.browser.metrics.StartupMetrics;
39 import org.chromium.chrome.browser.omnibox.LocationBarLayout.OmniboxLivenessList ener; 41 import org.chromium.chrome.browser.omnibox.LocationBarLayout.OmniboxLivenessList ener;
40 import org.chromium.chrome.browser.tab.Tab; 42 import org.chromium.chrome.browser.tab.Tab;
41 import org.chromium.chrome.browser.util.UrlUtilities; 43 import org.chromium.chrome.browser.util.UrlUtilities;
42 import org.chromium.content.browser.ContentViewCore; 44 import org.chromium.content.browser.ContentViewCore;
43 import org.chromium.ui.UiUtils; 45 import org.chromium.ui.UiUtils;
44 46
45 import java.net.MalformedURLException; 47 import java.net.MalformedURLException;
46 import java.net.URI; 48 import java.net.URI;
47 import java.net.URISyntaxException; 49 import java.net.URISyntaxException;
48 import java.net.URL; 50 import java.net.URL;
49 51
50 /** 52 /**
51 * The URL text entry view for the Omnibox. 53 * The URL text entry view for the Omnibox.
52 */ 54 */
53 public class UrlBar extends AutocompleteEditText { 55 public class UrlBar extends AutocompleteEditText {
54 private static final String TAG = "cr_UrlBar"; 56 private static final String TAG = "cr_UrlBar";
55 57
56 private static final boolean DEBUG = false; 58 private static final boolean DEBUG = false;
57 59
60 // TODO(tedchoc): Replace with EditorInfoCompat#IME_FLAG_NO_PERSONALIZED_LEA RNING or
61 // EditorInfo#IME_FLAG_NO_PERSONALIZED_LEARNING as soon as ei ther is available in
62 // all build config types.
63 private static final int IME_FLAG_NO_PERSONALIZED_LEARNING = 0x1000000;
64
58 // TextView becomes very slow on long strings, so we limit maximum length 65 // TextView becomes very slow on long strings, so we limit maximum length
59 // of what is displayed to the user, see limitDisplayableLength(). 66 // of what is displayed to the user, see limitDisplayableLength().
60 private static final int MAX_DISPLAYABLE_LENGTH = 4000; 67 private static final int MAX_DISPLAYABLE_LENGTH = 4000;
61 private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000; 68 private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000;
62 69
63 // Unicode "Left-To-Right Mark" (LRM) character. 70 // Unicode "Left-To-Right Mark" (LRM) character.
64 private static final char LRM = '\u200E'; 71 private static final char LRM = '\u200E';
65 72
66 /** The contents of the URL that precede the path/query after being formatte d. */ 73 /** The contents of the URL that precede the path/query after being formatte d. */
67 private String mFormattedUrlLocation; 74 private String mFormattedUrlLocation;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 /** 141 /**
135 * Delegate used to communicate with the content side and the parent layout. 142 * Delegate used to communicate with the content side and the parent layout.
136 */ 143 */
137 public interface UrlBarDelegate { 144 public interface UrlBarDelegate {
138 /** 145 /**
139 * @return The current active {@link Tab}. 146 * @return The current active {@link Tab}.
140 */ 147 */
141 Tab getCurrentTab(); 148 Tab getCurrentTab();
142 149
143 /** 150 /**
151 * @return Whether the user has entered incognito mode.
152 */
153 boolean isIncognito();
154
155 /**
144 * Called when the text state has changed and the autocomplete suggestio ns should be 156 * Called when the text state has changed and the autocomplete suggestio ns should be
145 * refreshed. 157 * refreshed.
146 * 158 *
147 * @param textDeleted Whether this change was as a result of text being deleted. 159 * @param textDeleted Whether this change was as a result of text being deleted.
148 */ 160 */
149 void onTextChangedForAutocomplete(boolean textDeleted); 161 void onTextChangedForAutocomplete(boolean textDeleted);
150 162
151 /** 163 /**
152 * @return Whether the light security theme should be used. 164 * @return Whether the light security theme should be used.
153 */ 165 */
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // outside the RTL-extent that contains the domain. crbug.com/723100 645 // outside the RTL-extent that contains the domain. crbug.com/723100
634 if (urlComponents.first.length() > 1) { 646 if (urlComponents.first.length() > 1) {
635 bringPointIntoView(1); 647 bringPointIntoView(1);
636 } 648 }
637 bringPointIntoView(urlComponents.first.length()); 649 bringPointIntoView(urlComponents.first.length());
638 650
639 return true; 651 return true;
640 } 652 }
641 653
642 @Override 654 @Override
655 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
656 InputConnection connection = super.onCreateInputConnection(outAttrs);
657 if (mUrlBarDelegate != null && mUrlBarDelegate.isIncognito()) {
Changwan Ryu 2017/05/23 18:54:23 This should arguably be assert mUrlBarDelegate !=
Ted C 2017/05/23 19:17:55 I think the null and assert seems safest. I would
658 outAttrs.imeOptions |= IME_FLAG_NO_PERSONALIZED_LEARNING;
659 }
660 return connection;
661 }
662
663 @Override
643 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { 664 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
644 super.onTextChanged(text, start, lengthBefore, lengthAfter); 665 super.onTextChanged(text, start, lengthBefore, lengthAfter);
645 mIsPastedText = false; 666 mIsPastedText = false;
646 } 667 }
647 668
648 @Override 669 @Override
649 public void setText(CharSequence text, BufferType type) { 670 public void setText(CharSequence text, BufferType type) {
650 if (DEBUG) Log.i(TAG, "setText -- text: %s", text); 671 if (DEBUG) Log.i(TAG, "setText -- text: %s", text);
651 super.setText(text, type); 672 super.setText(text, type);
652 fixupTextDirection(); 673 fixupTextDirection();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return (int) paint.measureText(ELLIPSIS); 822 return (int) paint.measureText(ELLIPSIS);
802 } 823 }
803 824
804 @Override 825 @Override
805 public void draw(Canvas canvas, CharSequence text, int start, int end, 826 public void draw(Canvas canvas, CharSequence text, int start, int end,
806 float x, int top, int y, int bottom, Paint paint) { 827 float x, int top, int y, int bottom, Paint paint) {
807 canvas.drawText(ELLIPSIS, x, y, paint); 828 canvas.drawText(ELLIPSIS, x, y, paint);
808 } 829 }
809 } 830 }
810 } 831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698