OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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/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/common/pref_names.h" | |
13 | |
14 | |
15 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( | |
16 Profile* profile, | |
17 content::MediaStreamType type, | |
18 ContentSettingBubbleModel* bubble_model, | |
19 Observer* observer) | |
20 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
21 profile_(profile), | |
22 type_(type), | |
23 media_bubble_model_(bubble_model), | |
24 observer_(observer) { | |
25 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
26 media_bubble_model_->content_type()); | |
27 BuildMenu(); | |
markusheintz_
2013/02/06 11:03:26
I guess we can inline BuildMenu here. I don't see
no longer working on chromium
2013/02/06 13:31:52
We can do this. But from the readability perspecti
markusheintz_
2013/02/06 14:43:19
SGTM.
| |
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( | |
markusheintz_
2013/02/06 11:03:26
Is it possible to open navigate and close the menu
no longer working on chromium
2013/02/06 13:31:52
Not sure here, I just filed a bug 174615.
Do you k
markusheintz_
2013/02/06 14:43:19
Got to double check this. Thanks for filing the bu
| |
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_->OnMeiaMenuClicked(type_, it->second.id); | |
51 | |
52 if (observer_) | |
53 observer_->UpdateMenuLabel(type_, it->second.name); | |
54 } | |
55 | |
56 void ContentSettingMediaMenuModel::BuildMenu() { | |
57 PrefService* prefs = profile_->GetPrefs(); | |
58 MediaCaptureDevicesDispatcher* dispatcher = | |
59 MediaCaptureDevicesDispatcher::GetInstance(); | |
60 content::MediaStreamDevices devices; | |
61 std::string default_device; | |
62 if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
63 devices = dispatcher->GetAudioCaptureDevices(); | |
64 default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); | |
65 } else if (type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
66 devices = dispatcher->GetVideoCaptureDevices(); | |
67 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); | |
68 } else { | |
69 NOTREACHED(); | |
70 } | |
71 | |
72 for (size_t i = 0; i < devices.size(); ++i) { | |
73 int command_id = commands_.size(); | |
74 commands_.insert(std::make_pair(command_id, devices[i])); | |
75 AddItem(i, UTF8ToUTF16(devices[i].name)); | |
76 } | |
77 } | |
OLD | NEW |