Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/ui/search/instant_controller.h

Issue 18223002: InstantExtended: Remove overlay control code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
110 // Loads a new NTP to replace |ntp_|.
samarth 2013/07/02 21:14:15 Can we keep this private if it's only used in test
Jered 2013/07/02 22:03:11 This is now called by BrowserInstantController ins
111 void ReloadStaleNTP();
112
217 // Returns the correct Instant URL to use from the following possibilities: 113 // Returns the correct Instant URL to use from the following possibilities:
218 // o The default search engine's Instant URL 114 // o The default search engine's Instant URL
219 // o The local page (see GetLocalInstantURL()) 115 // o The local page (see GetLocalInstantURL())
220 // Returns empty string if no valid Instant URL is available (this is only 116 // Returns empty string if no valid Instant URL is available (this is only
221 // possible in non-extended mode where we don't have a local page fall-back). 117 // possible in non-extended mode where we don't have a local page fall-back).
222 virtual std::string GetInstantURL() const; 118 virtual std::string GetInstantURL() const;
223 119
224 // See comments for |debug_events_| below. 120 // See comments for |debug_events_| below.
225 const std::list<std::pair<int64, std::string> >& debug_events() { 121 const std::list<std::pair<int64, std::string> >& debug_events() {
226 return debug_events_; 122 return debug_events_;
227 } 123 }
228 124
229 // Returns the transition type of the last AutocompleteMatch passed to Update.
230 content::PageTransition last_transition_type() const {
231 return last_transition_type_;
232 }
233
234 // Non-const for Add/RemoveObserver only. Other model changes should only
235 // happen through the InstantController interface.
236 InstantOverlayModel* model() { return &model_; }
237
238 // Used by BrowserInstantController to notify InstantController about the 125 // Used by BrowserInstantController to notify InstantController about the
239 // instant support change event for the active web contents. 126 // instant support change event for the active web contents.
240 void InstantSupportChanged(InstantSupportState instant_support); 127 void InstantSupportChanged(InstantSupportState instant_support);
241 128
242 protected: 129 protected:
243 // Accessors are made protected for testing purposes. 130 // Accessors are made protected for testing purposes.
244 virtual bool extended_enabled() const; 131 virtual bool extended_enabled() const;
245 132
246 virtual InstantOverlay* overlay() const;
247 virtual InstantTab* instant_tab() const; 133 virtual InstantTab* instant_tab() const;
248 virtual InstantNTP* ntp() const; 134 virtual InstantNTP* ntp() const;
249 135
250 virtual Profile* profile() const; 136 virtual Profile* profile() const;
251 137
252 // Returns true if Javascript is enabled and false otherwise. 138 // Returns true if Javascript is enabled and false otherwise.
253 virtual bool IsJavascriptEnabled() const; 139 virtual bool IsJavascriptEnabled() const;
254 140
255 // Returns true if the browser is in startup. 141 // Returns true if the browser is in startup.
256 virtual bool InStartup() const; 142 virtual bool InStartup() const;
257 143
258 private: 144 private:
259 friend class InstantExtendedManualTest; 145 friend class InstantExtendedManualTest;
260 friend class InstantTestBase; 146 friend class InstantTestBase;
261 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) 147 #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test)
262 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); 148 UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP);
263 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); 149 UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP);
264 UNIT_F(IsJavascriptEnabled); 150 UNIT_F(IsJavascriptEnabled);
265 UNIT_F(IsJavascriptEnabledChecksContentSettings); 151 UNIT_F(IsJavascriptEnabledChecksContentSettings);
266 UNIT_F(IsJavascriptEnabledChecksPrefs); 152 UNIT_F(IsJavascriptEnabledChecksPrefs);
267 UNIT_F(PrefersRemoteNTPOnStartup); 153 UNIT_F(PrefersRemoteNTPOnStartup);
268 UNIT_F(ShouldSwitchToLocalOverlay);
269 UNIT_F(SwitchesToLocalNTPIfJSDisabled); 154 UNIT_F(SwitchesToLocalNTPIfJSDisabled);
270 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); 155 UNIT_F(SwitchesToLocalNTPIfNoInstantSupport);
271 UNIT_F(SwitchesToLocalNTPIfNoNTPReady); 156 UNIT_F(SwitchesToLocalNTPIfNoNTPReady);
272 UNIT_F(SwitchesToLocalNTPIfPathBad); 157 UNIT_F(SwitchesToLocalNTPIfPathBad);
273 #undef UNIT_F 158 #undef UNIT_F
274 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); 159 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn);
275 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); 160 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited);
276 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); 161 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded);
277 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); 162 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab);
278 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); 163 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab);
(...skipping 27 matching lines...) Expand all
306 virtual void InstantPageRenderViewCreated( 191 virtual void InstantPageRenderViewCreated(
307 const content::WebContents* contents) OVERRIDE; 192 const content::WebContents* contents) OVERRIDE;
308 virtual void InstantSupportDetermined( 193 virtual void InstantSupportDetermined(
309 const content::WebContents* contents, 194 const content::WebContents* contents,
310 bool supports_instant) OVERRIDE; 195 bool supports_instant) OVERRIDE;
311 virtual void InstantPageRenderViewGone( 196 virtual void InstantPageRenderViewGone(
312 const content::WebContents* contents) OVERRIDE; 197 const content::WebContents* contents) OVERRIDE;
313 virtual void InstantPageAboutToNavigateMainFrame( 198 virtual void InstantPageAboutToNavigateMainFrame(
314 const content::WebContents* contents, 199 const content::WebContents* contents,
315 const GURL& url) OVERRIDE; 200 const GURL& url) OVERRIDE;
316 virtual void SetSuggestions(
317 const content::WebContents* contents,
318 const std::vector<InstantSuggestion>& suggestions) OVERRIDE;
319 virtual void ShowInstantOverlay(
320 const content::WebContents* contents,
321 int height,
322 InstantSizeUnits units) OVERRIDE;
323 virtual void LogDropdownShown() OVERRIDE;
324 virtual void FocusOmnibox(const content::WebContents* contents, 201 virtual void FocusOmnibox(const content::WebContents* contents,
325 OmniboxFocusState state) OVERRIDE; 202 OmniboxFocusState state) OVERRIDE;
326 virtual void NavigateToURL( 203 virtual void NavigateToURL(
327 const content::WebContents* contents, 204 const content::WebContents* contents,
328 const GURL& url, 205 const GURL& url,
329 content::PageTransition transition, 206 content::PageTransition transition,
330 WindowOpenDisposition disposition, 207 WindowOpenDisposition disposition,
331 bool is_search_type) OVERRIDE; 208 bool is_search_type) OVERRIDE;
332 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; 209 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE;
333 210
(...skipping 25 matching lines...) Expand all
359 // chrome::GetLocalInstantURL.) 236 // chrome::GetLocalInstantURL.)
360 virtual std::string GetLocalInstantURL() const; 237 virtual std::string GetLocalInstantURL() const;
361 238
362 // Returns true if |page| has an up-to-date Instant URL and supports Instant. 239 // Returns true if |page| has an up-to-date Instant URL and supports Instant.
363 // Note that local URLs will not pass this check. 240 // Note that local URLs will not pass this check.
364 bool PageIsCurrent(const InstantPage* page) const; 241 bool PageIsCurrent(const InstantPage* page) const;
365 242
366 // Recreates |ntp_| using |instant_url|. 243 // Recreates |ntp_| using |instant_url|.
367 void ResetNTP(const std::string& instant_url); 244 void ResetNTP(const std::string& instant_url);
368 245
369 // Reloads a new InstantNTP. Called when |ntp_| is stale.
370 void ReloadStaleNTP();
371
372 // Returns true if we should switch to using the local NTP. 246 // Returns true if we should switch to using the local NTP.
373 bool ShouldSwitchToLocalNTP() const; 247 bool ShouldSwitchToLocalNTP() const;
374 248
375 // Recreates |overlay_| using |instant_url|. |overlay_| will be NULL if
376 // |instant_url| is empty or if there is no active tab.
377 void ResetOverlay(const std::string& instant_url);
378
379 // Returns an enum value indicating the reason to fallback.
380 InstantFallbackReason ShouldSwitchToLocalOverlay() const;
381
382 // If the active tab is an Instant search results page, sets |instant_tab_| to 249 // If the active tab is an Instant search results page, sets |instant_tab_| to
383 // point to it. Else, deletes any existing |instant_tab_|. 250 // point to it. Else, deletes any existing |instant_tab_|.
384 void ResetInstantTab(); 251 void ResetInstantTab();
385 252
386 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. 253 // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab.
387 void UpdateInfoForInstantTab(); 254 void UpdateInfoForInstantTab();
388 255
389 // Returns whether input is in progress, i.e. if the omnibox has focus and the 256 // Returns whether input is in progress, i.e. if the omnibox has focus and the
390 // active tab is in mode SEARCH_SUGGESTIONS. 257 // active tab is in mode SEARCH_SUGGESTIONS.
391 bool IsInputInProgress() const; 258 bool IsInputInProgress() const;
392 259
393 // Hide the overlay. Also sends an onchange event (with blank query) to the
394 // overlay, telling it to clear out results for any old queries.
395 void HideOverlay();
396
397 // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay()
398 // unless you are going to call overlay_.reset() yourself subsequently.
399 void HideInternal();
400
401 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay
402 // with the given |height| in |units|.
403 void ShowOverlay(int height, InstantSizeUnits units);
404
405 // Send the omnibox popup bounds to the page.
406 void SendPopupBoundsToPage();
407
408 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns
409 // true if successful. (Note that |suggestion| may be modified even if this
410 // returns false.)
411 bool FixSuggestion(InstantSuggestion* suggestion) const;
412
413 // Returns true if the local page is being used. 260 // Returns true if the local page is being used.
414 bool UsingLocalPage() const; 261 bool UsingLocalPage() const;
415 262
416 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_|
417 // exists.
418 bool UseTabForSuggestions() const;
419
420 // Populates InstantAutocompleteResult with AutocompleteMatch details.
421 // |autocomplete_match_index| specifies the index of |match| in the
422 // AutocompleteResult. If the |match| is obtained from auto complete
423 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex.
424 void PopulateInstantAutocompleteResultFromMatch(
425 const AutocompleteMatch& match,
426 size_t autocomplete_match_index,
427 InstantAutocompleteResult* result);
428
429 // Returns the InstantService for the browser profile. 263 // Returns the InstantService for the browser profile.
430 InstantService* GetInstantService() const; 264 InstantService* GetInstantService() const;
431 265
432 BrowserInstantController* const browser_; 266 BrowserInstantController* const browser_;
433 267
434 // Whether the extended API and regular API are enabled. If both are false, 268 // Whether the extended API and regular API are enabled. If both are false,
435 // Instant is effectively disabled. 269 // Instant is effectively disabled.
436 const bool extended_enabled_; 270 const bool extended_enabled_;
437 bool instant_enabled_;
438 271
439 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. 272 // The instances of InstantPage maintained by InstantController.
440 bool use_local_page_only_;
441
442 // If true, preload an NTP into |ntp_|.
443 bool preload_ntp_;
444
445 // The state of the overlay page, i.e., the page owned by |overlay_|. Ignored
446 // if |instant_tab_| is in use.
447 InstantOverlayModel model_;
448
449 // The three instances of InstantPage maintained by InstantController as
450 // described above. All three may be non-NULL in extended mode. If
451 // |instant_tab_| is not NULL, then |overlay_| is guaranteed to be hidden and
452 // messages will be sent to |instant_tab_| instead.
453 //
454 // In non-extended mode, only |overlay_| is ever non-NULL.
455 scoped_ptr<InstantOverlay> overlay_;
456 scoped_ptr<InstantNTP> ntp_; 273 scoped_ptr<InstantNTP> ntp_;
457 scoped_ptr<InstantTab> instant_tab_; 274 scoped_ptr<InstantTab> instant_tab_;
458 275
459 // If true, send suggestion-related events (such as user key strokes, auto
460 // complete results, etc.) to |instant_tab_| instead of |overlay_|. Once set
461 // to false, will stay false until the overlay is hidden or committed.
462 bool use_tab_for_suggestions_;
463
464 // The most recent full_text passed to Update(). If empty, we'll not accept
465 // search suggestions from |overlay_| or |instant_tab_|.
466 string16 last_omnibox_text_;
467
468 // The most recent user_text passed to Update(). Used to filter out-of-date
469 // URL suggestions from the Instant page. Set in Update() and cleared when
470 // the page sets temporary text (SetSuggestions() with REPLACE behavior).
471 string16 last_user_text_;
472
473 // True if the last Update() had an inline autocompletion. Used only to make
474 // sure that we don't accidentally suggest gray text suggestion in that case.
475 bool last_omnibox_text_has_inline_autocompletion_;
476
477 // The most recent verbatim passed to Update(). Used only to ensure that we
478 // don't accidentally suggest an inline autocompletion.
479 bool last_verbatim_;
480
481 // The most recent suggestion received from the page, minus any prefix that
482 // the user has typed.
483 InstantSuggestion last_suggestion_;
484
485 // See comments on the getter above.
486 content::PageTransition last_transition_type_;
487
488 // True if the last match passed to Update() was a search (versus a URL).
489 // Used to ensure that the overlay page is committable.
490 bool last_match_was_search_;
491
492 // Omnibox focus state. 276 // Omnibox focus state.
493 OmniboxFocusState omnibox_focus_state_; 277 OmniboxFocusState omnibox_focus_state_;
494 278
495 // The reason for the most recent omnibox focus change. 279 // The reason for the most recent omnibox focus change.
496 OmniboxFocusChangeReason omnibox_focus_change_reason_; 280 OmniboxFocusChangeReason omnibox_focus_change_reason_;
497 281
498 // The search model mode for the active tab. 282 // The search model mode for the active tab.
499 SearchMode search_mode_; 283 SearchMode search_mode_;
500 284
501 // Current omnibox popup bounds.
502 gfx::Rect popup_bounds_;
503
504 // Last popup bounds passed to the page.
505 gfx::Rect last_popup_bounds_;
506
507 // The start-edge margin and width of the omnibox, used by the page to align 285 // The start-edge margin and width of the omnibox, used by the page to align
508 // its suggestions with the omnibox. 286 // its suggestions with the omnibox.
509 gfx::Rect omnibox_bounds_; 287 gfx::Rect omnibox_bounds_;
510 288
511 // Timer used to update the bounds of the omnibox popup.
512 base::OneShotTimer<InstantController> update_bounds_timer_;
513
514 // Search terms extraction (for autocomplete history matches) doesn't work
515 // on Instant URLs. So, whenever the user commits an Instant search, we add
516 // an equivalent non-Instant search URL to history, so that the search shows
517 // up in autocomplete history matches.
518 // TODO(sreeram): Remove when http://crbug.com/155373 is fixed.
519 GURL url_for_history_;
520
521 // The timestamp at which query editing began. This value is used when the
522 // overlay is showed and cleared when the overlay is hidden.
523 base::Time first_interaction_time_;
524
525 // Indicates that the first interaction time has already been logged.
526 bool first_interaction_time_recorded_;
527
528 // Whether to allow the overlay to show search suggestions. In general, the
529 // overlay is allowed to show search suggestions whenever |search_mode_| is
530 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false.
531 bool allow_overlay_to_show_search_suggestions_;
532
533 // List of events and their timestamps, useful in debugging Instant behaviour. 289 // List of events and their timestamps, useful in debugging Instant behaviour.
534 mutable std::list<std::pair<int64, std::string> > debug_events_; 290 mutable std::list<std::pair<int64, std::string> > debug_events_;
535 291
536 DISALLOW_COPY_AND_ASSIGN(InstantController); 292 DISALLOW_COPY_AND_ASSIGN(InstantController);
537 }; 293 };
538 294
539 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ 295 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698