Index: chrome/browser/ui/webui/options/content_settings_handler.cc |
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc |
index d0d5b1ba029a687c8a9415ebf9aada003e3a0daf..c2f68eb1ca0aafc97c722f422cb46d47cfe28657 100644 |
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc |
@@ -4,6 +4,7 @@ |
#include "chrome/browser/ui/webui/options/content_settings_handler.h" |
+#include <map> |
#include <string> |
#include <vector> |
@@ -13,10 +14,10 @@ |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/content_settings/content_settings_details.h" |
+#include "chrome/browser/content_settings/content_settings_pattern.h" |
#include "chrome/browser/content_settings/content_settings_utils.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
#include "chrome/browser/notifications/desktop_notification_service.h" |
#include "chrome/browser/notifications/desktop_notification_service_factory.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -40,6 +41,10 @@ struct ContentSettingsTypeNameEntry { |
const char* name; |
}; |
+typedef std::map<ContentSettingsPattern, ContentSetting> OnePatternSettings; |
+typedef std::map<ContentSettingsPattern, OnePatternSettings> |
+ AllPatternsSettings; |
+ |
const char* kDisplayPattern = "displayPattern"; |
const char* kSetting = "setting"; |
const char* kOrigin = "origin"; |
@@ -99,14 +104,16 @@ ContentSetting ContentSettingFromString(const std::string& name) { |
return CONTENT_SETTING_DEFAULT; |
} |
-std::string GeolocationExceptionToString(const GURL& origin, |
- const GURL& embedding_origin) { |
+std::string GeolocationExceptionToString( |
+ const ContentSettingsPattern& origin, |
+ const ContentSettingsPattern& embedding_origin) { |
if (origin == embedding_origin) |
- return content_settings_helper::OriginToString(origin); |
+ return origin.ToString(); |
// TODO(estade): the page needs to use CSS to indent the string. |
std::string indent(" "); |
- if (embedding_origin.is_empty()) { |
+ |
+ if (embedding_origin == ContentSettingsPattern::Wildcard()) { |
// NOTE: As long as the user cannot add/edit entries from the exceptions |
// dialog, it's impossible to actually have a non-default setting for some |
// origin "embedded on any other site", so this row will never appear. If |
@@ -118,7 +125,7 @@ std::string GeolocationExceptionToString(const GURL& origin, |
return indent + l10n_util::GetStringFUTF8( |
IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST, |
- UTF8ToUTF16(content_settings_helper::OriginToString(embedding_origin))); |
+ UTF8ToUTF16(embedding_origin.ToString())); |
} |
// Create a DictionaryValue* that will act as a data source for a single row |
@@ -144,9 +151,10 @@ DictionaryValue* GetExceptionForPage( |
// Create a DictionaryValue* that will act as a data source for a single row |
// in the Geolocation exceptions table. Ownership of the pointer is passed to |
// the caller. |
-DictionaryValue* GetGeolocationExceptionForPage(const GURL& origin, |
- const GURL& embedding_origin, |
- ContentSetting setting) { |
+DictionaryValue* GetGeolocationExceptionForPage( |
+ const ContentSettingsPattern& origin, |
+ const ContentSettingsPattern& embedding_origin, |
+ ContentSetting setting) { |
DictionaryValue* exception = new DictionaryValue(); |
exception->Set( |
kDisplayPattern, |
@@ -156,10 +164,10 @@ DictionaryValue* GetGeolocationExceptionForPage(const GURL& origin, |
new StringValue(ContentSettingToString(setting))); |
exception->Set( |
kOrigin, |
- new StringValue(origin.spec())); |
+ new StringValue(origin.ToString())); |
exception->Set( |
kEmbeddingOrigin, |
- new StringValue(embedding_origin.spec())); |
+ new StringValue(embedding_origin.ToString())); |
return exception; |
} |
@@ -432,36 +440,51 @@ void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( |
} |
void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
- GeolocationContentSettingsMap* map = |
- web_ui_->GetProfile()->GetGeolocationContentSettingsMap(); |
- GeolocationContentSettingsMap::AllOriginsSettings all_settings = |
- map->GetAllOriginsSettings(); |
- GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i; |
+ HostContentSettingsMap* map = |
+ web_ui_->GetProfile()->GetHostContentSettingsMap(); |
+ |
+ HostContentSettingsMap::SettingsForOneType all_settings; |
+ map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, |
+ std::string(), |
+ &all_settings); |
+ |
+ // Group geolocation settings by primary_pattern. |
+ AllPatternsSettings all_patterns_settings; |
+ for (HostContentSettingsMap::SettingsForOneType::iterator i = |
+ all_settings.begin(); |
+ i != all_settings.end(); |
+ ++i) { |
+ all_patterns_settings[i->a][i->b] = i->c; |
+ } |
ListValue exceptions; |
- for (i = all_settings.begin(); i != all_settings.end(); ++i) { |
- const GURL& origin = i->first; |
- const GeolocationContentSettingsMap::OneOriginSettings& one_settings = |
- i->second; |
+ for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); |
+ i != all_patterns_settings.end(); |
+ ++i) { |
+ const ContentSettingsPattern& primary_pattern = i->first; |
+ const OnePatternSettings& one_settings = i->second; |
- GeolocationContentSettingsMap::OneOriginSettings::const_iterator parent = |
- one_settings.find(origin); |
+ OnePatternSettings::const_iterator parent = |
+ one_settings.find(primary_pattern); |
// Add the "parent" entry for the non-embedded setting. |
ContentSetting parent_setting = |
parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; |
- exceptions.Append( |
- GetGeolocationExceptionForPage(origin, origin, parent_setting)); |
+ exceptions.Append(GetGeolocationExceptionForPage(primary_pattern, |
+ primary_pattern, |
+ parent_setting)); |
// Add the "children" for any embedded settings. |
- GeolocationContentSettingsMap::OneOriginSettings::const_iterator j; |
- for (j = one_settings.begin(); j != one_settings.end(); ++j) { |
+ for (OnePatternSettings::const_iterator j = one_settings.begin(); |
+ j != one_settings.end(); |
+ ++j) { |
// Skip the non-embedded setting which we already added above. |
if (j == parent) |
continue; |
exceptions.Append( |
- GetGeolocationExceptionForPage(origin, j->first, j->second)); |
+ GetGeolocationExceptionForPage(primary_pattern, j->first, j->second)); |
} |
} |
@@ -594,9 +617,11 @@ void ContentSettingsHandler::RemoveException(const ListValue* args) { |
rv = args->GetString(arg_i++, &embedding_origin); |
DCHECK(rv); |
- web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> |
- SetContentSetting(GURL(origin), |
- GURL(embedding_origin), |
+ web_ui_->GetProfile()->GetHostContentSettingsMap()-> |
+ SetContentSetting(ContentSettingsPattern::FromString(origin), |
+ ContentSettingsPattern::FromString(embedding_origin), |
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, |
+ std::string(), |
CONTENT_SETTING_DEFAULT); |
} else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
std::string origin; |