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

Unified Diff: components/omnibox/browser/omnibox_view.cc

Issue 2641003002: Show scheme in black and content in gray for data: protocol urls (Closed)
Patch Set: Update iOS Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/omnibox_view.cc
diff --git a/components/omnibox/browser/omnibox_view.cc b/components/omnibox/browser/omnibox_view.cc
index c05c1aeb1de32f491c94849fc7931fe76bcbaacb..267c8b4439f4e8fe308aeab337d10e6a965f1b46 100644
--- a/components/omnibox/browser/omnibox_view.cc
+++ b/components/omnibox/browser/omnibox_view.cc
@@ -19,6 +19,7 @@
#include "components/omnibox/browser/omnibox_edit_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/toolbar/toolbar_model.h"
+#include "extensions/common/constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/vector_icons_public.h"
@@ -185,3 +186,72 @@ void OmniboxView::TextChanged() {
if (model_.get())
model_->OnChanged();
}
+
+void OmniboxView::SetEmphasis(bool emphasize, gfx::Range) {
+ // No behavior if not overridden by subclasses.
+}
+
+void OmniboxView::UpdateSchemeEmphasis(gfx::Range) {
+ // No behavior if not overridden by subclasses.
+}
+
+void OmniboxView::ApplyEmphasis(
+ const base::string16& display_text,
+ const AutocompleteSchemeClassifier& classifier) {
+ enum DemphasizeComponents {
+ EVERYTHING,
+ ALL_BUT_SCHEME,
+ ALL_BUT_HOST,
+ NOTHING,
+ } deemphasize = NOTHING;
+
+ url::Component scheme, host;
+ AutocompleteInput::ParseForEmphasizeComponents(display_text, classifier,
+ &scheme, &host);
+
+ 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.
+ display_text.substr(scheme.begin, scheme.len);
+
+ if (model_->CurrentTextIsURL()) {
+ // Extension IDs are not human-readable, so deemphasize everything to draw
+ // attention to the human-readable name in the location icon text.
+ // Data URLs are rarely human-readable and can be used for spoofing, so draw
+ // attention to the scheme to emphasize "this is just a bunch of data".
+ // For normal URLs, the host is the best proxy for "identity".
+ if (url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme))
+ deemphasize = EVERYTHING;
+ else if (url_scheme == base::UTF8ToUTF16(url::kDataScheme))
+ deemphasize = ALL_BUT_SCHEME;
+ else if (host.is_nonempty())
+ deemphasize = ALL_BUT_HOST;
+ }
+
+ gfx::Range scheme_range = gfx::Range(scheme.begin, scheme.end());
+ switch (deemphasize) {
+ case EVERYTHING:
+ SetEmphasis(false, gfx::Range::InvalidRange());
+ break;
+ case NOTHING:
+ SetEmphasis(true, gfx::Range::InvalidRange());
+ break;
+ case ALL_BUT_SCHEME:
+ SetEmphasis(false, gfx::Range::InvalidRange());
+ SetEmphasis(true, scheme_range);
+ break;
+ case ALL_BUT_HOST:
+ SetEmphasis(false, gfx::Range::InvalidRange());
+ SetEmphasis(true, gfx::Range(host.begin, host.end()));
+ break;
+ }
+
+ // Emphasize the scheme for security UI display purposes (if necessary).
+ // Note that we check CurrentTextIsURL() because if we're replacing search
+ // URLs with search terms, we may have a non-URL even when the user is not
+ // editing; and in some cases, e.g. for "site:foo.com" searches, the parser
+ // may have incorrectly identified a qualifier as a scheme.
+ 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.
+ !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
+ scheme_range = gfx::Range::InvalidRange();
+ }
+ 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.
+}

Powered by Google App Engine
This is Rietveld 408576698