OLD | NEW |
1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "net/base/registry_controlled_domain.h" | 40 #include "net/base/registry_controlled_domain.h" |
41 | 41 |
42 #include "base/logging.h" | 42 #include "base/logging.h" |
43 #include "base/singleton.h" | 43 #include "base/singleton.h" |
44 #include "base/string_util.h" | 44 #include "base/string_util.h" |
45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
46 #include "googleurl/src/url_parse.h" | 46 #include "googleurl/src/url_parse.h" |
47 #include "net/base/net_module.h" | 47 #include "net/base/net_module.h" |
48 #include "net/base/net_util.h" | 48 #include "net/base/net_util.h" |
49 | 49 |
50 #if !defined(OS_MACOSX) | |
51 #include "net_resources.h" | |
52 #endif | |
53 | |
54 namespace net { | 50 namespace net { |
55 | 51 |
56 // This list of rules is used by unit tests and any other time that the main | |
57 // resource file is not available. It should be kept exceedingly short to | |
58 // avoid impacting unit test performance. | |
59 static const char kDefaultDomainData[] = "com\n" | |
60 "edu\n" | |
61 "gov\n" | |
62 "net\n" | |
63 "org\n" | |
64 "co.uk\n"; | |
65 | |
66 // static | 52 // static |
67 std::string RegistryControlledDomainService::GetDomainAndRegistry( | 53 std::string RegistryControlledDomainService::GetDomainAndRegistry( |
68 const GURL& gurl) { | 54 const GURL& gurl) { |
69 const url_parse::Component host = | 55 const url_parse::Component host = |
70 gurl.parsed_for_possibly_invalid_spec().host; | 56 gurl.parsed_for_possibly_invalid_spec().host; |
71 if ((host.len <= 0) || gurl.HostIsIPAddress()) | 57 if ((host.len <= 0) || gurl.HostIsIPAddress()) |
72 return std::string(); | 58 return std::string(); |
73 return GetDomainAndRegistryImpl(std::string( | 59 return GetDomainAndRegistryImpl(std::string( |
74 gurl.possibly_invalid_spec().data() + host.begin, host.len)); | 60 gurl.possibly_invalid_spec().data() + host.begin, host.len)); |
75 } | 61 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 266 } |
281 | 267 |
282 // static | 268 // static |
283 void RegistryControlledDomainService::UseDomainData(const std::string& data) { | 269 void RegistryControlledDomainService::UseDomainData(const std::string& data) { |
284 RegistryControlledDomainService* instance = GetInstance(); | 270 RegistryControlledDomainService* instance = GetInstance(); |
285 instance->copied_domain_data_ = data; | 271 instance->copied_domain_data_ = data; |
286 instance->ParseDomainData(instance->copied_domain_data_); | 272 instance->ParseDomainData(instance->copied_domain_data_); |
287 } | 273 } |
288 | 274 |
289 void RegistryControlledDomainService::Init() { | 275 void RegistryControlledDomainService::Init() { |
290 #if defined(OS_MACOSX) | 276 ParseDomainData(kDomainData); |
291 ParseDomainData(kDefaultDomainData); | |
292 #else | |
293 // The resource file isn't present for some unit tests, for example. Fall | |
294 // back to a tiny, basic list of rules in that case. | |
295 StringPiece res_data = NetModule::GetResource(IDR_EFFECTIVE_TLD_NAMES); | |
296 ParseDomainData(!res_data.empty() ? res_data : kDefaultDomainData); | |
297 #endif | |
298 } | 277 } |
299 | 278 |
300 void RegistryControlledDomainService::ParseDomainData(const StringPiece& data) { | 279 void RegistryControlledDomainService::ParseDomainData(const StringPiece& data) { |
301 domain_set_.clear(); | 280 domain_set_.clear(); |
302 | 281 |
303 size_t line_end = 0; | 282 size_t line_end = 0; |
304 size_t line_start = 0; | 283 size_t line_start = 0; |
305 while (line_start < data.size()) { | 284 while (line_start < data.size()) { |
306 line_end = data.find('\n', line_start); | 285 line_end = data.find('\n', line_start); |
307 if (line_end == StringPiece::npos) | 286 if (line_end == StringPiece::npos) |
(...skipping 22 matching lines...) Expand all Loading... |
330 // and an exception (ex *.google.com and !google.com). Sets are immutable, | 309 // and an exception (ex *.google.com and !google.com). Sets are immutable, |
331 // we'll erase the old one, and insert a new one with the new attributes. | 310 // we'll erase the old one, and insert a new one with the new attributes. |
332 rule.attributes.Combine(prev_rule->attributes); | 311 rule.attributes.Combine(prev_rule->attributes); |
333 domain_set_.erase(prev_rule); | 312 domain_set_.erase(prev_rule); |
334 } | 313 } |
335 | 314 |
336 domain_set_.insert(rule); | 315 domain_set_.insert(rule); |
337 } | 316 } |
338 | 317 |
339 } // namespace net | 318 } // namespace net |
OLD | NEW |