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