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