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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 2641003002: Show scheme in black and content in gray for data: protocol urls (Closed)
Patch Set: Address review feedback 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 unified diff | Download patch
OLDNEW
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/cocoa/omnibox/omnibox_view_mac.h" 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
6 6
7 #include <Carbon/Carbon.h> // kVK_Return 7 #include <Carbon/Carbon.h> // kVK_Return
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; 556 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
557 557
558 ApplyTextStyle(attributedString); 558 ApplyTextStyle(attributedString);
559 559
560 // A kinda hacky way to add breaking at periods. This is what Safari does. 560 // A kinda hacky way to add breaking at periods. This is what Safari does.
561 // This works for IDNs too, despite the "en_US". 561 // This works for IDNs too, despite the "en_US".
562 [attributedString addAttribute:@"NSLanguage" 562 [attributedString addAttribute:@"NSLanguage"
563 value:@"en_US_POSIX" 563 value:@"en_US_POSIX"
564 range:as_entire_string]; 564 range:as_entire_string];
565 565
566 [attributedString addAttribute:NSForegroundColorAttributeName
567 value:HostTextColor(in_dark_mode)
568 range:as_entire_string];
569
570 url::Component scheme, host; 566 url::Component scheme, host;
571 AutocompleteInput::ParseForEmphasizeComponents( 567 AutocompleteInput::ParseForEmphasizeComponents(
572 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, 568 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme,
573 &host); 569 &host);
574 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == 570
575 base::UTF8ToUTF16(extensions::kExtensionScheme); 571 const base::string16 url_scheme =
576 if (model()->CurrentTextIsURL() && 572 display_text.substr(scheme.begin, scheme.len);
577 (host.is_nonempty() || grey_out_url)) { 573
574 // As needed, deemphasize parts of the URL to draw attention to
575 // whatever best represents the "identity" of the URL.
576 enum Deemphasize {
577 EVERYTHING,
578 ALL_BUT_SCHEME,
579 ALL_BUT_HOST,
580 NOTHING,
581 } deemphasize = NOTHING;
582
583 if (model()->CurrentTextIsURL()) {
584 // Extension IDs are not human-readable, so deemphasize everything to draw
585 // attention to the human-readable name in the location icon text.
586 if (url_scheme == base::UTF8ToUTF16(extensions::kExtensionScheme))
587 deemphasize = EVERYTHING;
588 // Data URLs are rarely human-readable and can be used for spoofing, so draw
589 // attention to the scheme to emphasize "this is just a bunch of data".
590 else if (url_scheme == base::UTF8ToUTF16(url::kDataScheme))
591 deemphasize = ALL_BUT_SCHEME;
592 // For normal URLs, the host is the best proxy for "identity".
593 else if (host.is_nonempty())
594 deemphasize = ALL_BUT_HOST;
595 }
596
597 [attributedString
598 addAttribute:NSForegroundColorAttributeName
599 value:(deemphasize == NOTHING) ? HostTextColor(in_dark_mode)
600 : BaseTextColor(in_dark_mode)
601 range:as_entire_string];
602
603 if (deemphasize == ALL_BUT_SCHEME)
Peter Kasting 2017/02/23 01:30:43 Nit: {}
578 [attributedString addAttribute:NSForegroundColorAttributeName 604 [attributedString addAttribute:NSForegroundColorAttributeName
579 value:BaseTextColor(in_dark_mode) 605 value:HostTextColor(in_dark_mode)
580 range:as_entire_string]; 606 range:ComponentToNSRange(scheme)];
581 607 else if (deemphasize == ALL_BUT_HOST)
582 if (!grey_out_url) { 608 [attributedString addAttribute:NSForegroundColorAttributeName
583 [attributedString addAttribute:NSForegroundColorAttributeName 609 value:HostTextColor(in_dark_mode)
584 value:HostTextColor(in_dark_mode) 610 range:ComponentToNSRange(host)];
585 range:ComponentToNSRange(host)];
586 }
587 }
588 611
589 // TODO(shess): GTK has this as a member var, figure out why. 612 // TODO(shess): GTK has this as a member var, figure out why.
590 // [Could it be to not change if no change? If so, I'm guessing 613 // [Could it be to not change if no change? If so, I'm guessing
591 // AppKit may already handle that.] 614 // AppKit may already handle that.]
592 const security_state::SecurityLevel security_level = 615 const security_state::SecurityLevel security_level =
593 controller()->GetToolbarModel()->GetSecurityLevel(false); 616 controller()->GetToolbarModel()->GetSecurityLevel(false);
594 617
595 // Emphasize the scheme for security UI display purposes (if necessary). 618 // Emphasize the scheme for security UI display purposes (if necessary).
596 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && 619 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
597 scheme.is_nonempty() && 620 scheme.is_nonempty() &&
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 display_text); 1111 display_text);
1089 NSDictionary* notification_info = @{ 1112 NSDictionary* notification_info = @{
1090 NSAccessibilityAnnouncementKey : announcement, 1113 NSAccessibilityAnnouncementKey : announcement,
1091 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) 1114 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
1092 }; 1115 };
1093 NSAccessibilityPostNotificationWithUserInfo( 1116 NSAccessibilityPostNotificationWithUserInfo(
1094 [field_ window], 1117 [field_ window],
1095 NSAccessibilityAnnouncementRequestedNotification, 1118 NSAccessibilityAnnouncementRequestedNotification,
1096 notification_info); 1119 notification_info);
1097 } 1120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698