| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "extensions/common/permissions/permissions_data.h" | 49 #include "extensions/common/permissions/permissions_data.h" |
| 50 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
| 51 #include "grit/locale_settings.h" | 51 #include "grit/locale_settings.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 | 53 |
| 54 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 55 #include "components/user_manager/user_manager.h" | 55 #include "components/user_manager/user_manager.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 using base::UserMetricsAction; | 58 using base::UserMetricsAction; |
| 59 using content_settings::ContentSettingToString; |
| 60 using content_settings::ContentSettingFromString; |
| 59 using extensions::APIPermission; | 61 using extensions::APIPermission; |
| 60 | 62 |
| 61 namespace { | 63 namespace { |
| 62 | 64 |
| 63 struct ContentSettingsTypeNameEntry { | 65 struct ContentSettingsTypeNameEntry { |
| 64 ContentSettingsType type; | 66 ContentSettingsType type; |
| 65 const char* name; | 67 const char* name; |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 // Maps from a secondary pattern to a setting. | 70 // Maps from a secondary pattern to a setting. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 130 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
| 129 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 131 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
| 130 if (name == kContentSettingsTypeGroupNames[i].name) | 132 if (name == kContentSettingsTypeGroupNames[i].name) |
| 131 return kContentSettingsTypeGroupNames[i].type; | 133 return kContentSettingsTypeGroupNames[i].type; |
| 132 } | 134 } |
| 133 | 135 |
| 134 NOTREACHED() << name << " is not a recognized content settings type."; | 136 NOTREACHED() << name << " is not a recognized content settings type."; |
| 135 return CONTENT_SETTINGS_TYPE_DEFAULT; | 137 return CONTENT_SETTINGS_TYPE_DEFAULT; |
| 136 } | 138 } |
| 137 | 139 |
| 138 std::string ContentSettingToString(ContentSetting setting) { | |
| 139 switch (setting) { | |
| 140 case CONTENT_SETTING_ALLOW: | |
| 141 return "allow"; | |
| 142 case CONTENT_SETTING_ASK: | |
| 143 return "ask"; | |
| 144 case CONTENT_SETTING_BLOCK: | |
| 145 return "block"; | |
| 146 case CONTENT_SETTING_SESSION_ONLY: | |
| 147 return "session"; | |
| 148 case CONTENT_SETTING_DEFAULT: | |
| 149 return "default"; | |
| 150 case CONTENT_SETTING_NUM_SETTINGS: | |
| 151 NOTREACHED(); | |
| 152 } | |
| 153 | |
| 154 return std::string(); | |
| 155 } | |
| 156 | |
| 157 ContentSetting ContentSettingFromString(const std::string& name) { | |
| 158 if (name == "allow") | |
| 159 return CONTENT_SETTING_ALLOW; | |
| 160 if (name == "ask") | |
| 161 return CONTENT_SETTING_ASK; | |
| 162 if (name == "block") | |
| 163 return CONTENT_SETTING_BLOCK; | |
| 164 if (name == "session") | |
| 165 return CONTENT_SETTING_SESSION_ONLY; | |
| 166 | |
| 167 NOTREACHED() << name << " is not a recognized content setting."; | |
| 168 return CONTENT_SETTING_DEFAULT; | |
| 169 } | |
| 170 | |
| 171 // Create a DictionaryValue* that will act as a data source for a single row | 140 // Create a DictionaryValue* that will act as a data source for a single row |
| 172 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 141 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 173 // Ownership of the pointer is passed to the caller. | 142 // Ownership of the pointer is passed to the caller. |
| 174 base::DictionaryValue* GetExceptionForPage( | 143 base::DictionaryValue* GetExceptionForPage( |
| 175 const ContentSettingsPattern& pattern, | 144 const ContentSettingsPattern& pattern, |
| 176 const ContentSettingsPattern& secondary_pattern, | 145 const ContentSettingsPattern& secondary_pattern, |
| 177 const ContentSetting& setting, | 146 const ContentSetting& setting, |
| 178 const std::string& provider_name) { | 147 const std::string& provider_name) { |
| 179 base::DictionaryValue* exception = new base::DictionaryValue(); | 148 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 180 exception->SetString(kOrigin, pattern.ToString()); | 149 exception->SetString(kOrigin, pattern.ToString()); |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1543 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
| 1575 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1544 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 1576 // Exceptions apply only when the feature is enabled. | 1545 // Exceptions apply only when the feature is enabled. |
| 1577 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1546 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1578 web_ui()->CallJavascriptFunction( | 1547 web_ui()->CallJavascriptFunction( |
| 1579 "ContentSettings.enableProtectedContentExceptions", | 1548 "ContentSettings.enableProtectedContentExceptions", |
| 1580 base::FundamentalValue(enable_exceptions)); | 1549 base::FundamentalValue(enable_exceptions)); |
| 1581 } | 1550 } |
| 1582 | 1551 |
| 1583 } // namespace options | 1552 } // namespace options |
| OLD | NEW |