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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 last_match_was_search_(false), | 262 last_match_was_search_(false), |
263 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 263 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
264 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), | 264 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), |
265 omnibox_bounds_(-1, -1, 0, 0), | 265 omnibox_bounds_(-1, -1, 0, 0), |
266 allow_overlay_to_show_search_suggestions_(false) { | 266 allow_overlay_to_show_search_suggestions_(false) { |
267 | 267 |
268 // When the InstantController lives, the InstantService should live. | 268 // When the InstantController lives, the InstantService should live. |
269 // InstantService sets up profile-level facilities such as the ThemeSource for | 269 // InstantService sets up profile-level facilities such as the ThemeSource for |
270 // the NTP. | 270 // the NTP. |
271 // However, in some tests, browser_ may be null. | 271 // However, in some tests, browser_ may be null. |
272 if (browser_) | 272 if (browser_) { |
273 InstantServiceFactory::GetForProfile(browser_->profile()); | 273 InstantService* instant_service = |
274 InstantServiceFactory::GetForProfile(browser_->profile()); | |
275 instant_service->AddObserver(this); | |
276 } | |
274 } | 277 } |
275 | 278 |
276 InstantController::~InstantController() { | 279 InstantController::~InstantController() { |
280 if (browser_) { | |
281 InstantService* instant_service = | |
282 InstantServiceFactory::GetForProfile(browser_->profile()); | |
283 instant_service->RemoveObserver(this); | |
284 } | |
277 } | 285 } |
278 | 286 |
279 void InstantController::OnAutocompleteStart() { | 287 void InstantController::OnAutocompleteStart() { |
280 if (UseTabForSuggestions() && instant_tab_->supports_instant()) { | 288 if (UseTabForSuggestions() && instant_tab_->supports_instant()) { |
281 LOG_INSTANT_DEBUG_EVENT( | 289 LOG_INSTANT_DEBUG_EVENT( |
282 this, "OnAutocompleteStart: using InstantTab"); | 290 this, "OnAutocompleteStart: using InstantTab"); |
283 return; | 291 return; |
284 } | 292 } |
285 | 293 |
286 // Not using |instant_tab_|. Check if overlay is OK to use. | 294 // Not using |instant_tab_|. Check if overlay is OK to use. |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 | 1080 |
1073 // Preload the Instant NTP. | 1081 // Preload the Instant NTP. |
1074 ntp_.reset(); | 1082 ntp_.reset(); |
1075 if (extended_enabled() && preload_ntp_) | 1083 if (extended_enabled() && preload_ntp_) |
1076 ResetNTP(GetInstantURL()); | 1084 ResetNTP(GetInstantURL()); |
1077 | 1085 |
1078 if (instant_tab_) | 1086 if (instant_tab_) |
1079 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1087 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
1080 } | 1088 } |
1081 | 1089 |
1082 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { | 1090 void InstantController::ThemeInfoChanged( |
1083 if (!extended_enabled()) | 1091 const ThemeBackgroundInfo& theme_info) { |
1092 if (!extended_enabled() || !search_mode_.is_ntp()) | |
samarth
2013/06/19 00:14:36
Don't check for search_mode_ here. We'd want to up
kmadhusu
2013/06/19 02:27:24
Done.
| |
1084 return; | 1093 return; |
1085 | 1094 |
1086 if (overlay_) | 1095 if (overlay_ && GetOverlayContents() && |
1096 SearchTabHelper::FromWebContents(overlay_->contents())-> | |
1097 UpdateLastKnownThemeBackgroundInfo(theme_info)) { | |
1087 overlay_->SendThemeBackgroundInfo(theme_info); | 1098 overlay_->SendThemeBackgroundInfo(theme_info); |
1088 if (ntp_) | 1099 } |
1100 | |
1101 if (ntp_ && ntp_->contents() && | |
1102 SearchTabHelper::FromWebContents(ntp_->contents())-> | |
1103 UpdateLastKnownThemeBackgroundInfo(theme_info)) { | |
1089 ntp_->SendThemeBackgroundInfo(theme_info); | 1104 ntp_->SendThemeBackgroundInfo(theme_info); |
1090 if (instant_tab_) | 1105 } |
1106 | |
1107 if (instant_tab_ && instant_tab_->contents() && | |
1108 SearchTabHelper::FromWebContents(instant_tab_->contents())-> | |
1109 UpdateLastKnownThemeBackgroundInfo(theme_info)) { | |
1091 instant_tab_->SendThemeBackgroundInfo(theme_info); | 1110 instant_tab_->SendThemeBackgroundInfo(theme_info); |
1111 } | |
1092 } | 1112 } |
1093 | 1113 |
1094 void InstantController::SwappedOverlayContents() { | 1114 void InstantController::SwappedOverlayContents() { |
1095 model_.SetOverlayContents(GetOverlayContents()); | 1115 model_.SetOverlayContents(GetOverlayContents()); |
1096 } | 1116 } |
1097 | 1117 |
1098 void InstantController::FocusedOverlayContents() { | 1118 void InstantController::FocusedOverlayContents() { |
1099 #if defined(USE_AURA) | 1119 #if defined(USE_AURA) |
1100 // On aura the omnibox only receives a focus lost if we initiate the focus | 1120 // On aura the omnibox only receives a focus lost if we initiate the focus |
1101 // change. This does that. | 1121 // change. This does that. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1170 UpdateLastKnownMostVisitedItems(items)) { | 1190 UpdateLastKnownMostVisitedItems(items)) { |
1171 instant_tab_->SendMostVisitedItems(items); | 1191 instant_tab_->SendMostVisitedItems(items); |
1172 } | 1192 } |
1173 | 1193 |
1174 content::NotificationService::current()->Notify( | 1194 content::NotificationService::current()->Notify( |
1175 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1195 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
1176 content::Source<InstantController>(this), | 1196 content::Source<InstantController>(this), |
1177 content::NotificationService::NoDetails()); | 1197 content::NotificationService::NoDetails()); |
1178 } | 1198 } |
1179 | 1199 |
1200 void InstantController::UpdateThemeInfo() { | |
samarth
2013/06/19 00:14:36
If UpdateThemeInfo doesn't need to be called from
kmadhusu
2013/06/19 02:27:24
Done.
| |
1201 InstantService* instant_service = | |
1202 InstantServiceFactory::GetForProfile(profile()); | |
1203 if (instant_service) | |
1204 instant_service->UpdateThemeInfo(); | |
1205 } | |
1206 | |
1180 void InstantController::DeleteMostVisitedItem(const GURL& url) { | 1207 void InstantController::DeleteMostVisitedItem(const GURL& url) { |
1181 DCHECK(!url.is_empty()); | 1208 DCHECK(!url.is_empty()); |
1182 InstantService* instant_service = | 1209 InstantService* instant_service = |
1183 InstantServiceFactory::GetForProfile(profile()); | 1210 InstantServiceFactory::GetForProfile(profile()); |
1184 if (!instant_service) | 1211 if (!instant_service) |
1185 return; | 1212 return; |
1186 | 1213 |
1187 instant_service->DeleteMostVisitedItem(url); | 1214 instant_service->DeleteMostVisitedItem(url); |
1188 } | 1215 } |
1189 | 1216 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1223 } | 1250 } |
1224 | 1251 |
1225 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the | 1252 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the |
1226 // RenderViewHost being created which is not always true. Fix this. | 1253 // RenderViewHost being created which is not always true. Fix this. |
1227 void InstantController::InstantPageRenderViewCreated( | 1254 void InstantController::InstantPageRenderViewCreated( |
1228 const content::WebContents* contents) { | 1255 const content::WebContents* contents) { |
1229 if (!extended_enabled()) | 1256 if (!extended_enabled()) |
1230 return; | 1257 return; |
1231 | 1258 |
1232 // Update theme info so that the page picks it up. | 1259 // Update theme info so that the page picks it up. |
1233 browser_->UpdateThemeInfo(); | 1260 UpdateThemeInfo(); |
1234 | 1261 |
1235 // Ensure the searchbox API has the correct initial state. | 1262 // Ensure the searchbox API has the correct initial state. |
1236 if (IsContentsFrom(overlay(), contents)) { | 1263 if (IsContentsFrom(overlay(), contents)) { |
1237 overlay_->SetDisplayInstantResults(instant_enabled_); | 1264 overlay_->SetDisplayInstantResults(instant_enabled_); |
1238 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); | 1265 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); |
1239 overlay_->SetOmniboxBounds(omnibox_bounds_); | 1266 overlay_->SetOmniboxBounds(omnibox_bounds_); |
1240 overlay_->InitializeFonts(); | 1267 overlay_->InitializeFonts(); |
1241 } else if (IsContentsFrom(ntp(), contents)) { | 1268 } else if (IsContentsFrom(ntp(), contents)) { |
1242 ntp_->SetDisplayInstantResults(instant_enabled_); | 1269 ntp_->SetDisplayInstantResults(instant_enabled_); |
1243 ntp_->SetOmniboxBounds(omnibox_bounds_); | 1270 ntp_->SetOmniboxBounds(omnibox_bounds_); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1656 | 1683 |
1657 // Hide the |overlay_| since we are now using |instant_tab_| instead. | 1684 // Hide the |overlay_| since we are now using |instant_tab_| instead. |
1658 HideOverlay(); | 1685 HideOverlay(); |
1659 } else { | 1686 } else { |
1660 instant_tab_.reset(); | 1687 instant_tab_.reset(); |
1661 } | 1688 } |
1662 } | 1689 } |
1663 | 1690 |
1664 void InstantController::UpdateInfoForInstantTab() { | 1691 void InstantController::UpdateInfoForInstantTab() { |
1665 if (instant_tab_) { | 1692 if (instant_tab_) { |
1666 browser_->UpdateThemeInfo(); | 1693 UpdateThemeInfo(); |
1667 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1694 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
1668 instant_tab_->SetOmniboxBounds(omnibox_bounds_); | 1695 instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
1669 instant_tab_->InitializeFonts(); | 1696 instant_tab_->InitializeFonts(); |
1670 UpdateMostVisitedItems(); | 1697 UpdateMostVisitedItems(); |
1671 instant_tab_->FocusChanged(omnibox_focus_state_, | 1698 instant_tab_->FocusChanged(omnibox_focus_state_, |
1672 omnibox_focus_change_reason_); | 1699 omnibox_focus_change_reason_); |
1673 instant_tab_->SetInputInProgress(IsInputInProgress()); | 1700 instant_tab_->SetInputInProgress(IsInputInProgress()); |
1674 } | 1701 } |
1675 } | 1702 } |
1676 | 1703 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 result->transition = match.transition; | 1894 result->transition = match.transition; |
1868 result->relevance = match.relevance; | 1895 result->relevance = match.relevance; |
1869 result->autocomplete_match_index = autocomplete_match_index; | 1896 result->autocomplete_match_index = autocomplete_match_index; |
1870 | 1897 |
1871 DVLOG(1) << " " << result->relevance << " " | 1898 DVLOG(1) << " " << result->relevance << " " |
1872 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " | 1899 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " |
1873 << result->provider << " " << result->destination_url << " '" | 1900 << result->provider << " " << result->destination_url << " '" |
1874 << result->description << "' '" << result->search_query << "' " | 1901 << result->description << "' '" << result->search_query << "' " |
1875 << result->transition << " " << result->autocomplete_match_index; | 1902 << result->transition << " " << result->autocomplete_match_index; |
1876 } | 1903 } |
OLD | NEW |