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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SetManageLink() { | 121 void SetManageLink() { |
| 121 static const ContentSettingsTypeIdEntry kLinkIDs[] = { | 122 static const ContentSettingsTypeIdEntry kLinkIDs[] = { |
| 122 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, | 123 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, |
| 123 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 124 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
| 124 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 125 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
| 125 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 126 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
| 126 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, | 127 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
| 127 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, | 128 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
| 129 {CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, | |
| 130 IDS_HANDLERS_BUBBLE_MANAGE_LINK} | |
| 128 }; | 131 }; |
| 129 set_manage_link(l10n_util::GetStringUTF8( | 132 set_manage_link(l10n_util::GetStringUTF8( |
| 130 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| 131 } | 134 } |
| 132 | 135 |
| 133 virtual void OnManageLinkClicked() { | 136 virtual void OnManageLinkClicked() { |
| 134 if (delegate_) | 137 if (delegate_) |
| 135 delegate_->ShowContentSettingsPage(content_type()); | 138 delegate_->ShowContentSettingsPage(content_type()); |
| 136 } | 139 } |
| 137 | 140 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 settings_map->SetContentSetting( | 506 settings_map->SetContentSetting( |
| 504 ContentSettingsPattern::FromURLNoWildcard(it->first), | 507 ContentSettingsPattern::FromURLNoWildcard(it->first), |
| 505 ContentSettingsPattern::FromURLNoWildcard(embedder_url), | 508 ContentSettingsPattern::FromURLNoWildcard(embedder_url), |
| 506 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 509 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 507 std::string(), | 510 std::string(), |
| 508 CONTENT_SETTING_DEFAULT); | 511 CONTENT_SETTING_DEFAULT); |
| 509 } | 512 } |
| 510 } | 513 } |
| 511 }; | 514 }; |
| 512 | 515 |
| 516 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { | |
| 517 public: | |
| 518 ContentSettingRPHBubbleModel(Delegate* delegate, | |
| 519 TabContents* tab_contents, | |
| 520 Profile* profile, | |
| 521 ContentSettingsType content_type) | |
| 522 : ContentSettingTitleAndLinkModel( | |
| 523 delegate, tab_contents, profile, content_type), | |
| 524 selected_item_(0), | |
| 525 pending_handler_(ProtocolHandler::EmptyProtocolHandler()), | |
| 526 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { | |
| 527 DCHECK_EQ(CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, content_type); | |
| 528 | |
| 529 TabSpecificContentSettings* content_settings = | |
| 530 tab_contents->content_settings(); | |
| 531 pending_handler_ = content_settings->GetPendingProtocolHandler(); | |
| 532 previous_handler_ = content_settings->GetPreviousProtocolHandler(); | |
| 533 | |
| 534 string16 protocol = UTF8ToUTF16(pending_handler_.protocol()); | |
| 535 if (pending_handler_.protocol() == "mailto") { | |
| 536 protocol = l10n_util::GetStringUTF16( | |
| 537 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); | |
| 538 } | |
| 539 if (pending_handler_.protocol() == "webcal") { | |
| 540 protocol = l10n_util::GetStringUTF16( | |
| 541 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); | |
| 542 } | |
| 543 if (previous_handler_.IsEmpty()) { | |
| 544 set_title(l10n_util::GetStringFUTF8( | |
| 545 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | |
| 546 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), | |
| 547 protocol)); | |
| 548 } else { | |
| 549 set_title(l10n_util::GetStringFUTF8( | |
| 550 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | |
| 551 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), | |
| 552 protocol, previous_handler_.title())); | |
| 553 } | |
| 554 | |
| 555 std::string radio_allow_label = | |
| 556 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, | |
| 557 pending_handler_.title()); | |
| 558 std::string radio_deny_label = | |
| 559 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); | |
| 560 std::string radio_ignore_label = | |
| 561 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); | |
| 562 | |
| 563 GURL url = tab_contents->web_contents()->GetURL(); | |
| 564 RadioGroup radio_group; | |
| 565 radio_group.url = url; | |
| 566 | |
| 567 radio_group.radio_items.push_back(radio_allow_label); | |
| 568 radio_group.radio_items.push_back(radio_deny_label); | |
| 569 radio_group.radio_items.push_back(radio_ignore_label); | |
| 570 radio_group.default_item = 2; | |
| 571 selected_item_ = radio_group.default_item; | |
| 572 set_radio_group_enabled(true); | |
| 573 set_radio_group(radio_group); | |
| 574 } | |
| 575 | |
| 576 virtual void OnCustomLinkClicked() { | |
| 577 RegisterProtocolHandler(); | |
| 578 } | |
| 579 | |
| 580 virtual void OnRadioClicked(int radio_index) { | |
| 581 if (selected_item_ != radio_index) { | |
| 582 selected_item_ = radio_index; | |
| 583 | |
| 584 if (radio_index == 0) { | |
| 585 RegisterProtocolHandler(); | |
| 586 } else if (radio_index == 1) { | |
| 587 UnregisterProtocolHandler(); | |
| 588 } else if (radio_index == 2) { | |
| 589 IgnoreProtocolHandler(); | |
| 590 } | |
| 591 } | |
| 592 } | |
| 593 | |
| 594 void RegisterProtocolHandler() { | |
| 595 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( | |
| 596 pending_handler_); | |
| 597 } | |
| 598 | |
| 599 void UnregisterProtocolHandler() { | |
| 600 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( | |
| 601 pending_handler_); | |
| 602 if (!previous_handler_.IsEmpty()) { | |
|
koz (OOO until 15th September)
2012/06/21 23:03:50
There's still a subtle bug here. If the user click
Greg Billock
2012/06/21 23:10:59
I found this as well. Also added a tracker to make
| |
| 603 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( | |
| 604 previous_handler_); | |
| 605 } | |
| 606 } | |
| 607 | |
| 608 void IgnoreProtocolHandler() { | |
| 609 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( | |
| 610 pending_handler_); | |
| 611 } | |
| 612 | |
| 613 private: | |
| 614 int selected_item_; | |
| 615 ProtocolHandler pending_handler_; | |
| 616 ProtocolHandler previous_handler_; | |
| 617 }; | |
| 618 | |
| 619 | |
| 513 // static | 620 // static |
| 514 ContentSettingBubbleModel* | 621 ContentSettingBubbleModel* |
| 515 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 622 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 516 Delegate* delegate, | 623 Delegate* delegate, |
| 517 TabContents* tab_contents, | 624 TabContents* tab_contents, |
| 518 Profile* profile, | 625 Profile* profile, |
| 519 ContentSettingsType content_type) { | 626 ContentSettingsType content_type) { |
| 520 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 627 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 521 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, | 628 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, |
| 522 content_type); | 629 content_type); |
| 523 } | 630 } |
| 524 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 631 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 525 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, | 632 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, |
| 526 content_type); | 633 content_type); |
| 527 } | 634 } |
| 528 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 635 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 529 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, | 636 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, |
| 530 profile, content_type); | 637 profile, content_type); |
| 531 } | 638 } |
| 532 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 639 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 533 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, | 640 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, |
| 534 content_type); | 641 content_type); |
| 535 } | 642 } |
| 643 if (content_type == CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER) { | |
| 644 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile, | |
| 645 content_type); | |
| 646 } | |
| 536 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, | 647 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, |
| 537 content_type); | 648 content_type); |
| 538 } | 649 } |
| 539 | 650 |
| 540 ContentSettingBubbleModel::ContentSettingBubbleModel( | 651 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 541 TabContents* tab_contents, | 652 TabContents* tab_contents, |
| 542 Profile* profile, | 653 Profile* profile, |
| 543 ContentSettingsType content_type) | 654 ContentSettingsType content_type) |
| 544 : tab_contents_(tab_contents), | 655 : tab_contents_(tab_contents), |
| 545 profile_(profile), | 656 profile_(profile), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 const content::NotificationDetails& details) { | 691 const content::NotificationDetails& details) { |
| 581 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { | 692 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 582 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); | 693 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); |
| 583 tab_contents_ = NULL; | 694 tab_contents_ = NULL; |
| 584 } else { | 695 } else { |
| 585 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 696 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 586 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 697 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 587 profile_ = NULL; | 698 profile_ = NULL; |
| 588 } | 699 } |
| 589 } | 700 } |
| OLD | NEW |