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 bool OmniboxView::CurrentTextIsURL() { |
| 191 return model_->CurrentTextIsURL(); |
| 192 } |
| 193 |
| 194 void OmniboxView::UpdateTextStyle( |
| 195 const base::string16& display_text, |
| 196 const AutocompleteSchemeClassifier& classifier) { |
| 197 enum DemphasizeComponents { |
| 198 EVERYTHING, |
| 199 ALL_BUT_SCHEME, |
| 200 ALL_BUT_HOST, |
| 201 NOTHING, |
| 202 } deemphasize = NOTHING; |
| 203 |
| 204 url::Component scheme, host; |
| 205 AutocompleteInput::ParseForEmphasizeComponents(display_text, classifier, |
| 206 &scheme, &host); |
| 207 |
| 208 if (CurrentTextIsURL()) { |
| 209 const base::string16 url_scheme = |
| 210 display_text.substr(scheme.begin, scheme.len); |
| 211 // Extension IDs are not human-readable, so deemphasize everything to draw |
| 212 // attention to the human-readable name in the location icon text. |
| 213 // Data URLs are rarely human-readable and can be used for spoofing, so draw |
| 214 // attention to the scheme to emphasize "this is just a bunch of data". |
| 215 // For normal URLs, the host is the best proxy for "identity". |
| 216 if (url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme)) |
| 217 deemphasize = EVERYTHING; |
| 218 else if (url_scheme == base::UTF8ToUTF16(url::kDataScheme)) |
| 219 deemphasize = ALL_BUT_SCHEME; |
| 220 else if (host.is_nonempty()) |
| 221 deemphasize = ALL_BUT_HOST; |
| 222 } |
| 223 |
| 224 gfx::Range scheme_range = scheme.is_nonempty() |
| 225 ? gfx::Range(scheme.begin, scheme.end()) |
| 226 : gfx::Range::InvalidRange(); |
| 227 switch (deemphasize) { |
| 228 case EVERYTHING: |
| 229 SetEmphasis(false, gfx::Range::InvalidRange()); |
| 230 break; |
| 231 case NOTHING: |
| 232 SetEmphasis(true, gfx::Range::InvalidRange()); |
| 233 break; |
| 234 case ALL_BUT_SCHEME: |
| 235 DCHECK(scheme_range.IsValid()); |
| 236 SetEmphasis(false, gfx::Range::InvalidRange()); |
| 237 SetEmphasis(true, scheme_range); |
| 238 break; |
| 239 case ALL_BUT_HOST: |
| 240 SetEmphasis(false, gfx::Range::InvalidRange()); |
| 241 SetEmphasis(true, gfx::Range(host.begin, host.end())); |
| 242 break; |
| 243 } |
| 244 |
| 245 // Emphasize the scheme for security UI display purposes (if necessary). |
| 246 if (!model()->user_input_in_progress() && scheme_range.IsValid()) |
| 247 UpdateSchemeStyle(scheme_range); |
| 248 } |
OLD | NEW |