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

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

Issue 7484072: Migrate geolocation settings to host content settings map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 4 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
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 <string> 8 #include <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #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"
16 #include "chrome/browser/content_settings/content_settings_utils.h" 18 #include "chrome/browser/content_settings/content_settings_utils.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 19 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
19 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
20 #include "chrome/browser/notifications/desktop_notification_service.h" 21 #include "chrome/browser/notifications/desktop_notification_service.h"
21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/content_settings_helper.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/common/content_notification_types.h" 30 #include "content/common/content_notification_types.h"
30 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
31 #include "content/common/notification_source.h" 32 #include "content/common/notification_source.h"
32 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
33 #include "grit/locale_settings.h" 34 #include "grit/locale_settings.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 36
36 namespace { 37 namespace {
37 38
38 struct ContentSettingsTypeNameEntry { 39 struct ContentSettingsTypeNameEntry {
39 ContentSettingsType type; 40 ContentSettingsType type;
40 const char* name; 41 const char* name;
41 }; 42 };
42 43
44 typedef std::map<ContentSettingsPattern, ContentSetting> OnePatternSettings;
45 typedef std::map<ContentSettingsPattern, OnePatternSettings>
46 AllPatternsSettings;
47
43 const char* kDisplayPattern = "displayPattern"; 48 const char* kDisplayPattern = "displayPattern";
44 const char* kSetting = "setting"; 49 const char* kSetting = "setting";
45 const char* kOrigin = "origin"; 50 const char* kOrigin = "origin";
46 const char* kSource = "source"; 51 const char* kSource = "source";
47 const char* kEmbeddingOrigin = "embeddingOrigin"; 52 const char* kEmbeddingOrigin = "embeddingOrigin";
48 53
49 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { 54 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
50 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, 55 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"},
51 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, 56 {CONTENT_SETTINGS_TYPE_IMAGES, "images"},
52 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, 57 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"},
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return CONTENT_SETTING_ASK; 97 return CONTENT_SETTING_ASK;
93 if (name == "block") 98 if (name == "block")
94 return CONTENT_SETTING_BLOCK; 99 return CONTENT_SETTING_BLOCK;
95 if (name == "session") 100 if (name == "session")
96 return CONTENT_SETTING_SESSION_ONLY; 101 return CONTENT_SETTING_SESSION_ONLY;
97 102
98 NOTREACHED() << name << " is not a recognized content setting."; 103 NOTREACHED() << name << " is not a recognized content setting.";
99 return CONTENT_SETTING_DEFAULT; 104 return CONTENT_SETTING_DEFAULT;
100 } 105 }
101 106
102 std::string GeolocationExceptionToString(const GURL& origin, 107 std::string GeolocationExceptionToString(
103 const GURL& embedding_origin) { 108 const ContentSettingsPattern& origin,
109 const ContentSettingsPattern& embedding_origin) {
104 if (origin == embedding_origin) 110 if (origin == embedding_origin)
105 return content_settings_helper::OriginToString(origin); 111 return origin.ToString();
106 112
107 // TODO(estade): the page needs to use CSS to indent the string. 113 // TODO(estade): the page needs to use CSS to indent the string.
108 std::string indent(" "); 114 std::string indent(" ");
109 if (embedding_origin.is_empty()) { 115
116 if (embedding_origin == ContentSettingsPattern::Wildcard()) {
110 // NOTE: As long as the user cannot add/edit entries from the exceptions 117 // NOTE: As long as the user cannot add/edit entries from the exceptions
111 // dialog, it's impossible to actually have a non-default setting for some 118 // dialog, it's impossible to actually have a non-default setting for some
112 // origin "embedded on any other site", so this row will never appear. If 119 // origin "embedded on any other site", so this row will never appear. If
113 // we add the ability to add/edit exceptions, we'll need to decide when to 120 // we add the ability to add/edit exceptions, we'll need to decide when to
114 // display this and how "removing" it will function. 121 // display this and how "removing" it will function.
115 return indent + 122 return indent +
116 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ANY_OTHER); 123 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ANY_OTHER);
117 } 124 }
118 125
119 return indent + l10n_util::GetStringFUTF8( 126 return indent + l10n_util::GetStringFUTF8(
120 IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST, 127 IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST,
121 UTF8ToUTF16(content_settings_helper::OriginToString(embedding_origin))); 128 UTF8ToUTF16(embedding_origin.ToString()));
122 } 129 }
123 130
124 // Create a DictionaryValue* that will act as a data source for a single row 131 // Create a DictionaryValue* that will act as a data source for a single row
125 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). 132 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies).
126 // Ownership of the pointer is passed to the caller. 133 // Ownership of the pointer is passed to the caller.
127 DictionaryValue* GetExceptionForPage( 134 DictionaryValue* GetExceptionForPage(
128 const ContentSettingsPattern& pattern, 135 const ContentSettingsPattern& pattern,
129 ContentSetting setting, 136 ContentSetting setting,
130 std::string provider_name) { 137 std::string provider_name) {
131 DictionaryValue* exception = new DictionaryValue(); 138 DictionaryValue* exception = new DictionaryValue();
132 exception->Set( 139 exception->Set(
133 kDisplayPattern, 140 kDisplayPattern,
134 new StringValue(pattern.ToString())); 141 new StringValue(pattern.ToString()));
135 exception->Set( 142 exception->Set(
136 kSetting, 143 kSetting,
137 new StringValue(ContentSettingToString(setting))); 144 new StringValue(ContentSettingToString(setting)));
138 exception->Set( 145 exception->Set(
139 kSource, 146 kSource,
140 new StringValue(provider_name)); 147 new StringValue(provider_name));
141 return exception; 148 return exception;
142 } 149 }
143 150
144 // Create a DictionaryValue* that will act as a data source for a single row 151 // Create a DictionaryValue* that will act as a data source for a single row
145 // in the Geolocation exceptions table. Ownership of the pointer is passed to 152 // in the Geolocation exceptions table. Ownership of the pointer is passed to
146 // the caller. 153 // the caller.
147 DictionaryValue* GetGeolocationExceptionForPage(const GURL& origin, 154 DictionaryValue* GetGeolocationExceptionForPage(
148 const GURL& embedding_origin, 155 const ContentSettingsPattern& origin,
149 ContentSetting setting) { 156 const ContentSettingsPattern& embedding_origin,
157 ContentSetting setting) {
150 DictionaryValue* exception = new DictionaryValue(); 158 DictionaryValue* exception = new DictionaryValue();
151 exception->Set( 159 exception->Set(
152 kDisplayPattern, 160 kDisplayPattern,
153 new StringValue(GeolocationExceptionToString(origin, embedding_origin))); 161 new StringValue(GeolocationExceptionToString(origin, embedding_origin)));
Bernhard Bauer 2011/08/03 15:22:50 While you're here, could you change this to use Se
markusheintz_ 2011/08/04 12:45:56 Absolutely!
154 exception->Set( 162 exception->Set(
155 kSetting, 163 kSetting,
156 new StringValue(ContentSettingToString(setting))); 164 new StringValue(ContentSettingToString(setting)));
157 exception->Set( 165 exception->Set(
158 kOrigin, 166 kOrigin,
159 new StringValue(origin.spec())); 167 new StringValue(origin.ToString()));
160 exception->Set( 168 exception->Set(
161 kEmbeddingOrigin, 169 kEmbeddingOrigin,
162 new StringValue(embedding_origin.spec())); 170 new StringValue(embedding_origin.ToString()));
163 return exception; 171 return exception;
164 } 172 }
165 173
166 // Create a DictionaryValue* that will act as a data source for a single row 174 // 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 175 // in the desktop notifications exceptions table. Ownership of the pointer is
168 // passed to the caller. 176 // passed to the caller.
169 DictionaryValue* GetNotificationExceptionForPage( 177 DictionaryValue* GetNotificationExceptionForPage(
170 const GURL& url, 178 const GURL& url,
171 ContentSetting setting) { 179 ContentSetting setting) {
172 DictionaryValue* exception = new DictionaryValue(); 180 DictionaryValue* exception = new DictionaryValue();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 433 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
426 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 434 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
427 break; 435 break;
428 default: 436 default:
429 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 437 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
430 break; 438 break;
431 } 439 }
432 } 440 }
433 441
434 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { 442 void ContentSettingsHandler::UpdateGeolocationExceptionsView() {
435 GeolocationContentSettingsMap* map = 443 HostContentSettingsMap* map =
436 web_ui_->GetProfile()->GetGeolocationContentSettingsMap(); 444 web_ui_->GetProfile()->GetHostContentSettingsMap();
437 GeolocationContentSettingsMap::AllOriginsSettings all_settings = 445
438 map->GetAllOriginsSettings(); 446 HostContentSettingsMap::SettingsForOneType all_settings;
439 GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i; 447 map->GetSettingsForOneType(
448 CONTENT_SETTINGS_TYPE_GEOLOCATION,
449 std::string(),
450 &all_settings);
451
452 // Group geolocation settings by primary_pattern.
453 AllPatternsSettings all_patterns_settings;
454 for (HostContentSettingsMap::SettingsForOneType::iterator i =
455 all_settings.begin();
456 i != all_settings.end();
457 ++i) {
458 all_patterns_settings[i->a][i->b] = i->c;
459 }
440 460
441 ListValue exceptions; 461 ListValue exceptions;
442 for (i = all_settings.begin(); i != all_settings.end(); ++i) { 462 for (AllPatternsSettings::iterator i = all_patterns_settings.begin();
443 const GURL& origin = i->first; 463 i != all_patterns_settings.end();
444 const GeolocationContentSettingsMap::OneOriginSettings& one_settings = 464 ++i) {
445 i->second; 465 const ContentSettingsPattern& primary_pattern = i->first;
466 const OnePatternSettings& one_settings = i->second;
446 467
447 GeolocationContentSettingsMap::OneOriginSettings::const_iterator parent = 468 OnePatternSettings::const_iterator parent =
448 one_settings.find(origin); 469 one_settings.find(primary_pattern);
449 470
450 // Add the "parent" entry for the non-embedded setting. 471 // Add the "parent" entry for the non-embedded setting.
451 ContentSetting parent_setting = 472 ContentSetting parent_setting =
452 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; 473 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second;
453 exceptions.Append( 474 exceptions.Append(GetGeolocationExceptionForPage(primary_pattern,
454 GetGeolocationExceptionForPage(origin, origin, parent_setting)); 475 primary_pattern,
476 parent_setting));
455 477
456 // Add the "children" for any embedded settings. 478 // Add the "children" for any embedded settings.
457 GeolocationContentSettingsMap::OneOriginSettings::const_iterator j; 479 for (OnePatternSettings::const_iterator j = one_settings.begin();
458 for (j = one_settings.begin(); j != one_settings.end(); ++j) { 480 j != one_settings.end();
481 ++j) {
459 // Skip the non-embedded setting which we already added above. 482 // Skip the non-embedded setting which we already added above.
460 if (j == parent) 483 if (j == parent)
461 continue; 484 continue;
462 485
463 exceptions.Append( 486 exceptions.Append(
464 GetGeolocationExceptionForPage(origin, j->first, j->second)); 487 GetGeolocationExceptionForPage(primary_pattern, j->first, j->second));
465 } 488 }
466 } 489 }
467 490
468 StringValue type_string( 491 StringValue type_string(
469 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); 492 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION));
470 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", 493 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions",
471 type_string, exceptions); 494 type_string, exceptions);
472 495
473 // This is mainly here to keep this function ideologically parallel to 496 // This is mainly here to keep this function ideologically parallel to
474 // UpdateExceptionsViewFromHostContentSettingsMap(). 497 // UpdateExceptionsViewFromHostContentSettingsMap().
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 610
588 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 611 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
589 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 612 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
590 std::string origin; 613 std::string origin;
591 std::string embedding_origin; 614 std::string embedding_origin;
592 bool rv = args->GetString(arg_i++, &origin); 615 bool rv = args->GetString(arg_i++, &origin);
593 DCHECK(rv); 616 DCHECK(rv);
594 rv = args->GetString(arg_i++, &embedding_origin); 617 rv = args->GetString(arg_i++, &embedding_origin);
595 DCHECK(rv); 618 DCHECK(rv);
596 619
597 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> 620 web_ui_->GetProfile()->GetHostContentSettingsMap()->
598 SetContentSetting(GURL(origin), 621 SetContentSetting(ContentSettingsPattern::FromString(origin),
599 GURL(embedding_origin), 622 ContentSettingsPattern::FromString(embedding_origin),
623 CONTENT_SETTINGS_TYPE_GEOLOCATION,
624 std::string(),
600 CONTENT_SETTING_DEFAULT); 625 CONTENT_SETTING_DEFAULT);
601 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 626 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
602 std::string origin; 627 std::string origin;
603 std::string setting; 628 std::string setting;
604 bool rv = args->GetString(arg_i++, &origin); 629 bool rv = args->GetString(arg_i++, &origin);
605 DCHECK(rv); 630 DCHECK(rv);
606 rv = args->GetString(arg_i++, &setting); 631 rv = args->GetString(arg_i++, &setting);
607 DCHECK(rv); 632 DCHECK(rv);
608 ContentSetting content_setting = ContentSettingFromString(setting); 633 ContentSetting content_setting = ContentSettingFromString(setting);
609 if (content_setting == CONTENT_SETTING_ALLOW) { 634 if (content_setting == CONTENT_SETTING_ALLOW) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); 742 return web_ui_->GetProfile()->GetProtocolHandlerRegistry();
718 } 743 }
719 744
720 HostContentSettingsMap* 745 HostContentSettingsMap*
721 ContentSettingsHandler::GetOTRContentSettingsMap() { 746 ContentSettingsHandler::GetOTRContentSettingsMap() {
722 Profile* profile = web_ui_->GetProfile(); 747 Profile* profile = web_ui_->GetProfile();
723 if (profile->HasOffTheRecordProfile()) 748 if (profile->HasOffTheRecordProfile())
724 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 749 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
725 return NULL; 750 return NULL;
726 } 751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698