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