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 "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
11 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" | 11 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 | 16 |
17 // Implementation of per-tab class to control the save credit card bubble and | 17 // Implementation of per-tab class to control the save credit card bubble and |
18 // Omnibox icon. | 18 // Omnibox icon. |
19 // | 19 // |
20 // TODO(bondd): Add text strings so different dialog contents can be shown | 20 // TODO(bondd): Add text strings so different dialog contents can be shown |
21 // depending upon whether upstreaming is available. | 21 // depending upon whether upstreaming is available. |
22 class SaveCardBubbleControllerImpl | 22 class SaveCardBubbleControllerImpl |
23 : public SaveCardBubbleController, | 23 : public SaveCardBubbleController, |
24 public content::WebContentsObserver, | 24 public content::WebContentsObserver, |
25 public content::WebContentsUserData<SaveCardBubbleControllerImpl> { | 25 public content::WebContentsUserData<SaveCardBubbleControllerImpl> { |
26 public: | 26 public: |
27 // |save_card_callback| will be invoked if/when the Save button is pressed. | 27 // |save_card_callback| will be invoked if/when the Save button is pressed. |
28 void SetCallback(const base::Closure& save_card_callback); | 28 void SetCallback(const base::Closure& save_card_callback); |
29 | 29 |
| 30 // Example of valid |lines| data: |
| 31 // [ { |
| 32 // "template" : "The legal documents are: {0} and {1}", |
| 33 // "template_parameter" : [ { |
| 34 // "display_text" : "Terms of Service", |
| 35 // "url": "http://www.example.com/tos" |
| 36 // }, { |
| 37 // "display_text" : "Privacy Policy", |
| 38 // "url": "http://www.example.com/pp" |
| 39 // } ], |
| 40 // }, { |
| 41 // "template" : "This is the second line and it has no parameters" |
| 42 // } ] |
| 43 // |
| 44 // Caveats: |
| 45 // 1. '{' and '}' may be displayed by escaping them with an apostrophe in the |
| 46 // template string, e.g. "template" : "Here is a literal '{'" |
| 47 // 2. Two or more consecutive dollar signs in the template string will not |
| 48 // expand correctly. |
| 49 // 3. "${" anywhere in the template string is invalid. |
| 50 // 4. "\n" embedded anywhere in the template string, or an empty template |
| 51 // string, can be used to separate paragraphs. It is not possible to create |
| 52 // a completely blank line by using two consecutive newlines (they will be |
| 53 // treated as a single newline by views::StyledLabel). |
| 54 // |
| 55 // Returns false if contents of |lines| are invalid. |
| 56 bool SetLegalMessage(const base::ListValue& lines); |
| 57 void ClearLegalMessage(); |
| 58 |
30 // SetCallback() must be called first. | 59 // SetCallback() must be called first. |
31 void ShowBubble(); | 60 void ShowBubble(); |
32 | 61 |
33 // Returns true if Omnibox save credit card icon should be visible. | 62 // Returns true if Omnibox save credit card icon should be visible. |
34 bool IsIconVisible() const; | 63 bool IsIconVisible() const; |
35 | 64 |
36 // Returns true if Omnibox save credit card should be shown in its "toggled | 65 // Returns true if Omnibox save credit card should be shown in its "toggled |
37 // on" state. | 66 // on" state. |
38 bool IsIconToggled() const; | 67 bool IsIconToggled() const; |
39 | 68 |
40 // Returns nullptr if no bubble is currently shown. | 69 // Returns nullptr if no bubble is currently shown. |
41 SaveCardBubbleView* save_card_bubble_view() const; | 70 SaveCardBubbleView* save_card_bubble_view() const; |
42 | 71 |
43 // SaveCardBubbleController: | 72 // SaveCardBubbleController: |
44 void OnSaveButton() override; | 73 void OnSaveButton() override; |
45 void OnCancelButton() override; | 74 void OnCancelButton() override; |
46 void OnLearnMoreClicked() override; | 75 void OnLearnMoreClicked() override; |
| 76 void OnLegalMessageLinkClicked(const std::string& url) override; |
47 void OnBubbleClosed() override; | 77 void OnBubbleClosed() override; |
48 | 78 |
| 79 const std::vector<LegalMessageLine>& GetLegalMessageLines() const override; |
| 80 |
49 private: | 81 private: |
50 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; | 82 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; |
51 | 83 |
52 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); | 84 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); |
53 ~SaveCardBubbleControllerImpl() override; | 85 ~SaveCardBubbleControllerImpl() override; |
54 | 86 |
55 // Update the visibility and toggled state of the Omnibox save card icon. | 87 // Update the visibility and toggled state of the Omnibox save card icon. |
56 void UpdateIcon(); | 88 void UpdateIcon(); |
57 | 89 |
| 90 void OpenUrl(const std::string& url); |
| 91 |
58 // content::WebContentsObserver: | 92 // content::WebContentsObserver: |
59 void DidNavigateMainFrame( | 93 void DidNavigateMainFrame( |
60 const content::LoadCommittedDetails& details, | 94 const content::LoadCommittedDetails& details, |
61 const content::FrameNavigateParams& params) override; | 95 const content::FrameNavigateParams& params) override; |
62 | 96 |
63 // Weak reference. Will be nullptr if no bubble is currently shown. | 97 // Weak reference. Will be nullptr if no bubble is currently shown. |
64 SaveCardBubbleView* save_card_bubble_view_; | 98 SaveCardBubbleView* save_card_bubble_view_; |
65 | 99 |
66 // Callback to run if user presses Save button in the bubble. | 100 // Callback to run if user presses Save button in the bubble. |
67 // If save_card_callback_.is_null() is true then no bubble is available to | 101 // If save_card_callback_.is_null() is true then no bubble is available to |
68 // show and the icon is not visible. | 102 // show and the icon is not visible. |
69 base::Closure save_card_callback_; | 103 base::Closure save_card_callback_; |
70 | 104 |
| 105 // If no legal message should be shown then this variable is an empty vector. |
| 106 std::vector<LegalMessageLine> legal_message_lines_; |
| 107 |
71 // Used to measure the amount of time on a page; if it's less than some | 108 // Used to measure the amount of time on a page; if it's less than some |
72 // reasonable limit, then don't close the bubble upon navigation. | 109 // reasonable limit, then don't close the bubble upon navigation. |
73 scoped_ptr<base::ElapsedTimer> timer_; | 110 scoped_ptr<base::ElapsedTimer> timer_; |
74 | 111 |
75 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); | 112 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); |
76 }; | 113 }; |
77 | 114 |
78 } // namespace autofill | 115 } // namespace autofill |
79 | 116 |
80 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 117 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
OLD | NEW |