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