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