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

Side by Side Diff: chrome/common/extensions/manifest_handlers/externally_connectable.cc

Issue 22470007: Add a "key" entry to InstallWarnings, remove InstallWarning::Format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_infrastructure
Patch Set: Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/common/extensions/manifest_handlers/externally_connectable.h" 5 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 URLPattern pattern(URLPattern::SCHEME_ALL); 111 URLPattern pattern(URLPattern::SCHEME_ALL);
112 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) { 112 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) {
113 *error = ErrorUtils::FormatErrorMessageUTF16( 113 *error = ErrorUtils::FormatErrorMessageUTF16(
114 errors::kErrorInvalidMatchPattern, *it); 114 errors::kErrorInvalidMatchPattern, *it);
115 return scoped_ptr<ExternallyConnectableInfo>(); 115 return scoped_ptr<ExternallyConnectableInfo>();
116 } 116 }
117 117
118 // Wildcard hosts are not allowed. 118 // Wildcard hosts are not allowed.
119 if (pattern.host().empty()) { 119 if (pattern.host().empty()) {
120 // Warning not error for forwards compatibility. 120 // Warning not error for forwards compatibility.
121 install_warnings->push_back( 121 install_warnings->push_back(InstallWarning(
122 InstallWarning::Text(ErrorUtils::FormatErrorMessage( 122 ErrorUtils::FormatErrorMessage(
123 errors::kErrorWildcardHostsNotAllowed, *it))); 123 errors::kErrorWildcardHostsNotAllowed, *it),
124 keys::kExternallyConnectable,
125 *it));
124 continue; 126 continue;
125 } 127 }
126 128
127 // Wildcards on subdomains of a TLD are not allowed. 129 // Wildcards on subdomains of a TLD are not allowed.
128 size_t registry_length = rcd::GetRegistryLength( 130 size_t registry_length = rcd::GetRegistryLength(
129 pattern.host(), 131 pattern.host(),
130 // This means that things that look like TLDs - the foobar in 132 // This means that things that look like TLDs - the foobar in
131 // http://google.foobar - count as TLDs. 133 // http://google.foobar - count as TLDs.
132 rcd::INCLUDE_UNKNOWN_REGISTRIES, 134 rcd::INCLUDE_UNKNOWN_REGISTRIES,
133 // This means that effective TLDs like appspot.com count as TLDs; 135 // This means that effective TLDs like appspot.com count as TLDs;
134 // codereview.appspot.com and evil.appspot.com are different. 136 // codereview.appspot.com and evil.appspot.com are different.
135 rcd::INCLUDE_PRIVATE_REGISTRIES); 137 rcd::INCLUDE_PRIVATE_REGISTRIES);
136 138
137 if (registry_length == std::string::npos) { 139 if (registry_length == std::string::npos) {
138 // The URL parsing combined with host().empty() should have caught this. 140 // The URL parsing combined with host().empty() should have caught this.
139 NOTREACHED() << *it; 141 NOTREACHED() << *it;
140 *error = ErrorUtils::FormatErrorMessageUTF16( 142 *error = ErrorUtils::FormatErrorMessageUTF16(
141 errors::kErrorInvalidMatchPattern, *it); 143 errors::kErrorInvalidMatchPattern, *it);
142 return scoped_ptr<ExternallyConnectableInfo>(); 144 return scoped_ptr<ExternallyConnectableInfo>();
143 } 145 }
144 146
145 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" 147 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com"
146 // are not allowed. However just "appspot.com" is ok. 148 // are not allowed. However just "appspot.com" is ok.
147 if (registry_length == 0 && pattern.match_subdomains()) { 149 if (registry_length == 0 && pattern.match_subdomains()) {
148 // Warning not error for forwards compatibility. 150 // Warning not error for forwards compatibility.
149 install_warnings->push_back(InstallWarning::Text( 151 install_warnings->push_back(InstallWarning(
150 ErrorUtils::FormatErrorMessage( 152 ErrorUtils::FormatErrorMessage(
151 errors::kErrorTopLevelDomainsNotAllowed, 153 errors::kErrorTopLevelDomainsNotAllowed,
152 pattern.host().c_str(), 154 pattern.host().c_str(),
153 *it))); 155 *it),
156 keys::kExternallyConnectable,
157 *it));
154 continue; 158 continue;
155 } 159 }
156 160
157 matches.AddPattern(pattern); 161 matches.AddPattern(pattern);
158 } 162 }
159 } 163 }
160 164
161 std::vector<std::string> ids; 165 std::vector<std::string> ids;
162 bool all_ids = false; 166 bool all_ids = false;
163 167
164 if (externally_connectable->ids) { 168 if (externally_connectable->ids) {
165 for (std::vector<std::string>::iterator it = 169 for (std::vector<std::string>::iterator it =
166 externally_connectable->ids->begin(); 170 externally_connectable->ids->begin();
167 it != externally_connectable->ids->end(); ++it) { 171 it != externally_connectable->ids->end(); ++it) {
168 if (*it == kAllIds) { 172 if (*it == kAllIds) {
169 all_ids = true; 173 all_ids = true;
170 } else if (Extension::IdIsValid(*it)) { 174 } else if (Extension::IdIsValid(*it)) {
171 ids.push_back(*it); 175 ids.push_back(*it);
172 } else { 176 } else {
173 *error = ErrorUtils::FormatErrorMessageUTF16( 177 *error = ErrorUtils::FormatErrorMessageUTF16(
174 errors::kErrorInvalidId, *it); 178 errors::kErrorInvalidId, *it);
175 return scoped_ptr<ExternallyConnectableInfo>(); 179 return scoped_ptr<ExternallyConnectableInfo>();
176 } 180 }
177 } 181 }
178 } 182 }
179 183
180 if (!externally_connectable->matches && 184 if (!externally_connectable->matches &&
181 !externally_connectable->ids) { 185 !externally_connectable->ids) {
182 install_warnings->push_back(InstallWarning::Text( 186 install_warnings->push_back(InstallWarning(
183 errors::kErrorNothingSpecified)); 187 errors::kErrorNothingSpecified,
188 keys::kExternallyConnectable));
184 } 189 }
185 190
186 return make_scoped_ptr( 191 return make_scoped_ptr(
187 new ExternallyConnectableInfo(matches, ids, all_ids)); 192 new ExternallyConnectableInfo(matches, ids, all_ids));
188 } 193 }
189 194
190 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} 195 ExternallyConnectableInfo::~ExternallyConnectableInfo() {}
191 196
192 ExternallyConnectableInfo::ExternallyConnectableInfo( 197 ExternallyConnectableInfo::ExternallyConnectableInfo(
193 const URLPatternSet& matches, 198 const URLPatternSet& matches,
194 const std::vector<std::string>& ids, 199 const std::vector<std::string>& ids,
195 bool all_ids) 200 bool all_ids)
196 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} 201 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {}
197 202
198 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { 203 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) {
199 if (all_ids) 204 if (all_ids)
200 return true; 205 return true;
201 DCHECK(base::STLIsSorted(ids)); 206 DCHECK(base::STLIsSorted(ids));
202 return std::binary_search(ids.begin(), ids.end(), id); 207 return std::binary_search(ids.begin(), ids.end(), id);
203 } 208 }
204 209
205 } // namespace extensions 210 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest.cc ('k') | chrome/common/extensions/permissions/permissions_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698