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 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); | 591 |
592 SetColor(location_bar_view_->GetColor( | 592 // As needed, deemphasize parts of the URL to draw attention to |
593 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 593 // whatever best represents the "identity" of the URL. |
594 if (grey_base && !grey_out_url) { | 594 enum Deemphasize { |
595 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), | 595 EVERYTHING, |
596 gfx::Range(host.begin, host.end())); | 596 ALL_BUT_SCHEME, |
597 ALL_BUT_HOST, | |
598 NOTHING, | |
599 } deemphasize = NOTHING; | |
600 | |
601 if (text_is_url) { | |
602 // Extension IDs are not human-readable, so deemphasize everything to draw | |
603 // attention to the human-readable name in the location icon text. | |
604 if (url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme)) | |
605 deemphasize = EVERYTHING; | |
606 // Data URLs are rarely human-readable and can be used for spoofing, so draw | |
607 // attention to the scheme to emphasize "this is just a bunch of data". | |
608 else if (url_scheme == base::UTF8ToUTF16(url::kDataScheme)) | |
609 deemphasize = ALL_BUT_SCHEME; | |
610 // For normal URLs, the host is the best proxy for "identity". | |
611 else if (host.is_nonempty()) | |
612 deemphasize = ALL_BUT_HOST; | |
597 } | 613 } |
598 | 614 |
615 const SkColor color = location_bar_view_->GetColor(LocationBarView::TEXT); | |
Peter Kasting
2017/02/23 01:30:43
Nit: Wonder if this would be clearer as |emphasize
| |
616 SetColor(deemphasize == NOTHING ? color | |
617 : location_bar_view_->GetColor( | |
618 LocationBarView::DEEMPHASIZED_TEXT)); | |
619 if (deemphasize == ALL_BUT_SCHEME) | |
620 ApplyColor(color, gfx::Range(scheme.begin, scheme.end())); | |
621 else if (deemphasize == ALL_BUT_HOST) | |
622 ApplyColor(color, gfx::Range(host.begin, host.end())); | |
623 | |
599 // Emphasize the scheme for security UI display purposes (if necessary). | 624 // Emphasize the scheme for security UI display purposes (if necessary). |
600 // Note that we check CurrentTextIsURL() because if we're replacing search | 625 // 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 | 626 // 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 | 627 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
603 // may have incorrectly identified a qualifier as a scheme. | 628 // may have incorrectly identified a qualifier as a scheme. |
604 SetStyle(gfx::DIAGONAL_STRIKE, false); | 629 SetStyle(gfx::DIAGONAL_STRIKE, false); |
605 if (!model()->user_input_in_progress() && text_is_url && | 630 if (!model()->user_input_in_progress() && text_is_url && |
606 scheme.is_nonempty() && (security_level_ != security_state::NONE)) { | 631 scheme.is_nonempty() && (security_level_ != security_state::NONE)) { |
607 SkColor security_color = | 632 SkColor security_color = |
608 location_bar_view_->GetSecureTextColor(security_level_); | 633 location_bar_view_->GetSecureTextColor(security_level_); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1065 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1090 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
1066 | 1091 |
1067 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1092 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
1068 | 1093 |
1069 // Minor note: We use IDC_ for command id here while the underlying textfield | 1094 // 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 | 1095 // is using IDS_ for all its command ids. This is because views cannot depend |
1071 // on IDC_ for now. | 1096 // on IDC_ for now. |
1072 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1097 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1073 IDS_EDIT_SEARCH_ENGINES); | 1098 IDS_EDIT_SEARCH_ENGINES); |
1074 } | 1099 } |
OLD | NEW |