Chromium Code Reviews| 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 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 | 579 |
| 580 // See whether the contents are a URL with a non-empty host portion, which we | 580 // See whether the contents are a URL with a non-empty host portion, which we |
| 581 // should emphasize. To check for a URL, rather than using the type returned | 581 // should emphasize. To check for a URL, rather than using the type returned |
| 582 // by Parse(), ask the model, which will check the desired page transition for | 582 // by Parse(), ask the model, which will check the desired page transition for |
| 583 // this input. This can tell us whether an UNKNOWN input string is going to | 583 // this input. This can tell us whether an UNKNOWN input string is going to |
| 584 // be treated as a search or a navigation, and is the same method the Paste | 584 // be treated as a search or a navigation, and is the same method the Paste |
| 585 // And Go system uses. | 585 // And Go system uses. |
| 586 url::Component scheme, host; | 586 url::Component scheme, host; |
| 587 AutocompleteInput::ParseForEmphasizeComponents( | 587 AutocompleteInput::ParseForEmphasizeComponents( |
| 588 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host); | 588 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host); |
| 589 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | 589 |
| 590 base::UTF8ToUTF16(extensions::kExtensionScheme); | 590 const base::string16 url_scheme = text().substr(scheme.begin, scheme.len); |
| 591 | |
| 592 // Is the scheme one that might be abused for spoofing purposes? | |
|
Peter Kasting
2017/02/06 22:42:28
ALl this code feels a little piecemeal to me; the
| |
| 593 bool spoofy_scheme = url_scheme == base::UTF8ToUTF16(url::kDataScheme); | |
|
Peter Kasting
2017/02/06 22:42:28
Should we just go ahead and include blob: in this?
| |
| 594 | |
| 595 // Should the entire URL be deemphasized? | |
| 596 bool grey_out_url = | |
| 597 (spoofy_scheme || | |
| 598 url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme)); | |
| 599 | |
| 591 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); | 600 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); |
| 601 | |
|
Peter Kasting
2017/02/06 22:42:28
Nit: I wouldn't add this
| |
| 592 SetColor(location_bar_view_->GetColor( | 602 SetColor(location_bar_view_->GetColor( |
| 593 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 603 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
| 594 if (grey_base && !grey_out_url) { | 604 if (grey_base && !grey_out_url) { |
| 595 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), | 605 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), |
| 596 gfx::Range(host.begin, host.end())); | 606 gfx::Range(host.begin, host.end())); |
| 607 } else if (spoofy_scheme) { | |
| 608 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), | |
| 609 gfx::Range(scheme.begin, scheme.end())); | |
| 597 } | 610 } |
| 598 | 611 |
| 599 // Emphasize the scheme for security UI display purposes (if necessary). | 612 // Emphasize the scheme for security UI display purposes (if necessary). |
| 600 // Note that we check CurrentTextIsURL() because if we're replacing search | 613 // Note that we check CurrentTextIsURL() because if we're replacing search |
| 601 // URLs with search terms, we may have a non-URL even when the user is not | 614 // URLs with search terms, we may have a non-URL even when the user is not |
| 602 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | 615 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
| 603 // may have incorrectly identified a qualifier as a scheme. | 616 // may have incorrectly identified a qualifier as a scheme. |
| 604 SetStyle(gfx::DIAGONAL_STRIKE, false); | 617 SetStyle(gfx::DIAGONAL_STRIKE, false); |
| 605 if (!model()->user_input_in_progress() && text_is_url && | 618 if (!model()->user_input_in_progress() && text_is_url && |
| 606 scheme.is_nonempty() && (security_level_ != security_state::NONE)) { | 619 scheme.is_nonempty() && (security_level_ != security_state::NONE)) { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1078 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1066 | 1079 |
| 1067 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1080 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1068 | 1081 |
| 1069 // Minor note: We use IDC_ for command id here while the underlying textfield | 1082 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1070 // is using IDS_ for all its command ids. This is because views cannot depend | 1083 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1071 // on IDC_ for now. | 1084 // on IDC_ for now. |
| 1072 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1085 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1073 IDS_EDIT_SEARCH_ENGINES); | 1086 IDS_EDIT_SEARCH_ENGINES); |
| 1074 } | 1087 } |
| OLD | NEW |