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

Side by Side Diff: extensions/browser/ui/extension_bluetooth_chooser.cc

Issue 2005443002: Implement bluetooth chooser for Chrome Apps on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_chooser_bubble_ui_cocoa
Patch Set: rebase and display app name on the chooser title Created 4 years, 7 months 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 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
5 #include "extensions/browser/ui/extension_bluetooth_chooser.h"
6
7 #include "content/public/browser/web_contents.h"
8 #include "extensions/browser/extensions_browser_client.h"
9 #include "extensions/browser/ui/extension_chooser_dialog.h"
10
11 namespace extensions {
12
13 ExtensionBluetoothChooser::ExtensionBluetoothChooser(
14 content::RenderFrameHost* frame,
15 const content::BluetoothChooser::EventHandler& event_handler)
16 : ChooserController(frame), event_handler_(event_handler) {
17 content::WebContents* web_contents =
18 content::WebContents::FromRenderFrameHost(frame);
19 dialog_ = ExtensionsBrowserClient::Get()
20 ->CreateBluetoothChromeExtensionChooserDialog(web_contents);
21 dialog_->ShowDialog(this);
22 }
23
24 ExtensionBluetoothChooser::~ExtensionBluetoothChooser() {}
25
26 void ExtensionBluetoothChooser::SetAdapterPresence(AdapterPresence presence) {}
27
28 void ExtensionBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {}
29
30 void ExtensionBluetoothChooser::AddDevice(const std::string& device_id,
31 const base::string16& device_name) {
32 device_names_and_ids_.push_back(std::make_pair(device_name, device_id));
33 if (observer())
34 observer()->OnOptionAdded(device_names_and_ids_.size() - 1);
35 }
36
37 void ExtensionBluetoothChooser::RemoveDevice(const std::string& device_id) {
38 for (auto it = device_names_and_ids_.begin();
39 it != device_names_and_ids_.end(); ++it) {
40 if (it->second == device_id) {
41 size_t index = it - device_names_and_ids_.begin();
42 device_names_and_ids_.erase(it);
43 if (observer())
44 observer()->OnOptionRemoved(index);
45 return;
46 }
47 }
48 }
49
50 size_t ExtensionBluetoothChooser::NumOptions() const {
51 return device_names_and_ids_.size();
52 }
53
54 const base::string16& ExtensionBluetoothChooser::GetOption(size_t index) const {
55 DCHECK_LT(index, device_names_and_ids_.size());
56 return device_names_and_ids_[index].first;
57 }
58
59 void ExtensionBluetoothChooser::Select(size_t index) {
60 DCHECK_LT(index, device_names_and_ids_.size());
61 event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
62 device_names_and_ids_[index].second);
63 }
64
65 void ExtensionBluetoothChooser::Cancel() {
66 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
67 std::string());
68 }
69
70 void ExtensionBluetoothChooser::Close() {
71 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
72 std::string());
73 }
74
75 GURL ExtensionBluetoothChooser::GetHelpCenterUrl() const {
76 return dialog_->GetHelpCenterUrl();
77 }
78
79 void ExtensionBluetoothChooser::OpenHelpCenterUrl() const {
80 dialog_->OpenHelpCenterUrl();
81 }
82
83 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698