OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines helper functions shared by the various implementations | 5 // This file defines helper functions shared by the various implementations |
6 // of OmniboxView. | 6 // of OmniboxView. |
7 | 7 |
8 #include "components/omnibox/browser/omnibox_view.h" | 8 #include "components/omnibox/browser/omnibox_view.h" |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "components/grit/components_scaled_resources.h" | 16 #include "components/grit/components_scaled_resources.h" |
17 #include "components/omnibox/browser/autocomplete_match.h" | 17 #include "components/omnibox/browser/autocomplete_match.h" |
18 #include "components/omnibox/browser/omnibox_client.h" | 18 #include "components/omnibox/browser/omnibox_client.h" |
19 #include "components/omnibox/browser/omnibox_edit_controller.h" | 19 #include "components/omnibox/browser/omnibox_edit_controller.h" |
20 #include "components/omnibox/browser/omnibox_edit_model.h" | 20 #include "components/omnibox/browser/omnibox_edit_model.h" |
21 #include "components/toolbar/toolbar_model.h" | 21 #include "components/toolbar/toolbar_model.h" |
22 #include "extensions/common/constants.h" | |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/vector_icons_public.h" | 24 #include "ui/gfx/vector_icons_public.h" |
24 | 25 |
25 // static | 26 // static |
26 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { | 27 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { |
27 const base::string16 kJsPrefix( | 28 const base::string16 kJsPrefix( |
28 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":")); | 29 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":")); |
29 base::string16 out(text); | 30 base::string16 out(text); |
30 while (base::StartsWith(out, kJsPrefix, | 31 while (base::StartsWith(out, kJsPrefix, |
31 base::CompareCase::INSENSITIVE_ASCII)) { | 32 base::CompareCase::INSENSITIVE_ASCII)) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 if (client) { | 179 if (client) { |
179 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); | 180 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); |
180 } | 181 } |
181 } | 182 } |
182 | 183 |
183 void OmniboxView::TextChanged() { | 184 void OmniboxView::TextChanged() { |
184 EmphasizeURLComponents(); | 185 EmphasizeURLComponents(); |
185 if (model_.get()) | 186 if (model_.get()) |
186 model_->OnChanged(); | 187 model_->OnChanged(); |
187 } | 188 } |
189 | |
190 void OmniboxView::SetEmphasis(bool emphasize, gfx::Range) { | |
191 // No behavior if not overridden by subclasses. | |
192 } | |
193 | |
194 void OmniboxView::UpdateSchemeEmphasis(gfx::Range) { | |
195 // No behavior if not overridden by subclasses. | |
196 } | |
197 | |
198 void OmniboxView::ApplyEmphasis( | |
199 const base::string16& display_text, | |
200 const AutocompleteSchemeClassifier& classifier) { | |
201 enum DemphasizeComponents { | |
202 EVERYTHING, | |
203 ALL_BUT_SCHEME, | |
204 ALL_BUT_HOST, | |
205 NOTHING, | |
206 } deemphasize = NOTHING; | |
207 | |
208 url::Component scheme, host; | |
209 AutocompleteInput::ParseForEmphasizeComponents(display_text, classifier, | |
210 &scheme, &host); | |
211 | |
212 const base::string16 url_scheme = | |
Peter Kasting
2017/03/01 02:39:11
Nit: Move inside the next conditional
elawrence
2017/03/01 21:49:01
Done.
| |
213 display_text.substr(scheme.begin, scheme.len); | |
214 | |
215 if (model_->CurrentTextIsURL()) { | |
216 // Extension IDs are not human-readable, so deemphasize everything to draw | |
217 // attention to the human-readable name in the location icon text. | |
218 // Data URLs are rarely human-readable and can be used for spoofing, so draw | |
219 // attention to the scheme to emphasize "this is just a bunch of data". | |
220 // For normal URLs, the host is the best proxy for "identity". | |
221 if (url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme)) | |
222 deemphasize = EVERYTHING; | |
223 else if (url_scheme == base::UTF8ToUTF16(url::kDataScheme)) | |
224 deemphasize = ALL_BUT_SCHEME; | |
225 else if (host.is_nonempty()) | |
226 deemphasize = ALL_BUT_HOST; | |
227 } | |
228 | |
229 gfx::Range scheme_range = gfx::Range(scheme.begin, scheme.end()); | |
230 switch (deemphasize) { | |
231 case EVERYTHING: | |
232 SetEmphasis(false, gfx::Range::InvalidRange()); | |
233 break; | |
234 case NOTHING: | |
235 SetEmphasis(true, gfx::Range::InvalidRange()); | |
236 break; | |
237 case ALL_BUT_SCHEME: | |
238 SetEmphasis(false, gfx::Range::InvalidRange()); | |
239 SetEmphasis(true, scheme_range); | |
240 break; | |
241 case ALL_BUT_HOST: | |
242 SetEmphasis(false, gfx::Range::InvalidRange()); | |
243 SetEmphasis(true, gfx::Range(host.begin, host.end())); | |
244 break; | |
245 } | |
246 | |
247 // Emphasize the scheme for security UI display purposes (if necessary). | |
248 // Note that we check CurrentTextIsURL() because if we're replacing search | |
249 // URLs with search terms, we may have a non-URL even when the user is not | |
250 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | |
251 // may have incorrectly identified a qualifier as a scheme. | |
252 if (model()->user_input_in_progress() || !model_->CurrentTextIsURL() || | |
Peter Kasting
2017/03/01 02:39:11
I think we can nuke the CurrentTextIsURL() check a
elawrence
2017/03/01 21:49:01
Interesting. Updated.
| |
253 !scheme.is_nonempty()) { | |
Peter Kasting
2017/03/01 02:39:11
Nit: {} unnecessary
elawrence
2017/03/01 21:49:01
Technically yes, although the style guide seems to
| |
254 scheme_range = gfx::Range::InvalidRange(); | |
255 } | |
256 UpdateSchemeEmphasis(scheme_range); | |
Peter Kasting
2017/03/01 02:39:11
Do we always have to call this method? It seems l
elawrence
2017/03/01 21:49:01
I'm inclined to leave this as it is, because it ma
Peter Kasting
2017/03/01 23:18:47
It really depends how one thinks about these metho
elawrence
2017/03/02 19:08:01
Done.
| |
257 } | |
OLD | NEW |