OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/omnibox/chrome_omnibox_client.h" | 5 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll | 50 // highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll |
51 // return it. | 51 // return it. |
52 // | 52 // |
53 // If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the | 53 // If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the |
54 // prefetch suggestion even if it is not the default match. Otherwise we only | 54 // prefetch suggestion even if it is not the default match. Otherwise we only |
55 // care about matches that are the default or the second entry in the dropdown | 55 // care about matches that are the default or the second entry in the dropdown |
56 // (which can happen for non-default matches when a top verbatim match is | 56 // (which can happen for non-default matches when a top verbatim match is |
57 // shown); for other matches, we think the likelihood of the user selecting | 57 // shown); for other matches, we think the likelihood of the user selecting |
58 // them is low enough that prefetching isn't worth doing. | 58 // them is low enough that prefetching isn't worth doing. |
59 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { | 59 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { |
60 if (chrome::ShouldAllowPrefetchNonDefaultMatch()) { | 60 if (search::ShouldAllowPrefetchNonDefaultMatch()) { |
61 const AutocompleteResult::const_iterator prefetch_match = std::find_if( | 61 const AutocompleteResult::const_iterator prefetch_match = std::find_if( |
62 result.begin(), result.end(), SearchProvider::ShouldPrefetch); | 62 result.begin(), result.end(), SearchProvider::ShouldPrefetch); |
63 return prefetch_match != result.end() ? &(*prefetch_match) : NULL; | 63 return prefetch_match != result.end() ? &(*prefetch_match) : NULL; |
64 } | 64 } |
65 | 65 |
66 // If the default match should be prefetched, do that. | 66 // If the default match should be prefetched, do that. |
67 const auto default_match = result.default_match(); | 67 const auto default_match = result.default_match(); |
68 if ((default_match != result.end()) && | 68 if ((default_match != result.end()) && |
69 SearchProvider::ShouldPrefetch(*default_match)) | 69 SearchProvider::ShouldPrefetch(*default_match)) |
70 return &(*default_match); | 70 return &(*default_match); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 bool ChromeOmniboxClient::CurrentPageExists() const { | 128 bool ChromeOmniboxClient::CurrentPageExists() const { |
129 return (controller_->GetWebContents() != NULL); | 129 return (controller_->GetWebContents() != NULL); |
130 } | 130 } |
131 | 131 |
132 const GURL& ChromeOmniboxClient::GetURL() const { | 132 const GURL& ChromeOmniboxClient::GetURL() const { |
133 return controller_->GetWebContents()->GetURL(); | 133 return controller_->GetWebContents()->GetURL(); |
134 } | 134 } |
135 | 135 |
136 bool ChromeOmniboxClient::IsInstantNTP() const { | 136 bool ChromeOmniboxClient::IsInstantNTP() const { |
137 return chrome::IsInstantNTP(controller_->GetWebContents()); | 137 return search::IsInstantNTP(controller_->GetWebContents()); |
138 } | 138 } |
139 | 139 |
140 bool ChromeOmniboxClient::IsSearchResultsPage() const { | 140 bool ChromeOmniboxClient::IsSearchResultsPage() const { |
141 Profile* profile = Profile::FromBrowserContext( | 141 Profile* profile = Profile::FromBrowserContext( |
142 controller_->GetWebContents()->GetBrowserContext()); | 142 controller_->GetWebContents()->GetBrowserContext()); |
143 return TemplateURLServiceFactory::GetForProfile(profile)-> | 143 return TemplateURLServiceFactory::GetForProfile(profile)-> |
144 IsSearchResultsPageFromDefaultSearchProvider(GetURL()); | 144 IsSearchResultsPageFromDefaultSearchProvider(GetURL()); |
145 } | 145 } |
146 | 146 |
147 bool ChromeOmniboxClient::IsLoading() const { | 147 bool ChromeOmniboxClient::IsLoading() const { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (!controller_->GetWebContents()) | 197 if (!controller_->GetWebContents()) |
198 return; | 198 return; |
199 SearchTabHelper::FromWebContents( | 199 SearchTabHelper::FromWebContents( |
200 controller_->GetWebContents())->OmniboxFocusChanged(state, reason); | 200 controller_->GetWebContents())->OmniboxFocusChanged(state, reason); |
201 } | 201 } |
202 | 202 |
203 void ChromeOmniboxClient::OnResultChanged( | 203 void ChromeOmniboxClient::OnResultChanged( |
204 const AutocompleteResult& result, | 204 const AutocompleteResult& result, |
205 bool default_match_changed, | 205 bool default_match_changed, |
206 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) { | 206 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) { |
207 if (chrome::IsInstantExtendedAPIEnabled() && | 207 if (search::IsInstantExtendedAPIEnabled() && |
208 ((default_match_changed && result.default_match() != result.end()) || | 208 ((default_match_changed && result.default_match() != result.end()) || |
209 (chrome::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) { | 209 (search::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) { |
210 InstantSuggestion prefetch_suggestion; | 210 InstantSuggestion prefetch_suggestion; |
211 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result); | 211 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result); |
212 if (match_to_prefetch) { | 212 if (match_to_prefetch) { |
213 prefetch_suggestion.text = match_to_prefetch->contents; | 213 prefetch_suggestion.text = match_to_prefetch->contents; |
214 prefetch_suggestion.metadata = | 214 prefetch_suggestion.metadata = |
215 SearchProvider::GetSuggestMetadata(*match_to_prefetch); | 215 SearchProvider::GetSuggestMetadata(*match_to_prefetch); |
216 } | 216 } |
217 // Send the prefetch suggestion unconditionally to the InstantPage. If | 217 // Send the prefetch suggestion unconditionally to the InstantPage. If |
218 // there is no suggestion to prefetch, we need to send a blank query to | 218 // there is no suggestion to prefetch, we need to send a blank query to |
219 // clear the prefetched results. | 219 // clear the prefetched results. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 match.destination_url, | 283 match.destination_url, |
284 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); | 284 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); |
285 } | 285 } |
286 // We could prefetch the alternate nav URL, if any, but because there | 286 // We could prefetch the alternate nav URL, if any, but because there |
287 // can be many of these as a user types an initial series of characters, | 287 // can be many of these as a user types an initial series of characters, |
288 // the OS DNS cache could suffer eviction problems for minimal gain. | 288 // the OS DNS cache could suffer eviction problems for minimal gain. |
289 } | 289 } |
290 | 290 |
291 void ChromeOmniboxClient::SetSuggestionToPrefetch( | 291 void ChromeOmniboxClient::SetSuggestionToPrefetch( |
292 const InstantSuggestion& suggestion) { | 292 const InstantSuggestion& suggestion) { |
293 DCHECK(chrome::IsInstantExtendedAPIEnabled()); | 293 DCHECK(search::IsInstantExtendedAPIEnabled()); |
294 content::WebContents* web_contents = controller_->GetWebContents(); | 294 content::WebContents* web_contents = controller_->GetWebContents(); |
295 if (web_contents && | 295 if (web_contents && |
296 SearchTabHelper::FromWebContents(web_contents)->IsSearchResultsPage()) { | 296 SearchTabHelper::FromWebContents(web_contents)->IsSearchResultsPage()) { |
297 if (chrome::ShouldPrefetchSearchResultsOnSRP()) { | 297 if (search::ShouldPrefetchSearchResultsOnSRP()) { |
298 SearchTabHelper::FromWebContents(web_contents)-> | 298 SearchTabHelper::FromWebContents(web_contents)-> |
299 SetSuggestionToPrefetch(suggestion); | 299 SetSuggestionToPrefetch(suggestion); |
300 } | 300 } |
301 } else { | 301 } else { |
302 InstantSearchPrerenderer* prerenderer = | 302 InstantSearchPrerenderer* prerenderer = |
303 InstantSearchPrerenderer::GetForProfile(profile_); | 303 InstantSearchPrerenderer::GetForProfile(profile_); |
304 if (prerenderer) | 304 if (prerenderer) |
305 prerenderer->Prerender(suggestion); | 305 prerenderer->Prerender(suggestion); |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, | 309 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, |
310 const SkBitmap& bitmap) { | 310 const SkBitmap& bitmap) { |
311 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; | 311 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; |
312 callback.Run(bitmap); | 312 callback.Run(bitmap); |
313 } | 313 } |
OLD | NEW |