Chromium Code Reviews| Index: chrome/browser/ui/omnibox/omnibox_view.cc |
| diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc |
| index 50cc536f375c86913c17a507b34d81278d5c4ea0..92e390e78c65749fbafff807352dceb2611a9080 100644 |
| --- a/chrome/browser/ui/omnibox/omnibox_view.cc |
| +++ b/chrome/browser/ui/omnibox/omnibox_view.cc |
| @@ -24,6 +24,25 @@ string16 OmniboxView::StripJavascriptSchemas(const string16& text) { |
| } |
| // static |
| +string16 OmniboxView::SanitizeTextForPaste(const string16& text) { |
| + // Convert newlines to spaces. |
|
Peter Kasting
2013/08/09 18:11:59
These two implementation comments aren't quite cor
jfweitz
2013/08/09 18:49:55
Done.
|
| + // TODO(shess): It may also make sense to ignore leading or |
| + // trailing whitespace when making this determination. |
| + for (size_t i = 0; i < text.size(); ++i) { |
| + if (IsWhitespace(text[i]) && text[i] != '\n' && text[i] != '\r') { |
| + const string16 collapsed = CollapseWhitespace(text, false); |
| + // If the user is pasting all-whitespace, paste a single space |
| + // rather than nothing, since pasting nothing feels broken. |
| + return collapsed.empty() ? |
| + ASCIIToUTF16(" ") : StripJavascriptSchemas(collapsed); |
| + } |
| + } |
| + |
| + // If all whitespaces are newlines they have to be removed. |
| + return StripJavascriptSchemas(CollapseWhitespace(text, true)); |
| +} |
| + |
| +// static |
| string16 OmniboxView::GetClipboardText() { |
| // Try text format. |
| ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| @@ -31,26 +50,7 @@ string16 OmniboxView::GetClipboardText() { |
| ui::Clipboard::BUFFER_STANDARD)) { |
| string16 text; |
| clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); |
| - |
| - // If the input contains non-newline whitespace, treat it as |
| - // search data and convert newlines to spaces. For instance, a |
| - // street address. |
| - // TODO(shess): It may also make sense to ignore leading or |
| - // trailing whitespace when making this determination. |
| - for (size_t i = 0; i < text.size(); ++i) { |
| - if (IsWhitespace(text[i]) && text[i] != '\n' && text[i] != '\r') { |
| - const string16 collapsed = CollapseWhitespace(text, false); |
| - // If the user is pasting all-whitespace, paste a single space |
| - // rather than nothing, since pasting nothing feels broken. |
| - return collapsed.empty() ? |
| - ASCIIToUTF16(" ") : StripJavascriptSchemas(collapsed); |
| - } |
| - } |
| - |
| - // Otherwise, the only whitespace in |text| is newlines. Remove |
| - // these entirely, because users are most likely pasting URLs |
| - // split into multiple lines by terminals, email programs, etc. |
| - return StripJavascriptSchemas(CollapseWhitespace(text, true)); |
| + return SanitizeTextForPaste(text); |
| } |
| // Try bookmark format. |