| 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_UI_SEARCH_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/time/time.h" | |
| 18 #include "base/timer/timer.h" | |
| 19 #include "chrome/browser/search/instant_service_observer.h" | 17 #include "chrome/browser/search/instant_service_observer.h" |
| 20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | |
| 21 #include "chrome/browser/ui/search/instant_commit_type.h" | |
| 22 #include "chrome/browser/ui/search/instant_overlay_model.h" | |
| 23 #include "chrome/browser/ui/search/instant_page.h" | 18 #include "chrome/browser/ui/search/instant_page.h" |
| 24 #include "chrome/common/instant_types.h" | 19 #include "chrome/common/instant_types.h" |
| 25 #include "chrome/common/omnibox_focus_state.h" | 20 #include "chrome/common/omnibox_focus_state.h" |
| 26 #include "chrome/common/search_types.h" | 21 #include "chrome/common/search_types.h" |
| 27 #include "content/public/common/page_transition_types.h" | |
| 28 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 29 #include "ui/base/window_open_disposition.h" | 23 #include "ui/base/window_open_disposition.h" |
| 30 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
| 31 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 32 | 26 |
| 33 struct AutocompleteMatch; | |
| 34 struct InstantAutocompleteResult; | |
| 35 | |
| 36 class AutocompleteProvider; | |
| 37 class AutocompleteResult; | |
| 38 class BrowserInstantController; | 27 class BrowserInstantController; |
| 39 class InstantNTP; | 28 class InstantNTP; |
| 40 class InstantOverlay; | |
| 41 class InstantService; | 29 class InstantService; |
| 42 class InstantTab; | 30 class InstantTab; |
| 43 class TemplateURL; | 31 class Profile; |
| 44 | 32 |
| 45 namespace content { | 33 namespace content { |
| 46 class WebContents; | 34 class WebContents; |
| 47 } | 35 } |
| 48 | 36 |
| 49 // Macro used for logging debug events. |message| should be a std::string. | 37 // Macro used for logging debug events. |message| should be a std::string. |
| 50 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 38 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
| 51 controller->LogDebugEvent(message) | 39 controller->LogDebugEvent(message) |
| 52 | 40 |
| 53 // InstantController drives Chrome Instant, i.e., the browser implementation of | 41 // InstantController drives Chrome Instant, i.e., the browser implementation of |
| 54 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 42 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
| 55 // | 43 // |
| 56 // In extended mode, InstantController maintains and coordinates three | 44 // In extended mode, InstantController maintains and coordinates two |
| 57 // instances of InstantPage: | 45 // instances of InstantPage: |
| 58 // (1) An InstantOverlay instance that is used to show search suggestions and | 46 // (1) An InstantNTP instance which is a preloaded search page that will be |
| 59 // results in an overlay over a non-search page. | |
| 60 // (2) An InstantNTP instance which is a preloaded search page that will be | |
| 61 // swapped-in the next time the user navigates to the New Tab Page. It is | 47 // swapped-in the next time the user navigates to the New Tab Page. It is |
| 62 // never shown to the user in an uncommitted state. | 48 // never shown to the user in an uncommitted state. |
| 63 // (3) An InstantTab instance which points to the currently active tab, if it | 49 // (2) An InstantTab instance which points to the currently active tab, if it |
| 64 // supports the Embedded Search API. | 50 // supports the Embedded Search API. |
| 65 // | 51 // |
| 66 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 52 // Both are backed by a WebContents. InstantNTP owns its WebContents and |
| 67 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 53 // InstantTab does not. |
| 68 // only an InstantOverlay instance is kept. | |
| 69 // | 54 // |
| 70 // InstantController is owned by Browser via BrowserInstantController. | 55 // InstantController is owned by Browser via BrowserInstantController. |
| 71 class InstantController : public InstantPage::Delegate, | 56 class InstantController : public InstantPage::Delegate, |
| 72 public InstantServiceObserver { | 57 public InstantServiceObserver { |
| 73 public: | 58 public: |
| 74 // For reporting fallbacks to local overlay. | |
| 75 enum InstantFallbackReason { | |
| 76 INSTANT_FALLBACK_NONE = 0, | |
| 77 INSTANT_FALLBACK_UNKNOWN = 1, | |
| 78 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, | |
| 79 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, | |
| 80 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, | |
| 81 INSTANT_FALLBACK_NO_OVERLAY = 5, | |
| 82 INSTANT_FALLBACK_JAVASCRIPT_DISABLED = 6, | |
| 83 INSTANT_FALLBACK_MAX = 7, | |
| 84 }; | |
| 85 | |
| 86 InstantController(BrowserInstantController* browser, | 59 InstantController(BrowserInstantController* browser, |
| 87 bool extended_enabled); | 60 bool extended_enabled); |
| 88 virtual ~InstantController(); | 61 virtual ~InstantController(); |
| 89 | 62 |
| 90 // Called when the Autocomplete flow is about to start. Sets up the | |
| 91 // appropriate page to send user updates to. May reset |instant_tab_| or | |
| 92 // switch to a local fallback |overlay_| as necessary. | |
| 93 void OnAutocompleteStart(); | |
| 94 | |
| 95 // Invoked as the user types into the omnibox. |user_text| is what the user | |
| 96 // has typed. |full_text| is what the omnibox is showing. These may differ if | |
| 97 // the user typed only some text, and the rest was inline autocompleted. If | |
| 98 // |verbatim| is true, search results are shown for the exact omnibox text, | |
| 99 // rather than the best guess as to what the user means. Returns true if the | |
| 100 // update is accepted (i.e., if |match| is a search rather than a URL). | |
| 101 // |is_keyword_search| is true if keyword searching is in effect. | |
| 102 bool Update(const AutocompleteMatch& match, | |
| 103 const string16& user_text, | |
| 104 const string16& full_text, | |
| 105 size_t selection_start, | |
| 106 size_t selection_end, | |
| 107 bool verbatim, | |
| 108 bool user_input_in_progress, | |
| 109 bool omnibox_popup_is_open, | |
| 110 bool escape_pressed, | |
| 111 bool is_keyword_search); | |
| 112 | |
| 113 // Releases and returns the NTP WebContents. May be NULL. Loads a new | 63 // Releases and returns the NTP WebContents. May be NULL. Loads a new |
| 114 // WebContents for the NTP. | 64 // WebContents for the NTP. |
| 115 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | 65 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
| 116 | 66 |
| 117 // Sets the bounds of the omnibox popup, in screen coordinates. | |
| 118 void SetPopupBounds(const gfx::Rect& bounds); | |
| 119 | |
| 120 // Sets the stored start-edge margin and width of the omnibox. | 67 // Sets the stored start-edge margin and width of the omnibox. |
| 121 void SetOmniboxBounds(const gfx::Rect& bounds); | 68 void SetOmniboxBounds(const gfx::Rect& bounds); |
| 122 | 69 |
| 123 // Send autocomplete results from |providers| to the overlay page. | 70 // Called when the default search provider changes. Resets InstantNTP. |
| 124 void HandleAutocompleteResults( | |
| 125 const std::vector<AutocompleteProvider*>& providers, | |
| 126 const AutocompleteResult& result); | |
| 127 | |
| 128 // Called when the default search provider changes. Resets InstantNTP and | |
| 129 // InstantOverlay. | |
| 130 void OnDefaultSearchProviderChanged(); | 71 void OnDefaultSearchProviderChanged(); |
| 131 | 72 |
| 132 // Called when the user presses up or down. |count| is a repeat count, | |
| 133 // negative for moving up, positive for moving down. Returns true if Instant | |
| 134 // handled the key press. | |
| 135 bool OnUpOrDownKeyPressed(int count); | |
| 136 | |
| 137 // Called when the user has arrowed into the suggestions but wants to cancel, | |
| 138 // typically by pressing ESC. The omnibox text is expected to have been | |
| 139 // reverted to |full_text| by the OmniboxEditModel prior to calling this. | |
| 140 // |match| is the match reverted to. | |
| 141 void OnCancel(const AutocompleteMatch& match, | |
| 142 const string16& user_text, | |
| 143 const string16& full_text); | |
| 144 | |
| 145 // Called when the user navigates to a URL from the omnibox. This will send | |
| 146 // an onsubmit notification to the instant page. | |
| 147 void OmniboxNavigateToURL(); | |
| 148 | |
| 149 // Notifies |instant_Tab_| to toggle voice search. | 73 // Notifies |instant_Tab_| to toggle voice search. |
| 150 void ToggleVoiceSearch(); | 74 void ToggleVoiceSearch(); |
| 151 | 75 |
| 152 // The overlay WebContents. May be NULL. InstantController retains ownership. | |
| 153 content::WebContents* GetOverlayContents() const; | |
| 154 | |
| 155 // The ntp WebContents. May be NULL. InstantController retains ownership. | 76 // The ntp WebContents. May be NULL. InstantController retains ownership. |
| 156 content::WebContents* GetNTPContents() const; | 77 content::WebContents* GetNTPContents() const; |
| 157 | 78 |
| 158 // Returns true if Instant is showing a search results overlay. Returns false | |
| 159 // if the overlay is not showing, or if it's showing only suggestions. | |
| 160 bool IsOverlayingSearchResults() const; | |
| 161 | |
| 162 // Called if the browser is navigating to a search URL for |search_terms| with | 79 // Called if the browser is navigating to a search URL for |search_terms| with |
| 163 // search-term-replacement enabled. If |instant_tab_| can be used to process | 80 // search-term-replacement enabled. If |instant_tab_| can be used to process |
| 164 // the search, this does so and returns true. Else, returns false. | 81 // the search, this does so and returns true. Else, returns false. |
| 165 bool SubmitQuery(const string16& search_terms); | 82 bool SubmitQuery(const string16& search_terms); |
| 166 | 83 |
| 167 // If the overlay is showing search results, commits the overlay, calling | |
| 168 // CommitInstant() on the browser, and returns true. Else, returns false. | |
| 169 bool CommitIfPossible(InstantCommitType type); | |
| 170 | |
| 171 // Called to indicate that the omnibox focus state changed with the given | 84 // Called to indicate that the omnibox focus state changed with the given |
| 172 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to | 85 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
| 173 // the view gaining focus. | 86 // the view gaining focus. |
| 174 void OmniboxFocusChanged(OmniboxFocusState focus_state, | 87 void OmniboxFocusChanged(OmniboxFocusState focus_state, |
| 175 OmniboxFocusChangeReason reason, | 88 OmniboxFocusChangeReason reason, |
| 176 gfx::NativeView view_gaining_focus); | 89 gfx::NativeView view_gaining_focus); |
| 177 | 90 |
| 178 // The search mode in the active tab has changed. Pass the message down to | 91 // The search mode in the active tab has changed. Bind |instant_tab_| if the |
| 179 // the overlay which will notify the renderer. Create |instant_tab_| if the | |
| 180 // |new_mode| reflects an Instant search results page. | 92 // |new_mode| reflects an Instant search results page. |
| 181 void SearchModeChanged(const SearchMode& old_mode, | 93 void SearchModeChanged(const SearchMode& old_mode, |
| 182 const SearchMode& new_mode); | 94 const SearchMode& new_mode); |
| 183 | 95 |
| 184 // The user switched tabs. Hide the overlay. Create |instant_tab_| if the | 96 // The user switched tabs. Bind |instant_tab_| if the newly active tab is an |
| 185 // newly active tab is an Instant search results page. | 97 // Instant search results page. |
| 186 void ActiveTabChanged(); | 98 void ActiveTabChanged(); |
| 187 | 99 |
| 188 // The user is about to switch tabs. Commit the overlay if needed. | 100 // The user is about to switch tabs. |
| 189 void TabDeactivated(content::WebContents* contents); | 101 void TabDeactivated(content::WebContents* contents); |
| 190 | 102 |
| 191 // Sets whether Instant should show result overlays. |use_local_page_only| | |
| 192 // will force the use of baked-in page as the Instant URL and is only | |
| 193 // applicable if |extended_enabled_| is true. | |
| 194 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); | |
| 195 | |
| 196 // Called when someone else swapped in a different contents in the |overlay_|. | |
| 197 void SwappedOverlayContents(); | |
| 198 | |
| 199 // Called when contents for |overlay_| received focus. | |
| 200 void FocusedOverlayContents(); | |
| 201 | |
| 202 // Called when the |overlay_| might be stale. If it's actually stale, and the | |
| 203 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| | |
| 204 // is deleted and recreated. Else the refresh is skipped. | |
| 205 void ReloadOverlayIfStale(); | |
| 206 | |
| 207 // Called when the |overlay_|'s main frame has finished loading. | |
| 208 void OverlayLoadCompletedMainFrame(); | |
| 209 | |
| 210 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that | 103 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that |
| 211 // |debug_events_| doesn't get too large. | 104 // |debug_events_| doesn't get too large. |
| 212 void LogDebugEvent(const std::string& info) const; | 105 void LogDebugEvent(const std::string& info) const; |
| 213 | 106 |
| 214 // Resets list of debug events. | 107 // Resets list of debug events. |
| 215 void ClearDebugEvents(); | 108 void ClearDebugEvents(); |
| 216 | 109 |
| 217 // Gets the Most Visited items info from InstantService and forwards them to | 110 // Gets the Most Visited items info from InstantService and forwards them to |
| 218 // the Instant page renderer via the appropriate InstantPage subclass. | 111 // the Instant page renderer via the appropriate InstantPage subclass. |
| 219 void UpdateMostVisitedItems(); | 112 void UpdateMostVisitedItems(); |
| 220 | 113 |
| 114 // Loads a new NTP to replace |ntp_|. |
| 115 void ReloadStaleNTP(); |
| 116 |
| 221 // Returns the correct Instant URL to use from the following possibilities: | 117 // Returns the correct Instant URL to use from the following possibilities: |
| 222 // o The default search engine's Instant URL | 118 // o The default search engine's Instant URL |
| 223 // o The local page (see GetLocalInstantURL()) | 119 // o The local page (see GetLocalInstantURL()) |
| 224 // Returns empty string if no valid Instant URL is available (this is only | 120 // Returns empty string if no valid Instant URL is available (this is only |
| 225 // possible in non-extended mode where we don't have a local page fall-back). | 121 // possible in non-extended mode where we don't have a local page fall-back). |
| 226 virtual std::string GetInstantURL() const; | 122 virtual std::string GetInstantURL() const; |
| 227 | 123 |
| 228 // See comments for |debug_events_| below. | 124 // See comments for |debug_events_| below. |
| 229 const std::list<std::pair<int64, std::string> >& debug_events() { | 125 const std::list<std::pair<int64, std::string> >& debug_events() { |
| 230 return debug_events_; | 126 return debug_events_; |
| 231 } | 127 } |
| 232 | 128 |
| 233 // Returns the transition type of the last AutocompleteMatch passed to Update. | |
| 234 content::PageTransition last_transition_type() const { | |
| 235 return last_transition_type_; | |
| 236 } | |
| 237 | |
| 238 // Non-const for Add/RemoveObserver only. Other model changes should only | |
| 239 // happen through the InstantController interface. | |
| 240 InstantOverlayModel* model() { return &model_; } | |
| 241 | |
| 242 // Used by BrowserInstantController to notify InstantController about the | 129 // Used by BrowserInstantController to notify InstantController about the |
| 243 // instant support change event for the active web contents. | 130 // instant support change event for the active web contents. |
| 244 void InstantSupportChanged(InstantSupportState instant_support); | 131 void InstantSupportChanged(InstantSupportState instant_support); |
| 245 | 132 |
| 246 protected: | 133 protected: |
| 247 // Accessors are made protected for testing purposes. | 134 // Accessors are made protected for testing purposes. |
| 248 virtual bool extended_enabled() const; | 135 virtual bool extended_enabled() const; |
| 249 | 136 |
| 250 virtual InstantOverlay* overlay() const; | |
| 251 virtual InstantTab* instant_tab() const; | 137 virtual InstantTab* instant_tab() const; |
| 252 virtual InstantNTP* ntp() const; | 138 virtual InstantNTP* ntp() const; |
| 253 | 139 |
| 254 virtual Profile* profile() const; | 140 virtual Profile* profile() const; |
| 255 | 141 |
| 256 // Returns true if Javascript is enabled and false otherwise. | 142 // Returns true if Javascript is enabled and false otherwise. |
| 257 virtual bool IsJavascriptEnabled() const; | 143 virtual bool IsJavascriptEnabled() const; |
| 258 | 144 |
| 259 // Returns true if the browser is in startup. | 145 // Returns true if the browser is in startup. |
| 260 virtual bool InStartup() const; | 146 virtual bool InStartup() const; |
| 261 | 147 |
| 262 private: | 148 private: |
| 263 friend class InstantExtendedManualTest; | 149 friend class InstantExtendedManualTest; |
| 264 friend class InstantTestBase; | 150 friend class InstantTestBase; |
| 265 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) | 151 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) |
| 266 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); | 152 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); |
| 267 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); | 153 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); |
| 268 UNIT_F(IsJavascriptEnabled); | 154 UNIT_F(IsJavascriptEnabled); |
| 269 UNIT_F(IsJavascriptEnabledChecksContentSettings); | 155 UNIT_F(IsJavascriptEnabledChecksContentSettings); |
| 270 UNIT_F(IsJavascriptEnabledChecksPrefs); | 156 UNIT_F(IsJavascriptEnabledChecksPrefs); |
| 271 UNIT_F(PrefersRemoteNTPOnStartup); | 157 UNIT_F(PrefersRemoteNTPOnStartup); |
| 272 UNIT_F(ShouldSwitchToLocalOverlay); | |
| 273 UNIT_F(SwitchesToLocalNTPIfJSDisabled); | 158 UNIT_F(SwitchesToLocalNTPIfJSDisabled); |
| 274 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); | 159 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); |
| 275 UNIT_F(SwitchesToLocalNTPIfNoNTPReady); | 160 UNIT_F(SwitchesToLocalNTPIfNoNTPReady); |
| 276 UNIT_F(SwitchesToLocalNTPIfPathBad); | 161 UNIT_F(SwitchesToLocalNTPIfPathBad); |
| 277 #undef UNIT_F | 162 #undef UNIT_F |
| 278 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | 163 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
| 279 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); | 164 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); |
| 280 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); | 165 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); |
| 281 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); | 166 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); |
| 282 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); | 167 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 310 virtual void InstantPageRenderViewCreated( | 195 virtual void InstantPageRenderViewCreated( |
| 311 const content::WebContents* contents) OVERRIDE; | 196 const content::WebContents* contents) OVERRIDE; |
| 312 virtual void InstantSupportDetermined( | 197 virtual void InstantSupportDetermined( |
| 313 const content::WebContents* contents, | 198 const content::WebContents* contents, |
| 314 bool supports_instant) OVERRIDE; | 199 bool supports_instant) OVERRIDE; |
| 315 virtual void InstantPageRenderViewGone( | 200 virtual void InstantPageRenderViewGone( |
| 316 const content::WebContents* contents) OVERRIDE; | 201 const content::WebContents* contents) OVERRIDE; |
| 317 virtual void InstantPageAboutToNavigateMainFrame( | 202 virtual void InstantPageAboutToNavigateMainFrame( |
| 318 const content::WebContents* contents, | 203 const content::WebContents* contents, |
| 319 const GURL& url) OVERRIDE; | 204 const GURL& url) OVERRIDE; |
| 320 virtual void SetSuggestions( | |
| 321 const content::WebContents* contents, | |
| 322 const std::vector<InstantSuggestion>& suggestions) OVERRIDE; | |
| 323 virtual void ShowInstantOverlay( | |
| 324 const content::WebContents* contents, | |
| 325 int height, | |
| 326 InstantSizeUnits units) OVERRIDE; | |
| 327 virtual void LogDropdownShown() OVERRIDE; | |
| 328 virtual void FocusOmnibox(const content::WebContents* contents, | 205 virtual void FocusOmnibox(const content::WebContents* contents, |
| 329 OmniboxFocusState state) OVERRIDE; | 206 OmniboxFocusState state) OVERRIDE; |
| 330 virtual void NavigateToURL( | 207 virtual void NavigateToURL( |
| 331 const content::WebContents* contents, | 208 const content::WebContents* contents, |
| 332 const GURL& url, | 209 const GURL& url, |
| 333 content::PageTransition transition, | 210 content::PageTransition transition, |
| 334 WindowOpenDisposition disposition, | 211 WindowOpenDisposition disposition, |
| 335 bool is_search_type) OVERRIDE; | 212 bool is_search_type) OVERRIDE; |
| 336 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 213 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
| 337 | 214 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 361 // chrome::GetLocalInstantURL.) | 238 // chrome::GetLocalInstantURL.) |
| 362 virtual std::string GetLocalInstantURL() const; | 239 virtual std::string GetLocalInstantURL() const; |
| 363 | 240 |
| 364 // Returns true if |page| has an up-to-date Instant URL and supports Instant. | 241 // Returns true if |page| has an up-to-date Instant URL and supports Instant. |
| 365 // Note that local URLs will not pass this check. | 242 // Note that local URLs will not pass this check. |
| 366 bool PageIsCurrent(const InstantPage* page) const; | 243 bool PageIsCurrent(const InstantPage* page) const; |
| 367 | 244 |
| 368 // Recreates |ntp_| using |instant_url|. | 245 // Recreates |ntp_| using |instant_url|. |
| 369 void ResetNTP(const std::string& instant_url); | 246 void ResetNTP(const std::string& instant_url); |
| 370 | 247 |
| 371 // Reloads a new InstantNTP. Called when |ntp_| is stale. | |
| 372 void ReloadStaleNTP(); | |
| 373 | |
| 374 // Returns true if we should switch to using the local NTP. | 248 // Returns true if we should switch to using the local NTP. |
| 375 bool ShouldSwitchToLocalNTP() const; | 249 bool ShouldSwitchToLocalNTP() const; |
| 376 | 250 |
| 377 // Recreates |overlay_| using |instant_url|. |overlay_| will be NULL if | |
| 378 // |instant_url| is empty or if there is no active tab. | |
| 379 void ResetOverlay(const std::string& instant_url); | |
| 380 | |
| 381 // Returns an enum value indicating the reason to fallback. | |
| 382 InstantFallbackReason ShouldSwitchToLocalOverlay() const; | |
| 383 | |
| 384 // If the active tab is an Instant search results page, sets |instant_tab_| to | 251 // If the active tab is an Instant search results page, sets |instant_tab_| to |
| 385 // point to it. Else, deletes any existing |instant_tab_|. | 252 // point to it. Else, deletes any existing |instant_tab_|. |
| 386 void ResetInstantTab(); | 253 void ResetInstantTab(); |
| 387 | 254 |
| 388 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. | 255 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. |
| 389 void UpdateInfoForInstantTab(); | 256 void UpdateInfoForInstantTab(); |
| 390 | 257 |
| 391 // Returns whether input is in progress, i.e. if the omnibox has focus and the | 258 // Returns whether input is in progress, i.e. if the omnibox has focus and the |
| 392 // active tab is in mode SEARCH_SUGGESTIONS. | 259 // active tab is in mode SEARCH_SUGGESTIONS. |
| 393 bool IsInputInProgress() const; | 260 bool IsInputInProgress() const; |
| 394 | 261 |
| 395 // Hide the overlay. Also sends an onchange event (with blank query) to the | |
| 396 // overlay, telling it to clear out results for any old queries. | |
| 397 void HideOverlay(); | |
| 398 | |
| 399 // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay() | |
| 400 // unless you are going to call overlay_.reset() yourself subsequently. | |
| 401 void HideInternal(); | |
| 402 | |
| 403 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay | |
| 404 // with the given |height| in |units|. | |
| 405 void ShowOverlay(int height, InstantSizeUnits units); | |
| 406 | |
| 407 // Send the omnibox popup bounds to the page. | |
| 408 void SendPopupBoundsToPage(); | |
| 409 | |
| 410 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns | |
| 411 // true if successful. (Note that |suggestion| may be modified even if this | |
| 412 // returns false.) | |
| 413 bool FixSuggestion(InstantSuggestion* suggestion) const; | |
| 414 | |
| 415 // Returns true if the local page is being used. | 262 // Returns true if the local page is being used. |
| 416 bool UsingLocalPage() const; | 263 bool UsingLocalPage() const; |
| 417 | 264 |
| 418 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| | |
| 419 // exists. | |
| 420 bool UseTabForSuggestions() const; | |
| 421 | |
| 422 // Populates InstantAutocompleteResult with AutocompleteMatch details. | |
| 423 // |autocomplete_match_index| specifies the index of |match| in the | |
| 424 // AutocompleteResult. If the |match| is obtained from auto complete | |
| 425 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex. | |
| 426 void PopulateInstantAutocompleteResultFromMatch( | |
| 427 const AutocompleteMatch& match, | |
| 428 size_t autocomplete_match_index, | |
| 429 InstantAutocompleteResult* result); | |
| 430 | |
| 431 // Returns the InstantService for the browser profile. | 265 // Returns the InstantService for the browser profile. |
| 432 InstantService* GetInstantService() const; | 266 InstantService* GetInstantService() const; |
| 433 | 267 |
| 434 BrowserInstantController* const browser_; | 268 BrowserInstantController* const browser_; |
| 435 | 269 |
| 436 // Whether the extended API and regular API are enabled. If both are false, | 270 // Whether the extended API and regular API are enabled. If both are false, |
| 437 // Instant is effectively disabled. | 271 // Instant is effectively disabled. |
| 438 const bool extended_enabled_; | 272 const bool extended_enabled_; |
| 439 bool instant_enabled_; | |
| 440 | 273 |
| 441 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. | 274 // The instances of InstantPage maintained by InstantController. |
| 442 bool use_local_page_only_; | |
| 443 | |
| 444 // If true, preload an NTP into |ntp_|. | |
| 445 bool preload_ntp_; | |
| 446 | |
| 447 // The state of the overlay page, i.e., the page owned by |overlay_|. Ignored | |
| 448 // if |instant_tab_| is in use. | |
| 449 InstantOverlayModel model_; | |
| 450 | |
| 451 // The three instances of InstantPage maintained by InstantController as | |
| 452 // described above. All three may be non-NULL in extended mode. If | |
| 453 // |instant_tab_| is not NULL, then |overlay_| is guaranteed to be hidden and | |
| 454 // messages will be sent to |instant_tab_| instead. | |
| 455 // | |
| 456 // In non-extended mode, only |overlay_| is ever non-NULL. | |
| 457 scoped_ptr<InstantOverlay> overlay_; | |
| 458 scoped_ptr<InstantNTP> ntp_; | 275 scoped_ptr<InstantNTP> ntp_; |
| 459 scoped_ptr<InstantTab> instant_tab_; | 276 scoped_ptr<InstantTab> instant_tab_; |
| 460 | 277 |
| 461 // If true, send suggestion-related events (such as user key strokes, auto | |
| 462 // complete results, etc.) to |instant_tab_| instead of |overlay_|. Once set | |
| 463 // to false, will stay false until the overlay is hidden or committed. | |
| 464 bool use_tab_for_suggestions_; | |
| 465 | |
| 466 // The most recent full_text passed to Update(). If empty, we'll not accept | |
| 467 // search suggestions from |overlay_| or |instant_tab_|. | |
| 468 string16 last_omnibox_text_; | |
| 469 | |
| 470 // The most recent user_text passed to Update(). Used to filter out-of-date | |
| 471 // URL suggestions from the Instant page. Set in Update() and cleared when | |
| 472 // the page sets temporary text (SetSuggestions() with REPLACE behavior). | |
| 473 string16 last_user_text_; | |
| 474 | |
| 475 // True if the last Update() had an inline autocompletion. Used only to make | |
| 476 // sure that we don't accidentally suggest gray text suggestion in that case. | |
| 477 bool last_omnibox_text_has_inline_autocompletion_; | |
| 478 | |
| 479 // The most recent verbatim passed to Update(). Used only to ensure that we | |
| 480 // don't accidentally suggest an inline autocompletion. | |
| 481 bool last_verbatim_; | |
| 482 | |
| 483 // The most recent suggestion received from the page, minus any prefix that | |
| 484 // the user has typed. | |
| 485 InstantSuggestion last_suggestion_; | |
| 486 | |
| 487 // See comments on the getter above. | |
| 488 content::PageTransition last_transition_type_; | |
| 489 | |
| 490 // True if the last match passed to Update() was a search (versus a URL). | |
| 491 // Used to ensure that the overlay page is committable. | |
| 492 bool last_match_was_search_; | |
| 493 | |
| 494 // Omnibox focus state. | 278 // Omnibox focus state. |
| 495 OmniboxFocusState omnibox_focus_state_; | 279 OmniboxFocusState omnibox_focus_state_; |
| 496 | 280 |
| 497 // The reason for the most recent omnibox focus change. | 281 // The reason for the most recent omnibox focus change. |
| 498 OmniboxFocusChangeReason omnibox_focus_change_reason_; | 282 OmniboxFocusChangeReason omnibox_focus_change_reason_; |
| 499 | 283 |
| 500 // The search model mode for the active tab. | 284 // The search model mode for the active tab. |
| 501 SearchMode search_mode_; | 285 SearchMode search_mode_; |
| 502 | 286 |
| 503 // Current omnibox popup bounds. | |
| 504 gfx::Rect popup_bounds_; | |
| 505 | |
| 506 // Last popup bounds passed to the page. | |
| 507 gfx::Rect last_popup_bounds_; | |
| 508 | |
| 509 // The start-edge margin and width of the omnibox, used by the page to align | 287 // The start-edge margin and width of the omnibox, used by the page to align |
| 510 // its suggestions with the omnibox. | 288 // its suggestions with the omnibox. |
| 511 gfx::Rect omnibox_bounds_; | 289 gfx::Rect omnibox_bounds_; |
| 512 | 290 |
| 513 // Timer used to update the bounds of the omnibox popup. | |
| 514 base::OneShotTimer<InstantController> update_bounds_timer_; | |
| 515 | |
| 516 // Search terms extraction (for autocomplete history matches) doesn't work | |
| 517 // on Instant URLs. So, whenever the user commits an Instant search, we add | |
| 518 // an equivalent non-Instant search URL to history, so that the search shows | |
| 519 // up in autocomplete history matches. | |
| 520 // TODO(sreeram): Remove when http://crbug.com/155373 is fixed. | |
| 521 GURL url_for_history_; | |
| 522 | |
| 523 // The timestamp at which query editing began. This value is used when the | |
| 524 // overlay is showed and cleared when the overlay is hidden. | |
| 525 base::Time first_interaction_time_; | |
| 526 | |
| 527 // Indicates that the first interaction time has already been logged. | |
| 528 bool first_interaction_time_recorded_; | |
| 529 | |
| 530 // Whether to allow the overlay to show search suggestions. In general, the | |
| 531 // overlay is allowed to show search suggestions whenever |search_mode_| is | |
| 532 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | |
| 533 bool allow_overlay_to_show_search_suggestions_; | |
| 534 | |
| 535 // List of events and their timestamps, useful in debugging Instant behaviour. | 291 // List of events and their timestamps, useful in debugging Instant behaviour. |
| 536 mutable std::list<std::pair<int64, std::string> > debug_events_; | 292 mutable std::list<std::pair<int64, std::string> > debug_events_; |
| 537 | 293 |
| 538 DISALLOW_COPY_AND_ASSIGN(InstantController); | 294 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 539 }; | 295 }; |
| 540 | 296 |
| 541 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 297 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| OLD | NEW |