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

Side by Side Diff: chrome/browser/ui/autofill/save_card_bubble_controller.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: 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.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 "content/public/browser/navigation_details.h"
12
13 namespace {
14
15 // Minimal time span the bubble should survive implicit navigations.
16 // TODO(bondd): Share with ManagePasswordsUIController.
17 const int kBubbleMinTime = 5;
18
19 } // namespace
20
21 namespace autofill {
22
23 SaveCardBubbleController::SaveCardBubbleController(
24 content::WebContents* web_contents)
25 : content::WebContentsObserver(web_contents),
26 web_contents_(web_contents),
bondd 2015/10/09 01:36:02 Is it okay to save |web_contents| off like this fo
27 state_(INACTIVE_STATE) {
28 DCHECK(web_contents);
29 }
30
31 SaveCardBubbleController::~SaveCardBubbleController() {}
32
33 void SaveCardBubbleController::ShowBubble(
34 const base::Closure& save_card_callback) {
35 save_card_callback_ = save_card_callback;
36 state_ = BUBBLE_AVAILABLE_STATE;
37 ReshowBubble();
Justin Donnelly 2015/10/13 16:25:53 This seems a little awkward. This API feels more l
bondd 2015/10/15 22:27:07 Done. I flip-flopped a couple of times between the
38 }
39
40 void SaveCardBubbleController::ReshowBubble() {
41 DCHECK_EQ(state_, BUBBLE_AVAILABLE_STATE);
42
43 // Need to create location bar icon before bubble, otherwise bubble will be
44 // unanchored.
45 state_ = BUBBLE_VISIBLE_STATE;
46 UpdateIcon();
47
48 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
49 browser->window()->ShowSaveCreditCardBubble(web_contents_, this);
50
51 timer_.reset(new base::ElapsedTimer());
52 }
53
54 void SaveCardBubbleController::OnSaveButton() {
55 save_card_callback_.Run();
56 Deactivate();
57 }
58
59 void SaveCardBubbleController::OnCancelButton() {
60 Deactivate();
61 }
62
63 void SaveCardBubbleController::OnBubbleClosed() {
64 // Do nothing if bubble has already been closed because of a button press.
65 if (state_ == INACTIVE_STATE)
66 return;
67
68 state_ = BUBBLE_AVAILABLE_STATE;
69 UpdateIcon();
70 }
71
72 bool SaveCardBubbleController::WantIconVisible() const {
73 return state_ != INACTIVE_STATE;
74 }
75
76 bool SaveCardBubbleController::WantIconToggled() const {
77 return state_ == BUBBLE_VISIBLE_STATE;
78 }
79
80 void SaveCardBubbleController::UpdateIcon() {
81 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
82 LocationBar* location_bar = browser->window()->GetLocationBar();
83 DCHECK(location_bar);
84 location_bar->UpdateSaveCreditCardIcon();
85 }
86
87 void SaveCardBubbleController::Deactivate() {
88 save_card_callback_.Reset();
89 state_ = INACTIVE_STATE;
90 UpdateIcon();
91 }
92
93 base::TimeDelta SaveCardBubbleController::Elapsed() const {
94 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max();
95 }
96
97 void SaveCardBubbleController::DidNavigateMainFrame(
bondd 2015/10/09 01:36:02 This function is based on the one in ManagePasswor
Justin Donnelly 2015/10/13 16:25:53 Is there a motivation for not resetting the timer
bondd 2015/10/15 22:27:07 Yes, I considered resetting it at the end like Man
98 const content::LoadCommittedDetails& details,
99 const content::FrameNavigateParams& params) {
100 if (state_ == INACTIVE_STATE)
101 return;
102
103 // Don't react to in-page (fragment) navigations.
104 if (details.is_in_page)
105 return;
106
107 // Don't do anything if a navigation occurs before a user could reasonably
108 // interact with the bubble.
109 if (Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime))
110 return;
111
112 // Otherwise, make the bubble and icon inactive.
113 Deactivate();
114 }
115
116 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698