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

Side by Side Diff: chrome/browser/ui/autofill/save_card_bubble_controller_impl.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: Change object lifecycles + add interface classes. 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
6
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/location_bar/location_bar.h"
11 #include "components/autofill/core/browser/ui/save_card_bubble_view.h"
12 #include "content/public/browser/navigation_details.h"
13
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl);
15
16 namespace {
17
18 // Minimal time span the bubble should survive implicit navigations.
19 // TODO(bondd): Share with ManagePasswordsUIController.
20 const int kBubbleMinTime = 5;
21
22 } // namespace
23
24 namespace autofill {
25
26 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl(
27 content::WebContents* web_contents)
28 : content::WebContentsObserver(web_contents),
29 web_contents_(web_contents),
30 save_card_bubble_view_(nullptr),
31 state_(INACTIVE_STATE) {
32 DCHECK(web_contents);
33 }
34
35 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() {
36 if (save_card_bubble_view_)
37 save_card_bubble_view_->ControllerGone();
38 }
39
40 void SaveCardBubbleControllerImpl::CreateBubble(
Evan Stade 2015/10/16 01:20:44 CreateAndShow, and Show below, since you should ne
Justin Donnelly 2015/10/19 17:39:08 At the risk of going full bikeshed, I think you're
Evan Stade 2015/10/19 17:58:31 Sure, in fact my final suggestion did not include
bondd 2015/10/22 02:15:17 Done.
41 const base::Closure& save_card_callback) {
42 save_card_callback_ = save_card_callback;
43 state_ = BUBBLE_AVAILABLE_STATE;
44 }
45
46 void SaveCardBubbleControllerImpl::ShowBubble() {
47 DCHECK_EQ(state_, BUBBLE_AVAILABLE_STATE);
48
49 // Need to create location bar icon before bubble, otherwise bubble will be
hcarmona 2015/10/16 21:16:35 What happens if the location bar isn't visible? Li
bondd 2015/10/22 02:15:17 In fullscreen the arrow points up toward where the
50 // unanchored.
51 state_ = BUBBLE_VISIBLE_STATE;
52 UpdateIcon();
53
54 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
55 save_card_bubble_view_ =
56 browser->window()->ShowSaveCreditCardBubble(web_contents_, this);
57 DCHECK(save_card_bubble_view_);
58
59 timer_.reset(new base::ElapsedTimer());
60 }
61
62 void SaveCardBubbleControllerImpl::OnSaveButton() {
63 save_card_callback_.Run();
64 Deactivate();
65 }
66
67 void SaveCardBubbleControllerImpl::OnCancelButton() {
68 Deactivate();
69 }
70
71 void SaveCardBubbleControllerImpl::OnBubbleClosed() {
72 // Do nothing if bubble has already been closed because of a button press.
73 if (state_ == INACTIVE_STATE)
74 return;
75
76 state_ = BUBBLE_AVAILABLE_STATE;
77 save_card_bubble_view_ = nullptr;
78 UpdateIcon();
79 }
80
81 bool SaveCardBubbleControllerImpl::IsIconVisible() const {
82 return state_ != INACTIVE_STATE;
83 }
84
85 bool SaveCardBubbleControllerImpl::IsIconToggled() const {
86 return state_ == BUBBLE_VISIBLE_STATE;
87 }
88
89 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view()
90 const {
91 return save_card_bubble_view_;
92 }
93
94 void SaveCardBubbleControllerImpl::UpdateIcon() {
95 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
96 LocationBar* location_bar = browser->window()->GetLocationBar();
97 DCHECK(location_bar);
98 location_bar->UpdateSaveCreditCardIcon();
99 }
100
101 void SaveCardBubbleControllerImpl::Deactivate() {
102 save_card_callback_.Reset();
103 state_ = INACTIVE_STATE;
104 save_card_bubble_view_ = nullptr;
105 UpdateIcon();
106 }
107
108 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const {
109 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max();
Evan Stade 2015/10/16 01:20:44 not a particularly useful method IMO. I expect you
bondd 2015/10/22 02:15:17 Done.
110 }
111
112 void SaveCardBubbleControllerImpl::DidNavigateMainFrame(
113 const content::LoadCommittedDetails& details,
114 const content::FrameNavigateParams& params) {
115 if (state_ == INACTIVE_STATE)
116 return;
117
118 // Don't react to in-page (fragment) navigations.
119 if (details.is_in_page)
120 return;
121
122 // Don't do anything if a navigation occurs before a user could reasonably
123 // interact with the bubble.
124 if (Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime))
Evan Stade 2015/10/16 01:20:43 can just be if (timer_ && timer_->Elapsed() < ...
bondd 2015/10/22 02:15:17 Done.
125 return;
126
127 // Otherwise, make the bubble and icon inactive.
128 if (save_card_bubble_view_)
129 save_card_bubble_view_->Close();
130 Deactivate();
131 }
132
133 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698