| Index: extensions/browser/ui/extension_bluetooth_chooser.cc
|
| diff --git a/extensions/browser/ui/extension_bluetooth_chooser.cc b/extensions/browser/ui/extension_bluetooth_chooser.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d97c00eca3e4500f2b3c3c7a9079ec0aa91cdf02
|
| --- /dev/null
|
| +++ b/extensions/browser/ui/extension_bluetooth_chooser.cc
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "extensions/browser/ui/extension_bluetooth_chooser.h"
|
| +
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "extensions/browser/extensions_browser_client.h"
|
| +#include "extensions/browser/ui/extension_chooser_dialog.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +ExtensionBluetoothChooser::ExtensionBluetoothChooser(
|
| + content::RenderFrameHost* frame,
|
| + const content::BluetoothChooser::EventHandler& event_handler)
|
| + : ChooserController(frame), event_handler_(event_handler) {
|
| + content::WebContents* web_contents =
|
| + content::WebContents::FromRenderFrameHost(frame);
|
| + dialog_ = ExtensionsBrowserClient::Get()
|
| + ->CreateBluetoothChromeExtensionChooserDialog(web_contents);
|
| + dialog_->ShowDialog(this);
|
| +}
|
| +
|
| +ExtensionBluetoothChooser::~ExtensionBluetoothChooser() {}
|
| +
|
| +void ExtensionBluetoothChooser::SetAdapterPresence(AdapterPresence presence) {}
|
| +
|
| +void ExtensionBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {}
|
| +
|
| +void ExtensionBluetoothChooser::AddDevice(const std::string& device_id,
|
| + const base::string16& device_name) {
|
| + device_names_and_ids_.push_back(std::make_pair(device_name, device_id));
|
| + if (observer())
|
| + observer()->OnOptionAdded(device_names_and_ids_.size() - 1);
|
| +}
|
| +
|
| +void ExtensionBluetoothChooser::RemoveDevice(const std::string& device_id) {
|
| + for (auto it = device_names_and_ids_.begin();
|
| + it != device_names_and_ids_.end(); ++it) {
|
| + if (it->second == device_id) {
|
| + size_t index = it - device_names_and_ids_.begin();
|
| + device_names_and_ids_.erase(it);
|
| + if (observer())
|
| + observer()->OnOptionRemoved(index);
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| +size_t ExtensionBluetoothChooser::NumOptions() const {
|
| + return device_names_and_ids_.size();
|
| +}
|
| +
|
| +const base::string16& ExtensionBluetoothChooser::GetOption(size_t index) const {
|
| + DCHECK_LT(index, device_names_and_ids_.size());
|
| + return device_names_and_ids_[index].first;
|
| +}
|
| +
|
| +void ExtensionBluetoothChooser::Select(size_t index) {
|
| + DCHECK_LT(index, device_names_and_ids_.size());
|
| + event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
|
| + device_names_and_ids_[index].second);
|
| +}
|
| +
|
| +void ExtensionBluetoothChooser::Cancel() {
|
| + event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
|
| + std::string());
|
| +}
|
| +
|
| +void ExtensionBluetoothChooser::Close() {
|
| + event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
|
| + std::string());
|
| +}
|
| +
|
| +GURL ExtensionBluetoothChooser::GetHelpCenterUrl() const {
|
| + return dialog_->GetHelpCenterUrl();
|
| +}
|
| +
|
| +void ExtensionBluetoothChooser::OpenHelpCenterUrl() const {
|
| + dialog_->OpenHelpCenterUrl();
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|