Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/webui/favicon_source.h" | 5 #include "chrome/browser/ui/webui/favicon_source.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | 12 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 13 #include "chrome/browser/history/top_sites.h" | 13 #include "chrome/browser/history/top_sites.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search/instant_io_context.h" | 15 #include "chrome/browser/search/instant_io_context.h" |
| 16 #include "chrome/browser/sync/open_tabs_ui_delegate.h" | 16 #include "chrome/browser/sync/open_tabs_ui_delegate.h" |
| 17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 19 #include "chrome/common/favicon/favicon_url_parser.h" | 19 #include "chrome/common/favicon/favicon_url_parser.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/locale_settings.h" | 21 #include "chrome/grit/locale_settings.h" |
| 22 #include "components/favicon_base/fallback_icon_specs_builder.h" | |
| 22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/layout.h" | 25 #include "ui/base/layout.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/webui/web_ui_util.h" | 27 #include "ui/base/webui/web_ui_util.h" |
| 27 #include "ui/resources/grit/ui_resources.h" | 28 #include "ui/resources/grit/ui_resources.h" |
| 28 | 29 |
| 29 FaviconSource::IconRequest::IconRequest() | 30 FaviconSource::IconRequest::IconRequest() |
| 30 : size_in_dip(gfx::kFaviconSize), device_scale_factor(1.0f) { | 31 : size_in_dip(gfx::kFaviconSize), device_scale_factor(1.0f) { |
| 31 } | 32 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); | 76 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); |
| 76 if (!success) { | 77 if (!success) { |
| 77 SendDefaultResponse(callback); | 78 SendDefaultResponse(callback); |
| 78 return; | 79 return; |
| 79 } | 80 } |
| 80 | 81 |
| 81 GURL url(parsed.url); | 82 GURL url(parsed.url); |
| 82 int desired_size_in_pixel = | 83 int desired_size_in_pixel = |
| 83 std::ceil(parsed.size_in_dip * parsed.device_scale_factor); | 84 std::ceil(parsed.size_in_dip * parsed.device_scale_factor); |
| 84 | 85 |
| 85 if (parsed.is_icon_url) { | 86 if (parsed.fallback_specs_builder || parsed.is_icon_url) { |
| 86 // TODO(michaelbai): Change GetRawFavicon to support combination of | 87 favicon_base::FaviconRawBitmapCallback wrapped_callback = |
| 87 // IconType. | |
| 88 favicon_service->GetRawFavicon( | |
| 89 url, | |
| 90 favicon_base::FAVICON, | |
| 91 desired_size_in_pixel, | |
| 92 base::Bind( | 88 base::Bind( |
| 93 &FaviconSource::OnFaviconDataAvailable, | 89 &FaviconSource::OnFaviconDataAvailable, |
| 94 base::Unretained(this), | 90 base::Unretained(this), |
| 95 IconRequest( | 91 IconRequest( |
| 96 callback, url, parsed.size_in_dip, parsed.device_scale_factor)), | 92 callback, url, parsed.size_in_dip, parsed.device_scale_factor)); |
| 97 &cancelable_task_tracker_); | 93 if (parsed.fallback_specs_builder) { |
|
pkotwicz
2015/01/19 04:32:02
Can you move the code for parsing the URLs for fal
huangs
2015/01/20 22:20:41
Done.
| |
| 94 favicon_service->GetRawFallbackFaviconImage( | |
| 95 url, | |
| 96 icon_types_ == favicon_base::FAVICON ? | |
| 97 favicon_base::FAVICON : favicon_base::TOUCH_ICON, | |
| 98 desired_size_in_pixel, | |
| 99 parsed.fallback_specs_builder->Build(), | |
| 100 wrapped_callback, | |
| 101 &cancelable_task_tracker_); | |
| 102 } else { | |
| 103 DCHECK(parsed.is_icon_url); | |
| 104 // TODO(michaelbai): Change GetRawFavicon to support combination of | |
| 105 // IconType. | |
| 106 favicon_service->GetRawFavicon( | |
| 107 url, | |
| 108 favicon_base::FAVICON, | |
| 109 desired_size_in_pixel, | |
| 110 wrapped_callback, | |
| 111 &cancelable_task_tracker_); | |
| 112 } | |
| 98 } else { | 113 } else { |
| 99 // Intercept requests for prepopulated pages. | 114 // Intercept requests for prepopulated pages. |
| 100 for (int i = 0; i < history::kPrepopulatedPagesCount; i++) { | 115 for (int i = 0; i < history::kPrepopulatedPagesCount; i++) { |
| 101 if (url.spec() == | 116 if (url.spec() == |
| 102 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { | 117 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { |
| 103 ui::ScaleFactor resource_scale_factor = | 118 ui::ScaleFactor resource_scale_factor = |
| 104 ui::GetSupportedScaleFactor(parsed.device_scale_factor); | 119 ui::GetSupportedScaleFactor(parsed.device_scale_factor); |
| 105 callback.Run( | 120 callback.Run( |
| 106 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 121 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
| 107 history::kPrepopulatedPages[i].favicon_id, | 122 history::kPrepopulatedPages[i].favicon_id, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 ui::ScaleFactor resource_scale_factor = | 213 ui::ScaleFactor resource_scale_factor = |
| 199 ui::GetSupportedScaleFactor(icon_request.device_scale_factor); | 214 ui::GetSupportedScaleFactor(icon_request.device_scale_factor); |
| 200 default_favicon = | 215 default_favicon = |
| 201 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 216 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
| 202 resource_id, resource_scale_factor); | 217 resource_id, resource_scale_factor); |
| 203 default_favicons_[favicon_index] = default_favicon; | 218 default_favicons_[favicon_index] = default_favicon; |
| 204 } | 219 } |
| 205 | 220 |
| 206 icon_request.callback.Run(default_favicon); | 221 icon_request.callback.Run(default_favicon); |
| 207 } | 222 } |
| OLD | NEW |