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

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: 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 content_settings::ContentSettingToString(setting);
169 DCHECK(!setting_string.empty());
170 result->SetString(keys::kContentSettingKey, setting_string);
168 171
169 SetResult(result); 172 SetResult(result);
170 173
171 return true; 174 return true;
172 } 175 }
173 176
174 bool ContentSettingsContentSettingSetFunction::RunSync() { 177 bool ContentSettingsContentSettingSetFunction::RunSync() {
175 ContentSettingsType content_type; 178 ContentSettingsType content_type;
176 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); 179 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type));
177 180
(...skipping 23 matching lines...) Expand all
201 204
202 std::string resource_identifier; 205 std::string resource_identifier;
203 if (params->details.resource_identifier.get()) 206 if (params->details.resource_identifier.get())
204 resource_identifier = params->details.resource_identifier->id; 207 resource_identifier = params->details.resource_identifier->id;
205 208
206 std::string setting_str; 209 std::string setting_str;
207 EXTENSION_FUNCTION_VALIDATE( 210 EXTENSION_FUNCTION_VALIDATE(
208 params->details.setting->GetAsString(&setting_str)); 211 params->details.setting->GetAsString(&setting_str));
209 ContentSetting setting; 212 ContentSetting setting;
210 EXTENSION_FUNCTION_VALIDATE( 213 EXTENSION_FUNCTION_VALIDATE(
211 helpers::StringToContentSetting(setting_str, &setting)); 214 content_settings::ContentSettingFromString(setting_str, &setting));
212 EXTENSION_FUNCTION_VALIDATE(HostContentSettingsMap::IsSettingAllowedForType( 215 EXTENSION_FUNCTION_VALIDATE(HostContentSettingsMap::IsSettingAllowedForType(
213 GetProfile()->GetPrefs(), setting, content_type)); 216 GetProfile()->GetPrefs(), setting, content_type));
214 217
215 // Some content setting types support the full set of values listed in 218 // Some content setting types support the full set of values listed in
216 // content_settings.json only for exceptions. For the default setting, 219 // content_settings.json only for exceptions. For the default setting,
217 // some values might not be supported. 220 // some values might not be supported.
218 // For example, camera supports [allow, ask, block] for exceptions, but only 221 // For example, camera supports [allow, ask, block] for exceptions, but only
219 // [ask, block] for the default setting. 222 // [ask, block] for the default setting.
220 if (primary_pattern == ContentSettingsPattern::Wildcard() && 223 if (primary_pattern == ContentSettingsPattern::Wildcard() &&
221 secondary_pattern == ContentSettingsPattern::Wildcard() && 224 secondary_pattern == ContentSettingsPattern::Wildcard() &&
222 !HostContentSettingsMap::IsDefaultSettingAllowedForType( 225 !HostContentSettingsMap::IsDefaultSettingAllowedForType(
223 GetProfile()->GetPrefs(), setting, content_type)) { 226 GetProfile()->GetPrefs(), setting, content_type)) {
224 static const char kUnsupportedDefaultSettingError[] = 227 static const char kUnsupportedDefaultSettingError[] =
225 "'%s' is not supported as the default setting of %s."; 228 "'%s' is not supported as the default setting of %s.";
226 229
227 // TODO(msramek): Get the same human readable name as is presented 230 // TODO(msramek): Get the same human readable name as is presented
228 // externally in the API, i.e. chrome.contentSettings.<name>.set(). 231 // externally in the API, i.e. chrome.contentSettings.<name>.set().
229 std::string readable_type_name; 232 std::string readable_type_name;
230 switch (content_type) { 233 switch (content_type) {
231 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: 234 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
232 readable_type_name = "microphone"; 235 readable_type_name = "microphone";
233 break; 236 break;
234 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: 237 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
235 readable_type_name = "camera"; 238 readable_type_name = "camera";
236 break; 239 break;
237 default: 240 default:
238 DCHECK(false) << "No human-readable type name defined for this type."; 241 DCHECK(false) << "No human-readable type name defined for this type.";
239 } 242 }
240 243
244 setting_str = content_settings::ContentSettingToString(setting);
Bernhard Bauer 2015/10/07 15:05:44 This is unnecessary -- You get |setting| from |set
Deepak 2015/10/07 15:17:18 oops, I missed this. yes, we can directly use sett
245 DCHECK(!setting_str.empty());
246
241 error_ = base::StringPrintf( 247 error_ = base::StringPrintf(
242 kUnsupportedDefaultSettingError, 248 kUnsupportedDefaultSettingError,
243 content_settings_helpers::ContentSettingToString(setting), 249 setting_str.c_str(),
244 readable_type_name.c_str()); 250 readable_type_name.c_str());
245 return false; 251 return false;
246 } 252 }
247 253
248 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; 254 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular;
249 bool incognito = false; 255 bool incognito = false;
250 if (params->details.scope == 256 if (params->details.scope ==
251 api::content_settings::SCOPE_INCOGNITO_SESSION_ONLY) { 257 api::content_settings::SCOPE_INCOGNITO_SESSION_ONLY) {
252 scope = kExtensionPrefsScopeIncognitoSessionOnly; 258 scope = kExtensionPrefsScopeIncognitoSessionOnly;
253 incognito = true; 259 incognito = true;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 SetResult(list); 325 SetResult(list);
320 BrowserThread::PostTask( 326 BrowserThread::PostTask(
321 BrowserThread::UI, FROM_HERE, base::Bind( 327 BrowserThread::UI, FROM_HERE, base::Bind(
322 &ContentSettingsContentSettingGetResourceIdentifiersFunction:: 328 &ContentSettingsContentSettingGetResourceIdentifiersFunction::
323 SendResponse, 329 SendResponse,
324 this, 330 this,
325 true)); 331 true));
326 } 332 }
327 333
328 } // namespace extensions 334 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698