OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/clipboard/clipboard_util_win.h" | 5 #include "app/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> | 9 #include <wininet.h> |
10 | 10 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 if (line_start != std::string::npos) { | 481 if (line_start != std::string::npos) { |
482 size_t src_end = cf_html.find("\n", line_start); | 482 size_t src_end = cf_html.find("\n", line_start); |
483 size_t src_start = line_start + src_url_str.length(); | 483 size_t src_start = line_start + src_url_str.length(); |
484 if (src_end != std::string::npos && src_start != std::string::npos) { | 484 if (src_end != std::string::npos && src_start != std::string::npos) { |
485 *base_url = cf_html.substr(src_start, src_end - src_start); | 485 *base_url = cf_html.substr(src_start, src_end - src_start); |
486 TrimWhitespace(*base_url, TRIM_ALL, base_url); | 486 TrimWhitespace(*base_url, TRIM_ALL, base_url); |
487 } | 487 } |
488 } | 488 } |
489 } | 489 } |
490 | 490 |
491 // Find the markup between "<!--StartFragment -->" and "<!--EndFragment-->". | 491 // Find the markup between "<!--StartFragment-->" and "<!--EndFragment-->". |
| 492 // If the comments cannot be found, like copying from OpenOffice Writer, |
| 493 // we simply fall back to using StartFragment/EndFragment bytecount values |
| 494 // to get the markup. |
492 if (html) { | 495 if (html) { |
| 496 size_t fragment_start = std::string::npos; |
| 497 size_t fragment_end = std::string::npos; |
| 498 |
493 std::string cf_html_lower = StringToLowerASCII(cf_html); | 499 std::string cf_html_lower = StringToLowerASCII(cf_html); |
494 size_t markup_start = cf_html_lower.find("<html", 0); | 500 size_t markup_start = cf_html_lower.find("<html", 0); |
495 size_t tag_start = cf_html.find("StartFragment", markup_start); | 501 size_t tag_start = cf_html.find("<!--StartFragment", markup_start); |
496 size_t fragment_start = cf_html.find('>', tag_start) + 1; | 502 if (tag_start == std::string::npos) { |
497 size_t tag_end = cf_html.rfind("EndFragment", std::string::npos); | 503 static std::string start_fragment_str("StartFragment:"); |
498 size_t fragment_end = cf_html.rfind('<', tag_end); | 504 size_t start_fragment_start = cf_html.find(start_fragment_str); |
| 505 if (start_fragment_start != std::string::npos) { |
| 506 fragment_start = static_cast<size_t>(atoi(cf_html.c_str() + |
| 507 start_fragment_start + start_fragment_str.length())); |
| 508 } |
| 509 |
| 510 static std::string end_fragment_str("EndFragment:"); |
| 511 size_t end_fragment_start = cf_html.find(end_fragment_str); |
| 512 if (end_fragment_start != std::string::npos) { |
| 513 fragment_end = static_cast<size_t>(atoi(cf_html.c_str() + |
| 514 end_fragment_start + end_fragment_str.length())); |
| 515 } |
| 516 } else { |
| 517 fragment_start = cf_html.find('>', tag_start) + 1; |
| 518 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); |
| 519 fragment_end = cf_html.rfind('<', tag_end); |
| 520 } |
499 if (fragment_start != std::string::npos && | 521 if (fragment_start != std::string::npos && |
500 fragment_end != std::string::npos) { | 522 fragment_end != std::string::npos) { |
501 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); | 523 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); |
502 TrimWhitespace(*html, TRIM_ALL, html); | 524 TrimWhitespace(*html, TRIM_ALL, html); |
503 } | 525 } |
504 } | 526 } |
505 } | 527 } |
OLD | NEW |