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" | 22 #include "content/public/common/page_transition_types.h" |
28 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
29 #include "ui/base/window_open_disposition.h" | 24 #include "ui/base/window_open_disposition.h" |
30 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
31 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
32 #include "url/gurl.h" | 27 #include "url/gurl.h" |
33 | 28 |
34 struct AutocompleteMatch; | |
35 struct InstantAutocompleteResult; | |
36 | |
37 class AutocompleteProvider; | |
38 class AutocompleteResult; | |
39 class BrowserInstantController; | 29 class BrowserInstantController; |
40 class InstantNTP; | 30 class InstantNTP; |
41 class InstantOverlay; | |
42 class InstantService; | 31 class InstantService; |
43 class InstantTab; | 32 class InstantTab; |
44 class TemplateURL; | 33 class Profile; |
45 | 34 |
46 namespace content { | 35 namespace content { |
47 class WebContents; | 36 class WebContents; |
48 } | 37 } |
49 | 38 |
50 // Macro used for logging debug events. |message| should be a std::string. | 39 // Macro used for logging debug events. |message| should be a std::string. |
51 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 40 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
52 controller->LogDebugEvent(message) | 41 controller->LogDebugEvent(message) |
53 | 42 |
54 // InstantController drives Chrome Instant, i.e., the browser implementation of | 43 // InstantController drives Chrome Instant, i.e., the browser implementation of |
55 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 44 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
56 // | 45 // |
57 // In extended mode, InstantController maintains and coordinates three | 46 // In extended mode, InstantController maintains and coordinates two |
58 // instances of InstantPage: | 47 // instances of InstantPage: |
59 // (1) An InstantOverlay instance that is used to show search suggestions and | 48 // (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 | 49 // 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. | 50 // never shown to the user in an uncommitted state. |
64 // (3) An InstantTab instance which points to the currently active tab, if it | 51 // (2) An InstantTab instance which points to the currently active tab, if it |
65 // supports the Embedded Search API. | 52 // supports the Embedded Search API. |
66 // | 53 // |
67 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 54 // Both are backed by a WebContents. InstantNTP owns its WebContents and |
68 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 55 // InstantTab does not. |
69 // only an InstantOverlay instance is kept. | |
70 // | 56 // |
71 // InstantController is owned by Browser via BrowserInstantController. | 57 // InstantController is owned by Browser via BrowserInstantController. |
72 class InstantController : public InstantPage::Delegate, | 58 class InstantController : public InstantPage::Delegate, |
73 public InstantServiceObserver { | 59 public InstantServiceObserver { |
74 public: | 60 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, | 61 InstantController(BrowserInstantController* browser, |
88 bool extended_enabled); | 62 bool extended_enabled); |
89 virtual ~InstantController(); | 63 virtual ~InstantController(); |
90 | 64 |
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 | 65 // Releases and returns the NTP WebContents. May be NULL. Loads a new |
115 // WebContents for the NTP. | 66 // WebContents for the NTP. |
116 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | 67 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
117 | 68 |
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. | 69 // Sets the stored start-edge margin and width of the omnibox. |
122 void SetOmniboxBounds(const gfx::Rect& bounds); | 70 void SetOmniboxBounds(const gfx::Rect& bounds); |
123 | 71 |
124 // Send autocomplete results from |providers| to the overlay page. | 72 // 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(); | 73 void OnDefaultSearchProviderChanged(); |
132 | 74 |
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. | 75 // Notifies |instant_Tab_| to toggle voice search. |
151 void ToggleVoiceSearch(); | 76 void ToggleVoiceSearch(); |
152 | 77 |
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. | 78 // The ntp WebContents. May be NULL. InstantController retains ownership. |
157 content::WebContents* GetNTPContents() const; | 79 content::WebContents* GetNTPContents() const; |
158 | 80 |
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 | 81 // 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 | 82 // search-term-replacement enabled. If |instant_tab_| can be used to process |
165 // the search, this does so and returns true. Else, returns false. | 83 // the search, this does so and returns true. Else, returns false. |
166 bool SubmitQuery(const string16& search_terms); | 84 bool SubmitQuery(const string16& search_terms); |
167 | 85 |
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. | 86 // If the network status changes, try to reset NTP and Overlay. |
173 void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type); | 87 void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type); |
174 | 88 |
175 // Called to indicate that the omnibox focus state changed with the given | 89 // 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 | 90 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
177 // the view gaining focus. | 91 // the view gaining focus. |
178 void OmniboxFocusChanged(OmniboxFocusState focus_state, | 92 void OmniboxFocusChanged(OmniboxFocusState focus_state, |
179 OmniboxFocusChangeReason reason, | 93 OmniboxFocusChangeReason reason, |
180 gfx::NativeView view_gaining_focus); | 94 gfx::NativeView view_gaining_focus); |
181 | 95 |
182 // The search mode in the active tab has changed. Pass the message down to | 96 // 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. | 97 // |new_mode| reflects an Instant search results page. |
185 void SearchModeChanged(const SearchMode& old_mode, | 98 void SearchModeChanged(const SearchMode& old_mode, |
186 const SearchMode& new_mode); | 99 const SearchMode& new_mode); |
187 | 100 |
188 // The user switched tabs. Hide the overlay. Create |instant_tab_| if the | 101 // The user switched tabs. Bind |instant_tab_| if the newly active tab is an |
189 // newly active tab is an Instant search results page. | 102 // Instant search results page. |
190 void ActiveTabChanged(); | 103 void ActiveTabChanged(); |
191 | 104 |
192 // The user is about to switch tabs. Commit the overlay if needed. | 105 // The user is about to switch tabs. |
193 void TabDeactivated(content::WebContents* contents); | 106 void TabDeactivated(content::WebContents* contents); |
194 | 107 |
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 | 108 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that |
215 // |debug_events_| doesn't get too large. | 109 // |debug_events_| doesn't get too large. |
216 void LogDebugEvent(const std::string& info) const; | 110 void LogDebugEvent(const std::string& info) const; |
217 | 111 |
218 // Resets list of debug events. | 112 // Resets list of debug events. |
219 void ClearDebugEvents(); | 113 void ClearDebugEvents(); |
220 | 114 |
| 115 // Loads a new NTP to replace |ntp_|. |
| 116 void ReloadStaleNTP(); |
| 117 |
221 // Returns the correct Instant URL to use from the following possibilities: | 118 // Returns the correct Instant URL to use from the following possibilities: |
222 // o The default search engine's Instant URL | 119 // o The default search engine's Instant URL |
223 // o The local page (see GetLocalInstantURL()) | 120 // o The local page (see GetLocalInstantURL()) |
224 // Returns empty string if no valid Instant URL is available (this is only | 121 // 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). | 122 // possible in non-extended mode where we don't have a local page fall-back). |
226 virtual std::string GetInstantURL() const; | 123 virtual std::string GetInstantURL() const; |
227 | 124 |
228 // See comments for |debug_events_| below. | 125 // See comments for |debug_events_| below. |
229 const std::list<std::pair<int64, std::string> >& debug_events() { | 126 const std::list<std::pair<int64, std::string> >& debug_events() { |
230 return debug_events_; | 127 return debug_events_; |
231 } | 128 } |
232 | 129 |
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 | 130 // Used by BrowserInstantController to notify InstantController about the |
243 // instant support change event for the active web contents. | 131 // instant support change event for the active web contents. |
244 void InstantSupportChanged(InstantSupportState instant_support); | 132 void InstantSupportChanged(InstantSupportState instant_support); |
245 | 133 |
246 protected: | 134 protected: |
247 // Accessors are made protected for testing purposes. | 135 // Accessors are made protected for testing purposes. |
248 virtual bool extended_enabled() const; | 136 virtual bool extended_enabled() const; |
249 | 137 |
250 virtual InstantOverlay* overlay() const; | |
251 virtual InstantTab* instant_tab() const; | 138 virtual InstantTab* instant_tab() const; |
252 virtual InstantNTP* ntp() const; | 139 virtual InstantNTP* ntp() const; |
253 | 140 |
254 virtual Profile* profile() const; | 141 virtual Profile* profile() const; |
255 | 142 |
256 // Returns true if Javascript is enabled and false otherwise. | 143 // Returns true if Javascript is enabled and false otherwise. |
257 virtual bool IsJavascriptEnabled() const; | 144 virtual bool IsJavascriptEnabled() const; |
258 | 145 |
259 // Returns true if the browser is in startup. | 146 // Returns true if the browser is in startup. |
260 virtual bool InStartup() const; | 147 virtual bool InStartup() const; |
261 | 148 |
262 private: | 149 private: |
263 friend class InstantExtendedManualTest; | 150 friend class InstantExtendedManualTest; |
264 friend class InstantTestBase; | 151 friend class InstantTestBase; |
265 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) | 152 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) |
266 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); | 153 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); |
267 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); | 154 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); |
268 UNIT_F(IsJavascriptEnabled); | 155 UNIT_F(IsJavascriptEnabled); |
269 UNIT_F(IsJavascriptEnabledChecksContentSettings); | 156 UNIT_F(IsJavascriptEnabledChecksContentSettings); |
270 UNIT_F(IsJavascriptEnabledChecksPrefs); | 157 UNIT_F(IsJavascriptEnabledChecksPrefs); |
271 UNIT_F(PrefersRemoteNTPOnStartup); | 158 UNIT_F(PrefersRemoteNTPOnStartup); |
272 UNIT_F(ShouldSwitchToLocalOverlay); | |
273 UNIT_F(SwitchesToLocalNTPIfJSDisabled); | 159 UNIT_F(SwitchesToLocalNTPIfJSDisabled); |
274 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); | 160 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); |
275 UNIT_F(SwitchesToLocalNTPIfNoNTPReady); | 161 UNIT_F(SwitchesToLocalNTPIfNoNTPReady); |
276 UNIT_F(SwitchesToLocalNTPIfPathBad); | 162 UNIT_F(SwitchesToLocalNTPIfPathBad); |
277 #undef UNIT_F | 163 #undef UNIT_F |
278 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | 164 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
279 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); | 165 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); |
280 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); | 166 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); |
281 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); | 167 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); |
282 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); | 168 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); |
(...skipping 29 matching lines...) Expand all Loading... |
312 virtual void InstantPageRenderViewCreated( | 198 virtual void InstantPageRenderViewCreated( |
313 const content::WebContents* contents) OVERRIDE; | 199 const content::WebContents* contents) OVERRIDE; |
314 virtual void InstantSupportDetermined( | 200 virtual void InstantSupportDetermined( |
315 const content::WebContents* contents, | 201 const content::WebContents* contents, |
316 bool supports_instant) OVERRIDE; | 202 bool supports_instant) OVERRIDE; |
317 virtual void InstantPageRenderViewGone( | 203 virtual void InstantPageRenderViewGone( |
318 const content::WebContents* contents) OVERRIDE; | 204 const content::WebContents* contents) OVERRIDE; |
319 virtual void InstantPageAboutToNavigateMainFrame( | 205 virtual void InstantPageAboutToNavigateMainFrame( |
320 const content::WebContents* contents, | 206 const content::WebContents* contents, |
321 const GURL& url) OVERRIDE; | 207 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, | 208 virtual void FocusOmnibox(const content::WebContents* contents, |
331 OmniboxFocusState state) OVERRIDE; | 209 OmniboxFocusState state) OVERRIDE; |
332 virtual void NavigateToURL( | 210 virtual void NavigateToURL( |
333 const content::WebContents* contents, | 211 const content::WebContents* contents, |
334 const GURL& url, | 212 const GURL& url, |
335 content::PageTransition transition, | 213 content::PageTransition transition, |
336 WindowOpenDisposition disposition, | 214 WindowOpenDisposition disposition, |
337 bool is_search_type) OVERRIDE; | 215 bool is_search_type) OVERRIDE; |
338 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 216 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
339 | 217 |
(...skipping 25 matching lines...) Expand all Loading... |
365 // chrome::GetLocalInstantURL.) | 243 // chrome::GetLocalInstantURL.) |
366 virtual std::string GetLocalInstantURL() const; | 244 virtual std::string GetLocalInstantURL() const; |
367 | 245 |
368 // Returns true if |page| has an up-to-date Instant URL and supports Instant. | 246 // Returns true if |page| has an up-to-date Instant URL and supports Instant. |
369 // Note that local URLs will not pass this check. | 247 // Note that local URLs will not pass this check. |
370 bool PageIsCurrent(const InstantPage* page) const; | 248 bool PageIsCurrent(const InstantPage* page) const; |
371 | 249 |
372 // Recreates |ntp_| using |instant_url|. | 250 // Recreates |ntp_| using |instant_url|. |
373 void ResetNTP(const std::string& instant_url); | 251 void ResetNTP(const std::string& instant_url); |
374 | 252 |
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. | 253 // Returns true if we should switch to using the local NTP. |
379 bool ShouldSwitchToLocalNTP() const; | 254 bool ShouldSwitchToLocalNTP() const; |
380 | 255 |
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 | 256 // If the active tab is an Instant search results page, sets |instant_tab_| to |
389 // point to it. Else, deletes any existing |instant_tab_|. | 257 // point to it. Else, deletes any existing |instant_tab_|. |
390 void ResetInstantTab(); | 258 void ResetInstantTab(); |
391 | 259 |
392 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. | 260 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. |
393 void UpdateInfoForInstantTab(); | 261 void UpdateInfoForInstantTab(); |
394 | 262 |
395 // Returns whether input is in progress, i.e. if the omnibox has focus and the | 263 // Returns whether input is in progress, i.e. if the omnibox has focus and the |
396 // active tab is in mode SEARCH_SUGGESTIONS. | 264 // active tab is in mode SEARCH_SUGGESTIONS. |
397 bool IsInputInProgress() const; | 265 bool IsInputInProgress() const; |
398 | 266 |
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. | 267 // Returns true if the local page is being used. |
420 bool UsingLocalPage() const; | 268 bool UsingLocalPage() const; |
421 | 269 |
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. | 270 // Returns the InstantService for the browser profile. |
436 InstantService* GetInstantService() const; | 271 InstantService* GetInstantService() const; |
437 | 272 |
438 BrowserInstantController* const browser_; | 273 BrowserInstantController* const browser_; |
439 | 274 |
440 // Whether the extended API and regular API are enabled. If both are false, | 275 // Whether the extended API and regular API are enabled. If both are false, |
441 // Instant is effectively disabled. | 276 // Instant is effectively disabled. |
442 const bool extended_enabled_; | 277 const bool extended_enabled_; |
443 bool instant_enabled_; | |
444 | 278 |
445 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. | 279 // 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_; | 280 scoped_ptr<InstantNTP> ntp_; |
463 scoped_ptr<InstantTab> instant_tab_; | 281 scoped_ptr<InstantTab> instant_tab_; |
464 | 282 |
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. | 283 // Omnibox focus state. |
499 OmniboxFocusState omnibox_focus_state_; | 284 OmniboxFocusState omnibox_focus_state_; |
500 | 285 |
501 // The reason for the most recent omnibox focus change. | 286 // The reason for the most recent omnibox focus change. |
502 OmniboxFocusChangeReason omnibox_focus_change_reason_; | 287 OmniboxFocusChangeReason omnibox_focus_change_reason_; |
503 | 288 |
504 // The search model mode for the active tab. | 289 // The search model mode for the active tab. |
505 SearchMode search_mode_; | 290 SearchMode search_mode_; |
506 | 291 |
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 | 292 // The start-edge margin and width of the omnibox, used by the page to align |
514 // its suggestions with the omnibox. | 293 // its suggestions with the omnibox. |
515 gfx::Rect omnibox_bounds_; | 294 gfx::Rect omnibox_bounds_; |
516 | 295 |
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. | 296 // List of events and their timestamps, useful in debugging Instant behaviour. |
540 mutable std::list<std::pair<int64, std::string> > debug_events_; | 297 mutable std::list<std::pair<int64, std::string> > debug_events_; |
541 | 298 |
542 DISALLOW_COPY_AND_ASSIGN(InstantController); | 299 DISALLOW_COPY_AND_ASSIGN(InstantController); |
543 }; | 300 }; |
544 | 301 |
545 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 302 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
OLD | NEW |