OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "components/autofill/core/browser/autofill_metrics.h" | 13 #include "components/autofill/core/browser/autofill_metrics.h" |
14 #include "components/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
15 #include "ui/base/window_open_disposition.h" | 15 #include "ui/base/window_open_disposition.h" |
16 | 16 |
17 class CreditCard; | 17 namespace infobars { |
18 class PersonalDataManager; | 18 class InfoBarManager; |
19 class InfoBarService; | 19 } |
20 | 20 |
21 namespace autofill { | 21 namespace autofill { |
22 | 22 |
23 class AutofillDriver; | |
24 | |
23 // An InfoBar delegate that enables the user to allow or deny storing credit | 25 // An InfoBar delegate that enables the user to allow or deny storing credit |
24 // card information gathered from a form submission. | 26 // card information gathered from a form submission. |
25 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { | 27 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { |
26 public: | 28 public: |
27 // Creates an autofill credit card infobar and delegate and adds the infobar | 29 // Creates an autofill credit card infobar and delegate and add the infobar |
Peter Kasting
2014/12/29 22:24:30
The old comment was correct (except for using info
Pritam Nikam
2014/12/30 13:22:14
Done.
| |
28 // to |infobar_service|. | 30 // and associated |autofill_driver| to the |infobar_manager|. |
29 static void Create(InfoBarService* infobar_service, | 31 static void Create(infobars::InfoBarManager* infobar_manager, |
32 AutofillDriver* autofill_driver, | |
30 const base::Closure& save_card_callback); | 33 const base::Closure& save_card_callback); |
31 | 34 |
32 #if defined(UNIT_TEST) | 35 #if defined(UNIT_TEST) |
33 static scoped_ptr<ConfirmInfoBarDelegate> Create( | 36 static scoped_ptr<ConfirmInfoBarDelegate> Create( |
37 AutofillDriver* autofill_driver, | |
34 const base::Closure& save_card_callback) { | 38 const base::Closure& save_card_callback) { |
35 return scoped_ptr<ConfirmInfoBarDelegate>( | 39 return scoped_ptr<ConfirmInfoBarDelegate>( |
36 new AutofillCCInfoBarDelegate(save_card_callback)); | 40 new AutofillCCInfoBarDelegate(autofill_driver, save_card_callback)); |
37 } | 41 } |
38 #endif | 42 #endif |
39 | 43 |
40 private: | 44 private: |
41 explicit AutofillCCInfoBarDelegate(const base::Closure& save_card_callback); | 45 AutofillCCInfoBarDelegate(AutofillDriver* autofill_driver, |
46 const base::Closure& save_card_callback); | |
42 ~AutofillCCInfoBarDelegate() override; | 47 ~AutofillCCInfoBarDelegate() override; |
43 | 48 |
44 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); | 49 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); |
45 | 50 |
46 // ConfirmInfoBarDelegate: | 51 // ConfirmInfoBarDelegate: |
47 void InfoBarDismissed() override; | 52 void InfoBarDismissed() override; |
48 int GetIconID() const override; | 53 int GetIconID() const override; |
49 Type GetInfoBarType() const override; | 54 Type GetInfoBarType() const override; |
50 bool ShouldExpireInternal(const NavigationDetails& details) const override; | 55 bool ShouldExpireInternal(const NavigationDetails& details) const override; |
51 base::string16 GetMessageText() const override; | 56 base::string16 GetMessageText() const override; |
52 base::string16 GetButtonLabel(InfoBarButton button) const override; | 57 base::string16 GetButtonLabel(InfoBarButton button) const override; |
53 bool Accept() override; | 58 bool Accept() override; |
54 bool Cancel() override; | 59 bool Cancel() override; |
55 base::string16 GetLinkText() const override; | 60 base::string16 GetLinkText() const override; |
56 bool LinkClicked(WindowOpenDisposition disposition) override; | 61 bool LinkClicked(WindowOpenDisposition disposition) override; |
57 | 62 |
63 // Performs navigation to handle any link click. |autofill_driver_| is not | |
64 // owned and does not garantee to outlive the lifetime of |this| object. So | |
65 // care must be taken to avoid any unsafe access. Hence, instaed of using raw | |
66 // |autofill_driver_| pointers, it's recommended here to content within | |
67 // base::WeakPtr<>. E.g. AutofillDriver object associated to a form inside an | |
68 // iframe may get destroy long before the main frame (its tab). Apparantly, | |
69 // caching raw |autofill_driver_| pointer instead would be unsafe, performing | |
70 // LinkClinked() from infobar would be catastrophic. | |
Peter Kasting
2014/12/29 22:24:30
This comment is confusing, in part because of its
Pritam Nikam
2014/12/30 13:22:14
Sorry for confusion! maybe I didn't phrase it corr
Peter Kasting
2014/12/30 18:57:27
You keep speaking in abstract/hypothetical terms.
| |
71 base::WeakPtr<AutofillDriver> autofill_driver_; | |
72 | |
58 // The callback to save credit card if the user accepts the infobar. | 73 // The callback to save credit card if the user accepts the infobar. |
59 base::Closure save_card_callback_; | 74 base::Closure save_card_callback_; |
60 | 75 |
61 // Did the user ever explicitly accept or dismiss this infobar? | 76 // Did the user ever explicitly accept or dismiss this infobar? |
62 bool had_user_interaction_; | 77 bool had_user_interaction_; |
63 | 78 |
64 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); | 79 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); |
65 | 80 |
66 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); | 81 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); |
67 }; | 82 }; |
68 | 83 |
69 } // namespace autofill | 84 } // namespace autofill |
70 | 85 |
71 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 86 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
OLD | NEW |