OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/url_formatter/url_formatter.h" | 5 #include "components/url_formatter/url_formatter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 const FormatUrlType kFormatUrlOmitAll = | 360 const FormatUrlType kFormatUrlOmitAll = |
361 kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP | | 361 kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP | |
362 kFormatUrlOmitTrailingSlashOnBareHostname; | 362 kFormatUrlOmitTrailingSlashOnBareHostname; |
363 | 363 |
364 base::string16 FormatUrl(const GURL& url, | 364 base::string16 FormatUrl(const GURL& url, |
365 FormatUrlTypes format_types, | 365 FormatUrlTypes format_types, |
366 net::UnescapeRule::Type unescape_rules, | 366 net::UnescapeRule::Type unescape_rules, |
367 url::Parsed* new_parsed, | 367 url::Parsed* new_parsed, |
368 size_t* prefix_end, | 368 size_t* prefix_end, |
369 size_t* offset_for_adjustment) { | 369 size_t* offset_for_adjustment) { |
370 std::vector<size_t> offsets; | 370 base::OffsetAdjuster::Adjustments adjustments; |
371 if (offset_for_adjustment) | 371 base::string16 result = FormatUrlWithAdjustments( |
372 offsets.push_back(*offset_for_adjustment); | 372 url, format_types, unescape_rules, new_parsed, prefix_end, &adjustments); |
373 base::string16 result = | 373 if (offset_for_adjustment) { |
374 FormatUrlWithOffsets(url, format_types, unescape_rules, new_parsed, | 374 base::OffsetAdjuster::AdjustOffset(adjustments, offset_for_adjustment, |
375 prefix_end, &offsets); | 375 result.length()); |
376 if (offset_for_adjustment) | 376 } |
377 *offset_for_adjustment = offsets[0]; | |
378 return result; | 377 return result; |
379 } | 378 } |
380 | 379 |
381 base::string16 FormatUrlWithOffsets( | 380 base::string16 FormatUrlWithOffsets( |
Justin Donnelly
2017/06/27 15:28:46
I don't think this function is used anywhere now.
tommycli
2017/07/07 19:27:10
Acknowledged.
| |
382 const GURL& url, | 381 const GURL& url, |
383 FormatUrlTypes format_types, | 382 FormatUrlTypes format_types, |
384 net::UnescapeRule::Type unescape_rules, | 383 net::UnescapeRule::Type unescape_rules, |
385 url::Parsed* new_parsed, | 384 url::Parsed* new_parsed, |
386 size_t* prefix_end, | 385 size_t* prefix_end, |
387 std::vector<size_t>* offsets_for_adjustment) { | 386 std::vector<size_t>* offsets_for_adjustment) { |
388 base::OffsetAdjuster::Adjustments adjustments; | 387 base::OffsetAdjuster::Adjustments adjustments; |
389 const base::string16& format_url_return_value = | 388 const base::string16& result = FormatUrlWithAdjustments( |
390 FormatUrlWithAdjustments(url, format_types, unescape_rules, new_parsed, | 389 url, format_types, unescape_rules, new_parsed, prefix_end, &adjustments); |
391 prefix_end, &adjustments); | 390 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment, |
392 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); | 391 result.length()); |
393 if (offsets_for_adjustment) { | 392 return result; |
394 std::for_each( | |
395 offsets_for_adjustment->begin(), offsets_for_adjustment->end(), | |
396 base::LimitOffset<std::string>(format_url_return_value.length())); | |
397 } | |
398 return format_url_return_value; | |
399 } | 393 } |
400 | 394 |
401 base::string16 FormatUrlWithAdjustments( | 395 base::string16 FormatUrlWithAdjustments( |
402 const GURL& url, | 396 const GURL& url, |
403 FormatUrlTypes format_types, | 397 FormatUrlTypes format_types, |
404 net::UnescapeRule::Type unescape_rules, | 398 net::UnescapeRule::Type unescape_rules, |
405 url::Parsed* new_parsed, | 399 url::Parsed* new_parsed, |
406 size_t* prefix_end, | 400 size_t* prefix_end, |
407 base::OffsetAdjuster::Adjustments* adjustments) { | 401 base::OffsetAdjuster::Adjustments* adjustments) { |
408 DCHECK(adjustments != NULL); | 402 DCHECK(adjustments); |
409 adjustments->clear(); | 403 adjustments->clear(); |
410 url::Parsed parsed_temp; | 404 url::Parsed parsed_temp; |
411 if (!new_parsed) | 405 if (!new_parsed) |
412 new_parsed = &parsed_temp; | 406 new_parsed = &parsed_temp; |
413 else | 407 else |
414 *new_parsed = url::Parsed(); | 408 *new_parsed = url::Parsed(); |
415 | 409 |
416 // Special handling for view-source:. Don't use content::kViewSourceScheme | 410 // Special handling for view-source:. Don't use content::kViewSourceScheme |
417 // because this library shouldn't depend on chrome. | 411 // because this library shouldn't depend on chrome. |
418 const char kViewSource[] = "view-source"; | 412 const char kViewSource[] = "view-source"; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) | 571 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) |
578 ? text.substr(www.length()) : text; | 572 ? text.substr(www.length()) : text; |
579 } | 573 } |
580 | 574 |
581 base::string16 StripWWWFromHost(const GURL& url) { | 575 base::string16 StripWWWFromHost(const GURL& url) { |
582 DCHECK(url.is_valid()); | 576 DCHECK(url.is_valid()); |
583 return StripWWW(base::ASCIIToUTF16(url.host_piece())); | 577 return StripWWW(base::ASCIIToUTF16(url.host_piece())); |
584 } | 578 } |
585 | 579 |
586 } // namespace url_formatter | 580 } // namespace url_formatter |
OLD | NEW |