| 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[] = { | |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 101 |
| 114 return CONTENT_SETTINGS_TYPE_DEFAULT; | 102 return CONTENT_SETTINGS_TYPE_DEFAULT; |
| 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, | |
| 124 ContentSetting* setting) { | |
| 125 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) { | |
| 126 if (setting_str == kContentSettingNames[type]) { | |
| 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 } | |
| 139 | |
| 140 } // namespace content_settings_helpers | 111 } // namespace content_settings_helpers |
| 141 } // namespace extensions | 112 } // namespace extensions |
| OLD | NEW |