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/common/notification_service.h" | 32 #include "content/common/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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 default: | 458 default: |
458 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 459 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
459 break; | 460 break; |
460 } | 461 } |
461 } | 462 } |
462 | 463 |
463 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { | 464 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
464 Profile* profile = Profile::FromWebUI(web_ui_); | 465 Profile* profile = Profile::FromWebUI(web_ui_); |
465 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 466 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
466 | 467 |
467 HostContentSettingsMap::SettingsForOneType all_settings; | 468 ContentSettingsForOneType all_settings; |
468 map->GetSettingsForOneType( | 469 map->GetSettingsForOneType( |
469 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 470 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
470 std::string(), | 471 std::string(), |
471 &all_settings); | 472 &all_settings); |
472 | 473 |
473 // Group geolocation settings by primary_pattern. | 474 // Group geolocation settings by primary_pattern. |
474 AllPatternsSettings all_patterns_settings; | 475 AllPatternsSettings all_patterns_settings; |
475 for (HostContentSettingsMap::SettingsForOneType::iterator i = | 476 for (ContentSettingsForOneType::iterator i = |
476 all_settings.begin(); | 477 all_settings.begin(); |
477 i != all_settings.end(); | 478 i != all_settings.end(); |
478 ++i) { | 479 ++i) { |
479 all_patterns_settings[i->a][i->b] = i->c; | 480 all_patterns_settings[i->primary_pattern][i->secondary_pattern] = i->setting
; |
480 } | 481 } |
481 | 482 |
482 ListValue exceptions; | 483 ListValue exceptions; |
483 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); | 484 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); |
484 i != all_patterns_settings.end(); | 485 i != all_patterns_settings.end(); |
485 ++i) { | 486 ++i) { |
486 const ContentSettingsPattern& primary_pattern = i->first; | 487 const ContentSettingsPattern& primary_pattern = i->first; |
487 const OnePatternSettings& one_settings = i->second; | 488 const OnePatternSettings& one_settings = i->second; |
488 | 489 |
489 OnePatternSettings::const_iterator parent = | 490 OnePatternSettings::const_iterator parent = |
(...skipping 27 matching lines...) Expand all Loading... |
517 // This is mainly here to keep this function ideologically parallel to | 518 // This is mainly here to keep this function ideologically parallel to |
518 // UpdateExceptionsViewFromHostContentSettingsMap(). | 519 // UpdateExceptionsViewFromHostContentSettingsMap(). |
519 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 520 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
520 } | 521 } |
521 | 522 |
522 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 523 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
523 Profile* profile = Profile::FromWebUI(web_ui_); | 524 Profile* profile = Profile::FromWebUI(web_ui_); |
524 DesktopNotificationService* service = | 525 DesktopNotificationService* service = |
525 DesktopNotificationServiceFactory::GetForProfile(profile); | 526 DesktopNotificationServiceFactory::GetForProfile(profile); |
526 | 527 |
527 HostContentSettingsMap::SettingsForOneType settings; | 528 ContentSettingsForOneType settings; |
528 service->GetNotificationsSettings(&settings); | 529 service->GetNotificationsSettings(&settings); |
529 | 530 |
530 ListValue exceptions; | 531 ListValue exceptions; |
531 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = | 532 for (ContentSettingsForOneType::const_iterator i = |
532 settings.begin(); | 533 settings.begin(); |
533 i != settings.end(); | 534 i != settings.end(); |
534 ++i) { | 535 ++i) { |
535 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); | |
536 exceptions.Append( | 536 exceptions.Append( |
537 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); | 537 GetNotificationExceptionForPage(i->primary_pattern, i->setting, |
| 538 i->source)); |
538 } | 539 } |
539 | 540 |
540 StringValue type_string( | 541 StringValue type_string( |
541 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 542 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
542 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 543 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
543 type_string, exceptions); | 544 type_string, exceptions); |
544 | 545 |
545 // This is mainly here to keep this function ideologically parallel to | 546 // This is mainly here to keep this function ideologically parallel to |
546 // UpdateExceptionsViewFromHostContentSettingsMap(). | 547 // UpdateExceptionsViewFromHostContentSettingsMap(). |
547 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 548 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
548 } | 549 } |
549 | 550 |
550 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 551 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
551 ContentSettingsType type) { | 552 ContentSettingsType type) { |
552 HostContentSettingsMap::SettingsForOneType entries; | 553 ContentSettingsForOneType entries; |
553 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); | 554 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); |
554 | 555 |
555 ListValue exceptions; | 556 ListValue exceptions; |
556 for (size_t i = 0; i < entries.size(); ++i) { | 557 for (size_t i = 0; i < entries.size(); ++i) { |
557 // Skip default settings from extensions and policy, and the default content | 558 // Skip default settings from extensions and policy, and the default content |
558 // settings; all of them will affect the default setting UI. | 559 // settings; all of them will affect the default setting UI. |
559 if (entries[i].a == ContentSettingsPattern::Wildcard() && | 560 if (entries[i].primary_pattern == ContentSettingsPattern::Wildcard() && |
560 entries[i].b == ContentSettingsPattern::Wildcard() && | 561 entries[i].secondary_pattern == ContentSettingsPattern::Wildcard() && |
561 entries[i].d != "preference") { | 562 entries[i].source != "preference") { |
562 continue; | 563 continue; |
563 } | 564 } |
564 // The content settings UI does not support secondary content settings | 565 // The content settings UI does not support secondary content settings |
565 // pattern yet. For content settings set through the content settings UI the | 566 // pattern yet. For content settings set through the content settings UI the |
566 // secondary pattern is by default a wildcard pattern. Hence users are not | 567 // secondary pattern is by default a wildcard pattern. Hence users are not |
567 // able to modify content settings with a secondary pattern other than the | 568 // able to modify content settings with a secondary pattern other than the |
568 // wildcard pattern. So only show settings that the user is able to modify. | 569 // wildcard pattern. So only show settings that the user is able to modify. |
569 // TODO(bauerb): Support a read-only view for those patterns. | 570 // TODO(bauerb): Support a read-only view for those patterns. |
570 if (entries[i].b == ContentSettingsPattern::Wildcard()) { | 571 if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard()) { |
571 exceptions.Append( | 572 exceptions.Append( |
572 GetExceptionForPage(entries[i].a, entries[i].c, entries[i].d)); | 573 GetExceptionForPage(entries[i].primary_pattern, entries[i].setting, |
| 574 entries[i].source)); |
573 } else { | 575 } else { |
574 LOG(ERROR) << "Secondary content settings patterns are not " | 576 LOG(ERROR) << "Secondary content settings patterns are not " |
575 << "supported by the content settings UI"; | 577 << "supported by the content settings UI"; |
576 } | 578 } |
577 } | 579 } |
578 | 580 |
579 StringValue type_string(ContentSettingsTypeToGroupName(type)); | 581 StringValue type_string(ContentSettingsTypeToGroupName(type)); |
580 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string, | 582 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string, |
581 exceptions); | 583 exceptions); |
582 | 584 |
583 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 585 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
584 | 586 |
585 // The default may also have changed (we won't get a separate notification). | 587 // The default may also have changed (we won't get a separate notification). |
586 // If it hasn't changed, this call will be harmless. | 588 // If it hasn't changed, this call will be harmless. |
587 UpdateSettingDefaultFromModel(type); | 589 UpdateSettingDefaultFromModel(type); |
588 } | 590 } |
589 | 591 |
590 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 592 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
591 ContentSettingsType type) { | 593 ContentSettingsType type) { |
592 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 594 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
593 if (!otr_settings_map) | 595 if (!otr_settings_map) |
594 return; | 596 return; |
595 | 597 |
596 HostContentSettingsMap::SettingsForOneType otr_entries; | 598 ContentSettingsForOneType otr_entries; |
597 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); | 599 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); |
598 | 600 |
599 ListValue otr_exceptions; | 601 ListValue otr_exceptions; |
600 for (size_t i = 0; i < otr_entries.size(); ++i) { | 602 for (size_t i = 0; i < otr_entries.size(); ++i) { |
601 // Off-the-record HostContentSettingsMap contains incognito content settings | 603 // Off-the-record HostContentSettingsMap contains incognito content settings |
602 // as well as normal content settings. Here, we use the incongnito settings | 604 // as well as normal content settings. Here, we use the incongnito settings |
603 // only. | 605 // only. |
604 if (!otr_entries[i].e) | 606 if (!otr_entries[i].incognito) |
605 continue; | 607 continue; |
606 // The content settings UI does not support secondary content settings | 608 // The content settings UI does not support secondary content settings |
607 // pattern yet. For content settings set through the content settings UI the | 609 // pattern yet. For content settings set through the content settings UI the |
608 // secondary pattern is by default a wildcard pattern. Hence users are not | 610 // secondary pattern is by default a wildcard pattern. Hence users are not |
609 // able to modify content settings with a secondary pattern other than the | 611 // able to modify content settings with a secondary pattern other than the |
610 // wildcard pattern. So only show settings that the user is able to modify. | 612 // wildcard pattern. So only show settings that the user is able to modify. |
611 // TODO(bauerb): Support a read-only view for those patterns. | 613 // TODO(bauerb): Support a read-only view for those patterns. |
612 if (otr_entries[i].b == ContentSettingsPattern::Wildcard()) { | 614 if (otr_entries[i].secondary_pattern == |
| 615 ContentSettingsPattern::Wildcard()) { |
613 otr_exceptions.Append( | 616 otr_exceptions.Append( |
614 GetExceptionForPage(otr_entries[i].a, | 617 GetExceptionForPage(otr_entries[i].primary_pattern, |
615 otr_entries[i].c, | 618 otr_entries[i].setting, |
616 otr_entries[i].d)); | 619 otr_entries[i].source)); |
617 } else { | 620 } else { |
618 LOG(ERROR) << "Secondary content settings patterns are not " | 621 LOG(ERROR) << "Secondary content settings patterns are not " |
619 << "supported by the content settings UI"; | 622 << "supported by the content settings UI"; |
620 } | 623 } |
621 } | 624 } |
622 | 625 |
623 StringValue type_string(ContentSettingsTypeToGroupName(type)); | 626 StringValue type_string(ContentSettingsTypeToGroupName(type)); |
624 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", | 627 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", |
625 type_string, otr_exceptions); | 628 type_string, otr_exceptions); |
626 } | 629 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 801 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
799 } | 802 } |
800 | 803 |
801 HostContentSettingsMap* | 804 HostContentSettingsMap* |
802 ContentSettingsHandler::GetOTRContentSettingsMap() { | 805 ContentSettingsHandler::GetOTRContentSettingsMap() { |
803 Profile* profile = Profile::FromWebUI(web_ui_); | 806 Profile* profile = Profile::FromWebUI(web_ui_); |
804 if (profile->HasOffTheRecordProfile()) | 807 if (profile->HasOffTheRecordProfile()) |
805 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 808 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
806 return NULL; | 809 return NULL; |
807 } | 810 } |
OLD | NEW |