Chromium Code Reviews| 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 2be723464c9b10db360e5099e61e6be65c25390e..48e3b145d457de0ebbad88b63a8e2a94dfeb318c 100644 |
| --- a/ios/web/web_state/web_state_impl.mm |
| +++ b/ios/web/web_state/web_state_impl.mm |
| @@ -16,6 +16,7 @@ |
| #include "ios/web/navigation/navigation_item_impl.h" |
| #include "ios/web/net/request_group_util.h" |
| #include "ios/web/public/browser_state.h" |
| +#include "ios/web/public/image_fetcher/raw_image_fetcher.h" |
| #import "ios/web/public/java_script_dialog_presenter.h" |
| #include "ios/web/public/navigation_item.h" |
| #include "ios/web/public/url_util.h" |
| @@ -33,7 +34,10 @@ |
| #import "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
| #import "ios/web/webui/web_ui_ios_impl.h" |
| #include "net/http/http_response_headers.h" |
| +#include "net/url_request/url_fetcher.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 { |
| @@ -63,6 +67,8 @@ WebStateImpl::WebStateImpl(BrowserState* browser_state) |
| weak_factory_(this) { |
| GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
| web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
| + image_fetcher_.reset(new RawImageFetcher(web::WebThread::GetBlockingPool())); |
| + image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); |
| } |
| WebStateImpl::~WebStateImpl() { |
| @@ -538,9 +544,30 @@ int WebStateImpl::DownloadImage( |
| // 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); |
| - return [[web_controller_ delegate] downloadImageAtUrl:url |
| - maxBitmapSize:max_bitmap_size |
| - callback:callback]; |
| + |
| + static int g_download_id = 0; |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
nit: g_ prefix means "global", so please don't use
gambard
2016/12/01 15:14:21
Done.
|
| + int localDownloadId = ++g_download_id; |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
s/localDownloadId/local_download_id
Same comments
gambard
2016/12/01 15:14:21
Done.
|
| + __block web::WebState::ImageDownloadCallback localImageCallback = callback; |
| + __block GURL localUrl(url); |
| + ImageFetchedCallback localCallback = |
| + ^(const GURL& originalUrl, const int responseCode, NSData* data) { |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
nit: you can drop |originalUrl|
gambard
2016/12/01 15:14:21
Done.
|
| + 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 (responseCode != net::URLFetcher::RESPONSE_CODE_INVALID) { |
| + localImageCallback.Run(localDownloadId, responseCode, localUrl, |
| + frames, sizes); |
| + } |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
We should also call callback for failure cases, un
gambard
2016/12/01 15:14:21
This is not for failure. From the comments on the
|
| + }; |
| + // |imageFetcher_| may have been reset if the tab got closed. |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
Please don't mention tab here, web does not know a
gambard
2016/12/01 15:14:21
Done.
|
| + if (image_fetcher_) |
| + image_fetcher_->StartDownload(url, localCallback); |
| + return g_download_id; |
| } |
| service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { |