| OLD | NEW |
| (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 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | |
| 9 #include "chrome/common/url_constants.h" | |
| 10 #include "components/bubble/bubble_controller.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 BluetoothChooserBubbleController::BluetoothChooserBubbleController( | |
| 14 content::RenderFrameHost* owner) | |
| 15 : ChooserBubbleController(owner), bluetooth_chooser_(nullptr) {} | |
| 16 | |
| 17 BluetoothChooserBubbleController::~BluetoothChooserBubbleController() { | |
| 18 if (bluetooth_chooser_) | |
| 19 bluetooth_chooser_->set_bluetooth_chooser_bubble_controller(nullptr); | |
| 20 } | |
| 21 | |
| 22 size_t BluetoothChooserBubbleController::NumOptions() const { | |
| 23 return device_names_and_ids_.size(); | |
| 24 } | |
| 25 | |
| 26 const base::string16& BluetoothChooserBubbleController::GetOption( | |
| 27 size_t index) const { | |
| 28 DCHECK_LT(index, device_names_and_ids_.size()); | |
| 29 return device_names_and_ids_[index].first; | |
| 30 } | |
| 31 | |
| 32 void BluetoothChooserBubbleController::Select(size_t index) { | |
| 33 DCHECK_LT(index, device_names_and_ids_.size()); | |
| 34 if (bluetooth_chooser_) { | |
| 35 bluetooth_chooser_->CallEventHandler( | |
| 36 content::BluetoothChooser::Event::SELECTED, | |
| 37 device_names_and_ids_[index].second); | |
| 38 } | |
| 39 | |
| 40 if (bubble_reference_) | |
| 41 bubble_reference_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); | |
| 42 } | |
| 43 | |
| 44 void BluetoothChooserBubbleController::Cancel() { | |
| 45 if (bluetooth_chooser_) { | |
| 46 bluetooth_chooser_->CallEventHandler( | |
| 47 content::BluetoothChooser::Event::CANCELLED, std::string()); | |
| 48 } | |
| 49 | |
| 50 if (bubble_reference_) | |
| 51 bubble_reference_->CloseBubble(BUBBLE_CLOSE_CANCELED); | |
| 52 } | |
| 53 | |
| 54 void BluetoothChooserBubbleController::Close() { | |
| 55 if (bluetooth_chooser_) { | |
| 56 bluetooth_chooser_->CallEventHandler( | |
| 57 content::BluetoothChooser::Event::CANCELLED, std::string()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 GURL BluetoothChooserBubbleController::GetHelpCenterUrl() const { | |
| 62 return GURL(chrome::kChooserBluetoothOverviewURL); | |
| 63 } | |
| 64 | |
| 65 void BluetoothChooserBubbleController::AddDevice( | |
| 66 const std::string& device_id, | |
| 67 const base::string16& device_name) { | |
| 68 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); | |
| 69 if (observer()) | |
| 70 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); | |
| 71 } | |
| 72 | |
| 73 void BluetoothChooserBubbleController::RemoveDevice( | |
| 74 const std::string& device_id) { | |
| 75 for (auto it = device_names_and_ids_.begin(); | |
| 76 it != device_names_and_ids_.end(); ++it) { | |
| 77 if (it->second == device_id) { | |
| 78 size_t index = it - device_names_and_ids_.begin(); | |
| 79 device_names_and_ids_.erase(it); | |
| 80 if (observer()) | |
| 81 observer()->OnOptionRemoved(index); | |
| 82 return; | |
| 83 } | |
| 84 } | |
| 85 } | |
| OLD | NEW |