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