OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/content_settings/content_settings_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
36 | 36 |
37 #if defined(TOOLKIT_VIEWS) | 37 #if defined(TOOLKIT_VIEWS) |
38 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
39 #endif | 39 #endif |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 bool IsContentsFrom(const InstantPage* page, | 43 bool IsContentsFrom(const InstantPage* page, |
44 const content::WebContents* contents) { | 44 const content::WebContents* contents) { |
45 return page && (page->contents() == contents); | 45 return page && (page->web_contents() == contents); |
46 } | 46 } |
47 | 47 |
48 // Adds a transient NavigationEntry to the supplied |contents|'s | 48 // Adds a transient NavigationEntry to the supplied |contents|'s |
49 // NavigationController if the page's URL has not already been updated with the | 49 // NavigationController if the page's URL has not already been updated with the |
50 // supplied |search_terms|. Sets the |search_terms| on the transient entry for | 50 // supplied |search_terms|. Sets the |search_terms| on the transient entry for |
51 // search terms extraction to work correctly. | 51 // search terms extraction to work correctly. |
52 void EnsureSearchTermsAreSet(content::WebContents* contents, | 52 void EnsureSearchTermsAreSet(content::WebContents* contents, |
53 const base::string16& search_terms) { | 53 const base::string16& search_terms) { |
54 content::NavigationController* controller = &contents->GetController(); | 54 content::NavigationController* controller = &contents->GetController(); |
55 | 55 |
(...skipping 24 matching lines...) Expand all Loading... |
80 } | 80 } |
81 | 81 |
82 InstantController::~InstantController() { | 82 InstantController::~InstantController() { |
83 } | 83 } |
84 | 84 |
85 bool InstantController::SubmitQuery(const base::string16& search_terms) { | 85 bool InstantController::SubmitQuery(const base::string16& search_terms) { |
86 if (instant_tab_ && instant_tab_->supports_instant() && | 86 if (instant_tab_ && instant_tab_->supports_instant() && |
87 search_mode_.is_origin_search()) { | 87 search_mode_.is_origin_search()) { |
88 // Use |instant_tab_| to run the query if we're already on a search results | 88 // Use |instant_tab_| to run the query if we're already on a search results |
89 // page. (NOTE: in particular, we do not send the query to NTPs.) | 89 // page. (NOTE: in particular, we do not send the query to NTPs.) |
90 SearchTabHelper::FromWebContents(instant_tab_->contents())->Submit( | 90 SearchTabHelper::FromWebContents(instant_tab_->web_contents())->Submit( |
91 search_terms); | 91 search_terms); |
92 instant_tab_->contents()->Focus(); | 92 instant_tab_->web_contents()->Focus(); |
93 EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms); | 93 EnsureSearchTermsAreSet(instant_tab_->web_contents(), search_terms); |
94 return true; | 94 return true; |
95 } | 95 } |
96 return false; | 96 return false; |
97 } | 97 } |
98 | 98 |
99 void InstantController::SearchModeChanged(const SearchMode& old_mode, | 99 void InstantController::SearchModeChanged(const SearchMode& old_mode, |
100 const SearchMode& new_mode) { | 100 const SearchMode& new_mode) { |
101 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 101 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
102 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, | 102 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, |
103 old_mode.mode, new_mode.origin, new_mode.mode)); | 103 old_mode.mode, new_mode.origin, new_mode.mode)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 DCHECK(IsContentsFrom(instant_tab(), contents)); | 171 DCHECK(IsContentsFrom(instant_tab(), contents)); |
172 | 172 |
173 // The Instant tab navigated. Send it the data it needs to display | 173 // The Instant tab navigated. Send it the data it needs to display |
174 // properly. | 174 // properly. |
175 UpdateInfoForInstantTab(); | 175 UpdateInfoForInstantTab(); |
176 } | 176 } |
177 | 177 |
178 void InstantController::ResetInstantTab() { | 178 void InstantController::ResetInstantTab() { |
179 if (!search_mode_.is_origin_default()) { | 179 if (!search_mode_.is_origin_default()) { |
180 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 180 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
181 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 181 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { |
182 instant_tab_.reset(new InstantTab(this, browser_->profile())); | 182 instant_tab_.reset(new InstantTab(this, browser_->profile())); |
183 instant_tab_->Init(active_tab); | 183 instant_tab_->Init(active_tab); |
184 UpdateInfoForInstantTab(); | 184 UpdateInfoForInstantTab(); |
185 } | 185 } |
186 } else { | 186 } else { |
187 instant_tab_.reset(); | 187 instant_tab_.reset(); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void InstantController::UpdateInfoForInstantTab() { | 191 void InstantController::UpdateInfoForInstantTab() { |
192 if (instant_tab_) { | 192 if (instant_tab_) { |
193 // Update theme details. | 193 // Update theme details. |
194 InstantService* instant_service = GetInstantService(); | 194 InstantService* instant_service = GetInstantService(); |
195 if (instant_service) { | 195 if (instant_service) { |
196 instant_service->UpdateThemeInfo(); | 196 instant_service->UpdateThemeInfo(); |
197 instant_service->UpdateMostVisitedItemsInfo(); | 197 instant_service->UpdateMostVisitedItemsInfo(); |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 InstantService* InstantController::GetInstantService() const { | 202 InstantService* InstantController::GetInstantService() const { |
203 return InstantServiceFactory::GetForProfile(profile()); | 203 return InstantServiceFactory::GetForProfile(profile()); |
204 } | 204 } |
OLD | NEW |