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/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 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 thath there is only a single | |
|
Peter Kasting
2013/01/27 22:36:16
Nit: thath
markusheintz_
2013/01/28 10:06:47
Done.
| |
| 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, "", setting); | |
|
Peter Kasting
2013/01/27 22:36:16
Nit: "" -> std::string() (2 places)
markusheintz_
2013/01/28 10:06:47
Done.
| |
| 607 content_settings->SetContentSetting( | |
| 608 primary_pattern, secondary_pattern, | |
| 609 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "", setting); | |
| 610 } | |
| 611 } | |
| 612 | |
| 613 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | |
| 614 selected_item_ = radio_index; | |
| 615 } | |
| 616 | |
| 486 class ContentSettingDomainListBubbleModel | 617 class ContentSettingDomainListBubbleModel |
| 487 : public ContentSettingTitleAndLinkModel { | 618 : public ContentSettingTitleAndLinkModel { |
| 488 public: | 619 public: |
| 489 ContentSettingDomainListBubbleModel(Delegate* delegate, | 620 ContentSettingDomainListBubbleModel(Delegate* delegate, |
| 490 WebContents* web_contents, | 621 WebContents* web_contents, |
| 491 Profile* profile, | 622 Profile* profile, |
| 492 ContentSettingsType content_type); | 623 ContentSettingsType content_type); |
| 493 virtual ~ContentSettingDomainListBubbleModel() {} | 624 virtual ~ContentSettingDomainListBubbleModel() {} |
| 494 | 625 |
| 495 private: | 626 private: |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 content_type); | 878 content_type); |
| 748 } | 879 } |
| 749 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 880 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 750 return new ContentSettingPopupBubbleModel(delegate, web_contents, profile, | 881 return new ContentSettingPopupBubbleModel(delegate, web_contents, profile, |
| 751 content_type); | 882 content_type); |
| 752 } | 883 } |
| 753 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 884 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 754 return new ContentSettingDomainListBubbleModel(delegate, web_contents, | 885 return new ContentSettingDomainListBubbleModel(delegate, web_contents, |
| 755 profile, content_type); | 886 profile, content_type); |
| 756 } | 887 } |
| 888 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { | |
| 889 return new ContentSettingMediaStreamBubbleModel(delegate, web_contents, | |
| 890 profile); | |
| 891 } | |
| 757 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 892 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 758 return new ContentSettingPluginBubbleModel(delegate, web_contents, profile, | 893 return new ContentSettingPluginBubbleModel(delegate, web_contents, profile, |
| 759 content_type); | 894 content_type); |
| 760 } | 895 } |
| 761 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 896 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| 762 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, | 897 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, |
| 763 profile, content_type); | 898 profile, content_type); |
| 764 } | 899 } |
| 765 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 900 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 766 ProtocolHandlerRegistry* registry = | 901 ProtocolHandlerRegistry* registry = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 951 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 817 DCHECK_EQ(web_contents_, | 952 DCHECK_EQ(web_contents_, |
| 818 content::Source<WebContents>(source).ptr()); | 953 content::Source<WebContents>(source).ptr()); |
| 819 web_contents_ = NULL; | 954 web_contents_ = NULL; |
| 820 } else { | 955 } else { |
| 821 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 956 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 822 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 957 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 823 profile_ = NULL; | 958 profile_ = NULL; |
| 824 } | 959 } |
| 825 } | 960 } |
| OLD | NEW |