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

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: fixed the windows code. 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) {
Peter Kasting 2013/02/06 22:11:18 Nit: One arg per line
no longer working on chromium 2013/02/07 16:25:19 Done.
62 DCHECK(devices.size());
Peter Kasting 2013/02/06 22:11:18 Nit: !empty()
no longer working on chromium 2013/02/07 16:25:19 Done.
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 // A device with the |device_id| was not found. It is likely that the device
70 // has been unplugged from the OS. Return the first device as the default
71 // device.
72 return *devices.begin();
73 }
74
59 } // namespace 75 } // namespace
60 76
61 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( 77 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
62 Delegate* delegate, 78 Delegate* delegate,
63 WebContents* web_contents, 79 WebContents* web_contents,
64 Profile* profile, 80 Profile* profile,
65 ContentSettingsType content_type) 81 ContentSettingsType content_type)
66 : ContentSettingBubbleModel(web_contents, profile, content_type), 82 : ContentSettingBubbleModel(web_contents, profile, content_type),
67 delegate_(delegate) { 83 delegate_(delegate) {
68 // Notifications do not have a bubble. 84 // Notifications do not have a bubble.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 WebContents* web_contents, 514 WebContents* web_contents,
499 Profile* profile); 515 Profile* profile);
500 516
501 virtual ~ContentSettingMediaStreamBubbleModel(); 517 virtual ~ContentSettingMediaStreamBubbleModel();
502 518
503 private: 519 private:
504 // Sets the title of the bubble. 520 // Sets the title of the bubble.
505 void SetTitle(); 521 void SetTitle();
506 // Sets the data for the radio buttons of the bubble. 522 // Sets the data for the radio buttons of the bubble.
507 void SetRadioGroup(); 523 void SetRadioGroup();
524 // Sets the data for the media menus of the bubble.
525 void SetMediaMenus();
508 // Updates the camera and microphone setting with the passed |setting|. 526 // Updates the camera and microphone setting with the passed |setting|.
509 void UpdateSettings(ContentSetting setting); 527 void UpdateSettings(ContentSetting setting);
528 // Updates the camera and microphone default device with the passed |type|
529 // and device.
530 void UpdateDefaultDeviceForType(content::MediaStreamType type,
531 const std::string& device);
510 532
511 // ContentSettingBubbleModel implementation. 533 // ContentSettingBubbleModel implementation.
512 virtual void OnRadioClicked(int radio_index) OVERRIDE; 534 virtual void OnRadioClicked(int radio_index) OVERRIDE;
535 virtual void OnMediaMenuClicked(content::MediaStreamType type,
536 const std::string& selected_device) OVERRIDE;
513 537
514 // The index of the selected radio item. 538 // The index of the selected radio item.
515 int selected_item_; 539 int selected_item_;
516 // The content settings that are associated with the individual radio 540 // The content settings that are associated with the individual radio
517 // buttons. 541 // buttons.
518 ContentSetting radio_item_setting_[2]; 542 ContentSetting radio_item_setting_[2];
519 }; 543 };
520 544
521 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( 545 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
522 Delegate* delegate, 546 Delegate* delegate,
523 WebContents* web_contents, 547 WebContents* web_contents,
524 Profile* profile) 548 Profile* profile)
525 : ContentSettingTitleAndLinkModel( 549 : ContentSettingTitleAndLinkModel(
526 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), 550 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM),
527 selected_item_(0) { 551 selected_item_(0) {
552 DCHECK(profile);
528 // Initialize the content settings associated with the individual radio 553 // Initialize the content settings associated with the individual radio
529 // buttons. 554 // buttons.
530 radio_item_setting_[0] = CONTENT_SETTING_ASK; 555 radio_item_setting_[0] = CONTENT_SETTING_ASK;
531 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; 556 radio_item_setting_[1] = CONTENT_SETTING_BLOCK;
532 557
533 SetTitle(); 558 SetTitle();
534 SetRadioGroup(); 559 SetRadioGroup();
560 SetMediaMenus();
535 } 561 }
536 562
537 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { 563 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
538 // Update the media settings if the radio button selection was changed. 564 // Update the media settings if the radio button selection was changed.
539 if (selected_item_ != bubble_content().radio_group.default_item) 565 if (selected_item_ != bubble_content().radio_group.default_item)
540 UpdateSettings(radio_item_setting_[selected_item_]); 566 UpdateSettings(radio_item_setting_[selected_item_]);
567
568 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin();
569 it != bubble_content().media_menus.end(); ++it) {
570 if (it->second.selected_device.id != it->second.default_device.id) {
Peter Kasting 2013/02/06 22:11:18 Nit: {} not necessary
no longer working on chromium 2013/02/07 16:25:19 Done.
571 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id);
572 }
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, const std::string& device) {
Peter Kasting 2013/02/06 22:11:18 Nit: One arg per line
no longer working on chromium 2013/02/07 16:25:19 Done.
655 PrefService* prefs = profile()->GetPrefs();
656 switch (type) {
Peter Kasting 2013/02/06 22:11:18 Nit: Shorter: DCHECK((type == content::MEDIA_DE
no longer working on chromium 2013/02/07 16:25:19 Done with using the ifs.
657 case content::MEDIA_DEVICE_AUDIO_CAPTURE:
658 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device);
659 break;
660 case content::MEDIA_DEVICE_VIDEO_CAPTURE:
661 prefs->SetString(prefs::kDefaultVideoCaptureDevice, device);
662 break;
663 default:
664 NOTREACHED();
665 }
666 }
667
668 void ContentSettingMediaStreamBubbleModel::SetMediaMenus() {
669 // Add microphone menu.
670 PrefService* prefs = profile()->GetPrefs();
671 MediaCaptureDevicesDispatcher* dispatcher =
672 MediaCaptureDevicesDispatcher::GetInstance();
673 const content::MediaStreamDevices& microphones =
674 dispatcher->GetAudioCaptureDevices();
675 MediaMenu mic_menu;
676 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL);
677 if (microphones.size()) {
Peter Kasting 2013/02/06 22:11:18 Nit: !empty() (2 places)
no longer working on chromium 2013/02/07 16:25:19 Done.
678 std::string preferred_mic =
679 prefs->GetString(prefs::kDefaultAudioCaptureDevice);
680 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
681 mic_menu.selected_device = mic_menu.default_device;
682 }
683 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
684
685 // Add camera menu.
686 const content::MediaStreamDevices& cameras =
687 dispatcher->GetVideoCaptureDevices();
688 MediaMenu camera_menu;
689 camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL);
690 if (cameras.size()) {
691 std::string preferred_camera =
692 prefs->GetString(prefs::kDefaultVideoCaptureDevice);
693 camera_menu.default_device = GetMediaDeviceById(preferred_camera,
694 cameras);
695 camera_menu.selected_device = camera_menu.default_device;
696 }
697 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
698 }
699
620 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { 700 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
621 selected_item_ = radio_index; 701 selected_item_ = radio_index;
622 } 702 }
623 703
704 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked(
705 content::MediaStreamType type, const std::string& selected_device_id) {
706 DCHECK(bubble_content().media_menus.find(type) !=
Peter Kasting 2013/02/06 22:11:18 Nit: Use count() instead of find() (shorter)
no longer working on chromium 2013/02/07 16:25:19 Done.
707 bubble_content().media_menus.end());
708 MediaCaptureDevicesDispatcher* dispatcher =
709 MediaCaptureDevicesDispatcher::GetInstance();
710 content::MediaStreamDevices devices;
Peter Kasting 2013/02/06 22:11:18 Nit: I suggest using ?: to initialize this at its
no longer working on chromium 2013/02/07 16:25:19 Done.
711 switch (type) {
712 case content::MEDIA_DEVICE_AUDIO_CAPTURE:
713 devices = dispatcher->GetAudioCaptureDevices();
714 break;
715 case content::MEDIA_DEVICE_VIDEO_CAPTURE:
716 devices = dispatcher->GetVideoCaptureDevices();
717 break;
718 default:
719 NOTREACHED();
720 }
721 set_selected_device(GetMediaDeviceById(selected_device_id, devices));
722 }
723
624 class ContentSettingDomainListBubbleModel 724 class ContentSettingDomainListBubbleModel
625 : public ContentSettingTitleAndLinkModel { 725 : public ContentSettingTitleAndLinkModel {
626 public: 726 public:
627 ContentSettingDomainListBubbleModel(Delegate* delegate, 727 ContentSettingDomainListBubbleModel(Delegate* delegate,
628 WebContents* web_contents, 728 WebContents* web_contents,
629 Profile* profile, 729 Profile* profile,
630 ContentSettingsType content_type); 730 ContentSettingsType content_type);
631 virtual ~ContentSettingDomainListBubbleModel() {} 731 virtual ~ContentSettingDomainListBubbleModel() {}
632 732
633 private: 733 private:
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1058 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
959 DCHECK_EQ(web_contents_, 1059 DCHECK_EQ(web_contents_,
960 content::Source<WebContents>(source).ptr()); 1060 content::Source<WebContents>(source).ptr());
961 web_contents_ = NULL; 1061 web_contents_ = NULL;
962 } else { 1062 } else {
963 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1063 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
964 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1064 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
965 profile_ = NULL; 1065 profile_ = NULL;
966 } 1066 }
967 } 1067 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698