Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 12208010: Adding device selection menus to the content setting bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup and ready for review. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/api/infobars/infobar_service.h" 8 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "chrome/browser/content_settings/content_settings_utils.h" 9 #include "chrome/browser/content_settings/content_settings_utils.h"
10 #include "chrome/browser/content_settings/cookie_settings.h" 10 #include "chrome/browser/content_settings/cookie_settings.h"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 12 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
13 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 13 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
14 #include "chrome/browser/favicon/favicon_tab_helper.h" 14 #include "chrome/browser/favicon/favicon_tab_helper.h"
15 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 16 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 19 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
19 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h" 20 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h"
20 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 21 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
21 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 22 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
22 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/content_settings.h" 24 #include "chrome/common/content_settings.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
(...skipping 24 matching lines...) Expand all
49 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, 50 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
50 size_t num_entries, 51 size_t num_entries,
51 ContentSettingsType type) { 52 ContentSettingsType type) {
52 for (size_t i = 0; i < num_entries; ++i) { 53 for (size_t i = 0; i < num_entries; ++i) {
53 if (entries[i].type == type) 54 if (entries[i].type == type)
54 return entries[i].id; 55 return entries[i].id;
55 } 56 }
56 return 0; 57 return 0;
57 } 58 }
58 59
60 const content::MediaStreamDevice& GetMediaDeviceById(
61 const std::string& device_id, const content::MediaStreamDevices& devices) {
62 DCHECK(devices.size());
63 for (content::MediaStreamDevices::const_iterator it = devices.begin();
64 it != devices.end(); ++it) {
65 if (it->id == device_id)
66 return *(it);
67 }
68
69 // Could not find any device with |device_id|, likely the device has been
markusheintz_ 2013/02/06 11:03:26 Nit; changing this is up to you: A device with the
no longer working on chromium 2013/02/06 13:31:52 Done.
70 // unplugged from the OS. Return the first device as the default device.
71 return *devices.begin();
72 }
73
59 } // namespace 74 } // namespace
60 75
61 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( 76 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
62 Delegate* delegate, 77 Delegate* delegate,
63 WebContents* web_contents, 78 WebContents* web_contents,
64 Profile* profile, 79 Profile* profile,
65 ContentSettingsType content_type) 80 ContentSettingsType content_type)
66 : ContentSettingBubbleModel(web_contents, profile, content_type), 81 : ContentSettingBubbleModel(web_contents, profile, content_type),
67 delegate_(delegate) { 82 delegate_(delegate) {
68 // Notifications do not have a bubble. 83 // Notifications do not have a bubble.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 WebContents* web_contents, 513 WebContents* web_contents,
499 Profile* profile); 514 Profile* profile);
500 515
501 virtual ~ContentSettingMediaStreamBubbleModel(); 516 virtual ~ContentSettingMediaStreamBubbleModel();
502 517
503 private: 518 private:
504 // Sets the title of the bubble. 519 // Sets the title of the bubble.
505 void SetTitle(); 520 void SetTitle();
506 // Sets the data for the radio buttons of the bubble. 521 // Sets the data for the radio buttons of the bubble.
507 void SetRadioGroup(); 522 void SetRadioGroup();
523 // Sets the data for the media menus of the bubble.
524 void SetMediaMenus();
508 // Updates the camera and microphone setting with the passed |setting|. 525 // Updates the camera and microphone setting with the passed |setting|.
509 void UpdateSettings(ContentSetting setting); 526 void UpdateSettings(ContentSetting setting);
527 // Updates the camera and microphone default device with the passed |type|
528 // and device.
529 void UpdateDefaultDeviceForType(content::MediaStreamType type,
530 const std::string& device);
510 531
511 // ContentSettingBubbleModel implementation. 532 // ContentSettingBubbleModel implementation.
512 virtual void OnRadioClicked(int radio_index) OVERRIDE; 533 virtual void OnRadioClicked(int radio_index) OVERRIDE;
534 virtual void OnMeiaMenuClicked(content::MediaStreamType type,
535 const std::string& selected_device) OVERRIDE;
513 536
514 // The index of the selected radio item. 537 // The index of the selected radio item.
515 int selected_item_; 538 int selected_item_;
516 // The content settings that are associated with the individual radio 539 // The content settings that are associated with the individual radio
517 // buttons. 540 // buttons.
518 ContentSetting radio_item_setting_[2]; 541 ContentSetting radio_item_setting_[2];
519 }; 542 };
520 543
521 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( 544 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
522 Delegate* delegate, 545 Delegate* delegate,
523 WebContents* web_contents, 546 WebContents* web_contents,
524 Profile* profile) 547 Profile* profile)
525 : ContentSettingTitleAndLinkModel( 548 : ContentSettingTitleAndLinkModel(
526 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), 549 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM),
527 selected_item_(0) { 550 selected_item_(0) {
551 DCHECK(profile);
528 // Initialize the content settings associated with the individual radio 552 // Initialize the content settings associated with the individual radio
529 // buttons. 553 // buttons.
530 radio_item_setting_[0] = CONTENT_SETTING_ASK; 554 radio_item_setting_[0] = CONTENT_SETTING_ASK;
531 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; 555 radio_item_setting_[1] = CONTENT_SETTING_BLOCK;
532 556
533 SetTitle(); 557 SetTitle();
534 SetRadioGroup(); 558 SetRadioGroup();
559 SetMediaMenus();
535 } 560 }
536 561
537 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { 562 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
538 // Update the media settings if the radio button selection was changed. 563 // Update the media settings if the radio button selection was changed.
539 if (selected_item_ != bubble_content().radio_group.default_item) 564 if (selected_item_ != bubble_content().radio_group.default_item)
540 UpdateSettings(radio_item_setting_[selected_item_]); 565 UpdateSettings(radio_item_setting_[selected_item_]);
566
567 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin();
568 it != bubble_content().media_menus.end(); ++it) {
569 if (it->second.selected_device.id != it->second.default_device.id) {
570 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id);
571 }
572 }
541 } 573 }
542 574
543 void ContentSettingMediaStreamBubbleModel::SetTitle() { 575 void ContentSettingMediaStreamBubbleModel::SetTitle() {
544 TabSpecificContentSettings* content_settings = 576 TabSpecificContentSettings* content_settings =
545 TabSpecificContentSettings::FromWebContents(web_contents()); 577 TabSpecificContentSettings::FromWebContents(web_contents());
546 int title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_ALLOWED; 578 int title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_ALLOWED;
547 if (content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM)) 579 if (content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM))
548 title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_BLOCKED; 580 title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_BLOCKED;
549 set_title(l10n_util::GetStringUTF8(title_id)); 581 set_title(l10n_util::GetStringUTF8(title_id));
550 } 582 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 ContentSettingsPattern::Wildcard(); 642 ContentSettingsPattern::Wildcard();
611 content_settings->SetContentSetting( 643 content_settings->SetContentSetting(
612 primary_pattern, secondary_pattern, 644 primary_pattern, secondary_pattern,
613 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); 645 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
614 content_settings->SetContentSetting( 646 content_settings->SetContentSetting(
615 primary_pattern, secondary_pattern, 647 primary_pattern, secondary_pattern,
616 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); 648 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
617 } 649 }
618 } 650 }
619 651
652 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
653 content::MediaStreamType type, const std::string& device) {
654 PrefService* prefs = profile()->GetPrefs();
655 switch (type) {
656 case content::MEDIA_DEVICE_AUDIO_CAPTURE:
657 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device);
658 break;
659 case content::MEDIA_DEVICE_VIDEO_CAPTURE:
660 prefs->SetString(prefs::kDefaultVideoCaptureDevice, device);
661 break;
662 default:
663 NOTREACHED();
664 }
665 }
666
667 void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
668 // Add microphone menu.
669 PrefService* prefs = profile()->GetPrefs();
670 MediaCaptureDevicesDispatcher* dispatcher =
671 MediaCaptureDevicesDispatcher::GetInstance();
672 const content::MediaStreamDevices& micophones =
markusheintz_ 2013/02/06 11:03:26 typo: please s/micophones/microphones/g
no longer working on chromium 2013/02/06 13:31:52 Done.
673 dispatcher->GetAudioCaptureDevices();
674 MediaMenu mic_menu;
675 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL);
676 if (micophones.size()) {
677 std::string preferred_mic =
678 prefs->GetString(prefs::kDefaultAudioCaptureDevice);
679 mic_menu.default_device = GetMediaDeviceById(preferred_mic, micophones);
680 mic_menu.selected_device = mic_menu.default_device;
681 }
682 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
683
684 // Add camera menu.
685 const content::MediaStreamDevices& cameras =
686 dispatcher->GetVideoCaptureDevices();
687 MediaMenu camera_menu;
688 camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL);
689 if (cameras.size()) {
690 std::string preferred_camera =
691 prefs->GetString(prefs::kDefaultVideoCaptureDevice);
692 camera_menu.default_device = GetMediaDeviceById(preferred_camera,
693 cameras);
694 camera_menu.selected_device = camera_menu.default_device;
695 }
696 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
697 }
698
620 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { 699 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
621 selected_item_ = radio_index; 700 selected_item_ = radio_index;
622 } 701 }
623 702
703 void ContentSettingMediaStreamBubbleModel::OnMeiaMenuClicked(
704 content::MediaStreamType type, const std::string& selected_device_id) {
705 DCHECK(bubble_content().media_menus.find(type) !=
706 bubble_content().media_menus.end());
707 MediaCaptureDevicesDispatcher* dispatcher =
708 MediaCaptureDevicesDispatcher::GetInstance();
709 content::MediaStreamDevices devices;
710 switch (type) {
711 case content::MEDIA_DEVICE_AUDIO_CAPTURE:
712 devices = dispatcher->GetAudioCaptureDevices();
713 break;
714 case content::MEDIA_DEVICE_VIDEO_CAPTURE:
715 devices = dispatcher->GetVideoCaptureDevices();
716 break;
717 default:
718 NOTREACHED();
719 }
720 set_selected_device(GetMediaDeviceById(selected_device_id, devices));
721 }
722
624 class ContentSettingDomainListBubbleModel 723 class ContentSettingDomainListBubbleModel
625 : public ContentSettingTitleAndLinkModel { 724 : public ContentSettingTitleAndLinkModel {
626 public: 725 public:
627 ContentSettingDomainListBubbleModel(Delegate* delegate, 726 ContentSettingDomainListBubbleModel(Delegate* delegate,
628 WebContents* web_contents, 727 WebContents* web_contents,
629 Profile* profile, 728 Profile* profile,
630 ContentSettingsType content_type); 729 ContentSettingsType content_type);
631 virtual ~ContentSettingDomainListBubbleModel() {} 730 virtual ~ContentSettingDomainListBubbleModel() {}
632 731
633 private: 732 private:
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1057 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
959 DCHECK_EQ(web_contents_, 1058 DCHECK_EQ(web_contents_,
960 content::Source<WebContents>(source).ptr()); 1059 content::Source<WebContents>(source).ptr());
961 web_contents_ = NULL; 1060 web_contents_ = NULL;
962 } else { 1061 } else {
963 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1062 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
964 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1063 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
965 profile_ = NULL; 1064 profile_ = NULL;
966 } 1065 }
967 } 1066 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698