Commit 36b0a346 authored by gambard's avatar gambard Committed by Commit bot

Implement DownloadImage directly in WebStateImpl

The DownloadImage method in WebState was implemented in Tab.
This CL moves the implementation to WebStateImpl.

BUG=664988

Review-Url: https://codereview.chromium.org/2528043002
Cr-Commit-Position: refs/heads/master@{#436319}
parent 8c17a45f
......@@ -246,6 +246,7 @@ source_set("web") {
"//components/url_formatter",
"//ios/net",
"//ios/third_party/blink:html_tokenizer",
"//ios/web/public/image_fetcher",
"//mojo/public/cpp/system",
"//mojo/public/js",
"//net",
......
......@@ -103,11 +103,6 @@ struct Referrer;
onFormResubmissionForRequest:(NSURLRequest*)request
continueBlock:(ProceduralBlock)continueBlock
cancelBlock:(ProceduralBlock)cancelBlock;
// Returns the unique id of the download request and starts downloading the
// image at |url| without sending the cookies. Invokes |callback| on completion.
- (int)downloadImageAtUrl:(const GURL&)url
maxBitmapSize:(uint32_t)maxBitmapSize
callback:(const web::WebState::ImageDownloadCallback&)callback;
// ---------------------------------------------------------------------
// TODO(rohitrao): Eliminate as many of the following delegate methods as
......
include_rules = [
"+skia/ext/skia_utils_ios.h",
"+third_party/skia/include/core/SkBitmap.h",
]
......@@ -43,6 +43,7 @@ struct Credential;
struct FaviconURL;
struct LoadCommittedDetails;
class NavigationManager;
class ImageDataFetcher;
class WebInterstitialImpl;
class WebStateDelegate;
class WebStateFacadeDelegate;
......@@ -369,6 +370,9 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate {
// Mojo interface registry for this WebState.
std::unique_ptr<service_manager::InterfaceRegistry> mojo_interface_registry_;
// Image Fetcher used to images.
std::unique_ptr<ImageDataFetcher> image_fetcher_;
DISALLOW_COPY_AND_ASSIGN(WebStateImpl);
};
......
......@@ -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"
#import "ios/web/public/image_fetcher/image_data_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 ImageDataFetcher(web::WebThread::GetBlockingPool()));
image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext());
}
WebStateImpl::~WebStateImpl() {
......@@ -538,9 +544,28 @@ 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 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() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment