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/content_notification_types.h" | 32 #include "content/common/content_notification_types.h" |
32 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
33 #include "content/common/notification_source.h" | 34 #include "content/common/notification_source.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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 default: | 464 default: |
464 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 465 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
465 break; | 466 break; |
466 } | 467 } |
467 } | 468 } |
468 | 469 |
469 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { | 470 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
470 Profile* profile = Profile::FromWebUI(web_ui_); | 471 Profile* profile = Profile::FromWebUI(web_ui_); |
471 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 472 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
472 | 473 |
473 HostContentSettingsMap::SettingsForOneType all_settings; | 474 ContentSettingsForOneType all_settings; |
474 map->GetSettingsForOneType( | 475 map->GetSettingsForOneType( |
475 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 476 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
476 std::string(), | 477 std::string(), |
477 &all_settings); | 478 &all_settings); |
478 | 479 |
479 // Group geolocation settings by primary_pattern. | 480 // Group geolocation settings by primary_pattern. |
480 AllPatternsSettings all_patterns_settings; | 481 AllPatternsSettings all_patterns_settings; |
481 for (HostContentSettingsMap::SettingsForOneType::iterator i = | 482 for (ContentSettingsForOneType::iterator i = |
482 all_settings.begin(); | 483 all_settings.begin(); |
483 i != all_settings.end(); | 484 i != all_settings.end(); |
484 ++i) { | 485 ++i) { |
485 all_patterns_settings[i->a][i->b] = i->c; | 486 all_patterns_settings[i->a][i->b] = i->c; |
486 } | 487 } |
487 | 488 |
488 ListValue exceptions; | 489 ListValue exceptions; |
489 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); | 490 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); |
490 i != all_patterns_settings.end(); | 491 i != all_patterns_settings.end(); |
491 ++i) { | 492 ++i) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 // This is mainly here to keep this function ideologically parallel to | 524 // This is mainly here to keep this function ideologically parallel to |
524 // UpdateExceptionsViewFromHostContentSettingsMap(). | 525 // UpdateExceptionsViewFromHostContentSettingsMap(). |
525 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 526 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
526 } | 527 } |
527 | 528 |
528 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 529 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
529 Profile* profile = Profile::FromWebUI(web_ui_); | 530 Profile* profile = Profile::FromWebUI(web_ui_); |
530 DesktopNotificationService* service = | 531 DesktopNotificationService* service = |
531 DesktopNotificationServiceFactory::GetForProfile(profile); | 532 DesktopNotificationServiceFactory::GetForProfile(profile); |
532 | 533 |
533 HostContentSettingsMap::SettingsForOneType settings; | 534 ContentSettingsForOneType settings; |
534 service->GetNotificationsSettings(&settings); | 535 service->GetNotificationsSettings(&settings); |
535 | 536 |
536 ListValue exceptions; | 537 ListValue exceptions; |
537 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = | 538 for (ContentSettingsForOneType::const_iterator i = |
538 settings.begin(); | 539 settings.begin(); |
539 i != settings.end(); | 540 i != settings.end(); |
540 ++i) { | 541 ++i) { |
541 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); | 542 const ContentSettingPatternSourceTuple& tuple(*i); |
542 exceptions.Append( | 543 exceptions.Append( |
543 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); | 544 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); |
544 } | 545 } |
545 | 546 |
546 StringValue type_string( | 547 StringValue type_string( |
547 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 548 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
548 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 549 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
549 type_string, exceptions); | 550 type_string, exceptions); |
550 | 551 |
551 // This is mainly here to keep this function ideologically parallel to | 552 // This is mainly here to keep this function ideologically parallel to |
552 // UpdateExceptionsViewFromHostContentSettingsMap(). | 553 // UpdateExceptionsViewFromHostContentSettingsMap(). |
553 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 554 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
554 } | 555 } |
555 | 556 |
556 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 557 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
557 ContentSettingsType type) { | 558 ContentSettingsType type) { |
558 HostContentSettingsMap::SettingsForOneType entries; | 559 ContentSettingsForOneType entries; |
559 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); | 560 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); |
560 | 561 |
561 ListValue exceptions; | 562 ListValue exceptions; |
562 for (size_t i = 0; i < entries.size(); ++i) { | 563 for (size_t i = 0; i < entries.size(); ++i) { |
563 // The content settings UI does not support secondary content settings | 564 // The content settings UI does not support secondary content settings |
564 // pattern yet. For content settings set through the content settings UI the | 565 // pattern yet. For content settings set through the content settings UI the |
565 // secondary pattern is by default a wildcard pattern. Hence users are not | 566 // secondary pattern is by default a wildcard pattern. Hence users are not |
566 // able to modify content settings with a secondary pattern other than the | 567 // able to modify content settings with a secondary pattern other than the |
567 // wildcard pattern. So only show settings that the user is able to modify. | 568 // wildcard pattern. So only show settings that the user is able to modify. |
568 // TODO(bauerb): Support a read-only view for those patterns. | 569 // TODO(bauerb): Support a read-only view for those patterns. |
(...skipping 16 matching lines...) Expand all Loading... |
585 // If it hasn't changed, this call will be harmless. | 586 // If it hasn't changed, this call will be harmless. |
586 UpdateSettingDefaultFromModel(type); | 587 UpdateSettingDefaultFromModel(type); |
587 } | 588 } |
588 | 589 |
589 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 590 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
590 ContentSettingsType type) { | 591 ContentSettingsType type) { |
591 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 592 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
592 if (!otr_settings_map) | 593 if (!otr_settings_map) |
593 return; | 594 return; |
594 | 595 |
595 HostContentSettingsMap::SettingsForOneType otr_entries; | 596 ContentSettingsForOneType otr_entries; |
596 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); | 597 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); |
597 | 598 |
598 ListValue otr_exceptions; | 599 ListValue otr_exceptions; |
599 for (size_t i = 0; i < otr_entries.size(); ++i) { | 600 for (size_t i = 0; i < otr_entries.size(); ++i) { |
600 // Off-the-record HostContentSettingsMap contains incognito content settings | 601 // Off-the-record HostContentSettingsMap contains incognito content settings |
601 // as well as normal content settings. Here, we use the incongnito settings | 602 // as well as normal content settings. Here, we use the incongnito settings |
602 // only. | 603 // only. |
603 if (!otr_entries[i].e) | 604 if (!otr_entries[i].e) |
604 continue; | 605 continue; |
605 // The content settings UI does not support secondary content settings | 606 // The content settings UI does not support secondary content settings |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 798 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
798 } | 799 } |
799 | 800 |
800 HostContentSettingsMap* | 801 HostContentSettingsMap* |
801 ContentSettingsHandler::GetOTRContentSettingsMap() { | 802 ContentSettingsHandler::GetOTRContentSettingsMap() { |
802 Profile* profile = Profile::FromWebUI(web_ui_); | 803 Profile* profile = Profile::FromWebUI(web_ui_); |
803 if (profile->HasOffTheRecordProfile()) | 804 if (profile->HasOffTheRecordProfile()) |
804 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 805 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
805 return NULL; | 806 return NULL; |
806 } | 807 } |
OLD | NEW |