OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/content_settings_pattern.h" | 5 #include "chrome/browser/content_settings/content_settings_pattern.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 if (url.port().empty()) { | 303 if (url.port().empty()) { |
304 builder->WithPortWildcard(); | 304 builder->WithPortWildcard(); |
305 } else { | 305 } else { |
306 builder->WithPort(url.port()); | 306 builder->WithPort(url.port()); |
307 } | 307 } |
308 } | 308 } |
309 return builder->Build(); | 309 return builder->Build(); |
310 } | 310 } |
311 | 311 |
312 // static | 312 // static |
313 ContentSettingsPattern ContentSettingsPattern::LegacyFromURL( | |
314 const GURL& url) { | |
315 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | |
316 ContentSettingsPattern::CreateBuilder(true)); | |
317 | |
318 if (url.SchemeIsFile()) { | |
319 builder->WithScheme(url.scheme())->WithPath(url.path()); | |
320 } else { | |
321 // Please keep the order of the ifs below as URLs with an IP as host can | |
322 // also have a "http" scheme. | |
323 // TODO(markusheintz): For HTTPS we will create scheme specific patterns as | |
324 // soon as the pattern matching code in the HostContentSettingsMap is | |
325 // replaced. | |
326 if (url.HostIsIPAddress()) { | |
327 builder->WithSchemeWildcard()->WithHost(url.host()); | |
328 } else if (url.SchemeIs(chrome::kHttpScheme)) { | |
329 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host()); | |
330 } else if (url.SchemeIs(chrome::kHttpsScheme)) { | |
331 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( | |
332 url.host()); | |
333 } else { | |
334 // Unsupported scheme | |
335 } | |
336 builder->WithPortWildcard(); | |
337 } | |
338 return builder->Build(); | |
339 } | |
340 | |
341 // static | |
342 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( | 313 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( |
343 const GURL& url) { | 314 const GURL& url) { |
344 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 315 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
345 ContentSettingsPattern::CreateBuilder(false)); | 316 ContentSettingsPattern::CreateBuilder(false)); |
346 | 317 |
347 if (url.SchemeIsFile()) { | 318 if (url.SchemeIsFile()) { |
348 builder->WithScheme(url.scheme())->WithPath(url.path()); | 319 builder->WithScheme(url.scheme())->WithPath(url.path()); |
349 } else { | 320 } else { |
350 builder->WithScheme(url.scheme())->WithHost(url.host()); | 321 builder->WithScheme(url.scheme())->WithHost(url.host()); |
351 if (url.port().empty()) { | 322 if (url.port().empty()) { |
352 builder->WithPort(GetDefaultPort(url.scheme())); | 323 builder->WithPort(GetDefaultPort(url.scheme())); |
353 } else { | 324 } else { |
354 builder->WithPort(url.port()); | 325 builder->WithPort(url.port()); |
355 } | 326 } |
356 } | 327 } |
357 return builder->Build(); | 328 return builder->Build(); |
358 } | 329 } |
359 | 330 |
360 // static | 331 // static |
361 ContentSettingsPattern ContentSettingsPattern::LegacyFromURLNoWildcard( | |
362 const GURL& url) { | |
363 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | |
364 ContentSettingsPattern::CreateBuilder(true)); | |
365 | |
366 if (url.SchemeIsFile()) { | |
367 builder->WithScheme(url.scheme())->WithPath(url.path()); | |
368 } else { | |
369 builder->WithSchemeWildcard()->WithHost(url.host()); | |
370 } | |
371 builder->WithPortWildcard(); | |
372 return builder->Build(); | |
373 } | |
374 | |
375 // static | |
376 ContentSettingsPattern ContentSettingsPattern::FromString( | 332 ContentSettingsPattern ContentSettingsPattern::FromString( |
377 const std::string& pattern_spec) { | 333 const std::string& pattern_spec) { |
378 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 334 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
379 ContentSettingsPattern::CreateBuilder(false)); | 335 ContentSettingsPattern::CreateBuilder(false)); |
380 content_settings::PatternParser::Parse(pattern_spec, builder.get()); | 336 content_settings::PatternParser::Parse(pattern_spec, builder.get()); |
381 return builder->Build(); | 337 return builder->Build(); |
382 } | 338 } |
383 | 339 |
384 // static | 340 // static |
385 ContentSettingsPattern ContentSettingsPattern::LegacyFromString( | 341 ContentSettingsPattern ContentSettingsPattern::LegacyFromString( |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 593 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
638 return ContentSettingsPattern::PREDECESSOR; | 594 return ContentSettingsPattern::PREDECESSOR; |
639 | 595 |
640 int result = parts.port.compare(other_parts.port); | 596 int result = parts.port.compare(other_parts.port); |
641 if (result == 0) | 597 if (result == 0) |
642 return ContentSettingsPattern::IDENTITY; | 598 return ContentSettingsPattern::IDENTITY; |
643 if (result > 0) | 599 if (result > 0) |
644 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 600 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
645 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 601 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
646 } | 602 } |
OLD | NEW |