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 DCHECK_EQ(CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, content_type); | |
| 525 | |
| 526 TabSpecificContentSettings* content_settings = | |
| 527 tab_contents->content_settings(); | |
| 528 const ProtocolHandler& handler = | |
| 529 content_settings->UngesturedProtocolHandler(); | |
| 530 | |
| 531 string16 protocol = UTF8ToUTF16(handler.protocol()); | |
| 532 if (handler.protocol() == "mailto") { | |
| 533 protocol = l10n_util::GetStringUTF16( | |
| 534 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); | |
| 535 } | |
| 536 if (handler.protocol() == "webcal") { | |
| 537 protocol = l10n_util::GetStringUTF16( | |
| 538 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); | |
| 539 } | |
| 540 if (content_settings->OldRegisterProtocolHandlerTitle().empty()) { | |
| 541 set_title(l10n_util::GetStringFUTF8( | |
| 542 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | |
| 543 handler.title(), UTF8ToUTF16(handler.url().host()), | |
| 544 protocol)); | |
| 545 } else { | |
| 546 set_title(l10n_util::GetStringFUTF8( | |
| 547 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | |
| 548 handler.title(), UTF8ToUTF16(handler.url().host()), | |
| 549 protocol, content_settings->OldRegisterProtocolHandlerTitle())); | |
| 550 } | |
| 551 | |
| 552 std::string radio_allow_label = | |
| 553 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, | |
| 554 handler.title()); | |
| 555 std::string radio_block_label = | |
|
koz (OOO until 15th September)
2012/06/21 01:50:53
radio_block_label -> radio_deny_label
Greg Billock
2012/06/21 19:59:11
Done.
| |
| 556 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); | |
| 557 | |
| 558 /* | |
| 559 GURL url = tab_contents->web_contents()->GetURL(); | |
| 560 RadioGroup radio_group; | |
| 561 radio_group.url = url; | |
| 562 | |
| 563 radio_group.radio_items.push_back(radio_allow_label); | |
| 564 radio_group.radio_items.push_back(radio_block_label); | |
| 565 radio_group.default_item = 1; | |
| 566 selected_item_ = radio_group.default_item; | |
| 567 set_radio_group_enabled(true); | |
| 568 set_radio_group(radio_group); | |
| 569 */ | |
| 570 | |
| 571 set_custom_link(radio_allow_label); | |
| 572 set_custom_link_enabled(true); | |
| 573 } | |
| 574 | |
| 575 virtual void OnCustomLinkClicked() { | |
| 576 RegisterProtocolHandler(); | |
| 577 } | |
| 578 | |
| 579 virtual void OnRadioClicked(int radio_index) { | |
| 580 if (selected_item_ != radio_index) { | |
| 581 selected_item_ = radio_index; | |
| 582 if (radio_index == 0) { | |
| 583 RegisterProtocolHandler(); | |
| 584 } else { | |
| 585 UnregisterProtocolHandler(); | |
|
koz (OOO until 15th September)
2012/06/21 01:50:53
Is the idea here that there are two radio boxes th
Greg Billock
2012/06/21 19:59:11
Ah, that's a good point. I'll just save the whole
| |
| 586 } | |
| 587 } | |
| 588 } | |
| 589 | |
| 590 void RegisterProtocolHandler() { | |
| 591 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( | |
| 592 tab_contents()->content_settings()->UngesturedProtocolHandler()); | |
| 593 } | |
| 594 | |
| 595 void UnregisterProtocolHandler() { | |
| 596 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( | |
| 597 tab_contents()->content_settings()->UngesturedProtocolHandler()); | |
| 598 } | |
| 599 | |
| 600 private: | |
| 601 int selected_item_; | |
| 602 bool registered_; | |
| 603 }; | |
| 604 | |
| 605 | |
| 513 // static | 606 // static |
| 514 ContentSettingBubbleModel* | 607 ContentSettingBubbleModel* |
| 515 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 608 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 516 Delegate* delegate, | 609 Delegate* delegate, |
| 517 TabContents* tab_contents, | 610 TabContents* tab_contents, |
| 518 Profile* profile, | 611 Profile* profile, |
| 519 ContentSettingsType content_type) { | 612 ContentSettingsType content_type) { |
| 520 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 613 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 521 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, | 614 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, |
| 522 content_type); | 615 content_type); |
| 523 } | 616 } |
| 524 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 617 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 525 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, | 618 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, |
| 526 content_type); | 619 content_type); |
| 527 } | 620 } |
| 528 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 621 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 529 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, | 622 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, |
| 530 profile, content_type); | 623 profile, content_type); |
| 531 } | 624 } |
| 532 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 625 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 533 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, | 626 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, |
| 534 content_type); | 627 content_type); |
| 535 } | 628 } |
| 629 if (content_type == CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER) { | |
| 630 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile, | |
| 631 content_type); | |
| 632 } | |
| 536 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, | 633 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, |
| 537 content_type); | 634 content_type); |
| 538 } | 635 } |
| 539 | 636 |
| 540 ContentSettingBubbleModel::ContentSettingBubbleModel( | 637 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 541 TabContents* tab_contents, | 638 TabContents* tab_contents, |
| 542 Profile* profile, | 639 Profile* profile, |
| 543 ContentSettingsType content_type) | 640 ContentSettingsType content_type) |
| 544 : tab_contents_(tab_contents), | 641 : tab_contents_(tab_contents), |
| 545 profile_(profile), | 642 profile_(profile), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 const content::NotificationDetails& details) { | 677 const content::NotificationDetails& details) { |
| 581 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { | 678 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 582 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); | 679 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); |
| 583 tab_contents_ = NULL; | 680 tab_contents_ = NULL; |
| 584 } else { | 681 } else { |
| 585 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 682 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 586 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 683 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 587 profile_ = NULL; | 684 profile_ = NULL; |
| 588 } | 685 } |
| 589 } | 686 } |
| OLD | NEW |