Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1034)

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 7655019: Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove include of deleted notifications_prefs_cache.h Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
28 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
29 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
30 #include "content/browser/tab_contents/tab_contents.h" 29 #include "content/browser/tab_contents/tab_contents.h"
31 #include "content/common/content_notification_types.h" 30 #include "content/common/content_notification_types.h"
32 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
33 #include "content/common/notification_source.h" 32 #include "content/common/notification_source.h"
34 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
35 #include "grit/locale_settings.h" 34 #include "grit/locale_settings.h"
36 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
37 36
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 exception->SetString(kSetting, ContentSettingToString(setting)); 160 exception->SetString(kSetting, ContentSettingToString(setting));
162 exception->SetString(kOrigin, origin.ToString()); 161 exception->SetString(kOrigin, origin.ToString());
163 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); 162 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString());
164 return exception; 163 return exception;
165 } 164 }
166 165
167 // Create a DictionaryValue* that will act as a data source for a single row 166 // Create a DictionaryValue* that will act as a data source for a single row
168 // in the desktop notifications exceptions table. Ownership of the pointer is 167 // in the desktop notifications exceptions table. Ownership of the pointer is
169 // passed to the caller. 168 // passed to the caller.
170 DictionaryValue* GetNotificationExceptionForPage( 169 DictionaryValue* GetNotificationExceptionForPage(
171 const GURL& url, 170 const ContentSettingsPattern& pattern,
172 ContentSetting setting) { 171 ContentSetting setting) {
173 DictionaryValue* exception = new DictionaryValue(); 172 DictionaryValue* exception = new DictionaryValue();
174 exception->SetString(kDisplayPattern, 173 exception->SetString(kDisplayPattern, pattern.ToString());
175 content_settings_helper::OriginToString(url));
176 exception->SetString(kSetting, ContentSettingToString(setting)); 174 exception->SetString(kSetting, ContentSettingToString(setting));
177 exception->SetString(kOrigin, url.spec()); 175 exception->SetString(kOrigin, pattern.ToString());
178 return exception; 176 return exception;
179 } 177 }
180 178
181 } // namespace 179 } // namespace
182 180
183 ContentSettingsHandler::ContentSettingsHandler() { 181 ContentSettingsHandler::ContentSettingsHandler() {
184 } 182 }
185 183
186 ContentSettingsHandler::~ContentSettingsHandler() { 184 ContentSettingsHandler::~ContentSettingsHandler() {
187 } 185 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // This is mainly here to keep this function ideologically parallel to 501 // This is mainly here to keep this function ideologically parallel to
504 // UpdateExceptionsViewFromHostContentSettingsMap(). 502 // UpdateExceptionsViewFromHostContentSettingsMap().
505 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 503 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
506 } 504 }
507 505
508 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 506 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
509 Profile* profile = Profile::FromWebUI(web_ui_); 507 Profile* profile = Profile::FromWebUI(web_ui_);
510 DesktopNotificationService* service = 508 DesktopNotificationService* service =
511 DesktopNotificationServiceFactory::GetForProfile(profile); 509 DesktopNotificationServiceFactory::GetForProfile(profile);
512 510
513 std::vector<GURL> allowed(service->GetAllowedOrigins()); 511 HostContentSettingsMap::SettingsForOneType settings;
514 std::vector<GURL> blocked(service->GetBlockedOrigins()); 512 service->GetNotificationsSettings(&settings);
515 513
516 ListValue exceptions; 514 ListValue exceptions;
517 for (size_t i = 0; i < allowed.size(); ++i) { 515 for (HostContentSettingsMap::SettingsForOneType::const_iterator i =
516 settings.begin();
517 i != settings.end();
518 ++i) {
519 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i);
518 exceptions.Append( 520 exceptions.Append(
519 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); 521 GetNotificationExceptionForPage(tuple.a, tuple.c));
520 }
521 for (size_t i = 0; i < blocked.size(); ++i) {
522 exceptions.Append(
523 GetNotificationExceptionForPage(blocked[i], CONTENT_SETTING_BLOCK));
524 } 522 }
525 523
526 StringValue type_string( 524 StringValue type_string(
527 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); 525 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
528 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", 526 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions",
529 type_string, exceptions); 527 type_string, exceptions);
530 528
531 // This is mainly here to keep this function ideologically parallel to 529 // This is mainly here to keep this function ideologically parallel to
532 // UpdateExceptionsViewFromHostContentSettingsMap(). 530 // UpdateExceptionsViewFromHostContentSettingsMap().
533 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 531 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 std::string(), 642 std::string(),
645 CONTENT_SETTING_DEFAULT); 643 CONTENT_SETTING_DEFAULT);
646 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 644 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
647 std::string origin; 645 std::string origin;
648 std::string setting; 646 std::string setting;
649 bool rv = args->GetString(arg_i++, &origin); 647 bool rv = args->GetString(arg_i++, &origin);
650 DCHECK(rv); 648 DCHECK(rv);
651 rv = args->GetString(arg_i++, &setting); 649 rv = args->GetString(arg_i++, &setting);
652 DCHECK(rv); 650 DCHECK(rv);
653 ContentSetting content_setting = ContentSettingFromString(setting); 651 ContentSetting content_setting = ContentSettingFromString(setting);
654 if (content_setting == CONTENT_SETTING_ALLOW) { 652
655 DesktopNotificationServiceFactory::GetForProfile(profile)-> 653 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
656 ResetAllowedOrigin(GURL(origin)); 654 content_setting == CONTENT_SETTING_BLOCK);
657 } else { 655 DesktopNotificationServiceFactory::GetForProfile(profile)->
658 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); 656 ClearSetting(ContentSettingsPattern::FromString(origin));
659 DesktopNotificationServiceFactory::GetForProfile(profile)->
660 ResetBlockedOrigin(GURL(origin));
661 }
662 } else { 657 } else {
663 std::string mode; 658 std::string mode;
664 bool rv = args->GetString(arg_i++, &mode); 659 bool rv = args->GetString(arg_i++, &mode);
665 DCHECK(rv); 660 DCHECK(rv);
666 661
667 std::string pattern; 662 std::string pattern;
668 rv = args->GetString(arg_i++, &pattern); 663 rv = args->GetString(arg_i++, &pattern);
669 DCHECK(rv); 664 DCHECK(rv);
670 665
671 HostContentSettingsMap* settings_map = 666 HostContentSettingsMap* settings_map =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); 757 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry();
763 } 758 }
764 759
765 HostContentSettingsMap* 760 HostContentSettingsMap*
766 ContentSettingsHandler::GetOTRContentSettingsMap() { 761 ContentSettingsHandler::GetOTRContentSettingsMap() {
767 Profile* profile = Profile::FromWebUI(web_ui_); 762 Profile* profile = Profile::FromWebUI(web_ui_);
768 if (profile->HasOffTheRecordProfile()) 763 if (profile->HasOffTheRecordProfile())
769 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 764 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
770 return NULL; 765 return NULL;
771 } 766 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698