OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/autofill/save_card_bubble_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
6 | 6 |
7 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" | 7 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( | 28 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( |
29 content::WebContents* web_contents) | 29 content::WebContents* web_contents) |
30 : content::WebContentsObserver(web_contents), | 30 : content::WebContentsObserver(web_contents), |
31 save_card_bubble_view_(nullptr) { | 31 save_card_bubble_view_(nullptr) { |
32 DCHECK(web_contents); | 32 DCHECK(web_contents); |
33 } | 33 } |
34 | 34 |
35 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { | 35 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { |
36 if (save_card_bubble_view_) | 36 if (save_card_bubble_view_) |
37 save_card_bubble_view_->ControllerGone(); | 37 save_card_bubble_view_->Hide(); |
38 } | 38 } |
39 | 39 |
40 void SaveCardBubbleControllerImpl::SetCallback( | 40 void SaveCardBubbleControllerImpl::SetCallback( |
41 const base::Closure& save_card_callback) { | 41 const base::Closure& save_card_callback) { |
42 save_card_callback_ = save_card_callback; | 42 save_card_callback_ = save_card_callback; |
43 } | 43 } |
44 | 44 |
45 void SaveCardBubbleControllerImpl::ShowBubble() { | 45 void SaveCardBubbleControllerImpl::ShowBubble(bool user_action) { |
46 DCHECK(!save_card_callback_.is_null()); | 46 DCHECK(!save_card_callback_.is_null()); |
47 | 47 |
48 // Need to create location bar icon before bubble, otherwise bubble will be | 48 // Need to create location bar icon before bubble, otherwise bubble will be |
49 // unanchored. | 49 // unanchored. |
50 UpdateIcon(); | 50 UpdateIcon(); |
51 | 51 |
52 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 52 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
53 save_card_bubble_view_ = | 53 save_card_bubble_view_ = browser->window()->ShowSaveCreditCardBubble( |
54 browser->window()->ShowSaveCreditCardBubble(web_contents(), this); | 54 web_contents(), this, user_action); |
55 DCHECK(save_card_bubble_view_); | 55 DCHECK(save_card_bubble_view_); |
56 | 56 |
57 // Update icon after creating |save_card_bubble_view_| so that icon will show | 57 // Update icon after creating |save_card_bubble_view_| so that icon will show |
58 // its "toggled on" state. | 58 // its "toggled on" state. |
59 UpdateIcon(); | 59 UpdateIcon(); |
60 | 60 |
61 timer_.reset(new base::ElapsedTimer()); | 61 timer_.reset(new base::ElapsedTimer()); |
62 } | 62 } |
63 | 63 |
64 bool SaveCardBubbleControllerImpl::IsIconVisible() const { | 64 bool SaveCardBubbleControllerImpl::IsIconVisible() const { |
65 return !save_card_callback_.is_null(); | 65 return !save_card_callback_.is_null(); |
66 } | 66 } |
67 | 67 |
68 bool SaveCardBubbleControllerImpl::IsIconToggled() const { | |
69 return !!save_card_bubble_view_; | |
70 } | |
71 | |
72 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() | 68 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() |
73 const { | 69 const { |
74 return save_card_bubble_view_; | 70 return save_card_bubble_view_; |
75 } | 71 } |
76 | 72 |
77 void SaveCardBubbleControllerImpl::OnSaveButton() { | 73 void SaveCardBubbleControllerImpl::OnSaveButton() { |
78 save_card_callback_.Run(); | 74 save_card_callback_.Run(); |
79 save_card_callback_.Reset(); | 75 save_card_callback_.Reset(); |
80 } | 76 } |
81 | 77 |
(...skipping 30 matching lines...) Expand all Loading... |
112 return; | 108 return; |
113 | 109 |
114 // Don't do anything if a navigation occurs before a user could reasonably | 110 // Don't do anything if a navigation occurs before a user could reasonably |
115 // interact with the bubble. | 111 // interact with the bubble. |
116 if (timer_->Elapsed() < | 112 if (timer_->Elapsed() < |
117 base::TimeDelta::FromSeconds(kSurviveNavigationSeconds)) | 113 base::TimeDelta::FromSeconds(kSurviveNavigationSeconds)) |
118 return; | 114 return; |
119 | 115 |
120 // Otherwise, get rid of the bubble and icon. | 116 // Otherwise, get rid of the bubble and icon. |
121 save_card_callback_.Reset(); | 117 save_card_callback_.Reset(); |
122 if (save_card_bubble_view_) | 118 if (save_card_bubble_view_) { |
123 save_card_bubble_view_->Close(); | 119 save_card_bubble_view_->Hide(); |
124 else | 120 OnBubbleClosed(); |
| 121 } else { |
125 UpdateIcon(); | 122 UpdateIcon(); |
| 123 } |
126 } | 124 } |
127 | 125 |
128 } // namespace autofill | 126 } // namespace autofill |
OLD | NEW |