blob: d59fbb30ec6b6db2e9fd278fab4547b93293249d [file] [log] [blame]
juncaibf183dd2016-05-27 16:57:241// Copyright 2016 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
juncaibadc1daa2016-07-11 20:36:545#ifndef CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_
6#define CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_
juncaibf183dd2016-05-27 16:57:247
Jan Wilken Dörriead587c32021-03-11 14:09:278#include <string>
juncai0f6d2792016-11-23 18:38:079#include <vector>
10
juncaibf183dd2016-05-27 16:57:2411#include "base/macros.h"
12#include "base/strings/string16.h"
13
14namespace content {
15class RenderFrameHost;
16}
17
juncaibf183dd2016-05-27 16:57:2418// Subclass ChooserController to implement a chooser, which has some
19// introductory text and a list of options that users can pick one of.
20// Your subclass must define the set of options users can pick from;
21// the actions taken after users select an item or press the 'Cancel'
22// button or the chooser is closed.
23// After Select/Cancel/Close is called, this object is destroyed and
24// calls back into it are not allowed.
25class ChooserController {
26 public:
juncai6d9f7732016-07-14 00:46:5427 ChooserController(content::RenderFrameHost* owner,
28 int title_string_id_origin,
29 int title_string_id_extension);
juncaibf183dd2016-05-27 16:57:2430 virtual ~ChooserController();
31
32 // Since the set of options can change while the UI is visible an
juncai796733012016-07-20 22:30:4633 // implementation should register a view to observe changes.
34 class View {
juncaibf183dd2016-05-27 16:57:2435 public:
36 // Called after the options list is initialized for the first time.
37 // OnOptionsInitialized should only be called once.
38 virtual void OnOptionsInitialized() = 0;
39
40 // Called after GetOption(index) has been added to the options and the
41 // newly added option is the last element in the options list. Calling
42 // GetOption(index) from inside a call to OnOptionAdded will see the
43 // added string since the options have already been updated.
44 virtual void OnOptionAdded(size_t index) = 0;
45
46 // Called when GetOption(index) is no longer present, and all later
47 // options have been moved earlier by 1 slot. Calling GetOption(index)
48 // from inside a call to OnOptionRemoved will NOT see the removed string
49 // since the options have already been updated.
50 virtual void OnOptionRemoved(size_t index) = 0;
51
juncaibb5ba2302016-08-16 18:01:1352 // Called when the option at |index| has been updated.
53 virtual void OnOptionUpdated(size_t index) = 0;
54
juncai9c9d7512016-07-20 00:56:2355 // Called when the device adapter is turned on or off.
56 virtual void OnAdapterEnabledChanged(bool enabled) = 0;
57
James Hollyer6a6c9e32021-01-25 20:45:3458 // Called when the platform level device permission is changed.
59 // Currently only needed on macOS.
60 virtual void OnAdapterAuthorizationChanged(bool authorized);
61
juncai9c9d7512016-07-20 00:56:2362 // Called when refreshing options is in progress or complete.
63 virtual void OnRefreshStateChanged(bool refreshing) = 0;
64
juncaibf183dd2016-05-27 16:57:2465 protected:
juncai796733012016-07-20 22:30:4666 virtual ~View() {}
juncaibf183dd2016-05-27 16:57:2467 };
68
juncaia29e116d2016-07-13 02:53:3469 // Returns the text to be displayed in the chooser title.
Elly Fong-Jones1ec06c6e2020-07-16 14:44:2870 // Note that this is only called once, and there is no way to update the title
71 // for a given instance of ChooserController.
Jan Wilken Dörrief27844b2021-03-11 23:18:4872 std::u16string GetTitle() const;
juncaibf183dd2016-05-27 16:57:24