| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/messaging/native_messaging_host_manifest
.h" | 5 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 const base::ListValue* allowed_origins_list; | 105 const base::ListValue* allowed_origins_list; |
| 106 if (!dictionary->GetList("allowed_origins", &allowed_origins_list)) { | 106 if (!dictionary->GetList("allowed_origins", &allowed_origins_list)) { |
| 107 *error_message = | 107 *error_message = |
| 108 "Invalid value for allowed_origins. Expected a list of strings."; | 108 "Invalid value for allowed_origins. Expected a list of strings."; |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 allowed_origins_.ClearPatterns(); | 111 allowed_origins_.ClearPatterns(); |
| 112 for (base::ListValue::const_iterator it = allowed_origins_list->begin(); | 112 for (base::ListValue::const_iterator it = allowed_origins_list->begin(); |
| 113 it != allowed_origins_list->end(); ++it) { | 113 it != allowed_origins_list->end(); ++it) { |
| 114 std::string pattern_string; | 114 std::string pattern_string; |
| 115 if (!it->GetAsString(&pattern_string)) { | 115 if (!(*it)->GetAsString(&pattern_string)) { |
| 116 *error_message = "allowed_origins must be list of strings."; | 116 *error_message = "allowed_origins must be list of strings."; |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 120 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
| 121 URLPattern::ParseResult result = pattern.Parse(pattern_string); | 121 URLPattern::ParseResult result = pattern.Parse(pattern_string); |
| 122 if (result != URLPattern::PARSE_SUCCESS) { | 122 if (result != URLPattern::PARSE_SUCCESS) { |
| 123 *error_message = "Failed to parse pattern \"" + pattern_string + | 123 *error_message = "Failed to parse pattern \"" + pattern_string + |
| 124 "\": " + URLPattern::GetParseResultString(result); | 124 "\": " + URLPattern::GetParseResultString(result); |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Disallow patterns that are too broad. Set of allowed origins must be a | 128 // Disallow patterns that are too broad. Set of allowed origins must be a |
| 129 // fixed list of extensions. | 129 // fixed list of extensions. |
| 130 if (pattern.match_all_urls() || pattern.match_subdomains()) { | 130 if (pattern.match_all_urls() || pattern.match_subdomains()) { |
| 131 *error_message = "Pattern \"" + pattern_string + "\" is not allowed."; | 131 *error_message = "Pattern \"" + pattern_string + "\" is not allowed."; |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 allowed_origins_.AddPattern(pattern); | 135 allowed_origins_.AddPattern(pattern); |
| 136 } | 136 } |
| 137 | 137 |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace extensions | 141 } // namespace extensions |
| OLD | NEW |