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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 #include "components/omnibox/browser/autocomplete_match.h" | 41 #include "components/omnibox/browser/autocomplete_match.h" |
42 #include "components/omnibox/browser/autocomplete_result.h" | 42 #include "components/omnibox/browser/autocomplete_result.h" |
43 #include "components/omnibox/browser/search_provider.h" | 43 #include "components/omnibox/browser/search_provider.h" |
44 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
45 #include "components/search/search.h" | 45 #include "components/search/search.h" |
46 #include "components/search_engines/template_url_service.h" | 46 #include "components/search_engines/template_url_service.h" |
47 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
48 #include "content/public/browser/navigation_entry.h" | 48 #include "content/public/browser/navigation_entry.h" |
49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
50 #include "extensions/common/constants.h" | 50 #include "extensions/common/constants.h" |
51 #include "net/traffic_annotation/network_traffic_annotation.h" | |
51 #include "third_party/skia/include/core/SkBitmap.h" | 52 #include "third_party/skia/include/core/SkBitmap.h" |
52 #include "ui/base/window_open_disposition.h" | 53 #include "ui/base/window_open_disposition.h" |
53 #include "url/gurl.h" | 54 #include "url/gurl.h" |
54 | 55 |
55 using predictors::AutocompleteActionPredictor; | 56 using predictors::AutocompleteActionPredictor; |
56 | 57 |
57 namespace { | 58 namespace { |
58 | 59 |
59 // Returns the AutocompleteMatch that the InstantController should prefetch, if | 60 // Returns the AutocompleteMatch that the InstantController should prefetch, if |
60 // any. | 61 // any. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 } | 283 } |
283 | 284 |
284 const auto match = std::find_if( | 285 const auto match = std::find_if( |
285 result.begin(), result.end(), | 286 result.begin(), result.end(), |
286 [](const AutocompleteMatch& current) { return !!current.answer; }); | 287 [](const AutocompleteMatch& current) { return !!current.answer; }); |
287 if (match != result.end()) { | 288 if (match != result.end()) { |
288 BitmapFetcherService* image_service = | 289 BitmapFetcherService* image_service = |
289 BitmapFetcherServiceFactory::GetForBrowserContext(profile_); | 290 BitmapFetcherServiceFactory::GetForBrowserContext(profile_); |
290 if (image_service) { | 291 if (image_service) { |
291 image_service->CancelRequest(request_id_); | 292 image_service->CancelRequest(request_id_); |
293 | |
294 // TODO(jdonnelly@, rhalavati@): Create a helper function with Callback | |
Justin Donnelly
2017/02/16 14:53:18
Same here.
Ramin Halavati
2017/02/17 06:30:12
Done.
| |
295 // to create annotation and pass it to image_service, merging this | |
296 // annotation and the one in | |
297 // "c/b/autocomplete/chrome_autocomplete_provider_client.cc". | |
298 net::NetworkTrafficAnnotationTag traffic_annotation = | |
299 net::DefineNetworkTrafficAnnotation("omnibox_result_change", R"( | |
300 semantics { | |
301 sender: "Omnibox Suggest" | |
302 description: | |
303 "Google Chrome provides answers in the suggestion list to the " | |
304 "queries you type in the omnibox. This request retrieves a " | |
305 "small image (for example, an icon illustrating the current " | |
306 "weather conditions) when this can add information to the " | |
307 "answer." | |
308 trigger: | |
309 "Change of results for the query typed by the user in the " | |
310 "omnibox." | |
311 data: | |
312 "The only data sent is the path to an image. No user data is " | |
313 "included, although the general weather condition (sunny, " | |
314 "rainy, etc.) in the user's current location could be inferred " | |
315 "from the name of the image in the path." | |
316 destination: WEBSITE | |
317 } | |
318 policy { | |
319 cookies_allowed: true | |
320 cookies_store: "user" | |
321 setting: | |
322 "You can enable or disable this feature via 'Use a prediction " | |
323 "service to help complete searches and URLs typed in the " | |
324 "address bar.' in Chrome's settings under Advanced. The " | |
325 "feature is enabled by default." | |
326 policy { | |
327 SearchSuggestEnabled { | |
328 policy_options {mode: MANDATORY} | |
329 value: false | |
330 } | |
331 } | |
332 })"); | |
333 | |
292 request_id_ = image_service->RequestImage( | 334 request_id_ = image_service->RequestImage( |
293 match->answer->second_line().image_url(), | 335 match->answer->second_line().image_url(), |
294 new AnswerImageObserver( | 336 new AnswerImageObserver( |
295 base::Bind(&ChromeOmniboxClient::OnBitmapFetched, | 337 base::Bind(&ChromeOmniboxClient::OnBitmapFetched, |
296 base::Unretained(this), on_bitmap_fetched))); | 338 base::Unretained(this), on_bitmap_fetched)), |
339 traffic_annotation); | |
297 } | 340 } |
298 } | 341 } |
299 } | 342 } |
300 | 343 |
301 void ChromeOmniboxClient::OnCurrentMatchChanged( | 344 void ChromeOmniboxClient::OnCurrentMatchChanged( |
302 const AutocompleteMatch& match) { | 345 const AutocompleteMatch& match) { |
303 if (!prerender::IsOmniboxEnabled(profile_)) | 346 if (!prerender::IsOmniboxEnabled(profile_)) |
304 DoPreconnect(match); | 347 DoPreconnect(match); |
305 } | 348 } |
306 | 349 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 InstantSearchPrerenderer::GetForProfile(profile_); | 496 InstantSearchPrerenderer::GetForProfile(profile_); |
454 if (prerenderer) | 497 if (prerenderer) |
455 prerenderer->Prerender(suggestion); | 498 prerenderer->Prerender(suggestion); |
456 } | 499 } |
457 | 500 |
458 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, | 501 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, |
459 const SkBitmap& bitmap) { | 502 const SkBitmap& bitmap) { |
460 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; | 503 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; |
461 callback.Run(bitmap); | 504 callback.Run(bitmap); |
462 } | 505 } |
OLD | NEW |