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

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

Issue 10944016: Switch SearchTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const 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 #include "chrome/browser/ui/search/search_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include "chrome/browser/google/google_util.h" 7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/search/search.h"
9 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h" 15 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_widget_host_view.h" 16 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 18
19 int chrome::search::SearchTabHelper::kUserDataKey;
20
18 namespace { 21 namespace {
19 22
20 bool IsNTP(const GURL& url) { 23 bool IsNTP(const GURL& url) {
21 return url.SchemeIs(chrome::kChromeUIScheme) && 24 return url.SchemeIs(chrome::kChromeUIScheme) &&
22 url.host() == chrome::kChromeUINewTabHost; 25 url.host() == chrome::kChromeUINewTabHost;
23 } 26 }
24 27
28 bool IsSearchEnabled(content::WebContents* web_contents) {
29 Profile* profile =
30 Profile::FromBrowserContext(web_contents->GetBrowserContext());
31 return chrome::search::IsInstantExtendedAPIEnabled(profile);
32 }
33
25 } // namespace 34 } // namespace
26 35
27 namespace chrome { 36 namespace chrome {
28 namespace search { 37 namespace search {
29 38
30 SearchTabHelper::SearchTabHelper( 39 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
31 TabContents* contents, 40 : WebContentsObserver(web_contents),
32 bool is_search_enabled) 41 is_search_enabled_(IsSearchEnabled(web_contents)),
33 : WebContentsObserver(contents->web_contents()),
34 is_search_enabled_(is_search_enabled),
35 is_initial_navigation_commit_(true), 42 is_initial_navigation_commit_(true),
36 model_(contents), 43 model_(web_contents),
37 ntp_load_state_(DEFAULT), 44 ntp_load_state_(DEFAULT),
38 main_frame_id_(0) { 45 main_frame_id_(0) {
39 if (!is_search_enabled) 46 if (!is_search_enabled_)
40 return; 47 return;
41 48
42 registrar_.Add( 49 registrar_.Add(
43 this, 50 this,
44 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 51 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
45 content::Source<content::NavigationController>( 52 content::Source<content::NavigationController>(
46 &contents->web_contents()->GetController())); 53 &web_contents->GetController()));
47 } 54 }
48 55
49 SearchTabHelper::~SearchTabHelper() { 56 SearchTabHelper::~SearchTabHelper() {
50 } 57 }
51 58
52 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, 59 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress,
53 bool cancelling) { 60 bool cancelling) {
54 if (!is_search_enabled_) 61 if (!is_search_enabled_)
55 return; 62 return;
56 63
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 NTPLoadState load_state, 157 NTPLoadState load_state,
151 bool animate) { 158 bool animate) {
152 Mode::Type type = Mode::MODE_DEFAULT; 159 Mode::Type type = Mode::MODE_DEFAULT;
153 if (IsNTP(url)) 160 if (IsNTP(url))
154 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; 161 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING;
155 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) 162 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
156 type = Mode::MODE_SEARCH_RESULTS; 163 type = Mode::MODE_SEARCH_RESULTS;
157 model_.SetMode(Mode(type, animate)); 164 model_.SetMode(Mode(type, animate));
158 } 165 }
159 166
160 content::WebContents* SearchTabHelper::web_contents() { 167 const content::WebContents* SearchTabHelper::web_contents() const {
161 return model_.tab_contents()->web_contents(); 168 return model_.web_contents();
162 } 169 }
163 170
164 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { 171 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() {
165 content::RenderWidgetHostView* rwhv = 172 content::RenderWidgetHostView* rwhv =
166 web_contents()->GetRenderWidgetHostView(); 173 web_contents()->GetRenderWidgetHostView();
167 return rwhv ? rwhv->GetRenderWidgetHost() : NULL; 174 return rwhv ? rwhv->GetRenderWidgetHost() : NULL;
168 } 175 }
169 176
170 } // namespace search 177 } // namespace search
171 } // namespace chrome 178 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/browser/ui/search/toolbar_search_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698