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/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/content_settings/content_settings_details.h" | 16 #include "chrome/browser/content_settings/content_settings_details.h" |
17 #include "chrome/browser/content_settings/content_settings_pattern.h" | 17 #include "chrome/browser/content_settings/content_settings_pattern.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_helper.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "content/browser/tab_contents/tab_contents.h" | 30 #include "content/browser/tab_contents/tab_contents.h" |
30 #include "content/common/content_notification_types.h" | 31 #include "content/common/content_notification_types.h" |
31 #include "content/common/notification_service.h" | 32 #include "content/common/notification_service.h" |
32 #include "content/common/notification_source.h" | 33 #include "content/common/notification_source.h" |
33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
34 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
36 | 37 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 exception->SetString(kSetting, ContentSettingToString(setting)); | 161 exception->SetString(kSetting, ContentSettingToString(setting)); |
161 exception->SetString(kOrigin, origin.ToString()); | 162 exception->SetString(kOrigin, origin.ToString()); |
162 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); | 163 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); |
163 return exception; | 164 return exception; |
164 } | 165 } |
165 | 166 |
166 // Create a DictionaryValue* that will act as a data source for a single row | 167 // Create a DictionaryValue* that will act as a data source for a single row |
167 // in the desktop notifications exceptions table. Ownership of the pointer is | 168 // in the desktop notifications exceptions table. Ownership of the pointer is |
168 // passed to the caller. | 169 // passed to the caller. |
169 DictionaryValue* GetNotificationExceptionForPage( | 170 DictionaryValue* GetNotificationExceptionForPage( |
170 const ContentSettingsPattern& pattern, | 171 const GURL& url, |
171 ContentSetting setting) { | 172 ContentSetting setting) { |
172 DictionaryValue* exception = new DictionaryValue(); | 173 DictionaryValue* exception = new DictionaryValue(); |
173 exception->SetString(kDisplayPattern, pattern.ToString()); | 174 exception->SetString(kDisplayPattern, |
| 175 content_settings_helper::OriginToString(url)); |
174 exception->SetString(kSetting, ContentSettingToString(setting)); | 176 exception->SetString(kSetting, ContentSettingToString(setting)); |
175 exception->SetString(kOrigin, pattern.ToString()); | 177 exception->SetString(kOrigin, url.spec()); |
176 return exception; | 178 return exception; |
177 } | 179 } |
178 | 180 |
179 } // namespace | 181 } // namespace |
180 | 182 |
181 ContentSettingsHandler::ContentSettingsHandler() { | 183 ContentSettingsHandler::ContentSettingsHandler() { |
182 } | 184 } |
183 | 185 |
184 ContentSettingsHandler::~ContentSettingsHandler() { | 186 ContentSettingsHandler::~ContentSettingsHandler() { |
185 } | 187 } |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // This is mainly here to keep this function ideologically parallel to | 503 // This is mainly here to keep this function ideologically parallel to |
502 // UpdateExceptionsViewFromHostContentSettingsMap(). | 504 // UpdateExceptionsViewFromHostContentSettingsMap(). |
503 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 505 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
504 } | 506 } |
505 | 507 |
506 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 508 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
507 Profile* profile = Profile::FromWebUI(web_ui_); | 509 Profile* profile = Profile::FromWebUI(web_ui_); |
508 DesktopNotificationService* service = | 510 DesktopNotificationService* service = |
509 DesktopNotificationServiceFactory::GetForProfile(profile); | 511 DesktopNotificationServiceFactory::GetForProfile(profile); |
510 | 512 |
511 HostContentSettingsMap::SettingsForOneType settings; | 513 std::vector<GURL> allowed(service->GetAllowedOrigins()); |
512 service->GetNotificationsSettings(&settings); | 514 std::vector<GURL> blocked(service->GetBlockedOrigins()); |
513 | 515 |
514 ListValue exceptions; | 516 ListValue exceptions; |
515 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = | 517 for (size_t i = 0; i < allowed.size(); ++i) { |
516 settings.begin(); | |
517 i != settings.end(); | |
518 ++i) { | |
519 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); | |
520 exceptions.Append( | 518 exceptions.Append( |
521 GetNotificationExceptionForPage(tuple.a, tuple.c)); | 519 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); |
| 520 } |
| 521 for (size_t i = 0; i < blocked.size(); ++i) { |
| 522 exceptions.Append( |
| 523 GetNotificationExceptionForPage(blocked[i], CONTENT_SETTING_BLOCK)); |
522 } | 524 } |
523 | 525 |
524 StringValue type_string( | 526 StringValue type_string( |
525 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 527 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
526 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 528 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
527 type_string, exceptions); | 529 type_string, exceptions); |
528 | 530 |
529 // This is mainly here to keep this function ideologically parallel to | 531 // This is mainly here to keep this function ideologically parallel to |
530 // UpdateExceptionsViewFromHostContentSettingsMap(). | 532 // UpdateExceptionsViewFromHostContentSettingsMap(). |
531 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 533 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 std::string(), | 644 std::string(), |
643 CONTENT_SETTING_DEFAULT); | 645 CONTENT_SETTING_DEFAULT); |
644 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 646 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
645 std::string origin; | 647 std::string origin; |
646 std::string setting; | 648 std::string setting; |
647 bool rv = args->GetString(arg_i++, &origin); | 649 bool rv = args->GetString(arg_i++, &origin); |
648 DCHECK(rv); | 650 DCHECK(rv); |
649 rv = args->GetString(arg_i++, &setting); | 651 rv = args->GetString(arg_i++, &setting); |
650 DCHECK(rv); | 652 DCHECK(rv); |
651 ContentSetting content_setting = ContentSettingFromString(setting); | 653 ContentSetting content_setting = ContentSettingFromString(setting); |
652 | 654 if (content_setting == CONTENT_SETTING_ALLOW) { |
653 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 655 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
654 content_setting == CONTENT_SETTING_BLOCK); | 656 ResetAllowedOrigin(GURL(origin)); |
655 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 657 } else { |
656 ClearSetting(ContentSettingsPattern::FromString(origin)); | 658 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); |
| 659 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
| 660 ResetBlockedOrigin(GURL(origin)); |
| 661 } |
657 } else { | 662 } else { |
658 std::string mode; | 663 std::string mode; |
659 bool rv = args->GetString(arg_i++, &mode); | 664 bool rv = args->GetString(arg_i++, &mode); |
660 DCHECK(rv); | 665 DCHECK(rv); |
661 | 666 |
662 std::string pattern; | 667 std::string pattern; |
663 rv = args->GetString(arg_i++, &pattern); | 668 rv = args->GetString(arg_i++, &pattern); |
664 DCHECK(rv); | 669 DCHECK(rv); |
665 | 670 |
666 HostContentSettingsMap* settings_map = | 671 HostContentSettingsMap* settings_map = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 762 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
758 } | 763 } |
759 | 764 |
760 HostContentSettingsMap* | 765 HostContentSettingsMap* |
761 ContentSettingsHandler::GetOTRContentSettingsMap() { | 766 ContentSettingsHandler::GetOTRContentSettingsMap() { |
762 Profile* profile = Profile::FromWebUI(web_ui_); | 767 Profile* profile = Profile::FromWebUI(web_ui_); |
763 if (profile->HasOffTheRecordProfile()) | 768 if (profile->HasOffTheRecordProfile()) |
764 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 769 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
765 return NULL; | 770 return NULL; |
766 } | 771 } |
OLD | NEW |