Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "components/metrics/proto/omnibox_input_type.pb.h" | |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 #include "url/url_parse.h" | 15 #include "url/url_parse.h" |
| 15 | 16 |
| 16 // The user input for an autocomplete query. Allows copying. | 17 // The user input for an autocomplete query. Allows copying. |
| 17 class AutocompleteInput { | 18 class AutocompleteInput { |
| 18 public: | 19 public: |
| 19 // Note that the type below may be misleading. For example, "http:/" alone | |
| 20 // cannot be opened as a URL, so it is marked as a QUERY; yet the user | |
| 21 // probably intends to type more and have it eventually become a URL, so we | |
| 22 // need to make sure we still run it through inline autocomplete. | |
| 23 enum Type { | |
| 24 INVALID, // Empty input | |
| 25 UNKNOWN, // Valid input whose type cannot be determined | |
| 26 URL, // Input autodetected as a URL | |
| 27 QUERY, // Input autodetected as a query | |
| 28 FORCED_QUERY, // Input forced to be a query by an initial '?' | |
| 29 }; | |
| 30 | |
| 31 // The type of page currently displayed. | 20 // The type of page currently displayed. |
| 32 // Note: when adding an element to this enum, please add it at the end | 21 // Note: when adding an element to this enum, please add it at the end |
| 33 // and update omnibox_event.proto::PageClassification and | 22 // and update omnibox_event.proto::PageClassification and |
| 34 // omnibox_edit_model.cc::ClassifyPage() too. | 23 // omnibox_edit_model.cc::ClassifyPage() too. |
| 35 enum PageClassification { | 24 enum PageClassification { |
| 36 // An invalid URL; shouldn't happen. | 25 // An invalid URL; shouldn't happen. |
| 37 INVALID_SPEC = 0, | 26 INVALID_SPEC = 0, |
| 38 | 27 |
| 39 // chrome://newtab/. This can be either the built-in version or a | 28 // chrome://newtab/. This can be either the built-in version or a |
| 40 // replacement new tab page from an extension. Note that when Instant | 29 // replacement new tab page from an extension. Note that when Instant |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 const GURL& current_url, | 111 const GURL& current_url, |
| 123 PageClassification current_page_classification, | 112 PageClassification current_page_classification, |
| 124 bool prevent_inline_autocomplete, | 113 bool prevent_inline_autocomplete, |
| 125 bool prefer_keyword, | 114 bool prefer_keyword, |
| 126 bool allow_exact_keyword_match, | 115 bool allow_exact_keyword_match, |
| 127 bool want_asynchronous_matches); | 116 bool want_asynchronous_matches); |
| 128 ~AutocompleteInput(); | 117 ~AutocompleteInput(); |
| 129 | 118 |
| 130 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. | 119 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. |
| 131 // Returns number of leading characters removed. | 120 // Returns number of leading characters removed. |
| 132 static size_t RemoveForcedQueryStringIfNecessary(Type type, | 121 static size_t RemoveForcedQueryStringIfNecessary( |
| 133 base::string16* text); | 122 metrics::OmniboxInputType::Type type, base::string16* text); |
|
Ilya Sherman
2014/06/06 05:01:01
Optional nit: Within the scope of the class, you c
Peter Kasting
2014/06/06 18:13:07
I think this would be a good idea. It would elimi
Mark P
2014/06/06 20:22:51
I hoped I would get such a sweet suggestion. Than
Peter Kasting
2014/06/06 20:37:08
That's strange. The following code compiles for m
Mark P
2014/06/06 21:24:51
Judging by the stackoverflow question, it sounds l
| |
| 134 | 123 |
| 135 // Converts |type| to a string representation. Used in logging. | 124 // Converts |type| to a string representation. Used in logging. |
| 136 static std::string TypeToString(Type type); | 125 static std::string TypeToString(metrics::OmniboxInputType::Type type); |
| 137 | 126 |
| 138 // Parses |text| and returns the type of input this will be interpreted as. | 127 // Parses |text| and returns the type of input this will be interpreted as. |
| 139 // The components of the input are stored in the output parameter |parts|, if | 128 // The components of the input are stored in the output parameter |parts|, if |
| 140 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The | 129 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The |
| 141 // canonicalized URL is stored in |canonicalized_url|; however, this URL is | 130 // canonicalized URL is stored in |canonicalized_url|; however, this URL is |
| 142 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. | 131 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. |
| 143 static Type Parse(const base::string16& text, | 132 static metrics::OmniboxInputType::Type Parse( |
| 144 const base::string16& desired_tld, | 133 const base::string16& text, |
| 145 url::Parsed* parts, | 134 const base::string16& desired_tld, |
| 146 base::string16* scheme, | 135 url::Parsed* parts, |
| 147 GURL* canonicalized_url); | 136 base::string16* scheme, |
| 137 GURL* canonicalized_url); | |
| 148 | 138 |
| 149 // Parses |text| and fill |scheme| and |host| by the positions of them. | 139 // Parses |text| and fill |scheme| and |host| by the positions of them. |
| 150 // The results are almost as same as the result of Parse(), but if the scheme | 140 // The results are almost as same as the result of Parse(), but if the scheme |
| 151 // is view-source, this function returns the positions of scheme and host | 141 // is view-source, this function returns the positions of scheme and host |
| 152 // in the URL qualified by "view-source:" prefix. | 142 // in the URL qualified by "view-source:" prefix. |
| 153 static void ParseForEmphasizeComponents(const base::string16& text, | 143 static void ParseForEmphasizeComponents(const base::string16& text, |
| 154 url::Component* scheme, | 144 url::Component* scheme, |
| 155 url::Component* host); | 145 url::Component* host); |
| 156 | 146 |
| 157 // Code that wants to format URLs with a format flag including | 147 // Code that wants to format URLs with a format flag including |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 187 // The current URL, or an invalid GURL if query refinement is not desired. | 177 // The current URL, or an invalid GURL if query refinement is not desired. |
| 188 const GURL& current_url() const { return current_url_; } | 178 const GURL& current_url() const { return current_url_; } |
| 189 | 179 |
| 190 // The type of page that is currently behind displayed and how it is | 180 // The type of page that is currently behind displayed and how it is |
| 191 // displayed (e.g., with search term replacement or without). | 181 // displayed (e.g., with search term replacement or without). |
| 192 AutocompleteInput::PageClassification current_page_classification() const { | 182 AutocompleteInput::PageClassification current_page_classification() const { |
| 193 return current_page_classification_; | 183 return current_page_classification_; |
| 194 } | 184 } |
| 195 | 185 |
| 196 // The type of input supplied. | 186 // The type of input supplied. |
| 197 Type type() const { return type_; } | 187 metrics::OmniboxInputType::Type type() const { return type_; } |
| 198 | 188 |
| 199 // Returns parsed URL components. | 189 // Returns parsed URL components. |
| 200 const url::Parsed& parts() const { return parts_; } | 190 const url::Parsed& parts() const { return parts_; } |
| 201 | 191 |
| 202 // The scheme parsed from the provided text; only meaningful when type_ is | 192 // The scheme parsed from the provided text; only meaningful when type_ is |
| 203 // URL. | 193 // URL. |
| 204 const base::string16& scheme() const { return scheme_; } | 194 const base::string16& scheme() const { return scheme_; } |
| 205 | 195 |
| 206 // The input as an URL to navigate to, if possible. | 196 // The input as an URL to navigate to, if possible. |
| 207 const GURL& canonicalized_url() const { return canonicalized_url_; } | 197 const GURL& canonicalized_url() const { return canonicalized_url_; } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 229 | 219 |
| 230 private: | 220 private: |
| 231 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); | 221 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); |
| 232 | 222 |
| 233 // NOTE: Whenever adding a new field here, please make sure to update Clear() | 223 // NOTE: Whenever adding a new field here, please make sure to update Clear() |
| 234 // method. | 224 // method. |
| 235 base::string16 text_; | 225 base::string16 text_; |
| 236 size_t cursor_position_; | 226 size_t cursor_position_; |
| 237 GURL current_url_; | 227 GURL current_url_; |
| 238 AutocompleteInput::PageClassification current_page_classification_; | 228 AutocompleteInput::PageClassification current_page_classification_; |
| 239 Type type_; | 229 metrics::OmniboxInputType::Type type_; |
| 240 url::Parsed parts_; | 230 url::Parsed parts_; |
| 241 base::string16 scheme_; | 231 base::string16 scheme_; |
| 242 GURL canonicalized_url_; | 232 GURL canonicalized_url_; |
| 243 bool prevent_inline_autocomplete_; | 233 bool prevent_inline_autocomplete_; |
| 244 bool prefer_keyword_; | 234 bool prefer_keyword_; |
| 245 bool allow_exact_keyword_match_; | 235 bool allow_exact_keyword_match_; |
| 246 bool want_asynchronous_matches_; | 236 bool want_asynchronous_matches_; |
| 247 }; | 237 }; |
| 248 | 238 |
| 249 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 239 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
| OLD | NEW |