OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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/content_settings/content_setting_media_menu_model.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | |
10 | |
11 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( | |
12 content::MediaStreamType type, | |
13 ContentSettingBubbleModel* bubble_model, | |
14 const MenuLabelChangedCallback& callback) | |
15 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
16 type_(type), | |
17 media_bubble_model_(bubble_model), | |
18 callback_(callback) { | |
19 DCHECK(type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE || | |
20 type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
21 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
22 media_bubble_model_->content_type()); | |
23 MediaCaptureDevicesDispatcher* dispatcher = | |
24 MediaCaptureDevicesDispatcher::GetInstance(); | |
25 content::MediaStreamDevices devices; | |
26 if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) | |
27 devices = dispatcher->GetAudioCaptureDevices(); | |
28 else | |
29 devices = dispatcher->GetVideoCaptureDevices(); | |
Peter Kasting
2013/02/20 05:46:20
Nit: To do initialization at declaration time, how
no longer working on chromium
2013/02/20 15:23:40
Done.
| |
30 | |
31 for (size_t i = 0; i < devices.size(); ++i) { | |
32 commands_.insert(std::make_pair(commands_.size(), devices[i])); | |
33 AddItem(i, UTF8ToUTF16(devices[i].name)); | |
34 } | |
35 } | |
36 | |
37 ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() { | |
38 } | |
39 | |
40 bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const { | |
41 return false; | |
42 } | |
43 | |
44 bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const { | |
45 return true; | |
46 } | |
47 | |
48 bool ContentSettingMediaMenuModel::GetAcceleratorForCommandId( | |
49 int command_id, | |
50 ui::Accelerator* accelerator) { | |
51 return false; | |
52 } | |
53 | |
54 void ContentSettingMediaMenuModel::ExecuteCommand(int command_id) { | |
55 CommandMap::const_iterator it = commands_.find(command_id); | |
56 DCHECK(it != commands_.end()); | |
57 media_bubble_model_->OnMediaMenuClicked(type_, it->second.id); | |
58 | |
59 if (!callback_.is_null()) | |
60 callback_.Run(type_, it->second.name); | |
61 } | |
OLD | NEW |