OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/location_bar_view_mac.h" | 5 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
6 | 6 |
7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Make sure the TemplateURL still exists. | 55 // Make sure the TemplateURL still exists. |
56 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel | 56 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel |
57 // to track changes to the model, this should become a DCHECK. | 57 // to track changes to the model, this should become a DCHECK. |
58 const TemplateURL* template_url = | 58 const TemplateURL* template_url = |
59 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); | 59 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
60 if (template_url) | 60 if (template_url) |
61 return template_url->AdjustedShortNameForLocaleDirection(); | 61 return template_url->AdjustedShortNameForLocaleDirection(); |
62 return std::wstring(); | 62 return std::wstring(); |
63 } | 63 } |
64 | 64 |
65 // Values for the green text color displayed for EV certificates, based | 65 // Values for the label colors for different security states. |
66 // on the values for kEvTextColor in location_bar_view_gtk.cc. | 66 static const CGFloat kEVSecureTextColorRedComponent = 0.03; |
67 static const CGFloat kEvTextColorRedComponent = 0.0; | 67 static const CGFloat kEVSecureTextColorGreenComponent = 0.58; |
68 static const CGFloat kEvTextColorGreenComponent = 0.59; | 68 static const CGFloat kEVSecureTextColorBlueComponent = 0.0; |
69 static const CGFloat kEvTextColorBlueComponent = 0.08; | 69 static const CGFloat kSecurityErrorTextColorRedComponent = 0.63; |
| 70 static const CGFloat kSecurityErrorTextColorGreenComponent = 0.0; |
| 71 static const CGFloat kSecurityErrorTextColorBlueComponent = 0.0; |
70 | 72 |
71 // Build a short string to use in keyword-search when the field isn't | 73 // Build a short string to use in keyword-search when the field isn't |
72 // very big. | 74 // very big. |
73 // TODO(shess): Copied from views/location_bar_view.cc. Try to share. | 75 // TODO(shess): Copied from views/location_bar_view.cc. Try to share. |
74 std::wstring CalculateMinString(const std::wstring& description) { | 76 std::wstring CalculateMinString(const std::wstring& description) { |
75 // Chop at the first '.' or whitespace. | 77 // Chop at the first '.' or whitespace. |
76 const size_t dot_index = description.find(L'.'); | 78 const size_t dot_index = description.find(L'.'); |
77 const size_t ws_index = description.find_first_of(kWhitespaceWide); | 79 const size_t ws_index = description.find_first_of(kWhitespaceWide); |
78 size_t chop_index = std::min(dot_index, ws_index); | 80 size_t chop_index = std::min(dot_index, ws_index); |
79 std::wstring min_string; | 81 std::wstring min_string; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 200 } |
199 } | 201 } |
200 | 202 |
201 void LocationBarViewMac::SaveStateToContents(TabContents* contents) { | 203 void LocationBarViewMac::SaveStateToContents(TabContents* contents) { |
202 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 204 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
203 edit_view_->SaveStateToTab(contents); | 205 edit_view_->SaveStateToTab(contents); |
204 } | 206 } |
205 | 207 |
206 void LocationBarViewMac::Update(const TabContents* contents, | 208 void LocationBarViewMac::Update(const TabContents* contents, |
207 bool should_restore_state) { | 209 bool should_restore_state) { |
208 SetSecurityIcon(toolbar_model_->GetIcon()); | 210 SetSecurityIcon(toolbar_model_->GetSecurityIcon()); |
209 page_action_views_.RefreshViews(); | 211 page_action_views_.RefreshViews(); |
210 RefreshContentSettingsViews(); | 212 RefreshContentSettingsViews(); |
211 // AutocompleteEditView restores state if the tab is non-NULL. | 213 // AutocompleteEditView restores state if the tab is non-NULL. |
212 edit_view_->Update(should_restore_state ? contents : NULL); | 214 edit_view_->Update(should_restore_state ? contents : NULL); |
213 } | 215 } |
214 | 216 |
215 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, | 217 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, |
216 WindowOpenDisposition disposition, | 218 WindowOpenDisposition disposition, |
217 PageTransition::Type transition, | 219 PageTransition::Type transition, |
218 const GURL& alternate_nav_url) { | 220 const GURL& alternate_nav_url) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). | 450 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). |
449 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); | 451 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); |
450 if (skiaBitmap) { | 452 if (skiaBitmap) { |
451 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); | 453 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); |
452 } | 454 } |
453 } | 455 } |
454 return tab_button_image_; | 456 return tab_button_image_; |
455 } | 457 } |
456 | 458 |
457 void LocationBarViewMac::SetSecurityIconLabel() { | 459 void LocationBarViewMac::SetSecurityIconLabel() { |
458 std::wstring info_text; | 460 // TODO(shess): Separate from security icon and move icon to left of address. |
459 std::wstring info_tooltip; | 461 std::wstring security_info_text(toolbar_model_->GetSecurityInfoText()); |
460 ToolbarModel::InfoTextType info_text_type = | 462 if (security_info_text.empty()) { |
461 toolbar_model_->GetInfoText(&info_text, &info_tooltip); | 463 security_image_view_.SetLabel(nil, nil, nil); |
462 if (info_text_type == ToolbarModel::INFO_EV_TEXT) { | 464 } else { |
463 NSString* icon_label = base::SysWideToNSString(info_text); | 465 NSString* icon_label = base::SysWideToNSString(security_info_text); |
464 NSColor* color = [NSColor colorWithCalibratedRed:kEvTextColorRedComponent | 466 NSColor* color; |
465 green:kEvTextColorGreenComponent | 467 if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
466 blue:kEvTextColorBlueComponent | 468 color = [NSColor colorWithCalibratedRed:kEVSecureTextColorRedComponent |
467 alpha:1.0]; | 469 green:kEVSecureTextColorGreenComponent |
| 470 blue:kEVSecureTextColorBlueComponent |
| 471 alpha:1.0]; |
| 472 } else { |
| 473 color = |
| 474 [NSColor colorWithCalibratedRed:kSecurityErrorTextColorRedComponent |
| 475 green:kSecurityErrorTextColorGreenComponent |
| 476 blue:kSecurityErrorTextColorBlueComponent |
| 477 alpha:1.0]; |
| 478 } |
468 security_image_view_.SetLabel(icon_label, [field_ font], color); | 479 security_image_view_.SetLabel(icon_label, [field_ font], color); |
469 } else { | |
470 security_image_view_.SetLabel(nil, nil, nil); | |
471 } | 480 } |
472 } | 481 } |
473 | 482 |
474 void LocationBarViewMac::SetSecurityIcon(ToolbarModel::Icon icon) { | 483 void LocationBarViewMac::SetSecurityIcon(int resource_id) { |
475 switch (icon) { | 484 if (resource_id == 0) { |
476 case ToolbarModel::LOCK_ICON: | 485 security_image_view_.SetVisible(false); |
477 security_image_view_.SetImageShown(SecurityImageView::LOCK); | 486 } else { |
478 security_image_view_.SetVisible(true); | 487 security_image_view_.SetImageShown(resource_id); |
479 SetSecurityIconLabel(); | 488 security_image_view_.SetVisible(true); |
480 break; | 489 SetSecurityIconLabel(); |
481 case ToolbarModel::WARNING_ICON: | |
482 security_image_view_.SetImageShown(SecurityImageView::WARNING); | |
483 security_image_view_.SetVisible(true); | |
484 SetSecurityIconLabel(); | |
485 break; | |
486 case ToolbarModel::NO_ICON: | |
487 security_image_view_.SetVisible(false); | |
488 break; | |
489 default: | |
490 NOTREACHED(); | |
491 security_image_view_.SetVisible(false); | |
492 break; | |
493 } | 490 } |
494 [field_ resetFieldEditorFrameIfNeeded]; | 491 [field_ resetFieldEditorFrameIfNeeded]; |
495 } | 492 } |
496 | 493 |
497 void LocationBarViewMac::Observe(NotificationType type, | 494 void LocationBarViewMac::Observe(NotificationType type, |
498 const NotificationSource& source, | 495 const NotificationSource& source, |
499 const NotificationDetails& details) { | 496 const NotificationDetails& details) { |
500 switch (type.value) { | 497 switch (type.value) { |
501 case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: { | 498 case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: { |
502 TabContents* contents = GetTabContents(); | 499 TabContents* contents = GetTabContents(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 void LocationBarViewMac::LocationBarImageView::SetVisible(bool visible) { | 559 void LocationBarViewMac::LocationBarImageView::SetVisible(bool visible) { |
563 visible_ = visible; | 560 visible_ = visible; |
564 } | 561 } |
565 | 562 |
566 // SecurityImageView------------------------------------------------------------ | 563 // SecurityImageView------------------------------------------------------------ |
567 | 564 |
568 LocationBarViewMac::SecurityImageView::SecurityImageView( | 565 LocationBarViewMac::SecurityImageView::SecurityImageView( |
569 LocationBarViewMac* owner, | 566 LocationBarViewMac* owner, |
570 Profile* profile, | 567 Profile* profile, |
571 ToolbarModel* model) | 568 ToolbarModel* model) |
572 : lock_icon_(nil), | 569 : ev_secure_icon_(nil), |
573 warning_icon_(nil), | 570 secure_icon_(nil), |
| 571 security_warning_icon_(nil), |
| 572 security_error_icon_(nil), |
574 owner_(owner), | 573 owner_(owner), |
575 profile_(profile), | 574 profile_(profile), |
576 model_(model) {} | 575 model_(model) {} |
577 | 576 |
578 LocationBarViewMac::SecurityImageView::~SecurityImageView() {} | 577 LocationBarViewMac::SecurityImageView::~SecurityImageView() {} |
579 | 578 |
580 void LocationBarViewMac::SecurityImageView::SetImageShown(Image image) { | 579 void LocationBarViewMac::SecurityImageView::SetImageShown(int resource_id) { |
581 switch (image) { | 580 scoped_nsobject<NSImage>* icon; |
582 case LOCK: | 581 switch (resource_id) { |
583 if (!lock_icon_.get()) { | 582 case IDR_EV_SECURE: icon = &ev_secure_icon_; break; |
584 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 583 case IDR_SECURE: icon = &secure_icon_; break; |
585 lock_icon_.reset([rb.GetNSImageNamed(IDR_LOCK) retain]); | 584 case IDR_SECURITY_WARNING: icon = &security_warning_icon_; break; |
586 } | 585 case IDR_SECURITY_ERROR: icon = &security_error_icon_; break; |
587 SetImage(lock_icon_); | 586 default: NOTREACHED(); return; |
588 break; | |
589 case WARNING: | |
590 if (!warning_icon_.get()) { | |
591 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
592 warning_icon_.reset([rb.GetNSImageNamed(IDR_WARNING) retain]); | |
593 } | |
594 SetImage(warning_icon_); | |
595 break; | |
596 default: | |
597 NOTREACHED(); | |
598 break; | |
599 } | 587 } |
| 588 if (!icon->get()) { |
| 589 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 590 icon->reset([rb.GetNSImageNamed(resource_id) retain]); |
| 591 } |
| 592 SetImage(*icon); |
600 } | 593 } |
601 | 594 |
602 void LocationBarViewMac::SecurityImageView::OnMousePressed(NSRect bounds) { | 595 void LocationBarViewMac::SecurityImageView::OnMousePressed(NSRect bounds) { |
603 TabContents* tab = owner_->GetTabContents(); | 596 TabContents* tab = owner_->GetTabContents(); |
604 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); | 597 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); |
605 if (!nav_entry) { | 598 if (!nav_entry) { |
606 NOTREACHED(); | 599 NOTREACHED(); |
607 return; | 600 return; |
608 } | 601 } |
609 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); | 602 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 ++result; | 938 ++result; |
946 } | 939 } |
947 return result; | 940 return result; |
948 } | 941 } |
949 | 942 |
950 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, | 943 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, |
951 size_t index) { | 944 size_t index) { |
952 ViewAt(index)->OnMousePressed(iconFrame); | 945 ViewAt(index)->OnMousePressed(iconFrame); |
953 } | 946 } |
954 | 947 |
OLD | NEW |