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/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[] = { | 22 const char* const kContentSettingNames[] = { |
23 "default", | 23 "default", |
24 "allow", | 24 "allow", |
25 "block", | 25 "block", |
26 "ask", | 26 "ask", |
27 "session_only", | 27 "session", |
Bernhard Bauer
2015/10/05 11:15:41
We are probably going to have to do this the other
Deepak
2015/10/05 12:14:38
I have removed this array here, and updated the st
| |
28 "detect_important_content" | 28 "detect" |
29 }; | 29 }; |
30 static_assert(arraysize(kContentSettingNames) <= | 30 static_assert(arraysize(kContentSettingNames) <= |
31 CONTENT_SETTING_NUM_SETTINGS, | 31 CONTENT_SETTING_NUM_SETTINGS, |
32 "kContentSettingNames has an unexpected number of elements"); | 32 "kContentSettingNames has an unexpected number of elements"); |
33 | 33 |
34 // TODO(bauerb): Move this someplace where it can be reused. | 34 // TODO(bauerb): Move this someplace where it can be reused. |
35 std::string GetDefaultPort(const std::string& scheme) { | 35 std::string GetDefaultPort(const std::string& scheme) { |
36 if (scheme == url::kHttpScheme) | 36 if (scheme == url::kHttpScheme) |
37 return "80"; | 37 return "80"; |
38 if (scheme == url::kHttpsScheme) | 38 if (scheme == url::kHttpsScheme) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 | 113 |
114 return CONTENT_SETTINGS_TYPE_DEFAULT; | 114 return CONTENT_SETTINGS_TYPE_DEFAULT; |
115 } | 115 } |
116 | 116 |
117 std::string ContentSettingsTypeToString(ContentSettingsType type) { | 117 std::string ContentSettingsTypeToString(ContentSettingsType type) { |
118 return content_settings::WebsiteSettingsRegistry::GetInstance() | 118 return content_settings::WebsiteSettingsRegistry::GetInstance() |
119 ->Get(type) | 119 ->Get(type) |
120 ->name(); | 120 ->name(); |
121 } | 121 } |
122 | 122 |
123 bool StringToContentSetting(const std::string& setting_str, | 123 bool StringToContentSetting(const std::string& setting_str, |
Bernhard Bauer
2015/10/05 11:15:41
Can we remove this one as well? This version seems
Deepak
2015/10/05 12:14:38
I think as the return type of this API is bool, so
| |
124 ContentSetting* setting) { | 124 ContentSetting* setting) { |
125 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) { | 125 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) { |
126 if (setting_str == kContentSettingNames[type]) { | 126 if (setting_str == kContentSettingNames[type]) { |
127 *setting = static_cast<ContentSetting>(type); | 127 *setting = static_cast<ContentSetting>(type); |
128 return true; | 128 return true; |
129 } | 129 } |
130 } | 130 } |
131 return false; | 131 return false; |
132 } | 132 } |
133 | 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 } | |
139 | |
140 } // namespace content_settings_helpers | 134 } // namespace content_settings_helpers |
141 } // namespace extensions | 135 } // namespace extensions |
OLD | NEW |