| 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 f312e67618b1fe8e3722ce67dbbeca7c4113004f..3406ae8933158734849301b3ddc4565386c3ac70 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
|
| @@ -129,37 +136,25 @@ DictionaryValue* GetExceptionForPage(
|
| ContentSetting setting,
|
| std::string provider_name) {
|
| DictionaryValue* exception = new DictionaryValue();
|
| - exception->Set(
|
| - kDisplayPattern,
|
| - new StringValue(pattern.ToString()));
|
| - exception->Set(
|
| - kSetting,
|
| - new StringValue(ContentSettingToString(setting)));
|
| - exception->Set(
|
| - kSource,
|
| - new StringValue(provider_name));
|
| + exception->SetString(kDisplayPattern, pattern.ToString());
|
| + exception->SetString(kSetting, ContentSettingToString(setting));
|
| + exception->SetString(kSource, provider_name);
|
| return exception;
|
| }
|
|
|
| // 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,
|
| - new StringValue(GeolocationExceptionToString(origin, embedding_origin)));
|
| - exception->Set(
|
| - kSetting,
|
| - new StringValue(ContentSettingToString(setting)));
|
| - exception->Set(
|
| - kOrigin,
|
| - new StringValue(origin.spec()));
|
| - exception->Set(
|
| - kEmbeddingOrigin,
|
| - new StringValue(embedding_origin.spec()));
|
| + exception->SetString(kDisplayPattern,
|
| + GeolocationExceptionToString(origin, embedding_origin));
|
| + exception->SetString(kSetting, ContentSettingToString(setting));
|
| + exception->SetString(kOrigin, origin.ToString());
|
| + exception->SetString(kEmbeddingOrigin, embedding_origin.ToString());
|
| return exception;
|
| }
|
|
|
| @@ -170,15 +165,10 @@ DictionaryValue* GetNotificationExceptionForPage(
|
| const GURL& url,
|
| ContentSetting setting) {
|
| DictionaryValue* exception = new DictionaryValue();
|
| - exception->Set(
|
| - kDisplayPattern,
|
| - new StringValue(content_settings_helper::OriginToString(url)));
|
| - exception->Set(
|
| - kSetting,
|
| - new StringValue(ContentSettingToString(setting)));
|
| - exception->Set(
|
| - kOrigin,
|
| - new StringValue(url.spec()));
|
| + exception->SetString(kDisplayPattern,
|
| + content_settings_helper::OriginToString(url));
|
| + exception->SetString(kSetting, ContentSettingToString(setting));
|
| + exception->SetString(kOrigin, url.spec());
|
| return exception;
|
| }
|
|
|
| @@ -432,36 +422,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 +599,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;
|
|
|