| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/clipboard/clipboard_util_win.h" | 5 #include "ui/base/clipboard/clipboard_util_win.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
| 9 #include <wininet.h> // For INTERNET_MAX_URL_LENGTH. | 9 #include <wininet.h> // For INTERNET_MAX_URL_LENGTH. |
| 10 | 10 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 size_t fragment_start = std::string::npos; | 439 size_t fragment_start = std::string::npos; |
| 440 size_t fragment_end = std::string::npos; | 440 size_t fragment_end = std::string::npos; |
| 441 | 441 |
| 442 ClipboardUtil::CFHtmlExtractMetadata( | 442 ClipboardUtil::CFHtmlExtractMetadata( |
| 443 cf_html, base_url, NULL, &fragment_start, &fragment_end); | 443 cf_html, base_url, NULL, &fragment_start, &fragment_end); |
| 444 | 444 |
| 445 if (html && | 445 if (html && |
| 446 fragment_start != std::string::npos && | 446 fragment_start != std::string::npos && |
| 447 fragment_end != std::string::npos) { | 447 fragment_end != std::string::npos) { |
| 448 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); | 448 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); |
| 449 base::TrimWhitespace(*html, base::TRIM_ALL, html); | 449 base::TrimWhitespaceASCII(*html, base::TRIM_ALL, html); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 void ClipboardUtil::CFHtmlExtractMetadata(const std::string& cf_html, | 453 void ClipboardUtil::CFHtmlExtractMetadata(const std::string& cf_html, |
| 454 std::string* base_url, | 454 std::string* base_url, |
| 455 size_t* html_start, | 455 size_t* html_start, |
| 456 size_t* fragment_start, | 456 size_t* fragment_start, |
| 457 size_t* fragment_end) { | 457 size_t* fragment_end) { |
| 458 // Obtain base_url if present. | 458 // Obtain base_url if present. |
| 459 if (base_url) { | 459 if (base_url) { |
| 460 static std::string src_url_str("SourceURL:"); | 460 static std::string src_url_str("SourceURL:"); |
| 461 size_t line_start = cf_html.find(src_url_str); | 461 size_t line_start = cf_html.find(src_url_str); |
| 462 if (line_start != std::string::npos) { | 462 if (line_start != std::string::npos) { |
| 463 size_t src_end = cf_html.find("\n", line_start); | 463 size_t src_end = cf_html.find("\n", line_start); |
| 464 size_t src_start = line_start + src_url_str.length(); | 464 size_t src_start = line_start + src_url_str.length(); |
| 465 if (src_end != std::string::npos && src_start != std::string::npos) { | 465 if (src_end != std::string::npos && src_start != std::string::npos) { |
| 466 *base_url = cf_html.substr(src_start, src_end - src_start); | 466 *base_url = cf_html.substr(src_start, src_end - src_start); |
| 467 base::TrimWhitespace(*base_url, base::TRIM_ALL, base_url); | 467 base::TrimWhitespaceASCII(*base_url, base::TRIM_ALL, base_url); |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 // Find the markup between "<!--StartFragment-->" and "<!--EndFragment-->". | 472 // Find the markup between "<!--StartFragment-->" and "<!--EndFragment-->". |
| 473 // If the comments cannot be found, like copying from OpenOffice Writer, | 473 // If the comments cannot be found, like copying from OpenOffice Writer, |
| 474 // we simply fall back to using StartFragment/EndFragment bytecount values | 474 // we simply fall back to using StartFragment/EndFragment bytecount values |
| 475 // to determine the fragment indexes. | 475 // to determine the fragment indexes. |
| 476 std::string cf_html_lower = base::ToLowerASCII(cf_html); | 476 std::string cf_html_lower = base::ToLowerASCII(cf_html); |
| 477 size_t markup_start = cf_html_lower.find("<html", 0); | 477 size_t markup_start = cf_html_lower.find("<html", 0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 494 end_fragment_start + end_fragment_str.length())); | 494 end_fragment_start + end_fragment_str.length())); |
| 495 } | 495 } |
| 496 } else { | 496 } else { |
| 497 *fragment_start = cf_html.find('>', tag_start) + 1; | 497 *fragment_start = cf_html.find('>', tag_start) + 1; |
| 498 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); | 498 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); |
| 499 *fragment_end = cf_html.rfind('<', tag_end); | 499 *fragment_end = cf_html.rfind('<', tag_end); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 } // namespace ui | 503 } // namespace ui |
| OLD | NEW |