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 gfx::Range& link_range) override; | |
47 void OnBubbleClosed() override; | 77 void OnBubbleClosed() override; |
48 | 78 |
79 const base::string16& GetLegalMessage() const override; | |
80 const std::vector<gfx::Range>& GetLegalMessageLinkRanges() const override; | |
81 | |
82 // For testing. | |
83 const std::vector<std::string>& GetLegalMessageLinkUrlsForTesting() const; | |
bondd
2015/11/11 01:53:36
I'm not sure what the current best practice is for
| |
84 | |
49 private: | 85 private: |
50 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; | 86 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; |
51 | 87 |
52 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); | 88 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); |
53 ~SaveCardBubbleControllerImpl() override; | 89 ~SaveCardBubbleControllerImpl() override; |
54 | 90 |
55 // Update the visibility and toggled state of the Omnibox save card icon. | 91 // Update the visibility and toggled state of the Omnibox save card icon. |
56 void UpdateIcon(); | 92 void UpdateIcon(); |
57 | 93 |
94 void OpenUrl(const std::string& url); | |
95 | |
58 // content::WebContentsObserver: | 96 // content::WebContentsObserver: |
59 void DidNavigateMainFrame( | 97 void DidNavigateMainFrame( |
60 const content::LoadCommittedDetails& details, | 98 const content::LoadCommittedDetails& details, |
61 const content::FrameNavigateParams& params) override; | 99 const content::FrameNavigateParams& params) override; |
62 | 100 |
63 // Weak reference. Will be nullptr if no bubble is currently shown. | 101 // Weak reference. Will be nullptr if no bubble is currently shown. |
64 SaveCardBubbleView* save_card_bubble_view_; | 102 SaveCardBubbleView* save_card_bubble_view_; |
65 | 103 |
66 // Callback to run if user presses Save button in the bubble. | 104 // 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 | 105 // If save_card_callback_.is_null() is true then no bubble is available to |
68 // show and the icon is not visible. | 106 // show and the icon is not visible. |
69 base::Closure save_card_callback_; | 107 base::Closure save_card_callback_; |
70 | 108 |
109 // If no legal message should be shown then this variable is an empty string. | |
110 base::string16 legal_message_; | |
111 | |
112 // These two vectors describe all of the links in legal_message_. The two | |
113 // vectors will always be in sync with each other and legal_message_. Empty if | |
114 // legal_message_ is an empty string. | |
115 std::vector<gfx::Range> legal_message_link_ranges_; | |
116 std::vector<std::string> legal_message_link_urls_; | |
bondd
2015/11/11 01:53:36
Made these separate (instead of combining range an
Evan Stade
2015/11/11 22:22:54
make the testing function protected and create a T
bondd
2015/11/13 01:19:52
Thanks. If we stick with the new interface then I
| |
117 | |
71 // Used to measure the amount of time on a page; if it's less than some | 118 // 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. | 119 // reasonable limit, then don't close the bubble upon navigation. |
73 scoped_ptr<base::ElapsedTimer> timer_; | 120 scoped_ptr<base::ElapsedTimer> timer_; |
74 | 121 |
75 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); | 122 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); |
76 }; | 123 }; |
77 | 124 |
78 } // namespace autofill | 125 } // namespace autofill |
79 | 126 |
80 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 127 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
OLD | NEW |