Index: ios/web/web_state/web_state_impl.mm |
diff --git a/ios/web/web_state/web_state_impl.mm b/ios/web/web_state/web_state_impl.mm |
index c30fd510d0d55ef24b2c7bb100f33af4dd9ff8ae..05fb07a82a1d2e6d463e9457e0fa9110028db8d8 100644 |
--- a/ios/web/web_state/web_state_impl.mm |
+++ b/ios/web/web_state/web_state_impl.mm |
@@ -18,6 +18,7 @@ |
#import "ios/web/navigation/session_storage_builder.h" |
#include "ios/web/public/browser_state.h" |
#import "ios/web/public/crw_session_storage.h" |
+#import "ios/web/public/image_fetcher/image_data_fetcher.h" |
#import "ios/web/public/java_script_dialog_presenter.h" |
#import "ios/web/public/navigation_item.h" |
#include "ios/web/public/url_util.h" |
@@ -37,7 +38,11 @@ |
#include "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
#include "ios/web/webui/web_ui_ios_impl.h" |
#include "net/http/http_response_headers.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_request_context_getter.h" |
#include "services/service_manager/public/cpp/interface_registry.h" |
+#include "skia/ext/skia_utils_ios.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
namespace web { |
@@ -96,6 +101,10 @@ |
// Send creation event and create the web controller. |
GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
+ // Set up the image fetcher. |
+ image_fetcher_ = |
+ base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); |
+ image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); |
} |
WebStateImpl::~WebStateImpl() { |
@@ -553,6 +562,40 @@ |
} |
#pragma mark - RequestTracker management |
+ |
+int WebStateImpl::DownloadImage( |
+ const GURL& url, |
+ bool is_favicon, |
+ uint32_t max_bitmap_size, |
+ bool bypass_cache, |
+ const ImageDownloadCallback& callback) { |
+ // |is_favicon| specifies whether the download of the image occurs with |
+ // cookies or not. Currently, only downloads without cookies are supported. |
+ // |bypass_cache| is ignored since the downloads never go through a cache. |
+ DCHECK(is_favicon); |
+ |
+ static int downloaded_image_count = 0; |
+ int local_download_id = ++downloaded_image_count; |
+ __block web::WebState::ImageDownloadCallback local_image_callback = callback; |
+ __block GURL local_url(url); |
+ ImageFetchedCallback local_callback = |
+ ^(const GURL&, const int response_code, NSData* data) { |
+ std::vector<SkBitmap> frames; |
+ std::vector<gfx::Size> sizes; |
+ if (data) { |
+ frames = skia::ImageDataToSkBitmaps(data); |
+ for (auto& frame : frames) { |
+ sizes.push_back(gfx::Size(frame.width(), frame.height())); |
+ } |
+ } |
+ if (response_code != net::URLFetcher::RESPONSE_CODE_INVALID) { |
+ local_image_callback.Run(local_download_id, response_code, local_url, |
+ frames, sizes); |
+ } |
+ }; |
+ image_fetcher_->StartDownload(url, local_callback); |
+ return downloaded_image_count; |
+} |
service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { |
if (!mojo_interface_registry_) { |