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