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

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

Issue 1408193003: Add chrome side webusb permission UI code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments for ChooserBubbleDelegate 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
(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 // Subclass ChooserBubbleDelegate to implement a chooser bubble, which has
15 // 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
17 // BubbleManager::ShowBubble() to show the bubble. Your subclass must define
18 // 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.
20 // You can also override GetName() to identify the bubble you define for
21 // collecting metrics.
22 // After Select/Cancel/Close is called, this object is destroyed and call back
23 // into it is not allowed.
24 class ChooserBubbleDelegate : public BubbleDelegate {
25 public:
26 ChooserBubbleDelegate();
27 ~ChooserBubbleDelegate() override;
28
29 // Since the set of options can change while the UI is visible an
30 // implementation should register an observer.
31 class Observer {
32 public:
33 // Called after the options list is initialized for the first time.
34 // OnOptionsInitialized should only be called once.
35 virtual void OnOptionsInitialized() = 0;
36 // 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
38 // GetOptions()[index] from inside a call to OnOptionAdded will see the
39 // added string since the options have already been updated.
40 virtual void OnOptionAdded(int index) = 0;
41 // Called when GetOptions()[index] is no longer present, and all later
42 // options have been moved earlier by 1 slot. Calling GetOptions()[index]
43 // from inside a call to OnOptionRemoved will NOT see the removed string
44 // since the options have already been updated.
45 virtual void OnOptionRemoved(int index) = 0;
46
47 protected:
48 virtual ~Observer() {}
49 };
50
51 // BubbleDelegate:
52 std::string GetName() const override;
53
54 // 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
56 // so that users can grant permission.
57 virtual const std::vector<base::string16>& GetOptions() const = 0;
58
59 // These three functions are called just before this object is destroyed:
60 // Called when the user selects the |index|th element from the dialog.
61 virtual void Select(int index) = 0;
62 // Called when the user presses the 'Cancel' button in the dialog.
63 virtual void Cancel() = 0;
64 // Called when the user clicks outside the dialog or the dialog otherwise
65 // closes without the user taking an explicit action.
66 virtual void Close() = 0;
67
68 // Only one observer may be registered at a time.
69 void set_observer(Observer* observer) { observer_ = observer; }
70 Observer* observer() const { return observer_; }
71
72 private:
73 Observer* observer_ = nullptr;
74
75 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate);
76 };
77
78 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698