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

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: 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
25 } // namespace 28 } // namespace
26 29
27 namespace chrome { 30 namespace chrome {
28 namespace search { 31 namespace search {
29 32
30 SearchTabHelper::SearchTabHelper( 33 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
sky 2012/09/19 00:31:07 Move implementation to match new position in heade
31 TabContents* contents, 34 : WebContentsObserver(web_contents),
32 bool is_search_enabled)
33 : WebContentsObserver(contents->web_contents()),
34 is_search_enabled_(is_search_enabled),
35 is_initial_navigation_commit_(true), 35 is_initial_navigation_commit_(true),
36 model_(contents), 36 model_(web_contents),
37 ntp_load_state_(DEFAULT), 37 ntp_load_state_(DEFAULT),
38 main_frame_id_(0) { 38 main_frame_id_(0) {
39 if (!is_search_enabled) 39 Profile* profile =
sky 2012/09/19 00:31:07 Can you move determing if search is enabled to a f
Avi (use Gerrit) 2012/09/19 14:42:15 Clever! Yes, I'll do that.
40 Profile::FromBrowserContext(web_contents->GetBrowserContext());
41 is_search_enabled_ = chrome::search::IsInstantExtendedAPIEnabled(profile);
42
43 if (!is_search_enabled_)
40 return; 44 return;
41 45
42 registrar_.Add( 46 registrar_.Add(
43 this, 47 this,
44 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 48 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
45 content::Source<content::NavigationController>( 49 content::Source<content::NavigationController>(
46 &contents->web_contents()->GetController())); 50 &web_contents->GetController()));
47 } 51 }
48 52
49 SearchTabHelper::~SearchTabHelper() { 53 SearchTabHelper::~SearchTabHelper() {
50 } 54 }
51 55
52 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, 56 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress,
53 bool cancelling) { 57 bool cancelling) {
54 if (!is_search_enabled_) 58 if (!is_search_enabled_)
55 return; 59 return;
56 60
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 NTPLoadState load_state, 154 NTPLoadState load_state,
151 bool animate) { 155 bool animate) {
152 Mode::Type type = Mode::MODE_DEFAULT; 156 Mode::Type type = Mode::MODE_DEFAULT;
153 if (IsNTP(url)) 157 if (IsNTP(url))
154 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; 158 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING;
155 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) 159 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
156 type = Mode::MODE_SEARCH_RESULTS; 160 type = Mode::MODE_SEARCH_RESULTS;
157 model_.SetMode(Mode(type, animate)); 161 model_.SetMode(Mode(type, animate));
158 } 162 }
159 163
160 content::WebContents* SearchTabHelper::web_contents() { 164 const content::WebContents* SearchTabHelper::web_contents() const {
161 return model_.tab_contents()->web_contents(); 165 return model_.web_contents();
162 } 166 }
163 167
164 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { 168 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() {
165 content::RenderWidgetHostView* rwhv = 169 content::RenderWidgetHostView* rwhv =
166 web_contents()->GetRenderWidgetHostView(); 170 web_contents()->GetRenderWidgetHostView();
167 return rwhv ? rwhv->GetRenderWidgetHost() : NULL; 171 return rwhv ? rwhv->GetRenderWidgetHost() : NULL;
168 } 172 }
169 173
170 } // namespace search 174 } // namespace search
171 } // namespace chrome 175 } // 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