OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/timer.h" | 18 #include "base/timer.h" |
19 #include "chrome/browser/history/history_types.h" | |
20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
21 #include "chrome/browser/ui/search/instant_commit_type.h" | 20 #include "chrome/browser/ui/search/instant_commit_type.h" |
22 #include "chrome/browser/ui/search/instant_overlay_model.h" | 21 #include "chrome/browser/ui/search/instant_overlay_model.h" |
23 #include "chrome/browser/ui/search/instant_page.h" | 22 #include "chrome/browser/ui/search/instant_page.h" |
24 #include "chrome/common/instant_types.h" | 23 #include "chrome/common/instant_types.h" |
25 #include "chrome/common/omnibox_focus_state.h" | 24 #include "chrome/common/omnibox_focus_state.h" |
26 #include "chrome/common/search_types.h" | 25 #include "chrome/common/search_types.h" |
27 #include "content/public/browser/notification_observer.h" | |
28 #include "content/public/browser/notification_registrar.h" | |
29 #include "content/public/common/page_transition_types.h" | 26 #include "content/public/common/page_transition_types.h" |
30 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
31 #include "ui/base/window_open_disposition.h" | 28 #include "ui/base/window_open_disposition.h" |
32 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
33 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
34 | 31 |
35 struct AutocompleteMatch; | 32 struct AutocompleteMatch; |
36 struct InstantAutocompleteResult; | 33 struct InstantAutocompleteResult; |
37 | 34 |
38 class AutocompleteProvider; | 35 class AutocompleteProvider; |
(...skipping 23 matching lines...) Expand all Loading... |
62 // swapped-in the next time the user navigates to the New Tab Page. It is | 59 // swapped-in the next time the user navigates to the New Tab Page. It is |
63 // never shown to the user in an uncommitted state. | 60 // never shown to the user in an uncommitted state. |
64 // (3) An InstantTab instance which points to the currently active tab, if it | 61 // (3) An InstantTab instance which points to the currently active tab, if it |
65 // supports the Embedded Search API. | 62 // supports the Embedded Search API. |
66 // | 63 // |
67 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 64 // All three are backed by a WebContents. InstantOverlay and InstantNTP own |
68 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 65 // their corresponding WebContents; InstantTab does not. In non-extended mode, |
69 // only an InstantOverlay instance is kept. | 66 // only an InstantOverlay instance is kept. |
70 // | 67 // |
71 // InstantController is owned by Browser via BrowserInstantController. | 68 // InstantController is owned by Browser via BrowserInstantController. |
72 class InstantController : public InstantPage::Delegate, | 69 class InstantController : public InstantPage::Delegate { |
73 public content::NotificationObserver { | |
74 public: | 70 public: |
75 InstantController(BrowserInstantController* browser, | 71 InstantController(BrowserInstantController* browser, |
76 bool extended_enabled); | 72 bool extended_enabled); |
77 virtual ~InstantController(); | 73 virtual ~InstantController(); |
78 | 74 |
79 // Called when the Autocomplete flow is about to start. Sets up the | 75 // Called when the Autocomplete flow is about to start. Sets up the |
80 // appropriate page to send user updates to. May reset |instant_tab_| or | 76 // appropriate page to send user updates to. May reset |instant_tab_| or |
81 // switch to a local fallback |overlay_| as necessary. | 77 // switch to a local fallback |overlay_| as necessary. |
82 void OnAutocompleteStart(); | 78 void OnAutocompleteStart(); |
83 | 79 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 202 |
207 // Returns the transition type of the last AutocompleteMatch passed to Update. | 203 // Returns the transition type of the last AutocompleteMatch passed to Update. |
208 content::PageTransition last_transition_type() const { | 204 content::PageTransition last_transition_type() const { |
209 return last_transition_type_; | 205 return last_transition_type_; |
210 } | 206 } |
211 | 207 |
212 // Non-const for Add/RemoveObserver only. Other model changes should only | 208 // Non-const for Add/RemoveObserver only. Other model changes should only |
213 // happen through the InstantController interface. | 209 // happen through the InstantController interface. |
214 InstantOverlayModel* model() { return &model_; } | 210 InstantOverlayModel* model() { return &model_; } |
215 | 211 |
| 212 // Sends a collection of MostVisitedItems to the renderer process via |
| 213 // the appropriate InstantPage subclass. |
| 214 void SendMostVisitedItems( |
| 215 const std::vector<InstantMostVisitedItemIDPair>& items); |
| 216 |
216 private: | 217 private: |
217 friend class InstantTestBase; | 218 friend class InstantTestBase; |
218 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 219 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
219 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UsesOverlayIfTabNotReady); | 220 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UsesOverlayIfTabNotReady); |
220 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 221 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
221 SearchQueryNotDisplayedForNavsuggest); | 222 SearchQueryNotDisplayedForNavsuggest); |
222 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); | 223 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); |
223 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 224 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
224 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); | 225 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); |
225 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefreshDifferentOrder); | 226 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefreshDifferentOrder); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged); | 261 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged); |
261 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchProviderForLocalNTP); | 262 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchProviderForLocalNTP); |
262 FRIEND_TEST_ALL_PREFIXES( | 263 FRIEND_TEST_ALL_PREFIXES( |
263 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure); | 264 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure); |
264 | 265 |
265 Profile* profile() const; | 266 Profile* profile() const; |
266 InstantOverlay* overlay() const; | 267 InstantOverlay* overlay() const; |
267 InstantTab* instant_tab() const; | 268 InstantTab* instant_tab() const; |
268 InstantNTP* ntp() const; | 269 InstantNTP* ntp() const; |
269 | 270 |
270 // Overridden from content::NotificationObserver: | |
271 virtual void Observe(int type, | |
272 const content::NotificationSource& source, | |
273 const content::NotificationDetails& details) OVERRIDE; | |
274 | |
275 // Overridden from InstantPage::Delegate: | 271 // Overridden from InstantPage::Delegate: |
276 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | 272 // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
277 // the RenderViewHost being created which is not always true. Fix this. | 273 // the RenderViewHost being created which is not always true. Fix this. |
278 virtual void InstantPageRenderViewCreated( | 274 virtual void InstantPageRenderViewCreated( |
279 const content::WebContents* contents) OVERRIDE; | 275 const content::WebContents* contents) OVERRIDE; |
280 virtual void InstantSupportDetermined( | 276 virtual void InstantSupportDetermined( |
281 const content::WebContents* contents, | 277 const content::WebContents* contents, |
282 bool supports_instant) OVERRIDE; | 278 bool supports_instant) OVERRIDE; |
283 virtual void InstantPageRenderViewGone( | 279 virtual void InstantPageRenderViewGone( |
284 const content::WebContents* contents) OVERRIDE; | 280 const content::WebContents* contents) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
296 OmniboxFocusState state) OVERRIDE; | 292 OmniboxFocusState state) OVERRIDE; |
297 virtual void NavigateToURL( | 293 virtual void NavigateToURL( |
298 const content::WebContents* contents, | 294 const content::WebContents* contents, |
299 const GURL& url, | 295 const GURL& url, |
300 content::PageTransition transition, | 296 content::PageTransition transition, |
301 WindowOpenDisposition disposition) OVERRIDE; | 297 WindowOpenDisposition disposition) OVERRIDE; |
302 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 298 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
303 | 299 |
304 // Invoked by the InstantLoader when the Instant page wants to delete a | 300 // Invoked by the InstantLoader when the Instant page wants to delete a |
305 // Most Visited item. | 301 // Most Visited item. |
306 virtual void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id) | 302 virtual void DeleteMostVisitedItem(const GURL& item_url) OVERRIDE; |
307 OVERRIDE; | |
308 | 303 |
309 // Invoked by the InstantLoader when the Instant page wants to undo a | 304 // Invoked by the InstantLoader when the Instant page wants to undo a |
310 // Most Visited deletion. | 305 // Most Visited deletion. |
311 virtual void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id) | 306 virtual void UndoMostVisitedDeletion(const GURL& most_visited_item_url) |
312 OVERRIDE; | 307 OVERRIDE; |
313 | 308 |
314 // Invoked by the InstantLoader when the Instant page wants to undo all | 309 // Invoked by the InstantLoader when the Instant page wants to undo all |
315 // Most Visited deletions. | 310 // Most Visited deletions. |
316 virtual void UndoAllMostVisitedDeletions() OVERRIDE; | 311 virtual void UndoAllMostVisitedDeletions() OVERRIDE; |
317 | 312 |
318 // Helper function to navigate the given contents to the local fallback | 313 // Helper function to navigate the given contents to the local fallback |
319 // Instant URL and trim the history correctly. | 314 // Instant URL and trim the history correctly. |
320 void RedirectToLocalNTP(content::WebContents* contents); | 315 void RedirectToLocalNTP(content::WebContents* contents); |
321 | 316 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // unless you are going to call overlay_.reset() yourself subsequently. | 364 // unless you are going to call overlay_.reset() yourself subsequently. |
370 void HideInternal(); | 365 void HideInternal(); |
371 | 366 |
372 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay | 367 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay |
373 // with the given |height| in |units|. | 368 // with the given |height| in |units|. |
374 void ShowOverlay(int height, InstantSizeUnits units); | 369 void ShowOverlay(int height, InstantSizeUnits units); |
375 | 370 |
376 // Send the omnibox popup bounds to the page. | 371 // Send the omnibox popup bounds to the page. |
377 void SendPopupBoundsToPage(); | 372 void SendPopupBoundsToPage(); |
378 | 373 |
379 // Begin listening to change notifications from TopSites and fire off an | 374 // Gets the Most Visited items info from InstantService and forwards them to |
380 // initial request for most visited items. | 375 // the Instant page renderer. |
381 void StartListeningToMostVisitedChanges(); | 376 void UpdateMostVisitedItemsInfo(); |
382 | |
383 // Fire off an async request for most visited items to the TopNav code. | |
384 void RequestMostVisitedItems(); | |
385 | |
386 // Called when we get new most visited items from the TopNav code, | |
387 // registered as an async callback. Parses them and sends them to the | |
388 // renderer via SendMostVisitedItems. | |
389 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | |
390 | |
391 // Sends a collection of MostVisitedItems to the renderer process via | |
392 // the appropriate InstantPage subclass. | |
393 void SendMostVisitedItems( | |
394 const std::vector<InstantMostVisitedItemIDPair>& items); | |
395 | 377 |
396 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns | 378 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns |
397 // true if successful. (Note that |suggestion| may be modified even if this | 379 // true if successful. (Note that |suggestion| may be modified even if this |
398 // returns false.) | 380 // returns false.) |
399 bool FixSuggestion(InstantSuggestion* suggestion) const; | 381 bool FixSuggestion(InstantSuggestion* suggestion) const; |
400 | 382 |
401 // Returns true if the local page is being used. | 383 // Returns true if the local page is being used. |
402 bool UsingLocalPage() const; | 384 bool UsingLocalPage() const; |
403 | 385 |
404 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| | 386 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 base::Time first_interaction_time_; | 487 base::Time first_interaction_time_; |
506 | 488 |
507 // Whether to allow the overlay to show search suggestions. In general, the | 489 // Whether to allow the overlay to show search suggestions. In general, the |
508 // overlay is allowed to show search suggestions whenever |search_mode_| is | 490 // overlay is allowed to show search suggestions whenever |search_mode_| is |
509 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 491 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
510 bool allow_overlay_to_show_search_suggestions_; | 492 bool allow_overlay_to_show_search_suggestions_; |
511 | 493 |
512 // List of events and their timestamps, useful in debugging Instant behaviour. | 494 // List of events and their timestamps, useful in debugging Instant behaviour. |
513 mutable std::list<std::pair<int64, std::string> > debug_events_; | 495 mutable std::list<std::pair<int64, std::string> > debug_events_; |
514 | 496 |
515 // Used for Top Sites async retrieval. | |
516 base::WeakPtrFactory<InstantController> weak_ptr_factory_; | |
517 | |
518 // Used to get notifications about Most Visted changes. | |
519 content::NotificationRegistrar registrar_; | |
520 | |
521 DISALLOW_COPY_AND_ASSIGN(InstantController); | 497 DISALLOW_COPY_AND_ASSIGN(InstantController); |
522 }; | 498 }; |
523 | 499 |
524 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 500 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
OLD | NEW |