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