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

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: addressed Peter and Evan's comments. 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,
62 const content::MediaStreamDevices& devices) {
63 DCHECK(!devices.empty());
64 for (content::MediaStreamDevices::const_iterator it = devices.begin();
65 it != devices.end(); ++it) {
66 if (it->id == device_id)
67 return *(it);
68 }
69
70 // A device with the |device_id| was not found. It is likely that the device
71 // has been unplugged from the OS. Return the first device as the default
72 // device.
73 return *devices.begin();
74 }
75
59 } // namespace 76 } // namespace
60 77
61 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( 78 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
62 Delegate* delegate, 79 Delegate* delegate,
63 WebContents* web_contents, 80 WebContents* web_contents,
64 Profile* profile, 81 Profile* profile,
65 ContentSettingsType content_type) 82 ContentSettingsType content_type)
66 : ContentSettingBubbleModel(web_contents, profile, content_type), 83 : ContentSettingBubbleModel(web_contents, profile, content_type),
67 delegate_(delegate) { 84 delegate_(delegate) {
68 // Notifications do not have a bubble. 85 // Notifications do not have a bubble.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 WebContents* web_contents, 515 WebContents* web_contents,
499 Profile* profile); 516 Profile* profile);
500 517
501 virtual ~ContentSettingMediaStreamBubbleModel(); 518 virtual ~ContentSettingMediaStreamBubbleModel();
502 519
503 private: 520 private:
504 // Sets the title of the bubble. 521 // Sets the title of the bubble.
505 void SetTitle(); 522 void SetTitle();
506 // Sets the data for the radio buttons of the bubble. 523 // Sets the data for the radio buttons of the bubble.
507 void SetRadioGroup(); 524 void SetRadioGroup();
525 // Sets the data for the media menus of the bubble.
526 void SetMediaMenus();
508 // Updates the camera and microphone setting with the passed |setting|. 527 // Updates the camera and microphone setting with the passed |setting|.
509 void UpdateSettings(ContentSetting setting); 528 void UpdateSettings(ContentSetting setting);
529 // Updates the camera and microphone default device with the passed |type|
530 // and device.
531 void UpdateDefaultDeviceForType(content::MediaStreamType type,
532 const std::string& device);
510 533
511 // ContentSettingBubbleModel implementation. 534 // ContentSettingBubbleModel implementation.
512 virtual void OnRadioClicked(int radio_index) OVERRIDE; 535 virtual void OnRadioClicked(int radio_index) OVERRIDE;
536 virtual void OnMediaMenuClicked(content::MediaStreamType type,
537 const std::string& selected_device) OVERRIDE;
513 538
514 // The index of the selected radio item. 539 // The index of the selected radio item.
515 int selected_item_; 540 int selected_item_;
516 // The content settings that are associated with the individual radio 541 // The content settings that are associated with the individual radio
517 // buttons. 542 // buttons.
518 ContentSetting radio_item_setting_[2]; 543 ContentSetting radio_item_setting_[2];
519 }; 544 };
520 545
521 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( 546 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
522 Delegate* delegate, 547 Delegate* delegate,
523 WebContents* web_contents, 548 WebContents* web_contents,
524 Profile* profile) 549 Profile* profile)
525 : ContentSettingTitleAndLinkModel( 550 : ContentSettingTitleAndLinkModel(
526 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), 551 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM),
527 selected_item_(0) { 552 selected_item_(0) {
553 DCHECK(profile);
528 // Initialize the content settings associated with the individual radio 554 // Initialize the content settings associated with the individual radio
529 // buttons. 555 // buttons.
530 radio_item_setting_[0] = CONTENT_SETTING_ASK; 556 radio_item_setting_[0] = CONTENT_SETTING_ASK;
531 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; 557 radio_item_setting_[1] = CONTENT_SETTING_BLOCK;
532 558
533 SetTitle(); 559 SetTitle();
534 SetRadioGroup(); 560 SetRadioGroup();
561 SetMediaMenus();
535 } 562 }
536 563
537 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { 564 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
538 // Update the media settings if the radio button selection was changed. 565 // Update the media settings if the radio button selection was changed.
539 if (selected_item_ != bubble_content().radio_group.default_item) 566 if (selected_item_ != bubble_content().radio_group.default_item)
540 UpdateSettings(radio_item_setting_[selected_item_]); 567 UpdateSettings(radio_item_setting_[selected_item_]);
568
569 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin();
570 it != bubble_content().media_menus.end(); ++it) {
571 if (it->second.selected_device.id != it->second.default_device.id)
572 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id);
573 }
541 } 574 }
542 575
543 void ContentSettingMediaStreamBubbleModel::SetTitle() { 576 void ContentSettingMediaStreamBubbleModel::SetTitle() {
544 TabSpecificContentSettings* content_settings = 577 TabSpecificContentSettings* content_settings =
545 TabSpecificContentSettings::FromWebContents(web_contents()); 578 TabSpecificContentSettings::FromWebContents(web_contents());
546 int title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_ALLOWED; 579 int title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_ALLOWED;
547 if (content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM)) 580 if (content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM))
548 title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_BLOCKED; 581 title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_BLOCKED;
549 set_title(l10n_util::GetStringUTF8(title_id)); 582 set_title(l10n_util::GetStringUTF8(title_id));
550 } 583 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 ContentSettingsPattern::Wildcard(); 643 ContentSettingsPattern::Wildcard();
611 content_settings->SetContentSetting( 644 content_settings->SetContentSetting(
612 primary_pattern, secondary_pattern, 645 primary_pattern, secondary_pattern,
613 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); 646 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
614 content_settings->SetContentSetting( 647 content_settings->SetContentSetting(
615 primary_pattern, secondary_pattern, 648 primary_pattern, secondary_pattern,
616 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); 649 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
617 } 650 }
618 } 651 }
619 652
653 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
654 content::MediaStreamType type,
655 const std::string& device) {
656 PrefService* prefs = profile()->GetPrefs();
657 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
658 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device);
659 } else {
660 DCHECK_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, type);
661 prefs->SetString(prefs::kDefaultVideoCaptureDevice, device);
662 }
663 }
664
665 void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
666 // Add microphone menu.
667 PrefService* prefs = profile()->GetPrefs();
668 MediaCaptureDevicesDispatcher* dispatcher =
669 MediaCaptureDevicesDispatcher::GetInstance();
670 const content::MediaStreamDevices& microphones =
671 dispatcher->GetAudioCaptureDevices();
672 MediaMenu mic_menu;
673 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL);
674 if (!microphones.empty()) {
675 std::string preferred_mic =
676 prefs->GetString(prefs::kDefaultAudioCaptureDevice);
677 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
678 mic_menu.selected_device = mic_menu.default_device;
679 }
680 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
681
682 // Add camera menu.
683 const content::MediaStreamDevices& cameras =
684 dispatcher->GetVideoCaptureDevices();
685 MediaMenu camera_menu;
686 camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL);
687 if (!cameras.empty()) {
688 std::string preferred_camera =
689 prefs->GetString(prefs::kDefaultVideoCaptureDevice);
690 camera_menu.default_device = GetMediaDeviceById(preferred_camera,
691 cameras);
692 camera_menu.selected_device = camera_menu.default_device;
693 }
694 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
695 }
696
620 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { 697 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
621 selected_item_ = radio_index; 698 selected_item_ = radio_index;
622 } 699 }
623 700
701 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked(
702 content::MediaStreamType type, const std::string& selected_device_id) {
703 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
704 type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
705 DCHECK_EQ(1U, bubble_content().media_menus.count(type));
706 MediaCaptureDevicesDispatcher* dispatcher =
707 MediaCaptureDevicesDispatcher::GetInstance();
708 const content::MediaStreamDevices& devices =
709 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) ?
710 dispatcher->GetAudioCaptureDevices() :
711 dispatcher->GetVideoCaptureDevices();
712 set_selected_device(GetMediaDeviceById(selected_device_id, devices));
713 }
714
624 class ContentSettingDomainListBubbleModel 715 class ContentSettingDomainListBubbleModel
625 : public ContentSettingTitleAndLinkModel { 716 : public ContentSettingTitleAndLinkModel {
626 public: 717 public:
627 ContentSettingDomainListBubbleModel(Delegate* delegate, 718 ContentSettingDomainListBubbleModel(Delegate* delegate,
628 WebContents* web_contents, 719 WebContents* web_contents,
629 Profile* profile, 720 Profile* profile,
630 ContentSettingsType content_type); 721 ContentSettingsType content_type);
631 virtual ~ContentSettingDomainListBubbleModel() {} 722 virtual ~ContentSettingDomainListBubbleModel() {}
632 723
633 private: 724 private:
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1049 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
959 DCHECK_EQ(web_contents_, 1050 DCHECK_EQ(web_contents_,
960 content::Source<WebContents>(source).ptr()); 1051 content::Source<WebContents>(source).ptr());
961 web_contents_ = NULL; 1052 web_contents_ = NULL;
962 } else { 1053 } else {
963 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1054 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
964 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1055 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
965 profile_ = NULL; 1056 profile_ = NULL;
966 } 1057 }
967 } 1058 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698