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

Unified 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698