Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/ui/website_settings/chooser_bubble_delegate.h

Issue 1473393003: Add chooser permission UI code for Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wpu_1
Patch Set: merged changes from upstream, address reillyg@'s comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
15
14 // Subclass ChooserBubbleDelegate to implement a chooser bubble, which has 16 // Subclass ChooserBubbleDelegate to implement a chooser bubble, which has
15 // 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.
16 // Create an instance of your subclass and pass it to 18 // Create an instance of your subclass and pass it to
17 // BubbleManager::ShowBubble() to show the bubble. Your subclass must define 19 // BubbleManager::ShowBubble() to show the bubble. Your subclass must define
18 // 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
19 // 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.
20 // 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
21 // collecting metrics. 23 // collecting metrics.
22 // 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
23 // into it is not allowed. 25 // into it is not allowed.
24 class ChooserBubbleDelegate : public BubbleDelegate { 26 class ChooserBubbleDelegate : public BubbleDelegate {
25 public: 27 public:
26 ChooserBubbleDelegate(); 28 explicit ChooserBubbleDelegate(Browser* browser);
27 ~ChooserBubbleDelegate() override; 29 ~ChooserBubbleDelegate() override;
28 30
29 // 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
30 // implementation should register an observer. 32 // implementation should register an observer.
31 class Observer { 33 class Observer {
32 public: 34 public:
33 // Called after the options list is initialized for the first time. 35 // Called after the options list is initialized for the first time.
34 // OnOptionsInitialized should only be called once. 36 // OnOptionsInitialized should only be called once.
35 virtual void OnOptionsInitialized() = 0; 37 virtual void OnOptionsInitialized() = 0;
36 // Called after GetOptions()[index] has been added to the options and the 38 // Called after GetOptions()[index] has been added to the options and the
37 // newly added option is the last element in the options list. Calling 39 // newly added option is the last element in the options list. Calling
38 // GetOptions()[index] from inside a call to OnOptionAdded will see the 40 // GetOptions()[index] from inside a call to OnOptionAdded will see the
39 // added string since the options have already been updated. 41 // added string since the options have already been updated.
40 virtual void OnOptionAdded(int index) = 0; 42 virtual void OnOptionAdded(int index) = 0;
41 // Called when GetOptions()[index] is no longer present, and all later 43 // Called when GetOptions()[index] is no longer present, and all later
42 // options have been moved earlier by 1 slot. Calling GetOptions()[index] 44 // options have been moved earlier by 1 slot. Calling GetOptions()[index]
43 // from inside a call to OnOptionRemoved will NOT see the removed string 45 // from inside a call to OnOptionRemoved will NOT see the removed string
44 // since the options have already been updated. 46 // since the options have already been updated.
45 virtual void OnOptionRemoved(int index) = 0; 47 virtual void OnOptionRemoved(int index) = 0;
46 48
47 protected: 49 protected:
48 virtual ~Observer() {} 50 virtual ~Observer() {}
49 }; 51 };
50 52
51 // BubbleDelegate: 53 // BubbleDelegate:
52 std::string GetName() const override; 54 std::string GetName() const override;
55 scoped_ptr<BubbleUi> BuildBubbleUi() override;
53 56
54 // The set of options users can pick from. For example, it can be 57 // The set of options users can pick from. For example, it can be
55 // USB/Bluetooth devices names which are listed in the chooser bubble 58 // USB/Bluetooth devices names which are listed in the chooser bubble
56 // so that users can grant permission. 59 // so that users can grant permission.
57 virtual const std::vector<base::string16>& GetOptions() const = 0; 60 virtual const std::vector<base::string16>& GetOptions() const = 0;
58 61
59 // These three functions are called just before this object is destroyed: 62 // These three functions are called just before this object is destroyed:
60 // Called when the user selects the |index|th element from the dialog. 63 // Called when the user selects the |index|th element from the dialog.
61 virtual void Select(int index) = 0; 64 virtual void Select(int index) = 0;
62 // Called when the user presses the 'Cancel' button in the dialog. 65 // Called when the user presses the 'Cancel' button in the dialog.
63 virtual void Cancel() = 0; 66 virtual void Cancel() = 0;
64 // Called when the user clicks outside the dialog or the dialog otherwise 67 // Called when the user clicks outside the dialog or the dialog otherwise
65 // closes without the user taking an explicit action. 68 // closes without the user taking an explicit action.
66 virtual void Close() = 0; 69 virtual void Close() = 0;
67 70
68 // Only one observer may be registered at a time. 71 // Only one observer may be registered at a time.
69 void set_observer(Observer* observer) { observer_ = observer; } 72 void set_observer(Observer* observer) { observer_ = observer; }
70 Observer* observer() const { return observer_; } 73 Observer* observer() const { return observer_; }
71 74
72 private: 75 private:
76 Browser* browser_;
73 Observer* observer_ = nullptr; 77 Observer* observer_ = nullptr;
74 78
75 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate); 79 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate);
76 }; 80 };
77 81
78 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ 82 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698