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 |
30 // SetCallback() must be called first. | 58 // SetCallback() must be called first. |
31 void ShowBubble(bool user_action); | 59 void ShowBubble(bool user_action); |
32 | 60 |
33 // Returns true if Omnibox save credit card icon should be visible. | 61 // Returns true if Omnibox save credit card icon should be visible. |
34 bool IsIconVisible() const; | 62 bool IsIconVisible() const; |
35 | 63 |
36 // Returns nullptr if no bubble is currently shown. | 64 // Returns nullptr if no bubble is currently shown. |
37 SaveCardBubbleView* save_card_bubble_view() const; | 65 SaveCardBubbleView* save_card_bubble_view() const; |
38 | 66 |
39 // SaveCardBubbleController: | 67 // SaveCardBubbleController: |
40 void OnSaveButton() override; | 68 void OnSaveButton() override; |
41 void OnCancelButton() override; | 69 void OnCancelButton() override; |
42 void OnLearnMoreClicked() override; | 70 void OnLearnMoreClicked() override; |
| 71 void OnLegalMessageLinkClicked(const GURL& url) override; |
43 void OnBubbleClosed() override; | 72 void OnBubbleClosed() override; |
44 | 73 |
| 74 const LegalMessageLines& GetLegalMessageLines() const override; |
| 75 |
45 private: | 76 private: |
46 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; | 77 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; |
47 | 78 |
48 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); | 79 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); |
49 ~SaveCardBubbleControllerImpl() override; | 80 ~SaveCardBubbleControllerImpl() override; |
50 | 81 |
51 // Update the visibility and toggled state of the Omnibox save card icon. | 82 // Update the visibility and toggled state of the Omnibox save card icon. |
52 void UpdateIcon(); | 83 void UpdateIcon(); |
53 | 84 |
| 85 void OpenUrl(const GURL& url); |
| 86 |
54 // content::WebContentsObserver: | 87 // content::WebContentsObserver: |
55 void DidNavigateMainFrame( | 88 void DidNavigateMainFrame( |
56 const content::LoadCommittedDetails& details, | 89 const content::LoadCommittedDetails& details, |
57 const content::FrameNavigateParams& params) override; | 90 const content::FrameNavigateParams& params) override; |
58 | 91 |
59 // Weak reference. Will be nullptr if no bubble is currently shown. | 92 // Weak reference. Will be nullptr if no bubble is currently shown. |
60 SaveCardBubbleView* save_card_bubble_view_; | 93 SaveCardBubbleView* save_card_bubble_view_; |
61 | 94 |
62 // Callback to run if user presses Save button in the bubble. | 95 // Callback to run if user presses Save button in the bubble. |
63 // If save_card_callback_.is_null() is true then no bubble is available to | 96 // If save_card_callback_.is_null() is true then no bubble is available to |
64 // show and the icon is not visible. | 97 // show and the icon is not visible. |
65 base::Closure save_card_callback_; | 98 base::Closure save_card_callback_; |
66 | 99 |
| 100 // If no legal message should be shown then this variable is an empty vector. |
| 101 LegalMessageLines legal_message_lines_; |
| 102 |
67 // Used to measure the amount of time on a page; if it's less than some | 103 // Used to measure the amount of time on a page; if it's less than some |
68 // reasonable limit, then don't close the bubble upon navigation. | 104 // reasonable limit, then don't close the bubble upon navigation. |
69 scoped_ptr<base::ElapsedTimer> timer_; | 105 scoped_ptr<base::ElapsedTimer> timer_; |
70 | 106 |
71 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); | 107 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); |
72 }; | 108 }; |
73 | 109 |
74 } // namespace autofill | 110 } // namespace autofill |
75 | 111 |
76 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | 112 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ |
OLD | NEW |