Chromium Code Reviews| 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/memory/ptr_util.h" | |
| 8 #include "components/favicon/core/favicon_url.h" | 9 #include "components/favicon/core/favicon_url.h" |
| 9 #include "components/favicon/ios/favicon_url_util.h" | 10 #include "components/favicon/ios/favicon_url_util.h" |
| 10 #include "ios/web/public/browser_state.h" | 11 #include "ios/web/public/browser_state.h" |
| 11 #include "ios/web/public/favicon_status.h" | 12 #include "ios/web/public/favicon_status.h" |
| 12 #include "ios/web/public/navigation_item.h" | 13 #include "ios/web/public/navigation_item.h" |
| 13 #include "ios/web/public/navigation_manager.h" | 14 #include "ios/web/public/navigation_manager.h" |
| 14 #include "ios/web/public/web_state/web_state.h" | 15 #include "ios/web/public/web_state/web_state.h" |
| 16 #include "ios/web/public/web_thread.h" | |
| 17 #include "net/url_request/url_fetcher.h" | |
| 18 #include "skia/ext/skia_utils_ios.h" | |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | |
| 15 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 16 | 21 |
| 17 DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver); | 22 DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver); |
| 18 | 23 |
| 24 // Callback for the download of favicon. | |
| 25 using ImageDownloadCallback = | |
| 26 base::Callback<void(int image_id, | |
| 27 int http_status_code, | |
| 28 const GURL& image_url, | |
| 29 const std::vector<SkBitmap>& bitmaps, | |
| 30 const std::vector<gfx::Size>& sizes)>; | |
| 31 | |
| 19 namespace favicon { | 32 namespace favicon { |
| 20 | 33 |
| 21 // static | 34 // static |
| 22 void WebFaviconDriver::CreateForWebState( | 35 void WebFaviconDriver::CreateForWebState( |
| 23 web::WebState* web_state, | 36 web::WebState* web_state, |
| 24 FaviconService* favicon_service, | 37 FaviconService* favicon_service, |
| 25 history::HistoryService* history_service, | 38 history::HistoryService* history_service, |
| 26 bookmarks::BookmarkModel* bookmark_model) { | 39 bookmarks::BookmarkModel* bookmark_model) { |
| 27 if (FromWebState(web_state)) | 40 if (FromWebState(web_state)) |
| 28 return; | 41 return; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 48 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 61 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 49 return item ? item->GetFavicon().valid : false; | 62 return item ? item->GetFavicon().valid : false; |
| 50 } | 63 } |
| 51 | 64 |
| 52 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { | 65 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { |
| 53 if (WasUnableToDownloadFavicon(url)) { | 66 if (WasUnableToDownloadFavicon(url)) { |
| 54 DVLOG(1) << "Skip Failed FavIcon: " << url; | 67 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 55 return 0; | 68 return 0; |
| 56 } | 69 } |
| 57 | 70 |
| 58 return web_state()->DownloadImage( | 71 static int downloaded_image_count = 0; |
| 59 url, true, max_image_size, false, | 72 int local_download_id = ++downloaded_image_count; |
| 60 base::Bind(&FaviconDriverImpl::DidDownloadFavicon, | 73 |
| 61 base::Unretained(this))); | 74 ImageDownloadCallback local_image_callback = base::Bind( |
| 75 &FaviconDriverImpl::DidDownloadFavicon, base::Unretained(this)); | |
| 76 GURL local_url(url); | |
| 77 | |
| 78 image_fetcher::IOSImageDataFetcherCallback local_callback = | |
| 79 ^(NSData* data, const int response_code) { | |
| 80 std::vector<SkBitmap> frames; | |
| 81 std::vector<gfx::Size> sizes; | |
| 82 if (data) { | |
|
sdefresne
2017/02/06 17:33:33
Why convert data to std::vector<SkBitmap> to just
gambard
2017/02/07 10:03:33
Done.
| |
| 83 frames = skia::ImageDataToSkBitmaps(data); | |
| 84 for (const auto& frame : frames) { | |
| 85 sizes.push_back(gfx::Size(frame.width(), frame.height())); | |
| 86 } | |
| 87 } | |
| 88 if (response_code != net::URLFetcher::RESPONSE_CODE_INVALID) { | |
|
mef
2017/02/06 16:36:17
Is this the only reference from net/url_request/ur
gambard
2017/02/07 10:03:33
Done.
| |
| 89 local_image_callback.Run(local_download_id, response_code, local_url, | |
| 90 frames, sizes); | |
| 91 } | |
| 92 }; | |
| 93 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback); | |
| 94 | |
| 95 return downloaded_image_count; | |
| 62 } | 96 } |
| 63 | 97 |
| 64 bool WebFaviconDriver::IsOffTheRecord() { | 98 bool WebFaviconDriver::IsOffTheRecord() { |
| 65 DCHECK(web_state()); | 99 DCHECK(web_state()); |
| 66 return web_state()->GetBrowserState()->IsOffTheRecord(); | 100 return web_state()->GetBrowserState()->IsOffTheRecord(); |
| 67 } | 101 } |
| 68 | 102 |
| 69 GURL WebFaviconDriver::GetActiveURL() { | 103 GURL WebFaviconDriver::GetActiveURL() { |
| 70 web::NavigationItem* item = | 104 web::NavigationItem* item = |
| 71 web_state()->GetNavigationManager()->GetVisibleItem(); | 105 web_state()->GetNavigationManager()->GetVisibleItem(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 89 | 123 |
| 90 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, | 124 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, |
| 91 icon_url_changed, image); | 125 icon_url_changed, image); |
| 92 } | 126 } |
| 93 | 127 |
| 94 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 128 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
| 95 FaviconService* favicon_service, | 129 FaviconService* favicon_service, |
| 96 history::HistoryService* history_service, | 130 history::HistoryService* history_service, |
| 97 bookmarks::BookmarkModel* bookmark_model) | 131 bookmarks::BookmarkModel* bookmark_model) |
| 98 : web::WebStateObserver(web_state), | 132 : web::WebStateObserver(web_state), |
| 99 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 133 FaviconDriverImpl(favicon_service, history_service, bookmark_model), |
| 100 } | 134 image_fetcher_(web_state->GetBrowserState()->GetRequestContext(), |
| 135 web::WebThread::GetBlockingPool()) {} | |
| 101 | 136 |
| 102 WebFaviconDriver::~WebFaviconDriver() { | 137 WebFaviconDriver::~WebFaviconDriver() { |
| 103 } | 138 } |
| 104 | 139 |
| 105 void WebFaviconDriver::FaviconUrlUpdated( | 140 void WebFaviconDriver::FaviconUrlUpdated( |
| 106 const std::vector<web::FaviconURL>& candidates) { | 141 const std::vector<web::FaviconURL>& candidates) { |
| 107 DCHECK(!candidates.empty()); | 142 DCHECK(!candidates.empty()); |
| 108 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 143 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); |
| 109 } | 144 } |
| 110 | 145 |
| 111 } // namespace favicon | 146 } // namespace favicon |
| OLD | NEW |