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 #ifndef CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/timer/elapsed_timer.h" | 11 #include "base/timer/elapsed_timer.h" |
12 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" | |
13 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
16 | 16 |
17 namespace autofill { | 17 namespace autofill { |
18 | 18 |
19 // Implementation of per-tab class to control the save credit card bubble and | 19 // Implementation of per-tab class to control the save credit card bubble and |
20 // Omnibox icon. | 20 // Omnibox icon. |
21 class SaveCardBubbleControllerImpl | 21 class SaveCardBubbleControllerImpl |
22 : public SaveCardBubbleController, | 22 : public SaveCardBubbleController, |
23 public content::WebContentsObserver, | 23 public content::WebContentsObserver, |
24 public content::WebContentsUserData<SaveCardBubbleControllerImpl> { | 24 public content::WebContentsUserData<SaveCardBubbleControllerImpl> { |
25 public: | 25 public: |
26 // Sets up the controller for local save and shows the bubble. | 26 // Sets up the controller for local save and shows the bubble. |
27 // |save_card_callback| will be invoked if and when the Save button is | 27 // |save_card_callback| will be invoked if and when the Save button is |
28 // pressed. | 28 // pressed. |
29 void ShowBubbleForLocalSave(const CreditCard& card, | 29 void ShowBubbleForLocalSave(const CreditCard& card, |
30 const base::Closure& save_card_callback); | 30 const base::Closure& save_card_callback); |
31 | 31 |
32 // Sets up the controller for upload and shows the bubble. | 32 // Sets up the controller for upload and shows the bubble. |
33 // |save_card_callback| will be invoked if and when the Save button is | 33 // |save_card_callback| will be invoked if and when the Save button is |
34 // pressed. The contents of |legal_message| will be displayed in the bubble. | 34 // pressed. The contents of |legal_message| will be displayed in the bubble. |
| 35 // A field requesting CVC will appear in the bubble if |
| 36 // |should_cvc_be_requested| is true. |
35 void ShowBubbleForUpload(const CreditCard& card, | 37 void ShowBubbleForUpload(const CreditCard& card, |
36 std::unique_ptr<base::DictionaryValue> legal_message, | 38 std::unique_ptr<base::DictionaryValue> legal_message, |
| 39 bool should_cvc_be_requested, |
37 const base::Closure& save_card_callback); | 40 const base::Closure& save_card_callback); |
38 | 41 |
39 void HideBubble(); | 42 void HideBubble(); |
40 void ReshowBubble(); | 43 void ReshowBubble(); |
41 | 44 |
42 // Returns true if Omnibox save credit card icon should be visible. | 45 // Returns true if Omnibox save credit card icon should be visible. |
43 bool IsIconVisible() const; | 46 bool IsIconVisible() const; |
44 | 47 |
45 // Returns nullptr if no bubble is currently shown. | 48 // Returns nullptr if no bubble is currently shown. |
46 SaveCardBubbleView* save_card_bubble_view() const; | 49 SaveCardBubbleView* save_card_bubble_view() const; |
47 | 50 |
48 // SaveCardBubbleController: | 51 // SaveCardBubbleController: |
49 base::string16 GetWindowTitle() const override; | 52 base::string16 GetWindowTitle() const override; |
50 base::string16 GetExplanatoryMessage() const override; | 53 base::string16 GetExplanatoryMessage() const override; |
51 const CreditCard GetCard() const override; | 54 const CreditCard GetCard() const override; |
| 55 int GetCvcImageResourceId() const override; |
| 56 bool ShouldRequestCvcFromUser() const override; |
| 57 void SetCvcEnteredByUser(const base::string16& cvc) override; |
| 58 base::string16 GetCvcEnteredByUser() const override; |
52 void OnSaveButton() override; | 59 void OnSaveButton() override; |
53 void OnCancelButton() override; | 60 void OnCancelButton() override; |
54 void OnLearnMoreClicked() override; | 61 void OnLearnMoreClicked() override; |
55 void OnLegalMessageLinkClicked(const GURL& url) override; | 62 void OnLegalMessageLinkClicked(const GURL& url) override; |
56 void OnBubbleClosed() override; | 63 void OnBubbleClosed() override; |
57 | 64 |
58 const LegalMessageLines& GetLegalMessageLines() const override; | 65 const LegalMessageLines& GetLegalMessageLines() const override; |
59 | 66 |
| 67 // Used to check if an entered CVC value is a valid CVC for the current card. |
| 68 // Valid CVCs are a certain length for their card type (4 for AMEX, 3 |
| 69 // otherwise) and are comprised only of numbers. |
| 70 bool InputCvcIsValid(const base::string16& input_text) const override; |
| 71 |
60 protected: | 72 protected: |
61 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); | 73 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); |
62 ~SaveCardBubbleControllerImpl() override; | 74 ~SaveCardBubbleControllerImpl() override; |
63 | 75 |
64 // Returns the time elapsed since |timer_| was initialized. | 76 // Returns the time elapsed since |timer_| was initialized. |
65 // Exists for testing. | 77 // Exists for testing. |
66 virtual base::TimeDelta Elapsed() const; | 78 virtual base::TimeDelta Elapsed() const; |
67 | 79 |
68 // content::WebContentsObserver: | 80 // content::WebContentsObserver: |
69 void DidFinishNavigation( | 81 void DidFinishNavigation( |
(...skipping 16 matching lines...) Expand all Loading... |
86 // If save_card_callback_.is_null() is true then no bubble is available to | 98 // If save_card_callback_.is_null() is true then no bubble is available to |
87 // show and the icon is not visible. | 99 // show and the icon is not visible. |
88 base::Closure save_card_callback_; | 100 base::Closure save_card_callback_; |
89 | 101 |
90 // Governs whether the upload or local save version of the UI should be shown. | 102 // Governs whether the upload or local save version of the UI should be shown. |
91 bool is_uploading_; | 103 bool is_uploading_; |
92 | 104 |
93 // Whether ReshowBubble() has been called since ShowBubbleFor*() was called. | 105 // Whether ReshowBubble() has been called since ShowBubbleFor*() was called. |
94 bool is_reshow_; | 106 bool is_reshow_; |
95 | 107 |
| 108 // Whether the upload save version of the UI should ask the user for CVC. |
| 109 bool should_cvc_be_requested_; |
| 110 |
| 111 // The value of the CVC entered by the user (if it was requested). |
| 112 base::string16 cvc_entered_by_user_; |
| 113 |
96 // Contains the details of the card that will be saved if the user accepts. | 114 // Contains the details of the card that will be saved if the user accepts. |
97 CreditCard card_; | 115 CreditCard card_; |
98 | 116 |
99 // If no legal message should be shown then this variable is an empty vector. | 117 // If no legal message should be shown then this variable is an empty vector. |
100 LegalMessageLines legal_message_lines_; | 118 LegalMessageLines legal_message_lines_; |
101 | 119 |
102 // Used to measure the amount of time on a page; if it's less than some | 120 // Used to measure the amount of time on a page; if it's less than some |
103 // reasonable limit, then don't close the bubble upon navigation. | 121 // reasonable limit, then don't close the bubble upon navigation. |
104 std::unique_ptr<base::ElapsedTimer> timer_; | 122 std::unique_ptr<base::ElapsedTimer> timer_; |
105 | 123 |
106 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); | 124 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); |
107 }; | 125 }; |
108 | 126 |
109 } // namespace autofill | 127 } // namespace autofill |
110 | 128 |
111 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 129 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
OLD | NEW |