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