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" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 void ContentSettingTitleAndLinkModel::SetManageLink() { | 121 void ContentSettingTitleAndLinkModel::SetManageLink() { |
122 static const ContentSettingsTypeIdEntry kLinkIDs[] = { | 122 static const ContentSettingsTypeIdEntry kLinkIDs[] = { |
123 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, | 123 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, |
124 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 124 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
125 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 125 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
126 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 126 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
127 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, | 127 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
128 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, | 128 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
129 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, | 129 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, |
130 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, | 130 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK} |
131 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, IDS_MEDIASTREAM_BUBBLE_MANAGE_LINK} | |
132 }; | 131 }; |
133 set_manage_link(l10n_util::GetStringUTF8( | 132 set_manage_link(l10n_util::GetStringUTF8( |
134 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
135 } | 134 } |
136 | 135 |
137 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { | 136 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { |
138 if (delegate_) | 137 if (delegate_) |
139 delegate_->ShowContentSettingsPage(content_type()); | 138 delegate_->ShowContentSettingsPage(content_type()); |
140 } | 139 } |
141 | 140 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 ContentSettingsType content_type); | 183 ContentSettingsType content_type); |
185 virtual ~ContentSettingSingleRadioGroup(); | 184 virtual ~ContentSettingSingleRadioGroup(); |
186 | 185 |
187 protected: | 186 protected: |
188 bool settings_changed() const; | 187 bool settings_changed() const; |
189 | 188 |
190 private: | 189 private: |
191 void SetRadioGroup(); | 190 void SetRadioGroup(); |
192 void AddException(ContentSetting setting, | 191 void AddException(ContentSetting setting, |
193 const std::string& resource_identifier); | 192 const std::string& resource_identifier); |
194 virtual void OnRadioClicked(int radio_index) OVERRIDE; | 193 virtual void OnRadioClicked(int radio_index); |
195 | 194 |
196 ContentSetting block_setting_; | 195 ContentSetting block_setting_; |
197 int selected_item_; | 196 int selected_item_; |
198 }; | 197 }; |
199 | 198 |
200 ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup( | 199 ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup( |
201 Delegate* delegate, | 200 Delegate* delegate, |
202 WebContents* web_contents, | 201 WebContents* web_contents, |
203 Profile* profile, | 202 Profile* profile, |
204 ContentSettingsType content_type) | 203 ContentSettingsType content_type) |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 476 } |
478 } | 477 } |
479 | 478 |
480 void ContentSettingPopupBubbleModel::OnPopupClicked(int index) { | 479 void ContentSettingPopupBubbleModel::OnPopupClicked(int index) { |
481 if (web_contents()) { | 480 if (web_contents()) { |
482 BlockedContentTabHelper::FromWebContents(web_contents())-> | 481 BlockedContentTabHelper::FromWebContents(web_contents())-> |
483 LaunchForContents(bubble_content().popup_items[index].web_contents); | 482 LaunchForContents(bubble_content().popup_items[index].web_contents); |
484 } | 483 } |
485 } | 484 } |
486 | 485 |
487 // The model of the content settings bubble for media settings. | |
488 class ContentSettingMediaStreamBubbleModel | |
489 : public ContentSettingTitleAndLinkModel { | |
490 public: | |
491 ContentSettingMediaStreamBubbleModel(Delegate* delegate, | |
492 WebContents* web_contents, | |
493 Profile* profile); | |
494 | |
495 virtual ~ContentSettingMediaStreamBubbleModel(); | |
496 | |
497 private: | |
498 // Sets the title of the bubble. | |
499 void SetTitle(); | |
500 // Sets the data for the radio buttons of the bubble. | |
501 void SetRadioGroup(); | |
502 // Updates the camera and microphone setting with the passed |setting|. | |
503 void UpdateSettings(ContentSetting setting); | |
504 | |
505 // ContentSettingBubbleModel implementation. | |
506 virtual void OnRadioClicked(int radio_index) OVERRIDE; | |
507 | |
508 // The index of the selected radio item. | |
509 int selected_item_; | |
510 // The content settings that are associated with the individual radio | |
511 // buttons. | |
512 ContentSetting radio_item_setting_[2]; | |
513 }; | |
514 | |
515 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | |
516 Delegate* delegate, | |
517 WebContents* web_contents, | |
518 Profile* profile) | |
519 : ContentSettingTitleAndLinkModel( | |
520 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), | |
521 selected_item_(0) { | |
522 // Initialize the content settings associated with the individual radio | |
523 // buttons. | |
524 radio_item_setting_[0] = CONTENT_SETTING_ASK; | |
525 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; | |
526 | |
527 SetTitle(); | |
528 SetRadioGroup(); | |
529 } | |
530 | |
531 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | |
532 // Update the media settings if the radio button selection was changed. | |
533 if (selected_item_ != bubble_content().radio_group.default_item) | |
534 UpdateSettings(radio_item_setting_[selected_item_]); | |
535 } | |
536 | |
537 void ContentSettingMediaStreamBubbleModel::SetTitle() { | |
538 TabSpecificContentSettings* content_settings = | |
539 TabSpecificContentSettings::FromWebContents(web_contents()); | |
540 int title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_ALLOWED; | |
541 if (content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM)) | |
542 title_id = IDS_MEDIASTREAM_BUBBLE_SECTION_BLOCKED; | |
543 set_title(l10n_util::GetStringUTF8(title_id)); | |
544 } | |
545 | |
546 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { | |
547 GURL url = web_contents()->GetURL(); | |
548 RadioGroup radio_group; | |
549 radio_group.url = url; | |
550 | |
551 string16 display_host_utf16; | |
552 net::AppendFormattedHost( | |
553 url, | |
554 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | |
555 &display_host_utf16); | |
556 std::string display_host(UTF16ToUTF8(display_host_utf16)); | |
557 if (display_host.empty()) | |
558 display_host = url.spec(); | |
559 | |
560 TabSpecificContentSettings* content_settings = | |
561 TabSpecificContentSettings::FromWebContents(web_contents()); | |
562 bool media_stream_blocked = | |
563 content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM); | |
564 std::string radio_allow_label; | |
565 std::string radio_block_label; | |
566 if (media_stream_blocked) { | |
567 if (!url.SchemeIsSecure()) { | |
568 radio_allow_label = l10n_util::GetStringFUTF8( | |
569 IDS_BLOCKED_MEDIASTREAM_ASK, UTF8ToUTF16(display_host)); | |
570 } else { | |
571 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; | |
572 radio_allow_label = l10n_util::GetStringFUTF8( | |
573 IDS_BLOCKED_MEDIASTREAM_ALLOW, UTF8ToUTF16(display_host)); | |
574 } | |
575 radio_block_label = | |
576 l10n_util::GetStringUTF8(IDS_BLOCKED_MEDIASTREAM_NO_ACTION); | |
577 } else { | |
578 radio_allow_label = l10n_util::GetStringFUTF8( | |
579 IDS_ALLOWED_MEDIASTREAM_NO_ACTION, UTF8ToUTF16(display_host)); | |
580 radio_block_label = | |
581 l10n_util::GetStringUTF8(IDS_ALLOWED_MEDIASTREAM_BLOCK); | |
582 } | |
583 radio_group.default_item = media_stream_blocked ? 1 : 0; | |
584 radio_group.radio_items.push_back(radio_allow_label); | |
585 radio_group.radio_items.push_back(radio_block_label); | |
586 | |
587 set_radio_group(radio_group); | |
588 set_radio_group_enabled(true); | |
589 } | |
590 | |
591 void ContentSettingMediaStreamBubbleModel::UpdateSettings( | |
592 ContentSetting setting) { | |
593 if (profile()) { | |
594 HostContentSettingsMap* content_settings = | |
595 profile()->GetHostContentSettingsMap(); | |
596 // The same patterns must be used as in other places (e.g. the infobar) in | |
597 // order to override the existing rule. Otherwise a new rule is created. | |
598 // TODO(markusheintz): Extract to a helper so that there is only a single | |
599 // place to touch. | |
600 ContentSettingsPattern primary_pattern = | |
601 ContentSettingsPattern::FromURLNoWildcard(web_contents()->GetURL()); | |
602 ContentSettingsPattern secondary_pattern = | |
603 ContentSettingsPattern::Wildcard(); | |
604 content_settings->SetContentSetting( | |
605 primary_pattern, secondary_pattern, | |
606 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); | |
607 content_settings->SetContentSetting( | |
608 primary_pattern, secondary_pattern, | |
609 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); | |
610 } | |
611 } | |
612 | |
613 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | |
614 selected_item_ = radio_index; | |
615 } | |
616 | |
617 class ContentSettingDomainListBubbleModel | 486 class ContentSettingDomainListBubbleModel |
618 : public ContentSettingTitleAndLinkModel { | 487 : public ContentSettingTitleAndLinkModel { |
619 public: | 488 public: |
620 ContentSettingDomainListBubbleModel(Delegate* delegate, | 489 ContentSettingDomainListBubbleModel(Delegate* delegate, |
621 WebContents* web_contents, | 490 WebContents* web_contents, |
622 Profile* profile, | 491 Profile* profile, |
623 ContentSettingsType content_type); | 492 ContentSettingsType content_type); |
624 virtual ~ContentSettingDomainListBubbleModel() {} | 493 virtual ~ContentSettingDomainListBubbleModel() {} |
625 | 494 |
626 private: | 495 private: |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 content_type); | 747 content_type); |
879 } | 748 } |
880 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 749 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
881 return new ContentSettingPopupBubbleModel(delegate, web_contents, profile, | 750 return new ContentSettingPopupBubbleModel(delegate, web_contents, profile, |
882 content_type); | 751 content_type); |
883 } | 752 } |
884 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 753 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
885 return new ContentSettingDomainListBubbleModel(delegate, web_contents, | 754 return new ContentSettingDomainListBubbleModel(delegate, web_contents, |
886 profile, content_type); | 755 profile, content_type); |
887 } | 756 } |
888 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { | |
889 return new ContentSettingMediaStreamBubbleModel(delegate, web_contents, | |
890 profile); | |
891 } | |
892 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 757 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
893 return new ContentSettingPluginBubbleModel(delegate, web_contents, profile, | 758 return new ContentSettingPluginBubbleModel(delegate, web_contents, profile, |
894 content_type); | 759 content_type); |
895 } | 760 } |
896 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 761 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
897 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, | 762 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, |
898 profile, content_type); | 763 profile, content_type); |
899 } | 764 } |
900 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 765 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
901 ProtocolHandlerRegistry* registry = | 766 ProtocolHandlerRegistry* registry = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 816 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
952 DCHECK_EQ(web_contents_, | 817 DCHECK_EQ(web_contents_, |
953 content::Source<WebContents>(source).ptr()); | 818 content::Source<WebContents>(source).ptr()); |
954 web_contents_ = NULL; | 819 web_contents_ = NULL; |
955 } else { | 820 } else { |
956 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 821 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
957 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 822 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
958 profile_ = NULL; | 823 profile_ = NULL; |
959 } | 824 } |
960 } | 825 } |
OLD | NEW |