Chromium Code Reviews| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 // The model of the content settings bubble for media settings. | 571 // The model of the content settings bubble for media settings. |
| 572 class ContentSettingMediaStreamBubbleModel | 572 class ContentSettingMediaStreamBubbleModel |
| 573 : public ContentSettingTitleAndLinkModel { | 573 : public ContentSettingTitleAndLinkModel { |
| 574 public: | 574 public: |
| 575 ContentSettingMediaStreamBubbleModel(Delegate* delegate, | 575 ContentSettingMediaStreamBubbleModel(Delegate* delegate, |
| 576 WebContents* web_contents, | 576 WebContents* web_contents, |
| 577 Profile* profile); | 577 Profile* profile); |
| 578 | 578 |
| 579 ~ContentSettingMediaStreamBubbleModel() override; | 579 ~ContentSettingMediaStreamBubbleModel() override; |
| 580 | 580 |
| 581 void OnManageLinkClicked() override; | |
| 582 | |
| 581 private: | 583 private: |
| 582 void SetTitle(); | 584 void SetTitle(); |
| 583 // Sets the data for the radio buttons of the bubble. | 585 // Sets the data for the radio buttons of the bubble. |
| 584 void SetRadioGroup(); | 586 void SetRadioGroup(); |
| 585 // Sets the data for the media menus of the bubble. | 587 // Sets the data for the media menus of the bubble. |
| 586 void SetMediaMenus(); | 588 void SetMediaMenus(); |
| 589 // Set the settings management link. | |
| 590 void SetManageLink(); | |
| 587 void SetCustomLink(); | 591 void SetCustomLink(); |
| 588 // Updates the camera and microphone setting with the passed |setting|. | 592 // Updates the camera and microphone setting with the passed |setting|. |
| 589 void UpdateSettings(ContentSetting setting); | 593 void UpdateSettings(ContentSetting setting); |
| 590 // Updates the camera and microphone default device with the passed |type| | 594 // Updates the camera and microphone default device with the passed |type| |
| 591 // and device. | 595 // and device. |
| 592 void UpdateDefaultDeviceForType(content::MediaStreamType type, | 596 void UpdateDefaultDeviceForType(content::MediaStreamType type, |
| 593 const std::string& device); | 597 const std::string& device); |
| 594 | 598 |
| 595 // ContentSettingBubbleModel implementation. | 599 // ContentSettingBubbleModel implementation. |
| 596 void OnRadioClicked(int radio_index) override; | 600 void OnRadioClicked(int radio_index) override; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 607 }; | 611 }; |
| 608 | 612 |
| 609 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | 613 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
| 610 Delegate* delegate, | 614 Delegate* delegate, |
| 611 WebContents* web_contents, | 615 WebContents* web_contents, |
| 612 Profile* profile) | 616 Profile* profile) |
| 613 : ContentSettingTitleAndLinkModel( | 617 : ContentSettingTitleAndLinkModel( |
| 614 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), | 618 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), |
| 615 selected_item_(0), | 619 selected_item_(0), |
| 616 state_(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) { | 620 state_(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) { |
| 621 // TODO(msramek): Every bubble is tied to a particular content setting. | |
| 622 // The media bubble has three states - mic only, camera only, and both. | |
| 623 // However, it is always tied to the deprecated MEDIASTREAM setting. Refactor | |
| 624 // this so that it refers to the MIC setting for microphone and CAMERA | |
| 625 // setting for camera to reduce the duplication of code in practically every | |
| 626 // method. Furthermore, it should be possible not to tie the bubble to any | |
| 627 // particular content setting type, as we still need the bubble for both | |
| 628 // camera and microphone, but should not use the deprecated MEDIASTREAM | |
| 629 // setting. | |
| 630 | |
| 617 DCHECK(profile); | 631 DCHECK(profile); |
| 618 // Initialize the content settings associated with the individual radio | 632 // Initialize the content settings associated with the individual radio |
| 619 // buttons. | 633 // buttons. |
| 620 radio_item_setting_[0] = CONTENT_SETTING_ASK; | 634 radio_item_setting_[0] = CONTENT_SETTING_ASK; |
| 621 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; | 635 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; |
| 622 | 636 |
| 623 TabSpecificContentSettings* content_settings = | 637 TabSpecificContentSettings* content_settings = |
| 624 TabSpecificContentSettings::FromWebContents(web_contents); | 638 TabSpecificContentSettings::FromWebContents(web_contents); |
| 625 state_ = content_settings->GetMicrophoneCameraState(); | 639 state_ = content_settings->GetMicrophoneCameraState(); |
| 626 DCHECK(state_ & (TabSpecificContentSettings::MICROPHONE_ACCESSED | | 640 DCHECK(state_ & (TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 627 TabSpecificContentSettings::CAMERA_ACCESSED)); | 641 TabSpecificContentSettings::CAMERA_ACCESSED)); |
| 628 | 642 |
| 629 SetTitle(); | 643 SetTitle(); |
| 630 SetRadioGroup(); | 644 SetRadioGroup(); |
| 631 SetMediaMenus(); | 645 SetMediaMenus(); |
| 646 SetManageLink(); | |
| 632 SetCustomLink(); | 647 SetCustomLink(); |
| 633 } | 648 } |
| 634 | 649 |
| 635 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | 650 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
| 636 // On some platforms (e.g. MacOS X) it is possible to close a tab while the | 651 // On some platforms (e.g. MacOS X) it is possible to close a tab while the |
| 637 // media stream bubble is open. This resets the web contents to NULL. | 652 // media stream bubble is open. This resets the web contents to NULL. |
| 638 if (!web_contents()) | 653 if (!web_contents()) |
| 639 return; | 654 return; |
| 640 | 655 |
| 641 for (const std::pair<content::MediaStreamType, MediaMenu>& media_menu : | 656 for (const std::pair<content::MediaStreamType, MediaMenu>& media_menu : |
| 642 bubble_content().media_menus) { | 657 bubble_content().media_menus) { |
| 643 if (media_menu.second.selected_device.id != | 658 if (media_menu.second.selected_device.id != |
| 644 media_menu.second.default_device.id) { | 659 media_menu.second.default_device.id) { |
| 645 UpdateDefaultDeviceForType(media_menu.first, | 660 UpdateDefaultDeviceForType(media_menu.first, |
| 646 media_menu.second.selected_device.id); | 661 media_menu.second.selected_device.id); |
| 647 } | 662 } |
| 648 } | 663 } |
| 649 | 664 |
| 650 // Update the media settings if the radio button selection was changed. | 665 // Update the media settings if the radio button selection was changed. |
| 651 if (selected_item_ != bubble_content().radio_group.default_item) { | 666 if (selected_item_ != bubble_content().radio_group.default_item) { |
| 652 UpdateSettings(radio_item_setting_[selected_item_]); | 667 UpdateSettings(radio_item_setting_[selected_item_]); |
| 653 } | 668 } |
| 654 } | 669 } |
| 655 | 670 |
| 671 void ContentSettingMediaStreamBubbleModel::OnManageLinkClicked() { | |
| 672 if (!delegate()) | |
| 673 return; | |
| 674 | |
| 675 if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) { | |
| 676 delegate()->ShowContentSettingsPage( | |
| 677 state_ & TabSpecificContentSettings::CAMERA_ACCESSED | |
| 678 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM | |
| 679 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 680 } else { | |
| 681 delegate()->ShowContentSettingsPage( | |
| 682 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 683 } | |
| 684 } | |
| 685 | |
| 656 void ContentSettingMediaStreamBubbleModel::SetTitle() { | 686 void ContentSettingMediaStreamBubbleModel::SetTitle() { |
| 657 DCHECK_NE(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED, state_); | 687 DCHECK_NE(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED, state_); |
| 658 int title_id = 0; | 688 int title_id = 0; |
| 659 if (state_ & TabSpecificContentSettings::MICROPHONE_BLOCKED) { | 689 if (state_ & TabSpecificContentSettings::MICROPHONE_BLOCKED) { |
| 660 title_id = (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) ? | 690 title_id = (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) ? |
| 661 IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; | 691 IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
| 662 } else if (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) { | 692 } else if (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) { |
| 663 title_id = IDS_CAMERA_BLOCKED; | 693 title_id = IDS_CAMERA_BLOCKED; |
| 664 } else if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) { | 694 } else if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) { |
| 665 title_id = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) ? | 695 title_id = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) ? |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 677 RadioGroup radio_group; | 707 RadioGroup radio_group; |
| 678 radio_group.url = url; | 708 radio_group.url = url; |
| 679 | 709 |
| 680 base::string16 display_host_utf16 = | 710 base::string16 display_host_utf16 = |
| 681 secure_display::FormatUrlForSecurityDisplay( | 711 secure_display::FormatUrlForSecurityDisplay( |
| 682 url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 712 url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 683 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); | 713 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); |
| 684 if (display_host.empty()) | 714 if (display_host.empty()) |
| 685 display_host = url.spec(); | 715 display_host = url.spec(); |
| 686 | 716 |
| 687 bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; | 717 bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; |
|
msw
2015/07/30 17:15:27
nit: These could be helper functions used instead
msramek
2015/07/31 12:34:52
That's one of the things I wanted to leave for tha
| |
| 688 bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; | 718 bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; |
| 689 DCHECK(is_mic || is_cam); | 719 DCHECK(is_mic || is_cam); |
| 690 int radio_allow_label_id = 0; | 720 int radio_allow_label_id = 0; |
| 691 int radio_block_label_id = 0; | 721 int radio_block_label_id = 0; |
| 692 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED | | 722 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 693 TabSpecificContentSettings::CAMERA_BLOCKED)) { | 723 TabSpecificContentSettings::CAMERA_BLOCKED)) { |
| 694 if (content::IsOriginSecure(url)) { | 724 if (content::IsOriginSecure(url)) { |
| 695 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; | 725 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; |
| 696 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; | 726 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; |
| 697 if (is_mic) | 727 if (is_mic) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 } | 868 } |
| 839 | 869 |
| 840 camera_menu.default_device = | 870 camera_menu.default_device = |
| 841 GetMediaDeviceById(preferred_camera, cameras); | 871 GetMediaDeviceById(preferred_camera, cameras); |
| 842 camera_menu.selected_device = camera_menu.default_device; | 872 camera_menu.selected_device = camera_menu.default_device; |
| 843 } | 873 } |
| 844 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); | 874 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
| 845 } | 875 } |
| 846 } | 876 } |
| 847 | 877 |
| 878 void ContentSettingMediaStreamBubbleModel::SetManageLink() { | |
| 879 // By default, the manage link refers to both media types. We only need | |
| 880 // to change the text if only one media type was accessed. | |
|
msw
2015/07/30 17:15:27
nit: s/text/link/
msramek
2015/07/31 12:34:52
Actually, I wanted to emphasize that here we're ch
msw
2015/07/31 17:36:04
Acknowledged.
| |
| 881 if ((state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) && | |
| 882 (state_ & TabSpecificContentSettings::CAMERA_ACCESSED)) { | |
| 883 return; | |
| 884 } | |
| 885 | |
| 886 set_manage_link(state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 887 ? l10n_util::GetStringUTF8( | |
|
msw
2015/07/30 17:15:27
nit: put the trinary within l10n_util::GetStringUT
msramek
2015/07/31 12:34:52
Done.
| |
| 888 IDS_MEDIASTREAM_MICROPHONE_BUBBLE_MANAGE_LINK) | |
| 889 : l10n_util::GetStringUTF8( | |
| 890 IDS_MEDIASTREAM_CAMERA_BUBBLE_MANAGE_LINK)); | |
| 891 } | |
| 892 | |
| 848 void ContentSettingMediaStreamBubbleModel::SetCustomLink() { | 893 void ContentSettingMediaStreamBubbleModel::SetCustomLink() { |
| 849 TabSpecificContentSettings* content_settings = | 894 TabSpecificContentSettings* content_settings = |
| 850 TabSpecificContentSettings::FromWebContents(web_contents()); | 895 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 851 if (content_settings->IsMicrophoneCameraStateChanged()) { | 896 if (content_settings->IsMicrophoneCameraStateChanged()) { |
| 852 set_custom_link(l10n_util::GetStringUTF8( | 897 set_custom_link(l10n_util::GetStringUTF8( |
| 853 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE)); | 898 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE)); |
| 854 } | 899 } |
| 855 } | 900 } |
| 856 | 901 |
| 857 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | 902 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1299 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1344 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 1300 DCHECK_EQ(web_contents_, | 1345 DCHECK_EQ(web_contents_, |
| 1301 content::Source<WebContents>(source).ptr()); | 1346 content::Source<WebContents>(source).ptr()); |
| 1302 web_contents_ = NULL; | 1347 web_contents_ = NULL; |
| 1303 } else { | 1348 } else { |
| 1304 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1349 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 1305 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1350 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 1306 profile_ = NULL; | 1351 profile_ = NULL; |
| 1307 } | 1352 } |
| 1308 } | 1353 } |
| OLD | NEW |