| 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 "chrome/browser/autocomplete/autocomplete_input.h" | 5 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 9 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 10 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 current_page_classification_(current_page_classification), | 54 current_page_classification_(current_page_classification), |
| 55 prevent_inline_autocomplete_(prevent_inline_autocomplete), | 55 prevent_inline_autocomplete_(prevent_inline_autocomplete), |
| 56 prefer_keyword_(prefer_keyword), | 56 prefer_keyword_(prefer_keyword), |
| 57 allow_exact_keyword_match_(allow_exact_keyword_match), | 57 allow_exact_keyword_match_(allow_exact_keyword_match), |
| 58 matches_requested_(matches_requested) { | 58 matches_requested_(matches_requested) { |
| 59 DCHECK(cursor_position <= text.length() || | 59 DCHECK(cursor_position <= text.length() || |
| 60 cursor_position == base::string16::npos) | 60 cursor_position == base::string16::npos) |
| 61 << "Text: '" << text << "', cp: " << cursor_position; | 61 << "Text: '" << text << "', cp: " << cursor_position; |
| 62 // None of the providers care about leading white space so we always trim it. | 62 // None of the providers care about leading white space so we always trim it. |
| 63 // Providers that care about trailing white space handle trimming themselves. | 63 // Providers that care about trailing white space handle trimming themselves. |
| 64 if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0) | 64 if ((base::TrimWhitespace(text, base::TRIM_LEADING, &text_) & |
| 65 base::TRIM_LEADING) != 0) |
| 65 AdjustCursorPositionIfNecessary(text.length() - text_.length(), | 66 AdjustCursorPositionIfNecessary(text.length() - text_.length(), |
| 66 &cursor_position_); | 67 &cursor_position_); |
| 67 | 68 |
| 68 GURL canonicalized_url; | 69 GURL canonicalized_url; |
| 69 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); | 70 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); |
| 70 | 71 |
| 71 if (type_ == INVALID) | 72 if (type_ == INVALID) |
| 72 return; | 73 return; |
| 73 | 74 |
| 74 if (((type_ == UNKNOWN) || (type_ == URL)) && | 75 if (((type_ == UNKNOWN) || (type_ == URL)) && |
| 75 canonicalized_url.is_valid() && | 76 canonicalized_url.is_valid() && |
| 76 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || | 77 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || |
| 77 canonicalized_url.SchemeIsFileSystem() || | 78 canonicalized_url.SchemeIsFileSystem() || |
| 78 !canonicalized_url.host().empty())) | 79 !canonicalized_url.host().empty())) |
| 79 canonicalized_url_ = canonicalized_url; | 80 canonicalized_url_ = canonicalized_url; |
| 80 | 81 |
| 81 size_t chars_removed = RemoveForcedQueryStringIfNecessary(type_, &text_); | 82 size_t chars_removed = RemoveForcedQueryStringIfNecessary(type_, &text_); |
| 82 AdjustCursorPositionIfNecessary(chars_removed, &cursor_position_); | 83 AdjustCursorPositionIfNecessary(chars_removed, &cursor_position_); |
| 83 if (chars_removed) { | 84 if (chars_removed) { |
| 84 // Remove spaces between opening question mark and first actual character. | 85 // Remove spaces between opening question mark and first actual character. |
| 85 base::string16 trimmed_text; | 86 base::string16 trimmed_text; |
| 86 if ((TrimWhitespace(text_, TRIM_LEADING, &trimmed_text) & TRIM_LEADING) != | 87 if ((base::TrimWhitespace(text_, base::TRIM_LEADING, &trimmed_text) & |
| 87 0) { | 88 base::TRIM_LEADING) != 0) { |
| 88 AdjustCursorPositionIfNecessary(text_.length() - trimmed_text.length(), | 89 AdjustCursorPositionIfNecessary(text_.length() - trimmed_text.length(), |
| 89 &cursor_position_); | 90 &cursor_position_); |
| 90 text_ = trimmed_text; | 91 text_ = trimmed_text; |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 AutocompleteInput::~AutocompleteInput() { | 96 AutocompleteInput::~AutocompleteInput() { |
| 96 } | 97 } |
| 97 | 98 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 current_page_classification_ = AutocompleteInput::INVALID_SPEC; | 530 current_page_classification_ = AutocompleteInput::INVALID_SPEC; |
| 530 type_ = INVALID; | 531 type_ = INVALID; |
| 531 parts_ = url_parse::Parsed(); | 532 parts_ = url_parse::Parsed(); |
| 532 scheme_.clear(); | 533 scheme_.clear(); |
| 533 canonicalized_url_ = GURL(); | 534 canonicalized_url_ = GURL(); |
| 534 prevent_inline_autocomplete_ = false; | 535 prevent_inline_autocomplete_ = false; |
| 535 prefer_keyword_ = false; | 536 prefer_keyword_ = false; |
| 536 allow_exact_keyword_match_ = false; | 537 allow_exact_keyword_match_ = false; |
| 537 matches_requested_ = ALL_MATCHES; | 538 matches_requested_ = ALL_MATCHES; |
| 538 } | 539 } |
| OLD | NEW |