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