| 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/content_settings/content_settings_utils.h" | 8 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 9 #include "chrome/browser/content_settings/cookie_settings.h" | 9 #include "chrome/browser/content_settings/cookie_settings.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 12 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" | 17 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" |
| 17 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 18 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
| 18 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega
te.h" | 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega
te.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 122 |
| 122 void SetManageLink() { | 123 void SetManageLink() { |
| 123 static const ContentSettingsTypeIdEntry kLinkIDs[] = { | 124 static const ContentSettingsTypeIdEntry kLinkIDs[] = { |
| 124 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, | 125 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, |
| 125 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 126 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
| 126 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 127 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
| 127 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 128 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
| 128 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, | 129 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
| 129 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, | 130 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
| 130 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, | 131 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, |
| 132 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK} |
| 131 }; | 133 }; |
| 132 set_manage_link(l10n_util::GetStringUTF8( | 134 set_manage_link(l10n_util::GetStringUTF8( |
| 133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 135 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| 134 } | 136 } |
| 135 | 137 |
| 136 virtual void OnManageLinkClicked() { | 138 virtual void OnManageLinkClicked() { |
| 137 if (delegate_) | 139 if (delegate_) |
| 138 delegate_->ShowContentSettingsPage(content_type()); | 140 delegate_->ShowContentSettingsPage(content_type()); |
| 139 } | 141 } |
| 140 | 142 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 515 } |
| 514 } | 516 } |
| 515 }; | 517 }; |
| 516 | 518 |
| 517 class ContentSettingMixedScriptBubbleModel | 519 class ContentSettingMixedScriptBubbleModel |
| 518 : public ContentSettingTitleLinkAndCustomModel { | 520 : public ContentSettingTitleLinkAndCustomModel { |
| 519 public: | 521 public: |
| 520 ContentSettingMixedScriptBubbleModel(Delegate* delegate, | 522 ContentSettingMixedScriptBubbleModel(Delegate* delegate, |
| 521 TabContents* tab_contents, | 523 TabContents* tab_contents, |
| 522 Profile* profile, | 524 Profile* profile, |
| 523 ContentSettingsType content_type) | 525 ContentSettingsType content_type); |
| 524 : ContentSettingTitleLinkAndCustomModel( | |
| 525 delegate, tab_contents, profile, content_type) { | |
| 526 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); | |
| 527 set_custom_link_enabled(true); | |
| 528 } | |
| 529 | 526 |
| 530 virtual ~ContentSettingMixedScriptBubbleModel() {} | 527 virtual ~ContentSettingMixedScriptBubbleModel() {} |
| 531 | 528 |
| 532 private: | 529 private: |
| 533 virtual void OnCustomLinkClicked() OVERRIDE { | 530 virtual void OnCustomLinkClicked() OVERRIDE; |
| 534 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); | 531 }; |
| 535 DCHECK(tab_contents()); | 532 |
| 536 content::RenderViewHost* host = | 533 ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel( |
| 537 tab_contents()->web_contents()->GetRenderViewHost(); | 534 Delegate* delegate, |
| 538 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( | 535 TabContents* tab_contents, |
| 539 host->GetRoutingID(), true)); | 536 Profile* profile, |
| 537 ContentSettingsType content_type) |
| 538 : ContentSettingTitleLinkAndCustomModel( |
| 539 delegate, tab_contents, profile, content_type) { |
| 540 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); |
| 541 set_custom_link_enabled(true); |
| 542 } |
| 543 |
| 544 void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() { |
| 545 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); |
| 546 DCHECK(tab_contents()); |
| 547 content::RenderViewHost* host = |
| 548 tab_contents()->web_contents()->GetRenderViewHost(); |
| 549 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( |
| 550 host->GetRoutingID(), true)); |
| 551 } |
| 552 |
| 553 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { |
| 554 public: |
| 555 ContentSettingRPHBubbleModel(Delegate* delegate, |
| 556 TabContents* tab_contents, |
| 557 Profile* profile, |
| 558 ContentSettingsType content_type); |
| 559 |
| 560 virtual void OnRadioClicked(int radio_index) OVERRIDE; |
| 561 |
| 562 private: |
| 563 // These states must match the order of appearance of the radio buttons |
| 564 // in the XIB file for the Mac port. |
| 565 enum RPHState { |
| 566 RPH_ALLOW = 0, |
| 567 RPH_BLOCK, |
| 568 RPH_IGNORE, |
| 569 }; |
| 570 |
| 571 void RegisterProtocolHandler(); |
| 572 void UnregisterProtocolHandler(); |
| 573 void IgnoreProtocolHandler(); |
| 574 void ClearOrSetPreviousHandler(); |
| 575 |
| 576 int selected_item_; |
| 577 ProtocolHandler pending_handler_; |
| 578 ProtocolHandler previous_handler_; |
| 579 }; |
| 580 |
| 581 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel( |
| 582 Delegate* delegate, |
| 583 TabContents* tab_contents, |
| 584 Profile* profile, |
| 585 ContentSettingsType content_type) |
| 586 : ContentSettingTitleAndLinkModel( |
| 587 delegate, tab_contents, profile, content_type), |
| 588 selected_item_(0), |
| 589 pending_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 590 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { |
| 591 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type); |
| 592 |
| 593 TabSpecificContentSettings* content_settings = |
| 594 tab_contents->content_settings(); |
| 595 pending_handler_ = content_settings->pending_protocol_handler(); |
| 596 previous_handler_ = content_settings->previous_protocol_handler(); |
| 597 |
| 598 string16 protocol; |
| 599 if (pending_handler_.protocol() == "mailto") { |
| 600 protocol = l10n_util::GetStringUTF16( |
| 601 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); |
| 602 } else if (pending_handler_.protocol() == "webcal") { |
| 603 protocol = l10n_util::GetStringUTF16( |
| 604 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); |
| 605 } else { |
| 606 protocol = UTF8ToUTF16(pending_handler_.protocol()); |
| 540 } | 607 } |
| 541 }; | 608 |
| 609 if (previous_handler_.IsEmpty()) { |
| 610 set_title(l10n_util::GetStringFUTF8( |
| 611 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
| 612 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), |
| 613 protocol)); |
| 614 } else { |
| 615 set_title(l10n_util::GetStringFUTF8( |
| 616 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
| 617 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), |
| 618 protocol, previous_handler_.title())); |
| 619 } |
| 620 |
| 621 std::string radio_allow_label = |
| 622 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, |
| 623 pending_handler_.title()); |
| 624 std::string radio_deny_label = |
| 625 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); |
| 626 std::string radio_ignore_label = |
| 627 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); |
| 628 |
| 629 GURL url = tab_contents->web_contents()->GetURL(); |
| 630 RadioGroup radio_group; |
| 631 radio_group.url = url; |
| 632 |
| 633 radio_group.radio_items.push_back(radio_allow_label); |
| 634 radio_group.radio_items.push_back(radio_deny_label); |
| 635 radio_group.radio_items.push_back(radio_ignore_label); |
| 636 ContentSetting setting = |
| 637 content_settings->pending_protocol_handler_setting(); |
| 638 if (setting == CONTENT_SETTING_ALLOW) |
| 639 radio_group.default_item = RPH_ALLOW; |
| 640 else if (setting == CONTENT_SETTING_BLOCK) |
| 641 radio_group.default_item = RPH_BLOCK; |
| 642 else |
| 643 radio_group.default_item = RPH_IGNORE; |
| 644 |
| 645 selected_item_ = radio_group.default_item; |
| 646 set_radio_group_enabled(true); |
| 647 set_radio_group(radio_group); |
| 648 } |
| 649 |
| 650 void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) { |
| 651 if (selected_item_ == radio_index) |
| 652 return; |
| 653 |
| 654 selected_item_ = radio_index; |
| 655 |
| 656 if (radio_index == RPH_ALLOW) |
| 657 RegisterProtocolHandler(); |
| 658 else if (radio_index == RPH_BLOCK) |
| 659 UnregisterProtocolHandler(); |
| 660 else if (radio_index == RPH_IGNORE) |
| 661 IgnoreProtocolHandler(); |
| 662 else |
| 663 NOTREACHED(); |
| 664 } |
| 665 |
| 666 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() { |
| 667 // A no-op if the handler hasn't been ignored, but needed in case the user |
| 668 // selects sequences like register/ignore/register. |
| 669 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler( |
| 670 pending_handler_); |
| 671 |
| 672 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| 673 pending_handler_); |
| 674 tab_contents()->content_settings()->set_pending_protocol_handler_setting( |
| 675 CONTENT_SETTING_ALLOW); |
| 676 } |
| 677 |
| 678 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() { |
| 679 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( |
| 680 pending_handler_); |
| 681 tab_contents()->content_settings()->set_pending_protocol_handler_setting( |
| 682 CONTENT_SETTING_BLOCK); |
| 683 ClearOrSetPreviousHandler(); |
| 684 } |
| 685 |
| 686 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() { |
| 687 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( |
| 688 pending_handler_); |
| 689 tab_contents()->content_settings()->set_pending_protocol_handler_setting( |
| 690 CONTENT_SETTING_DEFAULT); |
| 691 ClearOrSetPreviousHandler(); |
| 692 } |
| 693 |
| 694 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { |
| 695 if (previous_handler_.IsEmpty()) { |
| 696 profile()->GetProtocolHandlerRegistry()->ClearDefault( |
| 697 pending_handler_.protocol()); |
| 698 } else { |
| 699 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| 700 previous_handler_); |
| 701 } |
| 702 } |
| 542 | 703 |
| 543 // static | 704 // static |
| 544 ContentSettingBubbleModel* | 705 ContentSettingBubbleModel* |
| 545 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 706 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 546 Delegate* delegate, | 707 Delegate* delegate, |
| 547 TabContents* tab_contents, | 708 TabContents* tab_contents, |
| 548 Profile* profile, | 709 Profile* profile, |
| 549 ContentSettingsType content_type) { | 710 ContentSettingsType content_type) { |
| 550 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 711 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 551 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, | 712 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, |
| 552 content_type); | 713 content_type); |
| 553 } | 714 } |
| 554 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 715 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 555 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, | 716 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, |
| 556 content_type); | 717 content_type); |
| 557 } | 718 } |
| 558 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 719 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 559 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, | 720 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, |
| 560 profile, content_type); | 721 profile, content_type); |
| 561 } | 722 } |
| 562 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 723 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 563 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, | 724 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, |
| 564 content_type); | 725 content_type); |
| 565 } | 726 } |
| 566 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 727 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| 567 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, | 728 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, |
| 568 profile, content_type); | 729 profile, content_type); |
| 569 } | 730 } |
| 731 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 732 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile, |
| 733 content_type); |
| 734 } |
| 570 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, | 735 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, |
| 571 content_type); | 736 content_type); |
| 572 } | 737 } |
| 573 | 738 |
| 574 ContentSettingBubbleModel::ContentSettingBubbleModel( | 739 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 575 TabContents* tab_contents, | 740 TabContents* tab_contents, |
| 576 Profile* profile, | 741 Profile* profile, |
| 577 ContentSettingsType content_type) | 742 ContentSettingsType content_type) |
| 578 : tab_contents_(tab_contents), | 743 : tab_contents_(tab_contents), |
| 579 profile_(profile), | 744 profile_(profile), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 const content::NotificationDetails& details) { | 779 const content::NotificationDetails& details) { |
| 615 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { | 780 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 616 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); | 781 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); |
| 617 tab_contents_ = NULL; | 782 tab_contents_ = NULL; |
| 618 } else { | 783 } else { |
| 619 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 784 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 620 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 785 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 621 profile_ = NULL; | 786 profile_ = NULL; |
| 622 } | 787 } |
| 623 } | 788 } |
| OLD | NEW |