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 "chrome/browser/ui/search/search_model.h" | 10 #include "chrome/browser/ui/search/search_model.h" |
10 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
12 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
13 | 14 |
14 class OmniboxEditModel; | |
15 | |
16 namespace content { | 15 namespace content { |
17 class WebContents; | 16 class WebContents; |
18 } | 17 } |
19 | 18 |
20 namespace chrome { | 19 namespace chrome { |
21 namespace search { | 20 namespace search { |
22 | 21 |
23 // Per-tab search "helper". Acts as the owner and controller of the tab's | 22 // Per-tab search "helper". Acts as the owner and controller of the tab's |
24 // search UI model. | 23 // search UI model. |
25 class SearchTabHelper : public content::NotificationObserver, | 24 class SearchTabHelper : public content::NotificationObserver, |
26 public content::WebContentsUserData<SearchTabHelper> { | 25 public content::WebContentsUserData<SearchTabHelper> { |
27 public: | 26 public: |
28 virtual ~SearchTabHelper(); | 27 virtual ~SearchTabHelper(); |
29 | 28 |
30 SearchModel* model() { | 29 SearchModel* model() { |
31 return &model_; | 30 return &model_; |
32 } | 31 } |
33 | 32 |
34 // Invoked when the OmniboxEditModel changes state in some way that might | 33 // Invoked when the OmniboxEditModel changes state in some way that might |
35 // affect the search mode. | 34 // affect the search mode. |
36 void OmniboxEditModelChanged(bool user_input_in_progress, bool cancelling); | 35 void OmniboxEditModelChanged(bool user_input_in_progress, bool cancelling); |
37 | 36 |
38 // Invoked when the active navigation entry is updated in some way that might | 37 // Invoked when the active navigation entry is updated in some way that might |
39 // affect the search mode. This is used by Instant when it "fixes up" the | 38 // affect the search mode. This is used by Instant when it "fixes up" the |
40 // virtual URL of the active entry. Regular navigations are captured through | 39 // virtual URL of the active entry. Regular navigations are captured through |
41 // the notification system and shouldn't call this method. | 40 // the notification system and shouldn't call this method. |
42 void NavigationEntryUpdated(); | 41 void NavigationEntryUpdated(); |
43 | 42 |
| 43 private: |
| 44 friend class content::WebContentsUserData<SearchTabHelper>; |
| 45 |
| 46 explicit SearchTabHelper(content::WebContents* web_contents); |
| 47 |
44 // Overridden from content::NotificationObserver: | 48 // Overridden from content::NotificationObserver: |
45 virtual void Observe(int type, | 49 virtual void Observe(int type, |
46 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
47 const content::NotificationDetails& details) OVERRIDE; | 51 const content::NotificationDetails& details) OVERRIDE; |
48 | 52 |
49 private: | 53 // Sets the mode of the model based on the current URL of web_contents(). |
50 explicit SearchTabHelper(content::WebContents* web_contents); | 54 void UpdateModel(); |
51 friend class content::WebContentsUserData<SearchTabHelper>; | |
52 | |
53 // Sets the mode of the model based on |url|. | |
54 void UpdateModelBasedOnURL(const GURL& url); | |
55 | 55 |
56 // Returns the web contents associated with the tab that owns this helper. | 56 // Returns the web contents associated with the tab that owns this helper. |
57 const content::WebContents* web_contents() const; | 57 const content::WebContents* web_contents() const; |
58 | 58 |
59 const bool is_search_enabled_; | 59 const bool is_search_enabled_; |
60 | 60 |
61 // Tracks the last value passed to OmniboxEditModelChanged(). | 61 // Tracks the last value passed to OmniboxEditModelChanged(). |
62 bool user_input_in_progress_; | 62 bool user_input_in_progress_; |
63 | 63 |
64 // Model object for UI that cares about search state. | 64 // Model object for UI that cares about search state. |
65 SearchModel model_; | 65 SearchModel model_; |
66 | 66 |
67 content::NotificationRegistrar registrar_; | 67 content::NotificationRegistrar registrar_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); | 69 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); |
70 }; | 70 }; |
71 | 71 |
72 } // namespace search | 72 } // namespace search |
73 } // namespace chrome | 73 } // namespace chrome |
74 | 74 |
75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ | 75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ |
OLD | NEW |