| 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 // For reporting fallbacks to local overlay. | 71 // For reporting fallbacks to local overlay. |
| 76 enum InstantFallbackReason { | 72 enum InstantFallbackReason { |
| 77 INSTANT_FALLBACK_NONE = 0, | 73 INSTANT_FALLBACK_NONE = 0, |
| 78 INSTANT_FALLBACK_UNKNOWN = 1, | 74 INSTANT_FALLBACK_UNKNOWN = 1, |
| 79 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, | 75 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, |
| 80 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, | 76 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, |
| 81 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, | 77 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, |
| 82 INSTANT_FALLBACK_NO_OVERLAY = 5, | 78 INSTANT_FALLBACK_NO_OVERLAY = 5, |
| 83 INSTANT_FALLBACK_MAX = 6, | 79 INSTANT_FALLBACK_MAX = 6, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 221 |
| 226 // Returns the transition type of the last AutocompleteMatch passed to Update. | 222 // Returns the transition type of the last AutocompleteMatch passed to Update. |
| 227 content::PageTransition last_transition_type() const { | 223 content::PageTransition last_transition_type() const { |
| 228 return last_transition_type_; | 224 return last_transition_type_; |
| 229 } | 225 } |
| 230 | 226 |
| 231 // Non-const for Add/RemoveObserver only. Other model changes should only | 227 // Non-const for Add/RemoveObserver only. Other model changes should only |
| 232 // happen through the InstantController interface. | 228 // happen through the InstantController interface. |
| 233 InstantOverlayModel* model() { return &model_; } | 229 InstantOverlayModel* model() { return &model_; } |
| 234 | 230 |
| 231 // Gets the Most Visited items info from InstantService and forwards them to |
| 232 // the Instant page renderer via the appropriate InstantPage subclass. |
| 233 void UpdateMostVisitedItems(); |
| 234 |
| 235 protected: | 235 protected: |
| 236 // Accessors are made protected for testing purposes. | 236 // Accessors are made protected for testing purposes. |
| 237 virtual bool extended_enabled() const; | 237 virtual bool extended_enabled() const; |
| 238 | 238 |
| 239 virtual InstantOverlay* overlay() const; | 239 virtual InstantOverlay* overlay() const; |
| 240 virtual InstantTab* instant_tab() const; | 240 virtual InstantTab* instant_tab() const; |
| 241 virtual InstantNTP* ntp() const; | 241 virtual InstantNTP* ntp() const; |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 friend class InstantTestBase; | 244 friend class InstantTestBase; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 294 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 295 ReloadSearchAfterBackReloadsCorrectQuery); | 295 ReloadSearchAfterBackReloadsCorrectQuery); |
| 296 FRIEND_TEST_ALL_PREFIXES( | 296 FRIEND_TEST_ALL_PREFIXES( |
| 297 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure); | 297 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure); |
| 298 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, LogDropdownShown); | 298 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, LogDropdownShown); |
| 299 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 299 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 300 OverlayDoesNotEchoSearchProviderNAVSUGGEST); | 300 OverlayDoesNotEchoSearchProviderNAVSUGGEST); |
| 301 | 301 |
| 302 Profile* profile() const; | 302 Profile* profile() const; |
| 303 | 303 |
| 304 // Overridden from content::NotificationObserver: | |
| 305 virtual void Observe(int type, | |
| 306 const content::NotificationSource& source, | |
| 307 const content::NotificationDetails& details) OVERRIDE; | |
| 308 | |
| 309 // Overridden from InstantPage::Delegate: | 304 // Overridden from InstantPage::Delegate: |
| 310 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | 305 // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
| 311 // the RenderViewHost being created which is not always true. Fix this. | 306 // the RenderViewHost being created which is not always true. Fix this. |
| 312 virtual void InstantPageRenderViewCreated( | 307 virtual void InstantPageRenderViewCreated( |
| 313 const content::WebContents* contents) OVERRIDE; | 308 const content::WebContents* contents) OVERRIDE; |
| 314 virtual void InstantSupportDetermined( | 309 virtual void InstantSupportDetermined( |
| 315 const content::WebContents* contents, | 310 const content::WebContents* contents, |
| 316 bool supports_instant) OVERRIDE; | 311 bool supports_instant) OVERRIDE; |
| 317 virtual void InstantPageRenderViewGone( | 312 virtual void InstantPageRenderViewGone( |
| 318 const content::WebContents* contents) OVERRIDE; | 313 const content::WebContents* contents) OVERRIDE; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 332 virtual void NavigateToURL( | 327 virtual void NavigateToURL( |
| 333 const content::WebContents* contents, | 328 const content::WebContents* contents, |
| 334 const GURL& url, | 329 const GURL& url, |
| 335 content::PageTransition transition, | 330 content::PageTransition transition, |
| 336 WindowOpenDisposition disposition, | 331 WindowOpenDisposition disposition, |
| 337 bool is_search_type) OVERRIDE; | 332 bool is_search_type) OVERRIDE; |
| 338 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 333 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
| 339 | 334 |
| 340 // Invoked by the InstantLoader when the Instant page wants to delete a | 335 // Invoked by the InstantLoader when the Instant page wants to delete a |
| 341 // Most Visited item. | 336 // Most Visited item. |
| 342 virtual void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id) | 337 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; |
| 343 OVERRIDE; | |
| 344 | 338 |
| 345 // Invoked by the InstantLoader when the Instant page wants to undo a | 339 // Invoked by the InstantLoader when the Instant page wants to undo a |
| 346 // Most Visited deletion. | 340 // Most Visited deletion. |
| 347 virtual void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id) | 341 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; |
| 348 OVERRIDE; | |
| 349 | 342 |
| 350 // Invoked by the InstantLoader when the Instant page wants to undo all | 343 // Invoked by the InstantLoader when the Instant page wants to undo all |
| 351 // Most Visited deletions. | 344 // Most Visited deletions. |
| 352 virtual void UndoAllMostVisitedDeletions() OVERRIDE; | 345 virtual void UndoAllMostVisitedDeletions() OVERRIDE; |
| 353 | 346 |
| 354 // Helper function to navigate the given contents to the local fallback | 347 // Helper function to navigate the given contents to the local fallback |
| 355 // Instant URL and trim the history correctly. | 348 // Instant URL and trim the history correctly. |
| 356 void RedirectToLocalNTP(content::WebContents* contents); | 349 void RedirectToLocalNTP(content::WebContents* contents); |
| 357 | 350 |
| 358 // Helper for OmniboxFocusChanged. Commit or discard the overlay. | 351 // Helper for OmniboxFocusChanged. Commit or discard the overlay. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // unless you are going to call overlay_.reset() yourself subsequently. | 390 // unless you are going to call overlay_.reset() yourself subsequently. |
| 398 void HideInternal(); | 391 void HideInternal(); |
| 399 | 392 |
| 400 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay | 393 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay |
| 401 // with the given |height| in |units|. | 394 // with the given |height| in |units|. |
| 402 void ShowOverlay(int height, InstantSizeUnits units); | 395 void ShowOverlay(int height, InstantSizeUnits units); |
| 403 | 396 |
| 404 // Send the omnibox popup bounds to the page. | 397 // Send the omnibox popup bounds to the page. |
| 405 void SendPopupBoundsToPage(); | 398 void SendPopupBoundsToPage(); |
| 406 | 399 |
| 407 // Begin listening to change notifications from TopSites and fire off an | |
| 408 // initial request for most visited items. | |
| 409 void StartListeningToMostVisitedChanges(); | |
| 410 | 400 |
| 411 // Fire off an async request for most visited items to the TopNav code. | |
| 412 void RequestMostVisitedItems(); | |
| 413 | |
| 414 // Called when we get new most visited items from the TopNav code, | |
| 415 // registered as an async callback. Parses them and sends them to the | |
| 416 // renderer via SendMostVisitedItems. | |
| 417 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | |
| 418 | |
| 419 // Sends a collection of MostVisitedItems to the renderer process via | |
| 420 // the appropriate InstantPage subclass. | |
| 421 void SendMostVisitedItems( | |
| 422 const std::vector<InstantMostVisitedItemIDPair>& items); | |
| 423 | 401 |
| 424 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns | 402 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns |
| 425 // true if successful. (Note that |suggestion| may be modified even if this | 403 // true if successful. (Note that |suggestion| may be modified even if this |
| 426 // returns false.) | 404 // returns false.) |
| 427 bool FixSuggestion(InstantSuggestion* suggestion) const; | 405 bool FixSuggestion(InstantSuggestion* suggestion) const; |
| 428 | 406 |
| 429 // Returns true if the local page is being used. | 407 // Returns true if the local page is being used. |
| 430 bool UsingLocalPage() const; | 408 bool UsingLocalPage() const; |
| 431 | 409 |
| 432 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| | 410 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 bool first_interaction_time_recorded_; | 517 bool first_interaction_time_recorded_; |
| 540 | 518 |
| 541 // Whether to allow the overlay to show search suggestions. In general, the | 519 // Whether to allow the overlay to show search suggestions. In general, the |
| 542 // overlay is allowed to show search suggestions whenever |search_mode_| is | 520 // overlay is allowed to show search suggestions whenever |search_mode_| is |
| 543 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 521 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
| 544 bool allow_overlay_to_show_search_suggestions_; | 522 bool allow_overlay_to_show_search_suggestions_; |
| 545 | 523 |
| 546 // List of events and their timestamps, useful in debugging Instant behaviour. | 524 // List of events and their timestamps, useful in debugging Instant behaviour. |
| 547 mutable std::list<std::pair<int64, std::string> > debug_events_; | 525 mutable std::list<std::pair<int64, std::string> > debug_events_; |
| 548 | 526 |
| 549 // Used for Top Sites async retrieval. | |
| 550 base::WeakPtrFactory<InstantController> weak_ptr_factory_; | |
| 551 | |
| 552 // Used to get notifications about Most Visted changes. | |
| 553 content::NotificationRegistrar registrar_; | |
| 554 | |
| 555 DISALLOW_COPY_AND_ASSIGN(InstantController); | 527 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 556 }; | 528 }; |
| 557 | 529 |
| 558 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 530 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| OLD | NEW |