OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_CONTROLLER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/strings/string16.h" | |
10 #include "components/bubble/bubble_delegate.h" | |
11 | |
12 class Browser; | |
13 class GURL; | |
14 | |
15 namespace url { | |
16 class Origin; | |
17 } | |
18 | |
19 // Subclass ChooserBubbleController to implement a chooser bubble, which has | |
20 // some introductory text and a list of options that users can pick one of. | |
21 // Create an instance of your subclass and pass it to | |
22 // BubbleManager::ShowBubble() to show the bubble. Your subclass must define | |
23 // the set of options users can pick from; the actions taken after users | |
24 // select an item or press the 'Cancel' button or the bubble is closed. | |
25 // You can also override GetName() to identify the bubble you define for | |
26 // collecting metrics. | |
27 // After Select/Cancel/Close is called, this object is destroyed and call back | |
28 // into it is not allowed. | |
29 class ChooserBubbleController : public BubbleDelegate { | |
30 public: | |
31 explicit ChooserBubbleController(content::RenderFrameHost* owner); | |
32 ~ChooserBubbleController() override; | |
33 | |
34 // Since the set of options can change while the UI is visible an | |
35 // implementation should register an observer. | |
36 class Observer { | |
37 public: | |
38 // Called after the options list is initialized for the first time. | |
39 // OnOptionsInitialized should only be called once. | |
40 virtual void OnOptionsInitialized() = 0; | |
41 | |
42 // Called after GetOption(index) has been added to the options and the | |
43 // newly added option is the last element in the options list. Calling | |
44 // GetOption(index) from inside a call to OnOptionAdded will see the | |
45 // added string since the options have already been updated. | |
46 virtual void OnOptionAdded(size_t index) = 0; | |
47 | |
48 // Called when GetOption(index) is no longer present, and all later | |
49 // options have been moved earlier by 1 slot. Calling GetOption(index) | |
50 // from inside a call to OnOptionRemoved will NOT see the removed string | |
51 // since the options have already been updated. | |
52 virtual void OnOptionRemoved(size_t index) = 0; | |
53 | |
54 protected: | |
55 virtual ~Observer() {} | |
56 }; | |
57 | |
58 // Return the origin URL to be displayed on the bubble title. | |
59 url::Origin GetOrigin() const; | |
60 | |
61 // Open help center URL. | |
62 void OpenHelpCenterUrl() const; | |
63 | |
64 // BubbleDelegate: | |
65 std::string GetName() const override; | |
66 std::unique_ptr<BubbleUi> BuildBubbleUi() override; | |
67 const content::RenderFrameHost* OwningFrame() const override; | |
68 | |
69 // The number of options users can pick from. For example, it can be | |
70 // the number of USB/Bluetooth device names which are listed in the | |
71 // chooser bubble so that users can grant permission. | |
72 virtual size_t NumOptions() const = 0; | |
73 | |
74 // The |index|th option string which is listed in the chooser bubble. | |
75 virtual const base::string16& GetOption(size_t index) const = 0; | |
76 | |
77 // These three functions are called just before this object is destroyed: | |
78 | |
79 // Called when the user selects the |index|th element from the dialog. | |
80 virtual void Select(size_t index) = 0; | |
81 | |
82 // Called when the user presses the 'Cancel' button in the dialog. | |
83 virtual void Cancel() = 0; | |
84 | |
85 // Called when the user clicks outside the dialog or the dialog otherwise | |
86 // closes without the user taking an explicit action. | |
87 virtual void Close() = 0; | |
88 | |
89 // Get help center URL. | |
90 virtual GURL GetHelpCenterUrl() const = 0; | |
91 | |
92 // Only one observer may be registered at a time. | |
93 void set_observer(Observer* observer) { observer_ = observer; } | |
94 Observer* observer() const { return observer_; } | |
95 | |
96 private: | |
97 Browser* browser_; | |
98 const content::RenderFrameHost* const owning_frame_; | |
99 Observer* observer_ = nullptr; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleController); | |
102 }; | |
103 | |
104 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_CONTROLLER_H_ | |
OLD | NEW |