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