Chromium Code Reviews| 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_SEARCH_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | |
| 12 #include "chrome/browser/ui/search/search_model.h" | 13 #include "chrome/browser/ui/search/search_model.h" |
| 13 #include "chrome/common/instant_types.h" | 14 #include "chrome/common/instant_types.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 class WebContents; | 21 class WebContents; |
| 21 } | 22 } |
| 22 | 23 |
| 24 class InstantPageTest; | |
| 25 | |
| 23 // Per-tab search "helper". Acts as the owner and controller of the tab's | 26 // Per-tab search "helper". Acts as the owner and controller of the tab's |
| 24 // search UI model. | 27 // search UI model. |
|
samarth
2013/06/19 05:25:02
I think this could a top-level comment of how inst
kmadhusu
2013/06/19 16:28:15
Done.
| |
| 25 class SearchTabHelper : public content::NotificationObserver, | 28 class SearchTabHelper : public content::NotificationObserver, |
| 26 public content::WebContentsObserver, | 29 public content::WebContentsObserver, |
| 27 public content::WebContentsUserData<SearchTabHelper> { | 30 public content::WebContentsUserData<SearchTabHelper> { |
| 28 public: | 31 public: |
| 29 virtual ~SearchTabHelper(); | 32 virtual ~SearchTabHelper(); |
| 30 | 33 |
| 31 SearchModel* model() { | 34 SearchModel* model() { |
| 32 return &model_; | 35 return &model_; |
| 33 } | 36 } |
| 34 | 37 |
| 35 // Invoked when the OmniboxEditModel changes state in some way that might | 38 // Invoked when the OmniboxEditModel changes state in some way that might |
| 36 // affect the search mode. | 39 // affect the search mode. |
| 37 void OmniboxEditModelChanged(bool user_input_in_progress, | 40 void OmniboxEditModelChanged(bool user_input_in_progress, |
| 38 bool cancelling, | 41 bool cancelling, |
| 39 bool popup_is_open, | 42 bool popup_is_open, |
| 40 bool user_text_is_empty); | 43 bool user_text_is_empty); |
| 41 | 44 |
| 42 // Invoked when the active navigation entry is updated in some way that might | 45 // Invoked when the active navigation entry is updated in some way that might |
| 43 // affect the search mode. This is used by Instant when it "fixes up" the | 46 // affect the search mode. This is used by Instant when it "fixes up" the |
| 44 // virtual URL of the active entry. Regular navigations are captured through | 47 // virtual URL of the active entry. Regular navigations are captured through |
| 45 // the notification system and shouldn't call this method. | 48 // the notification system and shouldn't call this method. |
| 46 void NavigationEntryUpdated(); | 49 void NavigationEntryUpdated(); |
| 47 | 50 |
| 48 // Updates |last_known_most_visited_items_| with |items|. | 51 // Updates |last_known_most_visited_items_| with |items|. |
| 49 // Returns false if |items| matches the |last_known_most_visited_items_|. | 52 // Returns false if |items| matches the |last_known_most_visited_items_|. |
| 50 bool UpdateLastKnownMostVisitedItems( | 53 bool UpdateLastKnownMostVisitedItems( |
| 51 const std::vector<InstantMostVisitedItem>& items); | 54 const std::vector<InstantMostVisitedItem>& items); |
| 52 | 55 |
| 56 // Invoked to update the instant support state. | |
| 57 void InstantSupportChanged(bool supports_instant); | |
| 58 | |
| 59 // Returns true if the page supports instant. If the instant support state is | |
| 60 // not determined or if the page does not support instant returns false. | |
| 61 bool SupportsInstant() const; | |
| 62 | |
| 53 private: | 63 private: |
| 54 friend class content::WebContentsUserData<SearchTabHelper>; | 64 friend class content::WebContentsUserData<SearchTabHelper>; |
| 65 friend class InstantPageTest; | |
| 66 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | |
| 67 DetermineIfPageSupportsInstant_Local); | |
| 68 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | |
| 69 DetermineIfPageSupportsInstant_NonLocal); | |
| 70 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | |
| 71 PageURLDoesntBelongToInstantRenderer); | |
| 72 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, PageSupportsInstant); | |
| 55 | 73 |
| 56 explicit SearchTabHelper(content::WebContents* web_contents); | 74 explicit SearchTabHelper(content::WebContents* web_contents); |
| 57 | 75 |
| 58 // Overridden from content::NotificationObserver: | 76 // Overridden from content::NotificationObserver: |
| 59 virtual void Observe(int type, | 77 virtual void Observe(int type, |
| 60 const content::NotificationSource& source, | 78 const content::NotificationSource& source, |
| 61 const content::NotificationDetails& details) OVERRIDE; | 79 const content::NotificationDetails& details) OVERRIDE; |
| 62 | 80 |
| 63 // Overridden from contents::WebContentsObserver: | 81 // Overridden from contents::WebContentsObserver: |
| 64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 83 virtual void DidFinishLoad( | |
| 84 int64 frame_id, | |
| 85 const GURL& validated_url, | |
| 86 bool is_main_frame, | |
| 87 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 65 | 88 |
| 66 // Sets the mode of the model based on the current URL of web_contents(). | 89 // Sets the mode of the model based on the current URL of web_contents(). |
| 67 void UpdateMode(); | 90 void UpdateMode(); |
| 68 | 91 |
| 92 // Tells the renderer to determine if the page supports the Instant API, which | |
| 93 // results in a call to OnInstantSupportDetermined() when the reply | |
| 94 // is received. | |
| 95 void DetermineIfPageSupportsInstant(); | |
| 96 | |
| 97 // Handler for when Instant support has been determined. | |
| 98 void OnInstantSupportDetermined(int page_id, bool supports_instant); | |
| 99 | |
| 69 // Handlers for SearchBox API to show and hide top bars (bookmark and info | 100 // Handlers for SearchBox API to show and hide top bars (bookmark and info |
| 70 // bars). | 101 // bars). |
| 71 void OnSearchBoxShowBars(int page_id); | 102 void OnSearchBoxShowBars(int page_id); |
| 72 void OnSearchBoxHideBars(int page_id); | 103 void OnSearchBoxHideBars(int page_id); |
| 73 | 104 |
| 74 const bool is_search_enabled_; | 105 const bool is_search_enabled_; |
| 75 | 106 |
| 76 // Tracks the last value passed to OmniboxEditModelChanged(). | 107 // Tracks the last value passed to OmniboxEditModelChanged(). |
| 77 bool user_input_in_progress_; | 108 bool user_input_in_progress_; |
| 78 bool popup_is_open_; | 109 bool popup_is_open_; |
| 79 bool user_text_is_empty_; | 110 bool user_text_is_empty_; |
| 80 | 111 |
| 81 // Model object for UI that cares about search state. | 112 // Model object for UI that cares about search state. |
| 82 SearchModel model_; | 113 SearchModel model_; |
| 83 | 114 |
| 84 content::NotificationRegistrar registrar_; | 115 content::NotificationRegistrar registrar_; |
| 85 | 116 |
| 86 content::WebContents* web_contents_; | 117 content::WebContents* web_contents_; |
| 87 | 118 |
| 88 // Tracks the last set of most visited items sent to the InstantPage renderer. | 119 // Tracks the last set of most visited items sent to the InstantPage renderer. |
| 89 // Used to prevent sending duplicate IPC messages to the renderer. | 120 // Used to prevent sending duplicate IPC messages to the renderer. |
| 90 std::vector<InstantMostVisitedItem> last_known_most_visited_items_; | 121 std::vector<InstantMostVisitedItem> last_known_most_visited_items_; |
| 91 | 122 |
| 92 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); | 123 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); |
| 93 }; | 124 }; |
| 94 | 125 |
| 95 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ | 126 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ |
| OLD | NEW |