| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 private: | 167 private: |
| 162 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 168 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
| 163 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 169 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
| 164 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 170 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
| 165 | 171 |
| 166 // Helper for OmniboxFocusChanged. Commit or discard the preview. | 172 // Helper for OmniboxFocusChanged. Commit or discard the preview. |
| 167 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | 173 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
| 168 | 174 |
| 169 // Creates a new loader if necessary, using the instant_url property of the | 175 // Creates a new loader if necessary, using the instant_url property of the |
| 170 // |template_url| (for example, if the Instant URL has changed since the last | 176 // |template_url| (for example, if the Instant URL has changed since the last |
| 171 // time the loader was created). Returns false if the |template_url| doesn't | 177 // time the loader was created). If |fallback_to_local| is true will use |
| 172 // have a valid Instant URL; true otherwise. | 178 // kLocalOmniboxPopupURL as the fallback url (in extended mode) in case |
| 179 // the |template_url| doesn't have a valid Instant URL. Returns true if an |
| 180 // instant URL could be determined. |
| 173 bool ResetLoader(const TemplateURL* template_url, | 181 bool ResetLoader(const TemplateURL* template_url, |
| 174 const content::WebContents* active_tab); | 182 const content::WebContents* active_tab, |
| 183 bool fallback_to_local); |
| 175 | 184 |
| 176 // Ensures that the |loader_| uses the default Instant URL, recreating it if | 185 // Ensures that the |loader_| uses the default Instant URL, recreating it if |
| 177 // necessary, and returns true. Returns false if the Instant URL could not be | 186 // necessary, and returns true. Returns false if the Instant URL could not be |
| 178 // determined or the active tab is NULL (browser is shutting down). | 187 // determined or the active tab is NULL (browser is shutting down). |
| 179 bool CreateDefaultLoader(); | 188 bool CreateDefaultLoader(); |
| 180 | 189 |
| 181 // Called when the |loader_| might be stale. If it's actually stale, and the | 190 // Called when the |loader_| might be stale. If it's actually stale, and the |
| 182 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is | 191 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is |
| 183 // deleted and recreated. Else the refresh is skipped. | 192 // deleted and recreated. Else the refresh is skipped. |
| 184 void OnStaleLoader(); | 193 void OnStaleLoader(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 215 bool GetInstantURL(const TemplateURL* template_url, | 224 bool GetInstantURL(const TemplateURL* template_url, |
| 216 std::string* instant_url) const; | 225 std::string* instant_url) const; |
| 217 | 226 |
| 218 chrome::BrowserInstantController* const browser_; | 227 chrome::BrowserInstantController* const browser_; |
| 219 | 228 |
| 220 // Whether the extended API and regular API are enabled. If both are false, | 229 // Whether the extended API and regular API are enabled. If both are false, |
| 221 // Instant is effectively disabled. | 230 // Instant is effectively disabled. |
| 222 const bool extended_enabled_; | 231 const bool extended_enabled_; |
| 223 bool instant_enabled_; | 232 bool instant_enabled_; |
| 224 | 233 |
| 234 // If true, the instant URL is set to kLocalOmniboxPopupURL. |
| 235 const bool use_local_preview_only_; |
| 236 |
| 225 // The state of the preview page, i.e., the page owned by |loader_|. Ignored | 237 // The state of the preview page, i.e., the page owned by |loader_|. Ignored |
| 226 // if |instant_tab_| is in use. | 238 // if |instant_tab_| is in use. |
| 227 InstantModel model_; | 239 InstantModel model_; |
| 228 | 240 |
| 229 // The preview WebContents. | 241 // The preview WebContents. |
| 230 scoped_ptr<InstantLoader> loader_; | 242 scoped_ptr<InstantLoader> loader_; |
| 231 | 243 |
| 232 // A committed WebContents that supports Instant. If non-NULL, the |loader_| | 244 // A committed WebContents that supports Instant. If non-NULL, the |loader_| |
| 233 // is guaranteed to be hidden and messages will be sent to this instead. | 245 // is guaranteed to be hidden and messages will be sent to this instead. |
| 234 scoped_ptr<InstantTab> instant_tab_; | 246 scoped_ptr<InstantTab> instant_tab_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 307 |
| 296 // Whether to allow the preview to show search suggestions. In general, the | 308 // Whether to allow the preview to show search suggestions. In general, the |
| 297 // preview is allowed to show search suggestions whenever |search_mode_| is | 309 // preview is allowed to show search suggestions whenever |search_mode_| is |
| 298 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 310 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
| 299 bool allow_preview_to_show_search_suggestions_; | 311 bool allow_preview_to_show_search_suggestions_; |
| 300 | 312 |
| 301 DISALLOW_COPY_AND_ASSIGN(InstantController); | 313 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 302 }; | 314 }; |
| 303 | 315 |
| 304 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 316 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |