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/prefs/pref_service.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | |
11 #include "chrome/common/pref_names.h" | |
12 | |
13 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( | |
14 PrefService* prefs, | |
15 content::MediaStreamType type, | |
16 ContentSettingBubbleModel* bubble_model, | |
17 const MenuLabelChangedCallback& callback) | |
18 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
19 prefs_(prefs), | |
20 type_(type), | |
21 media_bubble_model_(bubble_model), | |
22 callback_(callback) { | |
23 DCHECK(type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE || | |
24 type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
25 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
26 media_bubble_model_->content_type()); | |
27 BuildMenu(); | |
Peter Kasting
2013/02/16 02:55:13
I don't think there's much value in splitting this
no longer working on chromium
2013/02/18 17:20:04
Done.
| |
28 } | |
29 | |
30 ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() { | |
31 } | |
32 | |
33 bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const { | |
34 return false; | |
35 } | |
36 | |
37 bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const { | |
38 return true; | |
39 } | |
40 | |
41 bool ContentSettingMediaMenuModel::GetAcceleratorForCommandId( | |
42 int command_id, | |
43 ui::Accelerator* accelerator) { | |
44 return false; | |
45 } | |
46 | |
47 void ContentSettingMediaMenuModel::ExecuteCommand(int command_id) { | |
48 CommandMap::const_iterator it = commands_.find(command_id); | |
49 DCHECK(it != commands_.end()); | |
50 media_bubble_model_->OnMediaMenuClicked(type_, it->second.id); | |
51 | |
52 if (!callback_.is_null()) | |
53 callback_.Run(type_, it->second.name); | |
54 } | |
55 | |
56 void ContentSettingMediaMenuModel::BuildMenu() { | |
57 MediaCaptureDevicesDispatcher* dispatcher = | |
58 MediaCaptureDevicesDispatcher::GetInstance(); | |
59 content::MediaStreamDevices devices; | |
60 std::string default_device; | |
61 if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
62 devices = dispatcher->GetAudioCaptureDevices(); | |
63 default_device = prefs_->GetString(prefs::kDefaultAudioCaptureDevice); | |
64 } else { | |
65 devices = dispatcher->GetVideoCaptureDevices(); | |
66 default_device = prefs_->GetString(prefs::kDefaultVideoCaptureDevice); | |
67 } | |
68 | |
69 for (size_t i = 0; i < devices.size(); ++i) { | |
70 commands_.insert(std::make_pair(commands_.size(), devices[i])); | |
71 AddItem(i, UTF8ToUTF16(devices[i].name)); | |
72 } | |
73 } | |
OLD | NEW |