Chromium Code Reviews| Index: chrome/browser/ui/content_settings/content_setting_media_menu_model.cc |
| diff --git a/chrome/browser/ui/content_settings/content_setting_media_menu_model.cc b/chrome/browser/ui/content_settings/content_setting_media_menu_model.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9cd2e847053a033f9b7a4a42127574402a84b5fb |
| --- /dev/null |
| +++ b/chrome/browser/ui/content_settings/content_setting_media_menu_model.cc |
| @@ -0,0 +1,77 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| +#include "chrome/common/pref_names.h" |
| + |
| + |
| +ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( |
| + Profile* profile, |
| + content::MediaStreamType type, |
| + ContentSettingBubbleModel* bubble_model, |
| + Observer* observer) |
| + : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| + profile_(profile), |
| + type_(type), |
| + media_bubble_model_(bubble_model), |
| + observer_(observer) { |
| + DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
| + media_bubble_model_->content_type()); |
| + 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.
|
| +} |
| + |
| +ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() { |
| +} |
| + |
| +bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const { |
| + return false; |
| +} |
| + |
| +bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const { |
| + return true; |
| +} |
| + |
| +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
|
| + int command_id, |
| + ui::Accelerator* accelerator) { |
| + return false; |
| +} |
| + |
| +void ContentSettingMediaMenuModel::ExecuteCommand(int command_id) { |
| + CommandMap::const_iterator it = commands_.find(command_id); |
| + DCHECK(it != commands_.end()); |
| + media_bubble_model_->OnMeiaMenuClicked(type_, it->second.id); |
| + |
| + if (observer_) |
| + observer_->UpdateMenuLabel(type_, it->second.name); |
| +} |
| + |
| +void ContentSettingMediaMenuModel::BuildMenu() { |
| + PrefService* prefs = profile_->GetPrefs(); |
| + MediaCaptureDevicesDispatcher* dispatcher = |
| + MediaCaptureDevicesDispatcher::GetInstance(); |
| + content::MediaStreamDevices devices; |
| + std::string default_device; |
| + if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| + devices = dispatcher->GetAudioCaptureDevices(); |
| + default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
| + } else if (type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
| + devices = dispatcher->GetVideoCaptureDevices(); |
| + default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + for (size_t i = 0; i < devices.size(); ++i) { |
| + int command_id = commands_.size(); |
| + commands_.insert(std::make_pair(command_id, devices[i])); |
| + AddItem(i, UTF8ToUTF16(devices[i].name)); |
| + } |
| +} |