| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/ios/web_favicon_driver.h" | 5 #include "components/favicon/ios/web_favicon_driver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "components/favicon/core/favicon_url.h" | 9 #include "components/favicon/core/favicon_url.h" |
| 10 #include "components/favicon/ios/favicon_url_util.h" | 10 #include "components/favicon/ios/favicon_url_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 54 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 55 return item ? item->GetFavicon().image : gfx::Image(); | 55 return item ? item->GetFavicon().image : gfx::Image(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool WebFaviconDriver::FaviconIsValid() const { | 58 bool WebFaviconDriver::FaviconIsValid() const { |
| 59 web::NavigationItem* item = | 59 web::NavigationItem* item = |
| 60 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 60 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 61 return item ? item->GetFavicon().valid : false; | 61 return item ? item->GetFavicon().valid : false; |
| 62 } | 62 } |
| 63 | 63 |
| 64 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { | 64 int WebFaviconDriver::DownloadImage(const GURL& url, |
| 65 int max_image_size, |
| 66 ImageDownloadCallback callback) { |
| 65 if (WasUnableToDownloadFavicon(url)) { | 67 if (WasUnableToDownloadFavicon(url)) { |
| 66 DVLOG(1) << "Skip Failed FavIcon: " << url; | 68 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 67 return 0; | 69 return 0; |
| 68 } | 70 } |
| 69 | 71 |
| 70 static int downloaded_image_count = 0; | 72 static int downloaded_image_count = 0; |
| 71 int local_download_id = ++downloaded_image_count; | 73 int local_download_id = ++downloaded_image_count; |
| 72 | 74 |
| 73 ImageDownloadCallback local_image_callback = base::Bind( | |
| 74 &FaviconDriverImpl::DidDownloadFavicon, base::Unretained(this)); | |
| 75 GURL local_url(url); | 75 GURL local_url(url); |
| 76 | 76 |
| 77 image_fetcher::IOSImageDataFetcherCallback local_callback = | 77 image_fetcher::IOSImageDataFetcherCallback local_callback = |
| 78 ^(NSData* data, const image_fetcher::RequestMetadata& metadata) { | 78 ^(NSData* data, const image_fetcher::RequestMetadata& metadata) { |
| 79 if (metadata.response_code == | 79 if (metadata.response_code == |
| 80 image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID) | 80 image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 std::vector<SkBitmap> frames; | 83 std::vector<SkBitmap> frames; |
| 84 std::vector<gfx::Size> sizes; | 84 std::vector<gfx::Size> sizes; |
| 85 if (data) { | 85 if (data) { |
| 86 frames = skia::ImageDataToSkBitmaps(data); | 86 frames = skia::ImageDataToSkBitmaps(data); |
| 87 for (const auto& frame : frames) { | 87 for (const auto& frame : frames) { |
| 88 sizes.push_back(gfx::Size(frame.width(), frame.height())); | 88 sizes.push_back(gfx::Size(frame.width(), frame.height())); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 local_image_callback.Run(local_download_id, metadata.response_code, | 91 callback.Run(local_download_id, metadata.response_code, local_url, |
| 92 local_url, frames, sizes); | 92 frames, sizes); |
| 93 }; | 93 }; |
| 94 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback); | 94 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback); |
| 95 | 95 |
| 96 return downloaded_image_count; | 96 return downloaded_image_count; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool WebFaviconDriver::IsOffTheRecord() { | 99 bool WebFaviconDriver::IsOffTheRecord() { |
| 100 DCHECK(web_state()); | 100 DCHECK(web_state()); |
| 101 return web_state()->GetBrowserState()->IsOffTheRecord(); | 101 return web_state()->GetBrowserState()->IsOffTheRecord(); |
| 102 } | 102 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 WebFaviconDriver::~WebFaviconDriver() { | 138 WebFaviconDriver::~WebFaviconDriver() { |
| 139 } | 139 } |
| 140 | 140 |
| 141 void WebFaviconDriver::FaviconUrlUpdated( | 141 void WebFaviconDriver::FaviconUrlUpdated( |
| 142 const std::vector<web::FaviconURL>& candidates) { | 142 const std::vector<web::FaviconURL>& candidates) { |
| 143 DCHECK(!candidates.empty()); | 143 DCHECK(!candidates.empty()); |
| 144 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 144 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace favicon | 147 } // namespace favicon |
| OLD | NEW |