OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h" | 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_context.h" |
| 10 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_context_factory.h" |
8 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | 11 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
9 #include "components/bubble/bubble_controller.h" | 12 #include "components/bubble/bubble_controller.h" |
| 13 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/web_contents.h" |
10 | 15 |
11 BluetoothChooserBubbleDelegate::BluetoothChooserBubbleDelegate(Browser* browser) | 16 BluetoothChooserBubbleDelegate::BluetoothChooserBubbleDelegate( |
12 : ChooserBubbleDelegate(browser), bluetooth_chooser_(nullptr) {} | 17 Browser* browser, |
| 18 content::WebContents* web_contents, |
| 19 const GURL& origin) |
| 20 : ChooserBubbleDelegate(browser), |
| 21 web_contents_(web_contents), |
| 22 origin_(origin), |
| 23 bluetooth_chooser_(nullptr) {} |
13 | 24 |
14 BluetoothChooserBubbleDelegate::~BluetoothChooserBubbleDelegate() { | 25 BluetoothChooserBubbleDelegate::~BluetoothChooserBubbleDelegate() { |
15 if (bluetooth_chooser_) | 26 if (bluetooth_chooser_) |
16 bluetooth_chooser_->set_bluetooth_chooser_bubble_delegate(nullptr); | 27 bluetooth_chooser_->set_bluetooth_chooser_bubble_delegate(nullptr); |
17 } | 28 } |
18 | 29 |
19 size_t BluetoothChooserBubbleDelegate::NumOptions() const { | 30 size_t BluetoothChooserBubbleDelegate::NumOptions() const { |
20 return device_names_and_ids_.size(); | 31 return device_names_and_ids_.size(); |
21 } | 32 } |
22 | 33 |
23 const base::string16& BluetoothChooserBubbleDelegate::GetOption( | 34 const base::string16& BluetoothChooserBubbleDelegate::GetOption( |
24 size_t index) const { | 35 size_t index) const { |
25 DCHECK_LT(index, device_names_and_ids_.size()); | 36 DCHECK_LT(index, device_names_and_ids_.size()); |
26 return device_names_and_ids_[index].first; | 37 return device_names_and_ids_[index].first; |
27 } | 38 } |
28 | 39 |
29 void BluetoothChooserBubbleDelegate::Select(size_t index) { | 40 void BluetoothChooserBubbleDelegate::Select(size_t index) { |
30 DCHECK_LT(index, device_names_and_ids_.size()); | 41 DCHECK_LT(index, device_names_and_ids_.size()); |
31 if (bluetooth_chooser_) { | 42 if (bluetooth_chooser_) { |
32 bluetooth_chooser_->CallEventHandler( | 43 bluetooth_chooser_->CallEventHandler( |
33 content::BluetoothChooser::Event::SELECTED, | 44 content::BluetoothChooser::Event::SELECTED, |
34 device_names_and_ids_[index].second); | 45 device_names_and_ids_[index].second); |
35 } | 46 } |
36 | 47 |
| 48 GURL embedding_origin = |
| 49 web_contents_->GetMainFrame()->GetLastCommittedURL().GetOrigin(); |
| 50 Profile* profile = |
| 51 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 52 BluetoothChooserContext* chooser_context = |
| 53 BluetoothChooserContextFactory::GetForProfile(profile); |
| 54 chooser_context->GrantDevicePermission(origin_, embedding_origin, |
| 55 device_names_and_ids_[index].second); |
| 56 |
37 if (bubble_controller_) | 57 if (bubble_controller_) |
38 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); | 58 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); |
39 } | 59 } |
40 | 60 |
41 void BluetoothChooserBubbleDelegate::Cancel() { | 61 void BluetoothChooserBubbleDelegate::Cancel() { |
42 if (bluetooth_chooser_) { | 62 if (bluetooth_chooser_) { |
43 bluetooth_chooser_->CallEventHandler( | 63 bluetooth_chooser_->CallEventHandler( |
44 content::BluetoothChooser::Event::CANCELLED, std::string()); | 64 content::BluetoothChooser::Event::CANCELLED, std::string()); |
45 } | 65 } |
46 | 66 |
(...skipping 22 matching lines...) Expand all Loading... |
69 it != device_names_and_ids_.end(); ++it) { | 89 it != device_names_and_ids_.end(); ++it) { |
70 if (it->second == device_id) { | 90 if (it->second == device_id) { |
71 size_t index = it - device_names_and_ids_.begin(); | 91 size_t index = it - device_names_and_ids_.begin(); |
72 device_names_and_ids_.erase(it); | 92 device_names_and_ids_.erase(it); |
73 if (observer()) | 93 if (observer()) |
74 observer()->OnOptionRemoved(index); | 94 observer()->OnOptionRemoved(index); |
75 return; | 95 return; |
76 } | 96 } |
77 } | 97 } |
78 } | 98 } |
OLD | NEW |