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

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_helpers.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_helper s.h" 5 #include "chrome/browser/extensions/api/content_settings/content_settings_helper s.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "components/content_settings/core/browser/website_settings_info.h" 10 #include "components/content_settings/core/browser/website_settings_info.h"
11 #include "components/content_settings/core/browser/website_settings_registry.h" 11 #include "components/content_settings/core/browser/website_settings_registry.h"
12 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 #include "extensions/common/url_pattern.h" 13 #include "extensions/common/url_pattern.h"
14 14
15 namespace { 15 namespace {
16 16
17 const char kNoPathWildcardsError[] = 17 const char kNoPathWildcardsError[] =
18 "Path wildcards in file URL patterns are not allowed."; 18 "Path wildcards in file URL patterns are not allowed.";
19 const char kNoPathsError[] = "Specific paths are not allowed."; 19 const char kNoPathsError[] = "Specific paths are not allowed.";
20 const char kInvalidPatternError[] = "The pattern \"*\" is invalid."; 20 const char kInvalidPatternError[] = "The pattern \"*\" is invalid.";
21 21
22 const char* const kContentSettingNames[] = {
23 "default",
24 "allow",
25 "block",
26 "ask",
27 "session_only",
28 "detect_important_content"
29 };
30 static_assert(arraysize(kContentSettingNames) <=
31 CONTENT_SETTING_NUM_SETTINGS,
32 "kContentSettingNames has an unexpected number of elements");
33
34 // TODO(bauerb): Move this someplace where it can be reused. 22 // TODO(bauerb): Move this someplace where it can be reused.
35 std::string GetDefaultPort(const std::string& scheme) { 23 std::string GetDefaultPort(const std::string& scheme) {
36 if (scheme == url::kHttpScheme) 24 if (scheme == url::kHttpScheme)
37 return "80"; 25 return "80";
38 if (scheme == url::kHttpsScheme) 26 if (scheme == url::kHttpsScheme)
39 return "443"; 27 return "443";
40 NOTREACHED(); 28 NOTREACHED();
41 return std::string(); 29 return std::string();
42 } 30 }
43 31
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 103 }
116 104
117 std::string ContentSettingsTypeToString(ContentSettingsType type) { 105 std::string ContentSettingsTypeToString(ContentSettingsType type) {
118 return content_settings::WebsiteSettingsRegistry::GetInstance() 106 return content_settings::WebsiteSettingsRegistry::GetInstance()
119 ->Get(type) 107 ->Get(type)
120 ->name(); 108 ->name();
121 } 109 }
122 110
123 bool StringToContentSetting(const std::string& setting_str, 111 bool StringToContentSetting(const std::string& setting_str,
124 ContentSetting* setting) { 112 ContentSetting* setting) {
125 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) { 113 *setting = content_settings::ContentSettingFromString(setting_str);
Bernhard Bauer 2015/10/06 15:37:25 This is still incorrect. ContentSettingFromString
Deepak 2015/10/07 04:39:43 Done.
126 if (setting_str == kContentSettingNames[type]) { 114 return *setting != CONTENT_SETTING_DEFAULT;
127 *setting = static_cast<ContentSetting>(type);
128 return true;
129 }
130 }
131 return false;
132 }
133
134 const char* ContentSettingToString(ContentSetting setting) {
135 size_t index = static_cast<size_t>(setting);
136 DCHECK_LT(index, arraysize(kContentSettingNames));
137 return kContentSettingNames[index];
138 } 115 }
139 116
140 } // namespace content_settings_helpers 117 } // namespace content_settings_helpers
141 } // namespace extensions 118 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698