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 GURL WebFaviconDriver::GetActiveURL() { |
| 65 web::NavigationItem* item = |
| 66 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 67 return item ? item->GetURL() : GURL(); |
| 68 } |
| 69 |
| 70 int WebFaviconDriver::DownloadImage(const GURL& url, |
| 71 int max_image_size, |
| 72 ImageDownloadCallback callback) { |
65 if (WasUnableToDownloadFavicon(url)) { | 73 if (WasUnableToDownloadFavicon(url)) { |
66 DVLOG(1) << "Skip Failed FavIcon: " << url; | 74 DVLOG(1) << "Skip Failed FavIcon: " << url; |
67 return 0; | 75 return 0; |
68 } | 76 } |
69 | 77 |
70 static int downloaded_image_count = 0; | 78 static int downloaded_image_count = 0; |
71 int local_download_id = ++downloaded_image_count; | 79 int local_download_id = ++downloaded_image_count; |
72 | 80 |
73 ImageDownloadCallback local_image_callback = base::Bind( | |
74 &FaviconDriverImpl::DidDownloadFavicon, base::Unretained(this)); | |
75 GURL local_url(url); | 81 GURL local_url(url); |
76 | 82 |
77 image_fetcher::IOSImageDataFetcherCallback local_callback = | 83 image_fetcher::IOSImageDataFetcherCallback local_callback = |
78 ^(NSData* data, const image_fetcher::RequestMetadata& metadata) { | 84 ^(NSData* data, const image_fetcher::RequestMetadata& metadata) { |
79 if (metadata.response_code == | 85 if (metadata.response_code == |
80 image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID) | 86 image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID) |
81 return; | 87 return; |
82 | 88 |
83 std::vector<SkBitmap> frames; | 89 std::vector<SkBitmap> frames; |
84 std::vector<gfx::Size> sizes; | 90 std::vector<gfx::Size> sizes; |
85 if (data) { | 91 if (data) { |
86 frames = skia::ImageDataToSkBitmaps(data); | 92 frames = skia::ImageDataToSkBitmaps(data); |
87 for (const auto& frame : frames) { | 93 for (const auto& frame : frames) { |
88 sizes.push_back(gfx::Size(frame.width(), frame.height())); | 94 sizes.push_back(gfx::Size(frame.width(), frame.height())); |
89 } | 95 } |
90 } | 96 } |
91 local_image_callback.Run(local_download_id, metadata.response_code, | 97 callback.Run(local_download_id, metadata.response_code, local_url, |
92 local_url, frames, sizes); | 98 frames, sizes); |
93 }; | 99 }; |
94 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback); | 100 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback); |
95 | 101 |
96 return downloaded_image_count; | 102 return downloaded_image_count; |
97 } | 103 } |
98 | 104 |
99 bool WebFaviconDriver::IsOffTheRecord() { | 105 bool WebFaviconDriver::IsOffTheRecord() { |
100 DCHECK(web_state()); | 106 DCHECK(web_state()); |
101 return web_state()->GetBrowserState()->IsOffTheRecord(); | 107 return web_state()->GetBrowserState()->IsOffTheRecord(); |
102 } | 108 } |
103 | 109 |
104 GURL WebFaviconDriver::GetActiveURL() { | |
105 web::NavigationItem* item = | |
106 web_state()->GetNavigationManager()->GetVisibleItem(); | |
107 return item ? item->GetURL() : GURL(); | |
108 } | |
109 | |
110 void WebFaviconDriver::OnFaviconUpdated( | 110 void WebFaviconDriver::OnFaviconUpdated( |
111 const GURL& page_url, | 111 const GURL& page_url, |
112 FaviconDriverObserver::NotificationIconType notification_icon_type, | 112 FaviconDriverObserver::NotificationIconType notification_icon_type, |
113 const GURL& icon_url, | 113 const GURL& icon_url, |
114 bool icon_url_changed, | 114 bool icon_url_changed, |
115 const gfx::Image& image) { | 115 const gfx::Image& image) { |
116 // Check whether the active URL has changed since FetchFavicon() was called. | 116 // Check whether the active URL has changed since FetchFavicon() was called. |
117 // On iOS, the active URL can change between calls to FetchFavicon(). For | 117 // On iOS, the active URL can change between calls to FetchFavicon(). For |
118 // instance, FetchFavicon() is not synchronously called when the active URL | 118 // instance, FetchFavicon() is not synchronously called when the active URL |
119 // changes as a result of CRWSessionController::goToEntry(). | 119 // changes as a result of CRWSessionController::goToEntry(). |
(...skipping 18 matching lines...) Expand all 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 |