OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/timer.h" | 19 #include "base/timer.h" |
20 #include "chrome/browser/instant/instant_commit_type.h" | 20 #include "chrome/browser/instant/instant_commit_type.h" |
21 #include "chrome/browser/instant/instant_model.h" | 21 #include "chrome/browser/instant/instant_model.h" |
| 22 #include "chrome/browser/instant/instant_page.h" |
22 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 23 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
23 #include "chrome/common/instant_types.h" | 24 #include "chrome/common/instant_types.h" |
24 #include "chrome/common/search_types.h" | 25 #include "chrome/common/search_types.h" |
25 #include "content/public/common/page_transition_types.h" | 26 #include "content/public/common/page_transition_types.h" |
26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
27 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
28 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
29 | 30 |
30 struct AutocompleteMatch; | 31 struct AutocompleteMatch; |
31 class AutocompleteProvider; | 32 class AutocompleteProvider; |
32 class InstantLoader; | 33 class InstantNTP; |
| 34 class InstantOverlay; |
33 class InstantTab; | 35 class InstantTab; |
34 class TemplateURL; | 36 class TemplateURL; |
35 | 37 |
36 namespace chrome { | 38 namespace chrome { |
37 class BrowserInstantController; | 39 class BrowserInstantController; |
38 } | 40 } |
39 | 41 |
40 namespace content { | 42 namespace content { |
41 class WebContents; | 43 class WebContents; |
42 } | 44 } |
43 | 45 |
44 // Macro used for logging debug events. |message| should be a std::string. | 46 // Macro used for logging debug events. |message| should be a std::string. |
45 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 47 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
46 controller->LogDebugEvent(message) | 48 controller->LogDebugEvent(message) |
47 | 49 |
48 // InstantController maintains a WebContents that is intended to give a preview | 50 // InstantController drives Chrome Instant, i.e., the browser implementation of |
49 // of search suggestions and results. InstantController is owned by Browser via | 51 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
50 // BrowserInstantController. | 52 // |
51 class InstantController { | 53 // In extended mode, InstantController maintains and coordinates three |
| 54 // instances of InstantPage: |
| 55 // (1) An InstantOverlay instance that is used to show search suggestions and |
| 56 // results in an overlay over a non-search page. |
| 57 // (2) An InstantNTP instance which is a preloaded sarch page that will be |
| 58 // swapped-in the next time the user navigates to the New Tab Page. It is |
| 59 // never shown to the user in an uncommitted state. |
| 60 // (3) An InstantTab instance which points to the currently active tab, if it |
| 61 // supports the Embedded Search API. |
| 62 // |
| 63 // All three are backed by a WebContents. InstantOverlay and InstantNTP own |
| 64 // their corresponding WebContents; InstantTab does not. In non-extended mode, |
| 65 // only an InstantOverlay instance is kept. |
| 66 // |
| 67 // InstantController is owned by Browser via BrowserInstantController. |
| 68 class InstantController : public InstantPage::Delegate { |
52 public: | 69 public: |
53 // The URL for the local omnibox popup. | 70 // The URL for the local omnibox popup. |
54 static const char* kLocalOmniboxPopupURL; | 71 static const char* kLocalOmniboxPopupURL; |
55 | 72 |
56 // |use_local_preview_only| will force the use of kLocalOmniboxPopupURL as the | 73 // |use_local_preview_only| will force the use of kLocalOmniboxPopupURL as the |
57 // instant URL and is only applicable if |extended_enabled| is true. | 74 // instant URL and is only applicable if |extended_enabled| is true. |
58 InstantController(chrome::BrowserInstantController* browser, | 75 InstantController(chrome::BrowserInstantController* browser, |
59 bool extended_enabled, | 76 bool extended_enabled, |
60 bool use_local_preview_only); | 77 bool use_local_preview_only); |
61 ~InstantController(); | 78 virtual ~InstantController(); |
62 | 79 |
63 // Invoked as the user types into the omnibox. |user_text| is what the user | 80 // Invoked as the user types into the omnibox. |user_text| is what the user |
64 // has typed. |full_text| is what the omnibox is showing. These may differ if | 81 // has typed. |full_text| is what the omnibox is showing. These may differ if |
65 // the user typed only some text, and the rest was inline autocompleted. If | 82 // the user typed only some text, and the rest was inline autocompleted. If |
66 // |verbatim| is true, search results are shown for the exact omnibox text, | 83 // |verbatim| is true, search results are shown for the exact omnibox text, |
67 // rather than the best guess as to what the user means. Returns true if the | 84 // rather than the best guess as to what the user means. Returns true if the |
68 // update is accepted (i.e., if |match| is a search rather than a URL). | 85 // update is accepted (i.e., if |match| is a search rather than a URL). |
69 // |is_keyword_search| is true if keyword searching is in effect. | 86 // |is_keyword_search| is true if keyword searching is in effect. |
70 bool Update(const AutocompleteMatch& match, | 87 bool Update(const AutocompleteMatch& match, |
71 const string16& user_text, | 88 const string16& user_text, |
72 const string16& full_text, | 89 const string16& full_text, |
73 size_t selection_start, | 90 size_t selection_start, |
74 size_t selection_end, | 91 size_t selection_end, |
75 bool verbatim, | 92 bool verbatim, |
76 bool user_input_in_progress, | 93 bool user_input_in_progress, |
77 bool omnibox_popup_is_open, | 94 bool omnibox_popup_is_open, |
78 bool escape_pressed, | 95 bool escape_pressed, |
79 bool is_keyword_search); | 96 bool is_keyword_search); |
80 | 97 |
| 98 // Releases and returns the NTP WebContents. May be NULL. Loads a new |
| 99 // WebContents for the NTP. |
| 100 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
| 101 |
81 // Sets the bounds of the omnibox popup, in screen coordinates. | 102 // Sets the bounds of the omnibox popup, in screen coordinates. |
82 void SetPopupBounds(const gfx::Rect& bounds); | 103 void SetPopupBounds(const gfx::Rect& bounds); |
83 | 104 |
84 // Sets the start and end margins of the omnibox text area. | 105 // Sets the start and end margins of the omnibox text area. |
85 void SetMarginSize(int start, int end); | 106 void SetMarginSize(int start, int end); |
86 | 107 |
87 // Send autocomplete results from |providers| to the preview page. | 108 // Send autocomplete results from |providers| to the preview page. |
88 void HandleAutocompleteResults( | 109 void HandleAutocompleteResults( |
89 const std::vector<AutocompleteProvider*>& providers); | 110 const std::vector<AutocompleteProvider*>& providers); |
90 | 111 |
(...skipping 13 matching lines...) Expand all Loading... |
104 bool CommitIfPossible(InstantCommitType type); | 125 bool CommitIfPossible(InstantCommitType type); |
105 | 126 |
106 // Called to indicate that the omnibox focus state changed with the given | 127 // Called to indicate that the omnibox focus state changed with the given |
107 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to | 128 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
108 // the view gaining focus. | 129 // the view gaining focus. |
109 void OmniboxFocusChanged(OmniboxFocusState focus_state, | 130 void OmniboxFocusChanged(OmniboxFocusState focus_state, |
110 OmniboxFocusChangeReason reason, | 131 OmniboxFocusChangeReason reason, |
111 gfx::NativeView view_gaining_focus); | 132 gfx::NativeView view_gaining_focus); |
112 | 133 |
113 // The search mode in the active tab has changed. Pass the message down to | 134 // The search mode in the active tab has changed. Pass the message down to |
114 // the loader which will notify the renderer. Create |instant_tab_| if the | 135 // the overlay which will notify the renderer. Create |instant_tab_| if the |
115 // |new_mode| reflects an Instant search results page. | 136 // |new_mode| reflects an Instant search results page. |
116 void SearchModeChanged(const chrome::search::Mode& old_mode, | 137 void SearchModeChanged(const chrome::search::Mode& old_mode, |
117 const chrome::search::Mode& new_mode); | 138 const chrome::search::Mode& new_mode); |
118 | 139 |
119 // The user switched tabs. Hide the preview. Create |instant_tab_| if the | 140 // The user switched tabs. Hide the preview. Create |instant_tab_| if the |
120 // newly active tab is an Instant search results page. | 141 // newly active tab is an Instant search results page. |
121 void ActiveTabChanged(); | 142 void ActiveTabChanged(); |
122 | 143 |
123 // The user is about to switch tabs. Commit the preview if needed. | 144 // The user is about to switch tabs. Commit the preview if needed. |
124 void TabDeactivated(content::WebContents* contents); | 145 void TabDeactivated(content::WebContents* contents); |
125 | 146 |
126 // Sets whether Instant should show result previews. | 147 // Sets whether Instant should show result previews. |
127 void SetInstantEnabled(bool instant_enabled); | 148 void SetInstantEnabled(bool instant_enabled); |
128 | 149 |
129 // The theme has changed. Pass the message to the preview page. | 150 // The theme has changed. Pass the message to the preview page. |
130 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | 151 void ThemeChanged(const ThemeBackgroundInfo& theme_info); |
131 | 152 |
132 // The theme area height has changed. Pass the message to the preview page. | 153 // The theme area height has changed. Pass the message to the preview page. |
133 void ThemeAreaHeightChanged(int height); | 154 void ThemeAreaHeightChanged(int height); |
134 | 155 |
135 // Returns the transition type of the last AutocompleteMatch passed to Update. | 156 // Called when someone else swapped in a different contents in the |overlay_|. |
136 content::PageTransition last_transition_type() const { | 157 void SwappedOverlayContents(); |
137 return last_transition_type_; | |
138 } | |
139 | 158 |
140 // Non-const for Add/RemoveObserver only. Other model changes should only | 159 // Called when contents for |overlay_| received focus. |
141 // happen through the InstantController interface. | 160 void FocusedOverlayContents(); |
142 InstantModel* model() { return &model_; } | |
143 | 161 |
144 // Invoked by the page when it has suggested text. | 162 // Called when the |overlay_| might be stale. If it's actually stale, and the |
145 void SetSuggestions(const content::WebContents* contents, | 163 // omnibox doesn't have focus, and the preview isn't showing, the |overlay_| |
146 const std::vector<InstantSuggestion>& suggestions); | 164 // is deleted and recreated. Else the refresh is skipped. |
147 | 165 void ReloadOverlayIfStale(); |
148 // Invoked by the page when its support for the Instant API is determined. | |
149 void InstantSupportDetermined(const content::WebContents* contents, | |
150 bool supports_instant); | |
151 | |
152 // Invoked by InstantLoader to request that the preview be shown. | |
153 void ShowInstantPreview(InstantShownReason reason, | |
154 int height, | |
155 InstantSizeUnits units); | |
156 | |
157 // Invoked by InstantLoader to request the browser to start capturing user key | |
158 // strokes. | |
159 void StartCapturingKeyStrokes(); | |
160 | |
161 // Invoked by InstantLoader to request the browser to stop capturing user key | |
162 // strokes. | |
163 void StopCapturingKeyStrokes(); | |
164 | |
165 // Invoked by InstantLoader when it has swapped a different WebContents into | |
166 // the preview, usually because a prerendered page was navigated to. | |
167 void SwappedWebContents(); | |
168 | |
169 // Invoked by InstantLoader when the preview gains focus, usually due to the | |
170 // user clicking on it. | |
171 void InstantLoaderContentsFocused(); | |
172 | |
173 // Invoked by the InstantLoader when its RenderView crashes. | |
174 void InstantLoaderRenderViewGone(); | |
175 | |
176 // Invoked by InstantLoader when the instant page is about to navigate. | |
177 void InstantLoaderAboutToNavigateMainFrame(const GURL& url); | |
178 | |
179 // Invoked by InstantLoader when it's underlying RenderView is created. | |
180 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | |
181 // the RenderViewHost being created which is not always true. Fix this. | |
182 void InstantLoaderRenderViewCreated(); | |
183 | |
184 // Invoked by the InstantLoader when the instant page wants to navigate to | |
185 // the speicfied URL. | |
186 void NavigateToURL(const GURL& url, content::PageTransition transition); | |
187 | 166 |
188 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that | 167 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that |
189 // |debug_events_| doesn't get too large. | 168 // |debug_events_| doesn't get too large. |
190 void LogDebugEvent(const std::string& info) const; | 169 void LogDebugEvent(const std::string& info) const; |
191 | 170 |
192 // See comments for |debug_events_| below. | 171 // See comments for |debug_events_| below. |
193 const std::list<std::pair<int64, std::string> >& debug_events() { | 172 const std::list<std::pair<int64, std::string> >& debug_events() { |
194 return debug_events_; | 173 return debug_events_; |
195 } | 174 } |
196 | 175 |
| 176 // Returns the transition type of the last AutocompleteMatch passed to Update. |
| 177 content::PageTransition last_transition_type() const { |
| 178 return last_transition_type_; |
| 179 } |
| 180 |
| 181 // Non-const for Add/RemoveObserver only. Other model changes should only |
| 182 // happen through the InstantController interface. |
| 183 InstantModel* model() { return &model_; } |
| 184 |
197 private: | 185 private: |
198 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 186 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
199 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); | 187 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); |
200 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 188 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
201 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 189 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); |
202 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | 190 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
203 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); | 191 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); |
| 192 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); |
| 193 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); |
| 194 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); |
| 195 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
| 196 |
| 197 // Overridden from InstantPage::Delegate: |
| 198 // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
| 199 // the RenderViewHost being created which is not always true. Fix this. |
| 200 virtual void InstantPageRenderViewCreated( |
| 201 const content::WebContents* contents) OVERRIDE; |
| 202 virtual void InstantSupportDetermined( |
| 203 const content::WebContents* contents, |
| 204 bool supports_instant) OVERRIDE; |
| 205 virtual void InstantPageRenderViewGone( |
| 206 const content::WebContents* contents) OVERRIDE; |
| 207 virtual void InstantPageAboutToNavigateMainFrame( |
| 208 const content::WebContents* contents, |
| 209 const GURL& url) OVERRIDE; |
| 210 virtual void SetSuggestions( |
| 211 const content::WebContents* contents, |
| 212 const std::vector<InstantSuggestion>& suggestions) OVERRIDE; |
| 213 virtual void ShowInstantPreview( |
| 214 const content::WebContents* contents, |
| 215 InstantShownReason reason, |
| 216 int height, |
| 217 InstantSizeUnits units) OVERRIDE; |
| 218 virtual void StartCapturingKeyStrokes( |
| 219 const content::WebContents* contents) OVERRIDE; |
| 220 virtual void StopCapturingKeyStrokes(content::WebContents* contents) OVERRIDE; |
| 221 virtual void NavigateToURL( |
| 222 const content::WebContents* contents, |
| 223 const GURL& url, |
| 224 content::PageTransition transition) OVERRIDE; |
204 | 225 |
205 // Helper for OmniboxFocusChanged. Commit or discard the preview. | 226 // Helper for OmniboxFocusChanged. Commit or discard the preview. |
206 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | 227 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
207 | 228 |
208 // Ensures that |loader_| uses the Instant URL returned by GetInstantURL(), | 229 // Creates a new NTP, using the instant_url property of the default |
209 // creating a new loader if necessary. In extended mode, will fallback to | 230 // TemplateURL. |
| 231 void ResetNTP(); |
| 232 |
| 233 // Ensures that |overlay_| uses the Instant URL returned by GetInstantURL(), |
| 234 // creating a new overlay if necessary. In extended mode, will fallback to |
210 // using the kLocalOmniboxPopupURL as the Instant URL in case GetInstantURL() | 235 // using the kLocalOmniboxPopupURL as the Instant URL in case GetInstantURL() |
211 // returns false. Returns true if an Instant URL could be determined. | 236 // returns false. Returns true if an Instant URL could be determined. |
212 // For |ignore_blacklist| look at comments in |GetInstantURL|. | 237 // For |ignore_blacklist| look at comments in |GetInstantURL|. |
213 bool EnsureLoaderIsCurrent(bool ignore_blacklist); | 238 bool EnsureOverlayIsCurrent(bool ignore_blacklist); |
214 | 239 |
215 // Recreates the |loader_| with the input |instant_url|. The caller should | 240 // Recreates the |overlay_| with |instant_url|. Note that |overlay_| is |
216 // ensure that the |loader_| is not already on the stack since it is deleted | 241 // deleted in this call. |
217 // in this call. | 242 void CreateOverlay(const std::string& instant_url, |
218 void CreateLoader(const std::string& instant_url, | 243 const content::WebContents* active_tab); |
219 const content::WebContents* active_tab); | |
220 | 244 |
221 // Called when the |loader_| might be stale. If it's actually stale, and the | 245 // If the |overlay_| being used is in fallback mode, it will be switched back |
222 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is | 246 // to the remote overlay if the overlay is not showing and the omnibox does |
223 // deleted and recreated. Else the refresh is skipped. | 247 // not have focus. |
224 void OnStaleLoader(); | 248 void MaybeSwitchToRemoteOverlay(); |
225 | |
226 // If the |loader_| being used is in fallback mode, it will be switched back | |
227 // to the remote loader if the loader is not showing and the omnibox does not | |
228 // have focus. | |
229 void MaybeSwitchToRemoteLoader(); | |
230 | 249 |
231 // If the active tab is an Instant search results page, sets |instant_tab_| to | 250 // If the active tab is an Instant search results page, sets |instant_tab_| to |
232 // point to it. Else, deletes any existing |instant_tab_|. | 251 // point to it. Else, deletes any existing |instant_tab_|. |
233 void ResetInstantTab(); | 252 void ResetInstantTab(); |
234 | 253 |
235 // Hide the preview. Also sends an onchange event (with blank query) to the | 254 // Hide the preview. Also sends an onchange event (with blank query) to the |
236 // preview, telling it to clear out results for any old queries. | 255 // preview, telling it to clear out results for any old queries. |
237 void HideLoader(); | 256 void HideOverlay(); |
238 | 257 |
239 // Like HideLoader(), but doesn't call OnStaleLoader(). Use HideLoader() | 258 // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay() |
240 // unless you are going to call loader_.reset() yourself subsequently. | 259 // unless you are going to call overlay_.reset() yourself subsequently. |
241 void HideInternal(); | 260 void HideInternal(); |
242 | 261 |
243 // Counterpart to HideLoader(). Asks the |browser_| to display the preview | 262 // Counterpart to HideOverlay(). Asks the |browser_| to display the preview |
244 // with the given |height|. | 263 // with the given |height| in |units|. |
245 void ShowLoader(InstantShownReason reason, | 264 void ShowOverlay(InstantShownReason reason, |
246 int height, | 265 int height, |
247 InstantSizeUnits units); | 266 InstantSizeUnits units); |
248 | 267 |
249 // Send the omnibox popup bounds to the page. | 268 // Send the omnibox popup bounds to the page. |
250 void SendPopupBoundsToPage(); | 269 void SendPopupBoundsToPage(); |
251 | 270 |
252 // Determines the Instant URL based on a number of factors: | 271 // Determines the Instant URL based on a number of factors: |
253 // If |extended_enabled_|: | 272 // If |extended_enabled_|: |
254 // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else | 273 // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else |
255 // - If the Instant URL is specified by command line, returns it, else | 274 // - If the Instant URL is specified by command line, returns it, else |
256 // - If the default Instant URL is present returns it. | 275 // - If the default Instant URL is present returns it. |
257 // If !|extended_enabled_|: | 276 // If !|extended_enabled_|: |
258 // - If the Instant URL is specified by command line, returns it, else | 277 // - If the Instant URL is specified by command line, returns it, else |
259 // - If the default Instant URL is present returns it. | 278 // - If the default Instant URL is present returns it. |
260 // | 279 // |
261 // If |ignore_blacklist| is set to true, Instant URLs are not filtered through | 280 // If |ignore_blacklist| is set to true, Instant URLs are not filtered through |
262 // the blacklist. | 281 // the blacklist. |
263 // | 282 // |
264 // Returns true if a valid Instant URL could be found that is not blacklisted. | 283 // Returns true if a valid Instant URL could be found that is not blacklisted. |
265 bool GetInstantURL(const content::WebContents* active_tab, | 284 bool GetInstantURL(Profile* profile, |
266 bool ignore_blacklist, | 285 bool ignore_blacklist, |
267 std::string* instant_url) const; | 286 std::string* instant_url) const; |
268 | 287 |
| 288 // Adds the URL for the page to the blacklist. Deletes the contents held and |
| 289 // recreates a new page. |
| 290 void BlacklistAndResetOverlay(); |
| 291 void BlacklistAndResetNTP(); |
| 292 |
| 293 // Removes |url| from the blacklist. |
| 294 void RemoveFromBlacklist(const std::string& url); |
| 295 |
| 296 InstantOverlay* overlay() const { return overlay_.get(); } |
| 297 InstantTab* instant_tab() const { return instant_tab_.get(); } |
| 298 InstantNTP* ntp() const { return ntp_.get(); } |
| 299 |
269 chrome::BrowserInstantController* const browser_; | 300 chrome::BrowserInstantController* const browser_; |
270 | 301 |
271 // Whether the extended API and regular API are enabled. If both are false, | 302 // Whether the extended API and regular API are enabled. If both are false, |
272 // Instant is effectively disabled. | 303 // Instant is effectively disabled. |
273 const bool extended_enabled_; | 304 const bool extended_enabled_; |
274 bool instant_enabled_; | 305 bool instant_enabled_; |
275 | 306 |
276 // If true, the instant URL is set to kLocalOmniboxPopupURL. | 307 // If true, the instant URL is set to kLocalOmniboxPopupURL. |
277 const bool use_local_preview_only_; | 308 const bool use_local_preview_only_; |
278 | 309 |
279 // The state of the preview page, i.e., the page owned by |loader_|. Ignored | 310 // The state of the preview page, i.e., the page owned by |overlay_|. Ignored |
280 // if |instant_tab_| is in use. | 311 // if |instant_tab_| is in use. |
281 InstantModel model_; | 312 InstantModel model_; |
282 | 313 |
283 // The preview WebContents. | 314 // The three instances of InstantPage maintained by InstantController as |
284 scoped_ptr<InstantLoader> loader_; | 315 // described above. All three may be non-NULL in extended mode. If |
285 | 316 // |instant_tab_| is not NULL, then |overlay_| is guaranteed to be hidden and |
286 // A committed WebContents that supports Instant. If non-NULL, the |loader_| | 317 // messages will be sent to |instant_tab_| instead. |
287 // is guaranteed to be hidden and messages will be sent to this instead. | 318 // |
| 319 // In non-extended mode, only |overlay_| is ever non-NULL. |
| 320 scoped_ptr<InstantOverlay> overlay_; |
| 321 scoped_ptr<InstantNTP> ntp_; |
288 scoped_ptr<InstantTab> instant_tab_; | 322 scoped_ptr<InstantTab> instant_tab_; |
289 | 323 |
290 // The most recent full_text passed to Update(). If empty, we'll not accept | 324 // The most recent full_text passed to Update(). If empty, we'll not accept |
291 // search suggestions from |loader_| or |instant_tab_|. | 325 // search suggestions from |overlay_| or |instant_tab_|. |
292 string16 last_omnibox_text_; | 326 string16 last_omnibox_text_; |
293 | 327 |
294 // True if the last Update() had an inline autocompletion. Used only to make | 328 // True if the last Update() had an inline autocompletion. Used only to make |
295 // sure that we don't accidentally suggest gray text suggestion in that case. | 329 // sure that we don't accidentally suggest gray text suggestion in that case. |
296 bool last_omnibox_text_has_inline_autocompletion_; | 330 bool last_omnibox_text_has_inline_autocompletion_; |
297 | 331 |
298 // The most recent verbatim passed to Update(). Used only to ensure that we | 332 // The most recent verbatim passed to Update(). Used only to ensure that we |
299 // don't accidentally suggest an inline autocompletion. | 333 // don't accidentally suggest an inline autocompletion. |
300 bool last_verbatim_; | 334 bool last_verbatim_; |
301 | 335 |
(...skipping 22 matching lines...) Expand all Loading... |
324 | 358 |
325 // Size of the start-edge omnibox text area margin. | 359 // Size of the start-edge omnibox text area margin. |
326 int start_margin_; | 360 int start_margin_; |
327 | 361 |
328 // Size of the end-edge omnibox text area margin. | 362 // Size of the end-edge omnibox text area margin. |
329 int end_margin_; | 363 int end_margin_; |
330 | 364 |
331 // Timer used to update the bounds of the omnibox popup. | 365 // Timer used to update the bounds of the omnibox popup. |
332 base::OneShotTimer<InstantController> update_bounds_timer_; | 366 base::OneShotTimer<InstantController> update_bounds_timer_; |
333 | 367 |
334 // Timer used to ensure that the Instant page does not get too stale. | |
335 base::OneShotTimer<InstantController> stale_loader_timer_; | |
336 | |
337 // For each key K => value N, the map says that we found that the search | 368 // For each key K => value N, the map says that we found that the search |
338 // engine identified by Instant URL K didn't support the Instant API, or | 369 // engine identified by Instant URL K didn't support the Instant API, or |
339 // caused RenderView crashes in each of the last N times that we loaded it. | 370 // caused RenderView crashes in each of the last N times that we loaded it. |
340 // If an Instant URL isn't present in the map at all or has a value 0, | 371 // If an Instant URL isn't present in the map at all or has a value 0, |
341 // it means that search engine supports the Instant API (or we assume it does, | 372 // it means that search engine supports the Instant API (or we assume it does, |
342 // since we haven't determined it doesn't) and it did not cause a crash. | 373 // since we haven't determined it doesn't) and it did not cause a crash. |
343 std::map<std::string, int> blacklisted_urls_; | 374 std::map<std::string, int> blacklisted_urls_; |
344 | 375 |
345 // Search terms extraction (for autocomplete history matches) doesn't work | 376 // Search terms extraction (for autocomplete history matches) doesn't work |
346 // on Instant URLs. So, whenever the user commits an Instant search, we add | 377 // on Instant URLs. So, whenever the user commits an Instant search, we add |
(...skipping 11 matching lines...) Expand all Loading... |
358 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 389 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
359 bool allow_preview_to_show_search_suggestions_; | 390 bool allow_preview_to_show_search_suggestions_; |
360 | 391 |
361 // List of events and their timestamps, useful in debugging Instant behaviour. | 392 // List of events and their timestamps, useful in debugging Instant behaviour. |
362 mutable std::list<std::pair<int64, std::string> > debug_events_; | 393 mutable std::list<std::pair<int64, std::string> > debug_events_; |
363 | 394 |
364 DISALLOW_COPY_AND_ASSIGN(InstantController); | 395 DISALLOW_COPY_AND_ASSIGN(InstantController); |
365 }; | 396 }; |
366 | 397 |
367 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 398 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
OLD | NEW |