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

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_api.cc

Issue 1372353004: Making structure for ContentSettings and its corresponding strings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 2 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
OLDNEW
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/extensions/api/content_settings/content_settings_api.h" 5 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/content_settings/cookie_settings_factory.h" 15 #include "chrome/browser/content_settings/cookie_settings_factory.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co nstants.h" 17 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co nstants.h"
18 #include "chrome/browser/extensions/api/content_settings/content_settings_helper s.h" 18 #include "chrome/browser/extensions/api/content_settings/content_settings_helper s.h"
19 #include "chrome/browser/extensions/api/content_settings/content_settings_servic e.h" 19 #include "chrome/browser/extensions/api/content_settings/content_settings_servic e.h"
20 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" 20 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h"
21 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" 21 #include "chrome/browser/extensions/api/preference/preference_api_constants.h"
22 #include "chrome/browser/extensions/api/preference/preference_helpers.h" 22 #include "chrome/browser/extensions/api/preference/preference_helpers.h"
23 #include "chrome/browser/plugins/plugin_finder.h" 23 #include "chrome/browser/plugins/plugin_finder.h"
24 #include "chrome/browser/plugins/plugin_installer.h" 24 #include "chrome/browser/plugins/plugin_installer.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/extensions/api/content_settings.h" 27 #include "chrome/common/extensions/api/content_settings.h"
28 #include "components/content_settings/core/browser/content_settings_utils.h"
28 #include "components/content_settings/core/browser/cookie_settings.h" 29 #include "components/content_settings/core/browser/cookie_settings.h"
29 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
30 #include "content/public/browser/plugin_service.h" 31 #include "content/public/browser/plugin_service.h"
31 #include "extensions/browser/extension_prefs_scope.h" 32 #include "extensions/browser/extension_prefs_scope.h"
32 #include "extensions/common/error_utils.h" 33 #include "extensions/common/error_utils.h"
33 34
34 using content::BrowserThread; 35 using content::BrowserThread;
35 using content::PluginService; 36 using content::PluginService;
36 37
37 namespace Clear = extensions::api::content_settings::ContentSetting::Clear; 38 namespace Clear = extensions::api::content_settings::ContentSetting::Clear;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // TODO(jochen): Do we return the value for setting or for reading cookies? 157 // TODO(jochen): Do we return the value for setting or for reading cookies?
157 bool setting_cookie = false; 158 bool setting_cookie = false;
158 setting = cookie_settings->GetCookieSetting(primary_url, secondary_url, 159 setting = cookie_settings->GetCookieSetting(primary_url, secondary_url,
159 setting_cookie, NULL); 160 setting_cookie, NULL);
160 } else { 161 } else {
161 setting = map->GetContentSetting(primary_url, secondary_url, content_type, 162 setting = map->GetContentSetting(primary_url, secondary_url, content_type,
162 resource_identifier); 163 resource_identifier);
163 } 164 }
164 165
165 base::DictionaryValue* result = new base::DictionaryValue(); 166 base::DictionaryValue* result = new base::DictionaryValue();
166 result->SetString(keys::kContentSettingKey, 167 std::string setting_string;
167 helpers::ContentSettingToString(setting)); 168 bool return_value =
169 content_settings::ContentSettingToString(setting, &setting_string);
170 DCHECK(return_value);
171 result->SetString(keys::kContentSettingKey, setting_string);
168 172
169 SetResult(result); 173 SetResult(result);
170 174
171 return true; 175 return true;
172 } 176 }
173 177
174 bool ContentSettingsContentSettingSetFunction::RunSync() { 178 bool ContentSettingsContentSettingSetFunction::RunSync() {
175 ContentSettingsType content_type; 179 ContentSettingsType content_type;
176 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); 180 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type));
177 181
(...skipping 23 matching lines...) Expand all
201 205
202 std::string resource_identifier; 206 std::string resource_identifier;
203 if (params->details.resource_identifier.get()) 207 if (params->details.resource_identifier.get())
204 resource_identifier = params->details.resource_identifier->id; 208 resource_identifier = params->details.resource_identifier->id;
205 209
206 std::string setting_str; 210 std::string setting_str;
207 EXTENSION_FUNCTION_VALIDATE( 211 EXTENSION_FUNCTION_VALIDATE(
208 params->details.setting->GetAsString(&setting_str)); 212 params->details.setting->GetAsString(&setting_str));
209 ContentSetting setting; 213 ContentSetting setting;
210 EXTENSION_FUNCTION_VALIDATE( 214 EXTENSION_FUNCTION_VALIDATE(
211 helpers::StringToContentSetting(setting_str, &setting)); 215 content_settings::ContentSettingFromString(setting_str, &setting));
212 EXTENSION_FUNCTION_VALIDATE(HostContentSettingsMap::IsSettingAllowedForType( 216 EXTENSION_FUNCTION_VALIDATE(HostContentSettingsMap::IsSettingAllowedForType(
213 GetProfile()->GetPrefs(), setting, content_type)); 217 GetProfile()->GetPrefs(), setting, content_type));
214 218
215 // Some content setting types support the full set of values listed in 219 // Some content setting types support the full set of values listed in
216 // content_settings.json only for exceptions. For the default setting, 220 // content_settings.json only for exceptions. For the default setting,
217 // some values might not be supported. 221 // some values might not be supported.
218 // For example, camera supports [allow, ask, block] for exceptions, but only 222 // For example, camera supports [allow, ask, block] for exceptions, but only
219 // [ask, block] for the default setting. 223 // [ask, block] for the default setting.
220 if (primary_pattern == ContentSettingsPattern::Wildcard() && 224 if (primary_pattern == ContentSettingsPattern::Wildcard() &&
221 secondary_pattern == ContentSettingsPattern::Wildcard() && 225 secondary_pattern == ContentSettingsPattern::Wildcard() &&
222 !HostContentSettingsMap::IsDefaultSettingAllowedForType( 226 !HostContentSettingsMap::IsDefaultSettingAllowedForType(
223 GetProfile()->GetPrefs(), setting, content_type)) { 227 GetProfile()->GetPrefs(), setting, content_type)) {
224 static const char kUnsupportedDefaultSettingError[] = 228 static const char kUnsupportedDefaultSettingError[] =
225 "'%s' is not supported as the default setting of %s."; 229 "'%s' is not supported as the default setting of %s.";
226 230
227 // TODO(msramek): Get the same human readable name as is presented 231 // TODO(msramek): Get the same human readable name as is presented
228 // externally in the API, i.e. chrome.contentSettings.<name>.set(). 232 // externally in the API, i.e. chrome.contentSettings.<name>.set().
229 std::string readable_type_name; 233 std::string readable_type_name;
230 switch (content_type) { 234 switch (content_type) {
231 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: 235 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
232 readable_type_name = "microphone"; 236 readable_type_name = "microphone";
233 break; 237 break;
234 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: 238 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
235 readable_type_name = "camera"; 239 readable_type_name = "camera";
236 break; 240 break;
237 default: 241 default:
238 DCHECK(false) << "No human-readable type name defined for this type."; 242 DCHECK(false) << "No human-readable type name defined for this type.";
239 } 243 }
240 244
245 std::string setting_string;
246 bool return_value =
247 content_settings::ContentSettingToString(setting, &setting_string);
248 DCHECK(return_value);
249
241 error_ = base::StringPrintf( 250 error_ = base::StringPrintf(
242 kUnsupportedDefaultSettingError, 251 kUnsupportedDefaultSettingError,
243 content_settings_helpers::ContentSettingToString(setting), 252 setting_string.c_str(),
Bernhard Bauer 2015/10/07 11:38:21 Actually, just pass in |setting_str| here -- we al
Deepak 2015/10/07 13:54:43 Done.
244 readable_type_name.c_str()); 253 readable_type_name.c_str());
245 return false; 254 return false;
246 } 255 }
247 256
248 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; 257 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular;
249 bool incognito = false; 258 bool incognito = false;
250 if (params->details.scope == 259 if (params->details.scope ==
251 api::content_settings::SCOPE_INCOGNITO_SESSION_ONLY) { 260 api::content_settings::SCOPE_INCOGNITO_SESSION_ONLY) {
252 scope = kExtensionPrefsScopeIncognitoSessionOnly; 261 scope = kExtensionPrefsScopeIncognitoSessionOnly;
253 incognito = true; 262 incognito = true;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 SetResult(list); 328 SetResult(list);
320 BrowserThread::PostTask( 329 BrowserThread::PostTask(
321 BrowserThread::UI, FROM_HERE, base::Bind( 330 BrowserThread::UI, FROM_HERE, base::Bind(
322 &ContentSettingsContentSettingGetResourceIdentifiersFunction:: 331 &ContentSettingsContentSettingGetResourceIdentifiersFunction::
323 SendResponse, 332 SendResponse,
324 this, 333 this,
325 true)); 334 true));
326 } 335 }
327 336
328 } // namespace extensions 337 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698