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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1396923003: Autofill: Replace "save credit card" infobar with a bubble (Views only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak SaveCardBubbleControllerImpl::DidNavigateMainFrame logic. Created 5 years, 2 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/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/command_updater.h" 15 #include "chrome/browser/command_updater.h"
16 #include "chrome/browser/defaults.h" 16 #include "chrome/browser/defaults.h"
17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
18 #include "chrome/browser/extensions/extension_action.h" 18 #include "chrome/browser/extensions/extension_action.h"
19 #include "chrome/browser/extensions/extension_action_manager.h" 19 #include "chrome/browser/extensions/extension_action_manager.h"
20 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
21 #include "chrome/browser/extensions/location_bar_controller.h" 21 #include "chrome/browser/extensions/location_bar_controller.h"
22 #include "chrome/browser/extensions/tab_helper.h" 22 #include "chrome/browser/extensions/tab_helper.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/search/instant_service.h" 24 #include "chrome/browser/search/instant_service.h"
25 #include "chrome/browser/search/instant_service_factory.h" 25 #include "chrome/browser/search/instant_service_factory.h"
26 #include "chrome/browser/search/search.h" 26 #include "chrome/browser/search/search.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 27 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/translate/chrome_translate_client.h" 28 #include "chrome/browser/translate/chrome_translate_client.h"
29 #include "chrome/browser/translate/translate_service.h" 29 #include "chrome/browser/translate/translate_service.h"
30 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
30 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_instant_controller.h" 33 #include "chrome/browser/ui/browser_instant_controller.h"
33 #include "chrome/browser/ui/browser_window.h" 34 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
35 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" 37 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/browser/ui/view_ids.h" 38 #include "chrome/browser/ui/view_ids.h"
38 #include "chrome/browser/ui/views/browser_dialogs.h" 39 #include "chrome/browser/ui/views/browser_dialogs.h"
39 #include "chrome/browser/ui/views/layout_constants.h" 40 #include "chrome/browser/ui/views/layout_constants.h"
40 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
41 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
42 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
43 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
44 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
45 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
49 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h"
48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 50 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
49 #include "chrome/browser/ui/views/location_bar/star_view.h" 51 #include "chrome/browser/ui/views/location_bar/star_view.h"
50 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 52 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 53 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
52 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 54 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
53 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 55 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
54 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" 56 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h"
55 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" 57 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
56 #include "chrome/grit/generated_resources.h" 58 #include "chrome/grit/generated_resources.h"
57 #include "components/bookmarks/common/bookmark_pref_names.h" 59 #include "components/bookmarks/common/bookmark_pref_names.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 location_icon_view_(NULL), 138 location_icon_view_(NULL),
137 ev_bubble_view_(NULL), 139 ev_bubble_view_(NULL),
138 ime_inline_autocomplete_view_(NULL), 140 ime_inline_autocomplete_view_(NULL),
139 selected_keyword_view_(NULL), 141 selected_keyword_view_(NULL),
140 suggested_text_view_(NULL), 142 suggested_text_view_(NULL),
141 keyword_hint_view_(NULL), 143 keyword_hint_view_(NULL),
142 mic_search_view_(NULL), 144 mic_search_view_(NULL),
143 zoom_view_(NULL), 145 zoom_view_(NULL),
144 open_pdf_in_reader_view_(NULL), 146 open_pdf_in_reader_view_(NULL),
145 manage_passwords_icon_view_(NULL), 147 manage_passwords_icon_view_(NULL),
148 save_credit_card_icon_view_(NULL),
sky 2015/10/26 20:56:26 nullptr
bondd 2015/10/27 01:06:39 Done. I had originally used NULL to match the surr
146 translate_icon_view_(NULL), 149 translate_icon_view_(NULL),
147 star_view_(NULL), 150 star_view_(NULL),
148 size_animation_(this), 151 size_animation_(this),
149 is_popup_mode_(is_popup_mode), 152 is_popup_mode_(is_popup_mode),
150 show_focus_rect_(false), 153 show_focus_rect_(false),
151 template_url_service_(NULL), 154 template_url_service_(NULL),
152 dropdown_animation_offset_(0), 155 dropdown_animation_offset_(0),
153 web_contents_null_at_last_refresh_(true) { 156 web_contents_null_at_last_refresh_(true) {
154 edit_bookmarks_enabled_.Init( 157 edit_bookmarks_enabled_.Init(
155 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 158 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 303
301 zoom_view_ = new ZoomView(delegate_); 304 zoom_view_ = new ZoomView(delegate_);
302 AddChildView(zoom_view_); 305 AddChildView(zoom_view_);
303 306
304 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); 307 open_pdf_in_reader_view_ = new OpenPDFInReaderView();
305 AddChildView(open_pdf_in_reader_view_); 308 AddChildView(open_pdf_in_reader_view_);
306 309
307 manage_passwords_icon_view_ = new ManagePasswordsIconViews(command_updater()); 310 manage_passwords_icon_view_ = new ManagePasswordsIconViews(command_updater());
308 AddChildView(manage_passwords_icon_view_); 311 AddChildView(manage_passwords_icon_view_);
309 312
313 save_credit_card_icon_view_ =
314 new SaveCreditCardIconView(command_updater(), browser_);
315 save_credit_card_icon_view_->SetVisible(false);
316 AddChildView(save_credit_card_icon_view_);
317
310 translate_icon_view_ = new TranslateIconView(command_updater()); 318 translate_icon_view_ = new TranslateIconView(command_updater());
311 translate_icon_view_->SetVisible(false); 319 translate_icon_view_->SetVisible(false);
312 AddChildView(translate_icon_view_); 320 AddChildView(translate_icon_view_);
313 321
314 star_view_ = new StarView(command_updater(), browser_); 322 star_view_ = new StarView(command_updater(), browser_);
315 star_view_->SetVisible(false); 323 star_view_->SetVisible(false);
316 AddChildView(star_view_); 324 AddChildView(star_view_);
317 325
318 // Initialize the location entry. We do this to avoid a black flash which is 326 // Initialize the location entry. We do this to avoid a black flash which is
319 // visible when the location entry has just been initialized. 327 // visible when the location entry has just been initialized.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 GetToolbarModel()->GetEVCertName()).width(); 574 GetToolbarModel()->GetEVCertName()).width();
567 } else { 575 } else {
568 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 576 leading_width += padding + location_icon_view_->GetMinimumSize().width();
569 } 577 }
570 578
571 // Compute width of omnibox-trailing content. 579 // Compute width of omnibox-trailing content.
572 int trailing_width = horizontal_edge_thickness; 580 int trailing_width = horizontal_edge_thickness;
573 trailing_width += IncrementalMinimumWidth(star_view_) + 581 trailing_width += IncrementalMinimumWidth(star_view_) +
574 IncrementalMinimumWidth(translate_icon_view_) + 582 IncrementalMinimumWidth(translate_icon_view_) +
575 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 583 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
584 IncrementalMinimumWidth(save_credit_card_icon_view_) +
576 IncrementalMinimumWidth(manage_passwords_icon_view_) + 585 IncrementalMinimumWidth(manage_passwords_icon_view_) +
577 IncrementalMinimumWidth(zoom_view_) + 586 IncrementalMinimumWidth(zoom_view_) +
578 IncrementalMinimumWidth(mic_search_view_); 587 IncrementalMinimumWidth(mic_search_view_);
579 for (PageActionViews::const_iterator i(page_action_views_.begin()); 588 for (PageActionViews::const_iterator i(page_action_views_.begin());
580 i != page_action_views_.end(); ++i) 589 i != page_action_views_.end(); ++i)
581 trailing_width += IncrementalMinimumWidth((*i)); 590 trailing_width += IncrementalMinimumWidth((*i));
582 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 591 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
583 i != content_setting_views_.end(); ++i) 592 i != content_setting_views_.end(); ++i)
584 trailing_width += IncrementalMinimumWidth((*i)); 593 trailing_width += IncrementalMinimumWidth((*i));
585 594
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 star_view_); 673 star_view_);
665 } 674 }
666 if (translate_icon_view_->visible()) { 675 if (translate_icon_view_->visible()) {
667 trailing_decorations.AddDecoration(vertical_padding, location_height, 676 trailing_decorations.AddDecoration(vertical_padding, location_height,
668 translate_icon_view_); 677 translate_icon_view_);
669 } 678 }
670 if (open_pdf_in_reader_view_->visible()) { 679 if (open_pdf_in_reader_view_->visible()) {
671 trailing_decorations.AddDecoration(vertical_padding, location_height, 680 trailing_decorations.AddDecoration(vertical_padding, location_height,
672 open_pdf_in_reader_view_); 681 open_pdf_in_reader_view_);
673 } 682 }
683 if (save_credit_card_icon_view_->visible()) {
684 trailing_decorations.AddDecoration(vertical_padding, location_height,
685 save_credit_card_icon_view_);
686 }
674 if (manage_passwords_icon_view_->visible()) { 687 if (manage_passwords_icon_view_->visible()) {
675 trailing_decorations.AddDecoration(vertical_padding, location_height, 688 trailing_decorations.AddDecoration(vertical_padding, location_height,
676 manage_passwords_icon_view_); 689 manage_passwords_icon_view_);
677 } 690 }
678 for (PageActionViews::const_iterator i(page_action_views_.begin()); 691 for (PageActionViews::const_iterator i(page_action_views_.begin());
679 i != page_action_views_.end(); ++i) { 692 i != page_action_views_.end(); ++i) {
680 if ((*i)->visible()) { 693 if ((*i)->visible()) {
681 trailing_decorations.AddDecoration(vertical_padding, location_height, 694 trailing_decorations.AddDecoration(vertical_padding, location_height,
682 (*i)); 695 (*i));
683 } 696 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 } 822 }
810 823
811 void LocationBarView::Update(const WebContents* contents) { 824 void LocationBarView::Update(const WebContents* contents) {
812 mic_search_view_->SetVisible( 825 mic_search_view_->SetVisible(
813 !GetToolbarModel()->input_in_progress() && browser_ && 826 !GetToolbarModel()->input_in_progress() && browser_ &&
814 browser_->search_model()->voice_search_supported()); 827 browser_->search_model()->voice_search_supported());
815 RefreshContentSettingViews(); 828 RefreshContentSettingViews();
816 RefreshZoomView(); 829 RefreshZoomView();
817 RefreshPageActionViews(); 830 RefreshPageActionViews();
818 RefreshTranslateIcon(); 831 RefreshTranslateIcon();
832 RefreshSaveCreditCardIconView();
819 RefreshManagePasswordsIconView(); 833 RefreshManagePasswordsIconView();
820 content::WebContents* web_contents_for_sub_views = 834 content::WebContents* web_contents_for_sub_views =
821 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); 835 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents();
822 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 836 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
823 837
824 if (star_view_) 838 if (star_view_)
825 UpdateBookmarkStarVisibility(); 839 UpdateBookmarkStarVisibility();
826 840
827 if (contents) 841 if (contents)
828 omnibox_view_->OnTabChanged(contents); 842 omnibox_view_->OnTabChanged(contents);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); 996 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents));
983 if (!zoom_view_->visible()) 997 if (!zoom_view_->visible())
984 ZoomBubbleView::CloseBubble(); 998 ZoomBubbleView::CloseBubble();
985 return was_visible != zoom_view_->visible(); 999 return was_visible != zoom_view_->visible();
986 } 1000 }
987 1001
988 void LocationBarView::OnDefaultZoomLevelChanged() { 1002 void LocationBarView::OnDefaultZoomLevelChanged() {
989 RefreshZoomView(); 1003 RefreshZoomView();
990 } 1004 }
991 1005
1006 bool LocationBarView::RefreshSaveCreditCardIconView() {
1007 WebContents* web_contents = GetWebContents();
1008 if (!web_contents)
1009 return false;
1010
1011 const bool was_visible = save_credit_card_icon_view_->visible();
1012 // |controller| may be nullptr due to lazy initialization.
1013 autofill::SaveCardBubbleControllerImpl* controller =
1014 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents);
1015 bool enabled = controller && controller->IsIconVisible();
1016 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE,
1017 enabled);
1018 save_credit_card_icon_view_->SetVisible(enabled);
1019 if (enabled)
1020 save_credit_card_icon_view_->SetToggled(controller->IsIconToggled());
1021
1022 return was_visible != save_credit_card_icon_view_->visible();
1023 }
1024
992 void LocationBarView::RefreshTranslateIcon() { 1025 void LocationBarView::RefreshTranslateIcon() {
993 WebContents* web_contents = GetWebContents(); 1026 WebContents* web_contents = GetWebContents();
994 if (!web_contents) 1027 if (!web_contents)
995 return; 1028 return;
996 translate::LanguageState& language_state = 1029 translate::LanguageState& language_state =
997 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); 1030 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState();
998 bool enabled = language_state.translate_enabled(); 1031 bool enabled = language_state.translate_enabled();
999 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); 1032 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
1000 translate_icon_view_->SetVisible(enabled); 1033 translate_icon_view_->SetVisible(enabled);
1001 translate_icon_view_->SetToggled(language_state.IsPageTranslated()); 1034 translate_icon_view_->SetToggled(language_state.IsPageTranslated());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 } 1120 }
1088 } 1121 }
1089 1122
1090 void LocationBarView::UpdateManagePasswordsIconAndBubble() { 1123 void LocationBarView::UpdateManagePasswordsIconAndBubble() {
1091 if (RefreshManagePasswordsIconView()) { 1124 if (RefreshManagePasswordsIconView()) {
1092 Layout(); 1125 Layout();
1093 SchedulePaint(); 1126 SchedulePaint();
1094 } 1127 }
1095 } 1128 }
1096 1129
1130 void LocationBarView::UpdateSaveCreditCardIcon() {
1131 if (RefreshSaveCreditCardIconView()) {
1132 Layout();
1133 SchedulePaint();
1134 }
1135 }
1136
1097 void LocationBarView::UpdatePageActions() { 1137 void LocationBarView::UpdatePageActions() {
1098 if (RefreshPageActionViews()) { // Changed. 1138 if (RefreshPageActionViews()) { // Changed.
1099 Layout(); 1139 Layout();
1100 SchedulePaint(); 1140 SchedulePaint();
1101 } 1141 }
1102 } 1142 }
1103 1143
1104 void LocationBarView::UpdateBookmarkStarVisibility() { 1144 void LocationBarView::UpdateBookmarkStarVisibility() {
1105 if (star_view_) { 1145 if (star_view_) {
1106 star_view_->SetVisible( 1146 star_view_->SetVisible(
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 1458
1419 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1459 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1420 const SearchModel::State& new_state) { 1460 const SearchModel::State& new_state) {
1421 const bool visible = !GetToolbarModel()->input_in_progress() && 1461 const bool visible = !GetToolbarModel()->input_in_progress() &&
1422 new_state.voice_search_supported; 1462 new_state.voice_search_supported;
1423 if (mic_search_view_->visible() != visible) { 1463 if (mic_search_view_->visible() != visible) {
1424 mic_search_view_->SetVisible(visible); 1464 mic_search_view_->SetVisible(visible);
1425 Layout(); 1465 Layout();
1426 } 1466 }
1427 } 1467 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698