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

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: Move misplaced #include to mm files 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
« no previous file with comments | « components/omnibox/browser/omnibox_view.h ('k') | ios/chrome/browser/ui/omnibox/omnibox_view_ios.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0e3ac9a0d499b7cfad744e84f9a947e5fe1ec416 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,63 @@ void OmniboxView::TextChanged() {
if (model_.get())
model_->OnChanged();
}
+
+bool OmniboxView::CurrentTextIsURL() {
+ return model_->CurrentTextIsURL();
+}
+
+void OmniboxView::UpdateTextStyle(
+ 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);
+
+ if (CurrentTextIsURL()) {
+ const base::string16 url_scheme =
+ display_text.substr(scheme.begin, scheme.len);
+ // 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 = scheme.is_nonempty()
+ ? gfx::Range(scheme.begin, scheme.end())
+ : gfx::Range::InvalidRange();
+ switch (deemphasize) {
+ case EVERYTHING:
+ SetEmphasis(false, gfx::Range::InvalidRange());
+ break;
+ case NOTHING:
+ SetEmphasis(true, gfx::Range::InvalidRange());
+ break;
+ case ALL_BUT_SCHEME:
+ DCHECK(scheme_range.IsValid());
+ 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).
+ if (!model()->user_input_in_progress() && scheme_range.IsValid())
+ UpdateSchemeStyle(scheme_range);
+}
« no previous file with comments | « components/omnibox/browser/omnibox_view.h ('k') | ios/chrome/browser/ui/omnibox/omnibox_view_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698