OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
tfarina
2013/02/06 14:56:08
no (c), the new copyright doesn't have it.
crbug.
no longer working on chromium
2013/02/06 21:30:06
Done.
| |
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/prefs/pref_service.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | |
12 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | |
tfarina
2013/02/06 14:56:08
nit: this is the same include of line 5.
no longer working on chromium
2013/02/06 21:30:06
Done.
| |
13 #include "chrome/common/pref_names.h" | |
14 | |
tfarina
2013/02/06 14:56:08
nit: extra blank line
no longer working on chromium
2013/02/06 21:30:06
Done.
| |
15 | |
16 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( | |
17 Profile* profile, | |
18 content::MediaStreamType type, | |
19 ContentSettingBubbleModel* bubble_model, | |
20 const MenuLabelChangedCallback& callback) | |
21 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
22 profile_(profile), | |
23 type_(type), | |
24 media_bubble_model_(bubble_model), | |
25 callback_(callback) { | |
26 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
27 media_bubble_model_->content_type()); | |
28 BuildMenu(); | |
29 } | |
30 | |
31 ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() { | |
32 } | |
33 | |
34 bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const { | |
35 return false; | |
36 } | |
37 | |
38 bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const { | |
39 return true; | |
40 } | |
41 | |
42 bool ContentSettingMediaMenuModel::GetAcceleratorForCommandId( | |
43 int command_id, | |
44 ui::Accelerator* accelerator) { | |
45 return false; | |
46 } | |
47 | |
48 void ContentSettingMediaMenuModel::ExecuteCommand(int command_id) { | |
49 CommandMap::const_iterator it = commands_.find(command_id); | |
50 DCHECK(it != commands_.end()); | |
51 media_bubble_model_->OnMediaMenuClicked(type_, it->second.id); | |
52 | |
53 if (!callback_.is_null()) | |
54 callback_.Run(type_, it->second.name); | |
55 } | |
56 | |
57 void ContentSettingMediaMenuModel::BuildMenu() { | |
58 PrefService* prefs = profile_->GetPrefs(); | |
59 MediaCaptureDevicesDispatcher* dispatcher = | |
60 MediaCaptureDevicesDispatcher::GetInstance(); | |
61 content::MediaStreamDevices devices; | |
62 std::string default_device; | |
63 if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
64 devices = dispatcher->GetAudioCaptureDevices(); | |
65 default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); | |
66 } else if (type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
67 devices = dispatcher->GetVideoCaptureDevices(); | |
68 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); | |
69 } else { | |
70 NOTREACHED(); | |
71 } | |
72 | |
73 for (size_t i = 0; i < devices.size(); ++i) { | |
74 int command_id = commands_.size(); | |
75 commands_.insert(std::make_pair(command_id, devices[i])); | |
76 AddItem(i, UTF8ToUTF16(devices[i].name)); | |
77 } | |
78 } | |
OLD | NEW |