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/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_REGISTER_PROTOCOL_HANDLER, | |
| 133 IDS_HANDLERS_BUBBLE_MANAGE_LINK} | |
|
Bernhard Bauer
2012/06/25 16:52:20
Nit: Indent three more spaces?
Peter Kasting
2012/06/25 23:55:30
I'd do two more.
Greg Billock
2012/06/26 19:17:04
Done.
| |
| 131 }; | 134 }; |
| 132 set_manage_link(l10n_util::GetStringUTF8( | 135 set_manage_link(l10n_util::GetStringUTF8( |
| 133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 136 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| 134 } | 137 } |
| 135 | 138 |
| 136 virtual void OnManageLinkClicked() { | 139 virtual void OnManageLinkClicked() { |
| 137 if (delegate_) | 140 if (delegate_) |
| 138 delegate_->ShowContentSettingsPage(content_type()); | 141 delegate_->ShowContentSettingsPage(content_type()); |
| 139 } | 142 } |
| 140 | 143 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 virtual void OnCustomLinkClicked() OVERRIDE { | 536 virtual void OnCustomLinkClicked() OVERRIDE { |
| 534 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); | 537 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); |
| 535 DCHECK(tab_contents()); | 538 DCHECK(tab_contents()); |
| 536 content::RenderViewHost* host = | 539 content::RenderViewHost* host = |
| 537 tab_contents()->web_contents()->GetRenderViewHost(); | 540 tab_contents()->web_contents()->GetRenderViewHost(); |
| 538 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( | 541 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( |
| 539 host->GetRoutingID(), true)); | 542 host->GetRoutingID(), true)); |
| 540 } | 543 } |
| 541 }; | 544 }; |
| 542 | 545 |
| 546 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { | |
| 547 public: | |
| 548 ContentSettingRPHBubbleModel(Delegate* delegate, | |
|
Peter Kasting
2012/06/25 23:55:30
Nit: For consistency, people should de-inline clas
Greg Billock
2012/06/26 19:17:04
Fixed up me and one neighbor. :-)
On 2012/06/25 2
| |
| 549 TabContents* tab_contents, | |
| 550 Profile* profile, | |
| 551 ContentSettingsType content_type) | |
| 552 : ContentSettingTitleAndLinkModel( | |
| 553 delegate, tab_contents, profile, content_type), | |
| 554 selected_item_(0), | |
| 555 pending_handler_(ProtocolHandler::EmptyProtocolHandler()), | |
| 556 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { | |
| 557 DCHECK_EQ(CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, content_type); | |
| 558 | |
| 559 TabSpecificContentSettings* content_settings = | |
| 560 tab_contents->content_settings(); | |
| 561 pending_handler_ = content_settings->GetPendingProtocolHandler(); | |
| 562 previous_handler_ = content_settings->GetPreviousProtocolHandler(); | |
| 563 | |
| 564 string16 protocol = UTF8ToUTF16(pending_handler_.protocol()); | |
| 565 if (pending_handler_.protocol() == "mailto") { | |
| 566 protocol = l10n_util::GetStringUTF16( | |
| 567 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); | |
| 568 } | |
| 569 if (pending_handler_.protocol() == "webcal") { | |
|
Peter Kasting
2012/06/25 23:55:30
Nit: For clarity I'd make this "else if" and put t
Greg Billock
2012/06/26 19:17:04
Done.
| |
| 570 protocol = l10n_util::GetStringUTF16( | |
| 571 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); | |
| 572 } | |
| 573 if (previous_handler_.IsEmpty()) { | |
| 574 set_title(l10n_util::GetStringFUTF8( | |
| 575 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | |
| 576 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), | |
| 577 protocol)); | |
| 578 } else { | |
| 579 set_title(l10n_util::GetStringFUTF8( | |
| 580 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | |
| 581 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), | |
| 582 protocol, previous_handler_.title())); | |
| 583 } | |
| 584 | |
| 585 std::string radio_allow_label = | |
| 586 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, | |
| 587 pending_handler_.title()); | |
| 588 std::string radio_deny_label = | |
| 589 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); | |
| 590 std::string radio_ignore_label = | |
| 591 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); | |
| 592 | |
| 593 GURL url = tab_contents->web_contents()->GetURL(); | |
| 594 RadioGroup radio_group; | |
| 595 radio_group.url = url; | |
| 596 | |
| 597 radio_group.radio_items.push_back(radio_allow_label); | |
| 598 radio_group.radio_items.push_back(radio_deny_label); | |
| 599 radio_group.radio_items.push_back(radio_ignore_label); | |
| 600 ContentSetting setting = | |
| 601 content_settings->GetPendingProtocolHandlerSetting(); | |
| 602 if (setting == CONTENT_SETTING_ALLOW) | |
| 603 radio_group.default_item = RPH_ALLOW; | |
| 604 if (setting == CONTENT_SETTING_BLOCK) | |
|
Bernhard Bauer
2012/06/25 16:52:20
Nit: else if?
Peter Kasting
2012/06/25 23:55:30
Not just a nit -- all "allow"s will get set to RPH
Greg Billock
2012/06/26 19:17:04
Done.
| |
| 605 radio_group.default_item = RPH_BLOCK; | |
| 606 else | |
| 607 radio_group.default_item = RPH_IGNORE; | |
| 608 selected_item_ = radio_group.default_item; | |
| 609 set_radio_group_enabled(true); | |
| 610 set_radio_group(radio_group); | |
| 611 } | |
| 612 | |
| 613 virtual void OnCustomLinkClicked() { | |
| 614 RegisterProtocolHandler(); | |
| 615 } | |
| 616 | |
| 617 virtual void OnRadioClicked(int radio_index) { | |
| 618 if (selected_item_ != radio_index) { | |
| 619 selected_item_ = radio_index; | |
| 620 | |
| 621 if (radio_index == RPH_ALLOW) { | |
|
Bernhard Bauer
2012/06/25 16:52:20
You can either leave out the braces or leave them
Greg Billock
2012/06/26 19:17:04
Done.
| |
| 622 RegisterProtocolHandler(); | |
| 623 } else if (radio_index == RPH_BLOCK) { | |
| 624 UnregisterProtocolHandler(); | |
| 625 } else if (radio_index == RPH_IGNORE) { | |
| 626 IgnoreProtocolHandler(); | |
| 627 } | |
| 628 } | |
| 629 } | |
| 630 | |
| 631 void RegisterProtocolHandler() { | |
| 632 // A no-op if the handler hasn't been ignored, but needed in case the user | |
| 633 // selects sequences like register/ignore/register. | |
| 634 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler( | |
| 635 pending_handler_); | |
| 636 | |
| 637 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( | |
| 638 pending_handler_); | |
| 639 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( | |
| 640 CONTENT_SETTING_ALLOW); | |
| 641 } | |
| 642 | |
| 643 void UnregisterProtocolHandler() { | |
| 644 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( | |
| 645 pending_handler_); | |
| 646 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( | |
| 647 CONTENT_SETTING_BLOCK); | |
| 648 ClearOrSetPreviousHandler(); | |
| 649 } | |
| 650 | |
| 651 void IgnoreProtocolHandler() { | |
| 652 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( | |
| 653 pending_handler_); | |
| 654 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( | |
| 655 CONTENT_SETTING_DEFAULT); | |
| 656 ClearOrSetPreviousHandler(); | |
| 657 } | |
| 658 | |
| 659 void ClearOrSetPreviousHandler() { | |
| 660 if (previous_handler_.IsEmpty()) { | |
| 661 profile()->GetProtocolHandlerRegistry()->ClearDefault( | |
| 662 pending_handler_.protocol()); | |
| 663 } else { | |
| 664 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( | |
| 665 previous_handler_); | |
| 666 } | |
| 667 } | |
| 668 | |
| 669 private: | |
| 670 enum RPHState { | |
| 671 RPH_ALLOW = 0, | |
| 672 RPH_BLOCK, | |
| 673 RPH_IGNORE, | |
| 674 }; | |
| 675 | |
| 676 int selected_item_; | |
| 677 ProtocolHandler pending_handler_; | |
| 678 ProtocolHandler previous_handler_; | |
| 679 }; | |
| 680 | |
| 543 // static | 681 // static |
| 544 ContentSettingBubbleModel* | 682 ContentSettingBubbleModel* |
| 545 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 683 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 546 Delegate* delegate, | 684 Delegate* delegate, |
| 547 TabContents* tab_contents, | 685 TabContents* tab_contents, |
| 548 Profile* profile, | 686 Profile* profile, |
| 549 ContentSettingsType content_type) { | 687 ContentSettingsType content_type) { |
| 550 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 688 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 551 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, | 689 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, |
| 552 content_type); | 690 content_type); |
| 553 } | 691 } |
| 554 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 692 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 555 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, | 693 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, |
| 556 content_type); | 694 content_type); |
| 557 } | 695 } |
| 558 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 696 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 559 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, | 697 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, |
| 560 profile, content_type); | 698 profile, content_type); |
| 561 } | 699 } |
| 562 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 700 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 563 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, | 701 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, |
| 564 content_type); | 702 content_type); |
| 565 } | 703 } |
| 566 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 704 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| 567 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, | 705 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, |
| 568 profile, content_type); | 706 profile, content_type); |
| 569 } | 707 } |
| 708 if (content_type == CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER) { | |
| 709 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile, | |
| 710 content_type); | |
| 711 } | |
| 570 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, | 712 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, |
| 571 content_type); | 713 content_type); |
| 572 } | 714 } |
| 573 | 715 |
| 574 ContentSettingBubbleModel::ContentSettingBubbleModel( | 716 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 575 TabContents* tab_contents, | 717 TabContents* tab_contents, |
| 576 Profile* profile, | 718 Profile* profile, |
| 577 ContentSettingsType content_type) | 719 ContentSettingsType content_type) |
| 578 : tab_contents_(tab_contents), | 720 : tab_contents_(tab_contents), |
| 579 profile_(profile), | 721 profile_(profile), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 const content::NotificationDetails& details) { | 756 const content::NotificationDetails& details) { |
| 615 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { | 757 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 616 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); | 758 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); |
| 617 tab_contents_ = NULL; | 759 tab_contents_ = NULL; |
| 618 } else { | 760 } else { |
| 619 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 761 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 620 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 762 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 621 profile_ = NULL; | 763 profile_ = NULL; |
| 622 } | 764 } |
| 623 } | 765 } |
| OLD | NEW |