| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/options/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/content_settings/content_settings_details.h" | 17 #include "chrome/browser/content_settings/content_settings_details.h" |
| 18 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service.h" | 21 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/content_settings.h" |
| 27 #include "chrome/common/content_settings_pattern.h" | 28 #include "chrome/common/content_settings_pattern.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 30 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
| 31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 35 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 36 #include "grit/locale_settings.h" | 37 #include "grit/locale_settings.h" |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 default: | 462 default: |
| 462 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 463 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
| 463 break; | 464 break; |
| 464 } | 465 } |
| 465 } | 466 } |
| 466 | 467 |
| 467 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { | 468 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
| 468 Profile* profile = Profile::FromWebUI(web_ui_); | 469 Profile* profile = Profile::FromWebUI(web_ui_); |
| 469 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 470 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 470 | 471 |
| 471 HostContentSettingsMap::SettingsForOneType all_settings; | 472 ContentSettingsForOneType all_settings; |
| 472 map->GetSettingsForOneType( | 473 map->GetSettingsForOneType( |
| 473 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 474 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 474 std::string(), | 475 std::string(), |
| 475 &all_settings); | 476 &all_settings); |
| 476 | 477 |
| 477 // Group geolocation settings by primary_pattern. | 478 // Group geolocation settings by primary_pattern. |
| 478 AllPatternsSettings all_patterns_settings; | 479 AllPatternsSettings all_patterns_settings; |
| 479 for (HostContentSettingsMap::SettingsForOneType::iterator i = | 480 for (ContentSettingsForOneType::iterator i = |
| 480 all_settings.begin(); | 481 all_settings.begin(); |
| 481 i != all_settings.end(); | 482 i != all_settings.end(); |
| 482 ++i) { | 483 ++i) { |
| 483 all_patterns_settings[i->a][i->b] = i->c; | 484 all_patterns_settings[i->primary_pattern][i->secondary_pattern] = |
| 485 i->setting; |
| 484 } | 486 } |
| 485 | 487 |
| 486 ListValue exceptions; | 488 ListValue exceptions; |
| 487 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); | 489 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); |
| 488 i != all_patterns_settings.end(); | 490 i != all_patterns_settings.end(); |
| 489 ++i) { | 491 ++i) { |
| 490 const ContentSettingsPattern& primary_pattern = i->first; | 492 const ContentSettingsPattern& primary_pattern = i->first; |
| 491 const OnePatternSettings& one_settings = i->second; | 493 const OnePatternSettings& one_settings = i->second; |
| 492 | 494 |
| 493 OnePatternSettings::const_iterator parent = | 495 OnePatternSettings::const_iterator parent = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 521 // This is mainly here to keep this function ideologically parallel to | 523 // This is mainly here to keep this function ideologically parallel to |
| 522 // UpdateExceptionsViewFromHostContentSettingsMap(). | 524 // UpdateExceptionsViewFromHostContentSettingsMap(). |
| 523 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 525 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 524 } | 526 } |
| 525 | 527 |
| 526 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 528 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
| 527 Profile* profile = Profile::FromWebUI(web_ui_); | 529 Profile* profile = Profile::FromWebUI(web_ui_); |
| 528 DesktopNotificationService* service = | 530 DesktopNotificationService* service = |
| 529 DesktopNotificationServiceFactory::GetForProfile(profile); | 531 DesktopNotificationServiceFactory::GetForProfile(profile); |
| 530 | 532 |
| 531 HostContentSettingsMap::SettingsForOneType settings; | 533 ContentSettingsForOneType settings; |
| 532 service->GetNotificationsSettings(&settings); | 534 service->GetNotificationsSettings(&settings); |
| 533 | 535 |
| 534 ListValue exceptions; | 536 ListValue exceptions; |
| 535 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = | 537 for (ContentSettingsForOneType::const_iterator i = |
| 536 settings.begin(); | 538 settings.begin(); |
| 537 i != settings.end(); | 539 i != settings.end(); |
| 538 ++i) { | 540 ++i) { |
| 539 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); | |
| 540 exceptions.Append( | 541 exceptions.Append( |
| 541 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); | 542 GetNotificationExceptionForPage(i->primary_pattern, i->setting, |
| 543 i->source)); |
| 542 } | 544 } |
| 543 | 545 |
| 544 StringValue type_string( | 546 StringValue type_string( |
| 545 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 547 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 546 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 548 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
| 547 type_string, exceptions); | 549 type_string, exceptions); |
| 548 | 550 |
| 549 // This is mainly here to keep this function ideologically parallel to | 551 // This is mainly here to keep this function ideologically parallel to |
| 550 // UpdateExceptionsViewFromHostContentSettingsMap(). | 552 // UpdateExceptionsViewFromHostContentSettingsMap(). |
| 551 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 553 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 552 } | 554 } |
| 553 | 555 |
| 554 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 556 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
| 555 ContentSettingsType type) { | 557 ContentSettingsType type) { |
| 556 HostContentSettingsMap::SettingsForOneType entries; | 558 ContentSettingsForOneType entries; |
| 557 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); | 559 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); |
| 558 | 560 |
| 559 ListValue exceptions; | 561 ListValue exceptions; |
| 560 for (size_t i = 0; i < entries.size(); ++i) { | 562 for (size_t i = 0; i < entries.size(); ++i) { |
| 561 // Skip default settings from extensions and policy, and the default content | 563 // Skip default settings from extensions and policy, and the default content |
| 562 // settings; all of them will affect the default setting UI. | 564 // settings; all of them will affect the default setting UI. |
| 563 if (entries[i].a == ContentSettingsPattern::Wildcard() && | 565 if (entries[i].primary_pattern == ContentSettingsPattern::Wildcard() && |
| 564 entries[i].b == ContentSettingsPattern::Wildcard() && | 566 entries[i].secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 565 entries[i].d != "preference") { | 567 entries[i].source != "preference") { |
| 566 continue; | 568 continue; |
| 567 } | 569 } |
| 568 // The content settings UI does not support secondary content settings | 570 // The content settings UI does not support secondary content settings |
| 569 // pattern yet. For content settings set through the content settings UI the | 571 // pattern yet. For content settings set through the content settings UI the |
| 570 // secondary pattern is by default a wildcard pattern. Hence users are not | 572 // secondary pattern is by default a wildcard pattern. Hence users are not |
| 571 // able to modify content settings with a secondary pattern other than the | 573 // able to modify content settings with a secondary pattern other than the |
| 572 // wildcard pattern. So only show settings that the user is able to modify. | 574 // wildcard pattern. So only show settings that the user is able to modify. |
| 573 // TODO(bauerb): Support a read-only view for those patterns. | 575 // TODO(bauerb): Support a read-only view for those patterns. |
| 574 if (entries[i].b == ContentSettingsPattern::Wildcard()) { | 576 if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard()) { |
| 575 exceptions.Append( | 577 exceptions.Append( |
| 576 GetExceptionForPage(entries[i].a, entries[i].c, entries[i].d)); | 578 GetExceptionForPage(entries[i].primary_pattern, entries[i].setting, |
| 579 entries[i].source)); |
| 577 } else { | 580 } else { |
| 578 LOG(ERROR) << "Secondary content settings patterns are not " | 581 LOG(ERROR) << "Secondary content settings patterns are not " |
| 579 << "supported by the content settings UI"; | 582 << "supported by the content settings UI"; |
| 580 } | 583 } |
| 581 } | 584 } |
| 582 | 585 |
| 583 StringValue type_string(ContentSettingsTypeToGroupName(type)); | 586 StringValue type_string(ContentSettingsTypeToGroupName(type)); |
| 584 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string, | 587 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string, |
| 585 exceptions); | 588 exceptions); |
| 586 | 589 |
| 587 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 590 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
| 588 | 591 |
| 589 // The default may also have changed (we won't get a separate notification). | 592 // The default may also have changed (we won't get a separate notification). |
| 590 // If it hasn't changed, this call will be harmless. | 593 // If it hasn't changed, this call will be harmless. |
| 591 UpdateSettingDefaultFromModel(type); | 594 UpdateSettingDefaultFromModel(type); |
| 592 } | 595 } |
| 593 | 596 |
| 594 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 597 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
| 595 ContentSettingsType type) { | 598 ContentSettingsType type) { |
| 596 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 599 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
| 597 if (!otr_settings_map) | 600 if (!otr_settings_map) |
| 598 return; | 601 return; |
| 599 | 602 |
| 600 HostContentSettingsMap::SettingsForOneType otr_entries; | 603 ContentSettingsForOneType otr_entries; |
| 601 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); | 604 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); |
| 602 | 605 |
| 603 ListValue otr_exceptions; | 606 ListValue otr_exceptions; |
| 604 for (size_t i = 0; i < otr_entries.size(); ++i) { | 607 for (size_t i = 0; i < otr_entries.size(); ++i) { |
| 605 // Off-the-record HostContentSettingsMap contains incognito content settings | 608 // Off-the-record HostContentSettingsMap contains incognito content settings |
| 606 // as well as normal content settings. Here, we use the incongnito settings | 609 // as well as normal content settings. Here, we use the incongnito settings |
| 607 // only. | 610 // only. |
| 608 if (!otr_entries[i].e) | 611 if (!otr_entries[i].incognito) |
| 609 continue; | 612 continue; |
| 610 // The content settings UI does not support secondary content settings | 613 // The content settings UI does not support secondary content settings |
| 611 // pattern yet. For content settings set through the content settings UI the | 614 // pattern yet. For content settings set through the content settings UI the |
| 612 // secondary pattern is by default a wildcard pattern. Hence users are not | 615 // secondary pattern is by default a wildcard pattern. Hence users are not |
| 613 // able to modify content settings with a secondary pattern other than the | 616 // able to modify content settings with a secondary pattern other than the |
| 614 // wildcard pattern. So only show settings that the user is able to modify. | 617 // wildcard pattern. So only show settings that the user is able to modify. |
| 615 // TODO(bauerb): Support a read-only view for those patterns. | 618 // TODO(bauerb): Support a read-only view for those patterns. |
| 616 if (otr_entries[i].b == ContentSettingsPattern::Wildcard()) { | 619 if (otr_entries[i].secondary_pattern == |
| 620 ContentSettingsPattern::Wildcard()) { |
| 617 otr_exceptions.Append( | 621 otr_exceptions.Append( |
| 618 GetExceptionForPage(otr_entries[i].a, | 622 GetExceptionForPage(otr_entries[i].primary_pattern, |
| 619 otr_entries[i].c, | 623 otr_entries[i].setting, |
| 620 otr_entries[i].d)); | 624 otr_entries[i].source)); |
| 621 } else { | 625 } else { |
| 622 LOG(ERROR) << "Secondary content settings patterns are not " | 626 LOG(ERROR) << "Secondary content settings patterns are not " |
| 623 << "supported by the content settings UI"; | 627 << "supported by the content settings UI"; |
| 624 } | 628 } |
| 625 } | 629 } |
| 626 | 630 |
| 627 StringValue type_string(ContentSettingsTypeToGroupName(type)); | 631 StringValue type_string(ContentSettingsTypeToGroupName(type)); |
| 628 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", | 632 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", |
| 629 type_string, otr_exceptions); | 633 type_string, otr_exceptions); |
| 630 } | 634 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 806 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
| 803 } | 807 } |
| 804 | 808 |
| 805 HostContentSettingsMap* | 809 HostContentSettingsMap* |
| 806 ContentSettingsHandler::GetOTRContentSettingsMap() { | 810 ContentSettingsHandler::GetOTRContentSettingsMap() { |
| 807 Profile* profile = Profile::FromWebUI(web_ui_); | 811 Profile* profile = Profile::FromWebUI(web_ui_); |
| 808 if (profile->HasOffTheRecordProfile()) | 812 if (profile->HasOffTheRecordProfile()) |
| 809 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 813 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
| 810 return NULL; | 814 return NULL; |
| 811 } | 815 } |
| OLD | NEW |