Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.h

Issue 10944016: Switch SearchTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/tab_contents/web_contents_user_data.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_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 14
14 class OmniboxEditModel; 15 class OmniboxEditModel;
15 class TabContents;
16 16
17 namespace content { 17 namespace content {
18 class RenderViewHost; 18 class RenderViewHost;
19 class RenderWidgetHost; 19 class RenderWidgetHost;
20 class WebContents; 20 class WebContents;
21 } 21 }
22 22
23 namespace chrome { 23 namespace chrome {
24 namespace search { 24 namespace search {
25 25
26 // Per-tab search "helper". Acts as the owner and controller of the tab's 26 // Per-tab search "helper". Acts as the owner and controller of the tab's
27 // search UI model. 27 // search UI model.
28 class SearchTabHelper : public content::WebContentsObserver, 28 class SearchTabHelper : public content::WebContentsObserver,
29 public content::NotificationObserver { 29 public content::NotificationObserver,
30 public WebContentsUserData<SearchTabHelper> {
30 public: 31 public:
31 SearchTabHelper(TabContents* contents, bool is_search_enabled);
32 virtual ~SearchTabHelper(); 32 virtual ~SearchTabHelper();
33 33
34 SearchModel* model() { 34 SearchModel* model() {
35 return &model_; 35 return &model_;
36 } 36 }
37 37
38 // Invoked when the OmniboxEditModel changes state in some way that might 38 // Invoked when the OmniboxEditModel changes state in some way that might
39 // affect the search mode. 39 // affect the search mode.
40 void OmniboxEditModelChanged(bool user_input_in_progress, bool cancelling); 40 void OmniboxEditModelChanged(bool user_input_in_progress, bool cancelling);
41 41
(...skipping 10 matching lines...) Expand all
52 virtual void DocumentLoadedInFrame( 52 virtual void DocumentLoadedInFrame(
53 int64 frame_id, 53 int64 frame_id,
54 content::RenderViewHost* render_view_host) OVERRIDE; 54 content::RenderViewHost* render_view_host) OVERRIDE;
55 55
56 // Overridden from content::NotificationObserver: 56 // Overridden from content::NotificationObserver:
57 virtual void Observe(int type, 57 virtual void Observe(int type,
58 const content::NotificationSource& source, 58 const content::NotificationSource& source,
59 const content::NotificationDetails& details) OVERRIDE; 59 const content::NotificationDetails& details) OVERRIDE;
60 60
61 private: 61 private:
62 explicit SearchTabHelper(content::WebContents* web_contents);
63 static int kUserDataKey;
64 friend class WebContentsUserData<SearchTabHelper>;
65
62 // Enum of the load states for the NTP. 66 // Enum of the load states for the NTP.
63 // 67 //
64 // Once the user loads the NTP the |ntp_load_state_| changes to 68 // Once the user loads the NTP the |ntp_load_state_| changes to
65 // WAITING_FOR_FRAME_ID and the search::mode::Type changes to 69 // WAITING_FOR_FRAME_ID and the search::mode::Type changes to
66 // MODE_NTP_LOADING. The |ntp_load_state_| progresses through the remaining 70 // MODE_NTP_LOADING. The |ntp_load_state_| progresses through the remaining
67 // states and when done search::mode::Type is changed to MODE_NTP. 71 // states and when done search::mode::Type is changed to MODE_NTP.
68 // 72 //
69 // This code is intended to avoid a flash between white (default background 73 // This code is intended to avoid a flash between white (default background
70 // color) and the background the pages wants (gray). We know the CSS has been 74 // color) and the background the pages wants (gray). We know the CSS has been
71 // applied once we get DocumentLoadedInFrame() and we know the backing store 75 // applied once we get DocumentLoadedInFrame() and we know the backing store
(...skipping 15 matching lines...) Expand all
87 // The document finished painting. 91 // The document finished painting.
88 PAINTED, 92 PAINTED,
89 }; 93 };
90 94
91 // Sets the mode of the model based on |url|. |state| distinguishes between 95 // Sets the mode of the model based on |url|. |state| distinguishes between
92 // loading and loaded ntp states. |animate| is based on initial navigation 96 // loading and loaded ntp states. |animate| is based on initial navigation
93 // and used for the mode change on the |model_|. 97 // and used for the mode change on the |model_|.
94 void UpdateModelBasedOnURL(const GURL& url, NTPLoadState state, bool animate); 98 void UpdateModelBasedOnURL(const GURL& url, NTPLoadState state, bool animate);
95 99
96 // Returns the web contents associated with the tab that owns this helper. 100 // Returns the web contents associated with the tab that owns this helper.
97 content::WebContents* web_contents(); 101 const content::WebContents* web_contents() const;
98 102
99 // Returns the current RenderWidgetHost of the |web_contents()|. 103 // Returns the current RenderWidgetHost of the |web_contents()|.
100 content::RenderWidgetHost* GetRenderWidgetHost(); 104 content::RenderWidgetHost* GetRenderWidgetHost();
101 105
102 const bool is_search_enabled_; 106 bool is_search_enabled_;
103 107
104 bool is_initial_navigation_commit_; 108 bool is_initial_navigation_commit_;
105 109
106 // Model object for UI that cares about search state. 110 // Model object for UI that cares about search state.
107 SearchModel model_; 111 SearchModel model_;
108 112
109 content::NotificationRegistrar registrar_; 113 content::NotificationRegistrar registrar_;
110 114
111 // See description above NTPLoadState. 115 // See description above NTPLoadState.
112 NTPLoadState ntp_load_state_; 116 NTPLoadState ntp_load_state_;
113 117
114 // See description above NTPLoadState. 118 // See description above NTPLoadState.
115 int64 main_frame_id_; 119 int64 main_frame_id_;
116 120
117 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); 121 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper);
118 }; 122 };
119 123
120 } // namespace search 124 } // namespace search
121 } // namespace chrome 125 } // namespace chrome
122 126
123 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ 127 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698