| OLD | NEW |
| 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/browser/ui/content_settings/content_setting_changed_infobar_del
egate.h" | 23 #include "chrome/browser/ui/content_settings/content_setting_changed_infobar_del
egate.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/content_settings.h" | 25 #include "chrome/common/content_settings.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, | 52 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, |
| 52 size_t num_entries, | 53 size_t num_entries, |
| 53 ContentSettingsType type) { | 54 ContentSettingsType type) { |
| 54 for (size_t i = 0; i < num_entries; ++i) { | 55 for (size_t i = 0; i < num_entries; ++i) { |
| 55 if (entries[i].type == type) | 56 if (entries[i].type == type) |
| 56 return entries[i].id; | 57 return entries[i].id; |
| 57 } | 58 } |
| 58 return 0; | 59 return 0; |
| 59 } | 60 } |
| 60 | 61 |
| 62 const content::MediaStreamDevice& GetMediaDeviceById( |
| 63 const std::string& device_id, |
| 64 const content::MediaStreamDevices& devices) { |
| 65 DCHECK(!devices.empty()); |
| 66 for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
| 67 it != devices.end(); ++it) { |
| 68 if (it->id == device_id) |
| 69 return *(it); |
| 70 } |
| 71 |
| 72 // A device with the |device_id| was not found. It is likely that the device |
| 73 // has been unplugged from the OS. Return the first device as the default |
| 74 // device. |
| 75 return *devices.begin(); |
| 76 } |
| 77 |
| 61 } // namespace | 78 } // namespace |
| 62 | 79 |
| 63 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( | 80 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( |
| 64 Delegate* delegate, | 81 Delegate* delegate, |
| 65 WebContents* web_contents, | 82 WebContents* web_contents, |
| 66 Profile* profile, | 83 Profile* profile, |
| 67 ContentSettingsType content_type) | 84 ContentSettingsType content_type) |
| 68 : ContentSettingBubbleModel(web_contents, profile, content_type), | 85 : ContentSettingBubbleModel(web_contents, profile, content_type), |
| 69 delegate_(delegate) { | 86 delegate_(delegate) { |
| 70 // Notifications do not have a bubble. | 87 // Notifications do not have a bubble. |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 WebContents* web_contents, | 517 WebContents* web_contents, |
| 501 Profile* profile); | 518 Profile* profile); |
| 502 | 519 |
| 503 virtual ~ContentSettingMediaStreamBubbleModel(); | 520 virtual ~ContentSettingMediaStreamBubbleModel(); |
| 504 | 521 |
| 505 private: | 522 private: |
| 506 // Sets the title of the bubble. | 523 // Sets the title of the bubble. |
| 507 void SetTitle(); | 524 void SetTitle(); |
| 508 // Sets the data for the radio buttons of the bubble. | 525 // Sets the data for the radio buttons of the bubble. |
| 509 void SetRadioGroup(); | 526 void SetRadioGroup(); |
| 527 // Sets the data for the media menus of the bubble. |
| 528 void SetMediaMenus(); |
| 510 // Updates the camera and microphone setting with the passed |setting|. | 529 // Updates the camera and microphone setting with the passed |setting|. |
| 511 void UpdateSettings(ContentSetting setting); | 530 void UpdateSettings(ContentSetting setting); |
| 531 // Updates the camera and microphone default device with the passed |type| |
| 532 // and device. |
| 533 void UpdateDefaultDeviceForType(content::MediaStreamType type, |
| 534 const std::string& device); |
| 512 | 535 |
| 513 // ContentSettingBubbleModel implementation. | 536 // ContentSettingBubbleModel implementation. |
| 514 virtual void OnRadioClicked(int radio_index) OVERRIDE; | 537 virtual void OnRadioClicked(int radio_index) OVERRIDE; |
| 538 virtual void OnMediaMenuClicked(content::MediaStreamType type, |
| 539 const std::string& selected_device) OVERRIDE; |
| 515 | 540 |
| 516 // The index of the selected radio item. | 541 // The index of the selected radio item. |
| 517 int selected_item_; | 542 int selected_item_; |
| 518 // The content settings that are associated with the individual radio | 543 // The content settings that are associated with the individual radio |
| 519 // buttons. | 544 // buttons. |
| 520 ContentSetting radio_item_setting_[2]; | 545 ContentSetting radio_item_setting_[2]; |
| 521 }; | 546 }; |
| 522 | 547 |
| 523 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | 548 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
| 524 Delegate* delegate, | 549 Delegate* delegate, |
| 525 WebContents* web_contents, | 550 WebContents* web_contents, |
| 526 Profile* profile) | 551 Profile* profile) |
| 527 : ContentSettingTitleAndLinkModel( | 552 : ContentSettingTitleAndLinkModel( |
| 528 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), | 553 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), |
| 529 selected_item_(0) { | 554 selected_item_(0) { |
| 555 DCHECK(profile); |
| 530 // Initialize the content settings associated with the individual radio | 556 // Initialize the content settings associated with the individual radio |
| 531 // buttons. | 557 // buttons. |
| 532 radio_item_setting_[0] = CONTENT_SETTING_ASK; | 558 radio_item_setting_[0] = CONTENT_SETTING_ASK; |
| 533 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; | 559 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; |
| 534 | 560 |
| 535 SetTitle(); | 561 SetTitle(); |
| 536 SetRadioGroup(); | 562 SetRadioGroup(); |
| 563 SetMediaMenus(); |
| 537 } | 564 } |
| 538 | 565 |
| 539 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | 566 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
| 567 bool media_setting_changed = false; |
| 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) { |
| 571 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); |
| 572 media_setting_changed = true; |
| 573 } |
| 574 } |
| 575 |
| 540 // Update the media settings if the radio button selection was changed. | 576 // Update the media settings if the radio button selection was changed. |
| 541 if (selected_item_ != bubble_content().radio_group.default_item) { | 577 if (selected_item_ != bubble_content().radio_group.default_item) { |
| 542 UpdateSettings(radio_item_setting_[selected_item_]); | 578 UpdateSettings(radio_item_setting_[selected_item_]); |
| 579 media_setting_changed = true; |
| 580 } |
| 581 |
| 582 // Trigger the reload infobar if the media setting has been changed. |
| 583 if (media_setting_changed) { |
| 543 ContentSettingChangedInfoBarDelegate::Create( | 584 ContentSettingChangedInfoBarDelegate::Create( |
| 544 InfoBarService::FromWebContents(web_contents()), | 585 InfoBarService::FromWebContents(web_contents()), |
| 545 IDR_INFOBAR_MEDIA_STREAM_CAMERA, | 586 IDR_INFOBAR_MEDIA_STREAM_CAMERA, |
| 546 IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE); | 587 IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE); |
| 547 } | 588 } |
| 548 } | 589 } |
| 549 | 590 |
| 550 void ContentSettingMediaStreamBubbleModel::SetTitle() { | 591 void ContentSettingMediaStreamBubbleModel::SetTitle() { |
| 551 TabSpecificContentSettings* content_settings = | 592 TabSpecificContentSettings* content_settings = |
| 552 TabSpecificContentSettings::FromWebContents(web_contents()); | 593 TabSpecificContentSettings::FromWebContents(web_contents()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 ContentSettingsPattern::Wildcard(); | 658 ContentSettingsPattern::Wildcard(); |
| 618 content_settings->SetContentSetting( | 659 content_settings->SetContentSetting( |
| 619 primary_pattern, secondary_pattern, | 660 primary_pattern, secondary_pattern, |
| 620 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); | 661 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); |
| 621 content_settings->SetContentSetting( | 662 content_settings->SetContentSetting( |
| 622 primary_pattern, secondary_pattern, | 663 primary_pattern, secondary_pattern, |
| 623 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); | 664 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); |
| 624 } | 665 } |
| 625 } | 666 } |
| 626 | 667 |
| 668 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
| 669 content::MediaStreamType type, |
| 670 const std::string& device) { |
| 671 PrefService* prefs = profile()->GetPrefs(); |
| 672 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 673 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); |
| 674 } else { |
| 675 DCHECK_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, type); |
| 676 prefs->SetString(prefs::kDefaultVideoCaptureDevice, device); |
| 677 } |
| 678 } |
| 679 |
| 680 void ContentSettingMediaStreamBubbleModel::SetMediaMenus() { |
| 681 // Add microphone menu. |
| 682 PrefService* prefs = profile()->GetPrefs(); |
| 683 MediaCaptureDevicesDispatcher* dispatcher = |
| 684 MediaCaptureDevicesDispatcher::GetInstance(); |
| 685 const content::MediaStreamDevices& microphones = |
| 686 dispatcher->GetAudioCaptureDevices(); |
| 687 MediaMenu mic_menu; |
| 688 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); |
| 689 if (!microphones.empty()) { |
| 690 std::string preferred_mic = |
| 691 prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
| 692 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); |
| 693 mic_menu.selected_device = mic_menu.default_device; |
| 694 } |
| 695 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); |
| 696 |
| 697 // Add camera menu. |
| 698 const content::MediaStreamDevices& cameras = |
| 699 dispatcher->GetVideoCaptureDevices(); |
| 700 MediaMenu camera_menu; |
| 701 camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); |
| 702 if (!cameras.empty()) { |
| 703 std::string preferred_camera = |
| 704 prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
| 705 camera_menu.default_device = GetMediaDeviceById(preferred_camera, |
| 706 cameras); |
| 707 camera_menu.selected_device = camera_menu.default_device; |
| 708 } |
| 709 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
| 710 } |
| 711 |
| 627 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | 712 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
| 628 selected_item_ = radio_index; | 713 selected_item_ = radio_index; |
| 629 } | 714 } |
| 630 | 715 |
| 716 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( |
| 717 content::MediaStreamType type, const std::string& selected_device_id) { |
| 718 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 719 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 720 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); |
| 721 MediaCaptureDevicesDispatcher* dispatcher = |
| 722 MediaCaptureDevicesDispatcher::GetInstance(); |
| 723 const content::MediaStreamDevices& devices = |
| 724 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) ? |
| 725 dispatcher->GetAudioCaptureDevices() : |
| 726 dispatcher->GetVideoCaptureDevices(); |
| 727 set_selected_device(GetMediaDeviceById(selected_device_id, devices)); |
| 728 } |
| 729 |
| 631 class ContentSettingDomainListBubbleModel | 730 class ContentSettingDomainListBubbleModel |
| 632 : public ContentSettingTitleAndLinkModel { | 731 : public ContentSettingTitleAndLinkModel { |
| 633 public: | 732 public: |
| 634 ContentSettingDomainListBubbleModel(Delegate* delegate, | 733 ContentSettingDomainListBubbleModel(Delegate* delegate, |
| 635 WebContents* web_contents, | 734 WebContents* web_contents, |
| 636 Profile* profile, | 735 Profile* profile, |
| 637 ContentSettingsType content_type); | 736 ContentSettingsType content_type); |
| 638 virtual ~ContentSettingDomainListBubbleModel() {} | 737 virtual ~ContentSettingDomainListBubbleModel() {} |
| 639 | 738 |
| 640 private: | 739 private: |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1064 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 966 DCHECK_EQ(web_contents_, | 1065 DCHECK_EQ(web_contents_, |
| 967 content::Source<WebContents>(source).ptr()); | 1066 content::Source<WebContents>(source).ptr()); |
| 968 web_contents_ = NULL; | 1067 web_contents_ = NULL; |
| 969 } else { | 1068 } else { |
| 970 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1069 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 971 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1070 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 972 profile_ = NULL; | 1071 profile_ = NULL; |
| 973 } | 1072 } |
| 974 } | 1073 } |
| OLD | NEW |