OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/memory/scoped_ptr.h" | |
10 #include "chrome/browser/ui/search/search_model.h" | 9 #include "chrome/browser/ui/search/search_model.h" |
11 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
14 | 13 |
15 class OmniboxEditModel; | 14 class OmniboxEditModel; |
16 class TabContents; | 15 class TabContents; |
17 | 16 |
18 namespace content { | |
19 class WebContents; | |
20 }; | |
21 | |
22 namespace chrome { | 17 namespace chrome { |
23 namespace search { | 18 namespace search { |
24 | 19 |
25 // 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 |
26 // search UI model. | 21 // search UI model. |
27 class SearchTabHelper : public content::WebContentsObserver, | 22 class SearchTabHelper : public content::WebContentsObserver, |
28 public content::NotificationObserver { | 23 public content::NotificationObserver { |
29 public: | 24 public: |
30 SearchTabHelper(TabContents* contents, bool is_search_enabled); | 25 SearchTabHelper(TabContents* contents, bool is_search_enabled); |
31 virtual ~SearchTabHelper(); | 26 virtual ~SearchTabHelper(); |
32 | 27 |
33 SearchModel* model() { | 28 SearchModel* model() { |
34 return &model_; | 29 return &model_; |
35 } | 30 } |
36 | 31 |
37 // Lazily create web contents for NTP. Owned by SearchTabHelper. | |
38 content::WebContents* GetNTPWebContents(); | |
39 | |
40 // Invoked when the OmniboxEditModel changes state in some way that might | 32 // Invoked when the OmniboxEditModel changes state in some way that might |
41 // affect the search mode. | 33 // affect the search mode. |
42 void OmniboxEditModelChanged(OmniboxEditModel* edit_model); | 34 void OmniboxEditModelChanged(OmniboxEditModel* edit_model); |
43 | 35 |
44 // content::WebContentsObserver overrides: | 36 // content::WebContentsObserver overrides: |
45 virtual void NavigateToPendingEntry( | 37 virtual void NavigateToPendingEntry( |
46 const GURL& url, | 38 const GURL& url, |
47 content::NavigationController::ReloadType reload_type) OVERRIDE; | 39 content::NavigationController::ReloadType reload_type) OVERRIDE; |
48 | 40 |
49 // Overridden from content::NotificationObserver: | 41 // Overridden from content::NotificationObserver: |
50 virtual void Observe(int type, | 42 virtual void Observe(int type, |
51 const content::NotificationSource& source, | 43 const content::NotificationSource& source, |
52 const content::NotificationDetails& details) OVERRIDE; | 44 const content::NotificationDetails& details) OVERRIDE; |
53 | 45 |
54 private: | 46 private: |
55 // Sets the mode of the model based on |url|. | 47 // Sets the mode of the model based on |url|. |
56 void UpdateModel(const GURL& url); | 48 void UpdateModel(const GURL& url); |
57 | 49 |
58 // On navigation away from NTP and Search pages, delete |ntp_web_contents_|. | |
59 void FlushNTP(const GURL& url); | |
60 | |
61 const bool is_search_enabled_; | 50 const bool is_search_enabled_; |
62 | 51 |
63 // Model object for UI that cares about search state. | 52 // Model object for UI that cares about search state. |
64 SearchModel model_; | 53 SearchModel model_; |
65 | 54 |
66 // Lazily created web contents for NTP. | |
67 scoped_ptr<content::WebContents> ntp_web_contents_; | |
68 | |
69 content::NotificationRegistrar registrar_; | 55 content::NotificationRegistrar registrar_; |
70 | 56 |
71 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); | 57 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); |
72 }; | 58 }; |
73 | 59 |
74 } // namespace search | 60 } // namespace search |
75 } // namespace chrome | 61 } // namespace chrome |
76 | 62 |
77 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ | 63 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ |
OLD | NEW |