| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_INSTANT_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace content { | 38 namespace content { |
| 39 class WebContents; | 39 class WebContents; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // InstantController maintains a WebContents that is intended to give a preview | 42 // InstantController maintains a WebContents that is intended to give a preview |
| 43 // of search suggestions and results. InstantController is owned by Browser via | 43 // of search suggestions and results. InstantController is owned by Browser via |
| 44 // BrowserInstantController. | 44 // BrowserInstantController. |
| 45 class InstantController { | 45 class InstantController { |
| 46 public: | 46 public: |
| 47 // The URL for the local omnibox popup. |
| 48 static const char* kLocalOmniboxPopupURL; |
| 49 |
| 50 // |use_local_preview_only| will force the use of kLocalOmniboxPopupURL as the |
| 51 // instant URL and is only applicable if |extended_enabled| is true. |
| 47 InstantController(chrome::BrowserInstantController* browser, | 52 InstantController(chrome::BrowserInstantController* browser, |
| 48 bool extended_enabled); | 53 bool extended_enabled, |
| 54 bool use_local_preview_only); |
| 49 ~InstantController(); | 55 ~InstantController(); |
| 50 | 56 |
| 51 // Invoked as the user types into the omnibox. |user_text| is what the user | 57 // Invoked as the user types into the omnibox. |user_text| is what the user |
| 52 // has typed. |full_text| is what the omnibox is showing. These may differ if | 58 // has typed. |full_text| is what the omnibox is showing. These may differ if |
| 53 // the user typed only some text, and the rest was inline autocompleted. If | 59 // the user typed only some text, and the rest was inline autocompleted. If |
| 54 // |verbatim| is true, search results are shown for the exact omnibox text, | 60 // |verbatim| is true, search results are shown for the exact omnibox text, |
| 55 // rather than the best guess as to what the user means. Returns true if the | 61 // rather than the best guess as to what the user means. Returns true if the |
| 56 // update is accepted (i.e., if |match| is a search rather than a URL). | 62 // update is accepted (i.e., if |match| is a search rather than a URL). |
| 57 bool Update(const AutocompleteMatch& match, | 63 bool Update(const AutocompleteMatch& match, |
| 58 const string16& user_text, | 64 const string16& user_text, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 private: | 173 private: |
| 168 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 174 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
| 169 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 175 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
| 170 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 176 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
| 171 | 177 |
| 172 // Helper for OmniboxFocusChanged. Commit or discard the preview. | 178 // Helper for OmniboxFocusChanged. Commit or discard the preview. |
| 173 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | 179 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
| 174 | 180 |
| 175 // Creates a new loader if necessary, using the instant_url property of the | 181 // Creates a new loader if necessary, using the instant_url property of the |
| 176 // |template_url| (for example, if the Instant URL has changed since the last | 182 // |template_url| (for example, if the Instant URL has changed since the last |
| 177 // time the loader was created). Returns false if the |template_url| doesn't | 183 // time the loader was created). If |fallback_to_local| is true will use |
| 178 // have a valid Instant URL; true otherwise. | 184 // kLocalOmniboxPopupURL as the fallback url (in extended mode) in case |
| 185 // the |template_url| doesn't have a valid Instant URL. Returns true if an |
| 186 // instant URL could be determined. |
| 179 bool ResetLoader(const TemplateURL* template_url, | 187 bool ResetLoader(const TemplateURL* template_url, |
| 180 const content::WebContents* active_tab); | 188 const content::WebContents* active_tab, |
| 189 bool fallback_to_local); |
| 181 | 190 |
| 182 // Ensures that the |loader_| uses the default Instant URL, recreating it if | 191 // Ensures that the |loader_| uses the default Instant URL, recreating it if |
| 183 // necessary, and returns true. Returns false if the Instant URL could not be | 192 // necessary, and returns true. Returns false if the Instant URL could not be |
| 184 // determined or the active tab is NULL (browser is shutting down). | 193 // determined or the active tab is NULL (browser is shutting down). |
| 185 bool CreateDefaultLoader(); | 194 bool CreateDefaultLoader(); |
| 186 | 195 |
| 187 // Called when the |loader_| might be stale. If it's actually stale, and the | 196 // Called when the |loader_| might be stale. If it's actually stale, and the |
| 188 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is | 197 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is |
| 189 // deleted and recreated. Else the refresh is skipped. | 198 // deleted and recreated. Else the refresh is skipped. |
| 190 void OnStaleLoader(); | 199 void OnStaleLoader(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 221 bool GetInstantURL(const TemplateURL* template_url, | 230 bool GetInstantURL(const TemplateURL* template_url, |
| 222 std::string* instant_url) const; | 231 std::string* instant_url) const; |
| 223 | 232 |
| 224 chrome::BrowserInstantController* const browser_; | 233 chrome::BrowserInstantController* const browser_; |
| 225 | 234 |
| 226 // Whether the extended API and regular API are enabled. If both are false, | 235 // Whether the extended API and regular API are enabled. If both are false, |
| 227 // Instant is effectively disabled. | 236 // Instant is effectively disabled. |
| 228 const bool extended_enabled_; | 237 const bool extended_enabled_; |
| 229 bool instant_enabled_; | 238 bool instant_enabled_; |
| 230 | 239 |
| 240 // If true, the instant URL is set to kLocalOmniboxPopupURL. |
| 241 const bool use_local_preview_only_; |
| 242 |
| 231 // The state of the preview page, i.e., the page owned by |loader_|. Ignored | 243 // The state of the preview page, i.e., the page owned by |loader_|. Ignored |
| 232 // if |instant_tab_| is in use. | 244 // if |instant_tab_| is in use. |
| 233 InstantModel model_; | 245 InstantModel model_; |
| 234 | 246 |
| 235 // The preview WebContents. | 247 // The preview WebContents. |
| 236 scoped_ptr<InstantLoader> loader_; | 248 scoped_ptr<InstantLoader> loader_; |
| 237 | 249 |
| 238 // A committed WebContents that supports Instant. If non-NULL, the |loader_| | 250 // A committed WebContents that supports Instant. If non-NULL, the |loader_| |
| 239 // is guaranteed to be hidden and messages will be sent to this instead. | 251 // is guaranteed to be hidden and messages will be sent to this instead. |
| 240 scoped_ptr<InstantTab> instant_tab_; | 252 scoped_ptr<InstantTab> instant_tab_; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 319 |
| 308 // Whether to allow the preview to show search suggestions. In general, the | 320 // Whether to allow the preview to show search suggestions. In general, the |
| 309 // preview is allowed to show search suggestions whenever |search_mode_| is | 321 // preview is allowed to show search suggestions whenever |search_mode_| is |
| 310 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 322 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
| 311 bool allow_preview_to_show_search_suggestions_; | 323 bool allow_preview_to_show_search_suggestions_; |
| 312 | 324 |
| 313 DISALLOW_COPY_AND_ASSIGN(InstantController); | 325 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 314 }; | 326 }; |
| 315 | 327 |
| 316 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 328 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |