1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_
6 #define CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_
11 #include "base/memory/scoped_vector.h"
12 #include "content/public/renderer/render_view_observer.h"
13 #include "googleurl/src/gurl.h"
17 namespace webkit_glue
{
18 class MultiResolutionImageResourceFetcher
;
23 // This class deals with image downloading.
24 // One instance of ImageLoadingHelper is owned by RenderView.
25 class ImageLoadingHelper
: public RenderViewObserver
{
27 explicit ImageLoadingHelper(RenderView
* render_view
);
30 virtual ~ImageLoadingHelper();
33 void OnDownloadImage(int id
,
34 const GURL
& image_url
,
38 // Requests to download an image. When done, the ImageLoadingHelper
39 // is notified by way of DidDownloadImage. Returns true if the
40 // request was successfully started, false otherwise. id is used to
41 // uniquely identify the request and passed back to the
42 // DidDownloadImage method. If the image is a favicon, cookies will not be
43 // sent nor accepted during download. If the image has multiple frames, the
44 // frame whose size is image_size is returned. If the image doesn't
45 // have a frame at the specified size, the first is returned.
46 bool DownloadImage(int id
,
47 const GURL
& image_url
,
51 // This callback is triggered when DownloadImage completes, either
52 // succesfully or with a failure. See DownloadImage for more
54 void DidDownloadImage(
56 webkit_glue::MultiResolutionImageResourceFetcher
* fetcher
,
57 const std::vector
<SkBitmap
>& images
);
59 // Decodes a data: URL image or returns an empty image in case of failure.
60 SkBitmap
ImageFromDataUrl(const GURL
&) const;
62 // RenderViewObserver implementation.
63 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
65 typedef ScopedVector
<webkit_glue::MultiResolutionImageResourceFetcher
>
66 ImageResourceFetcherList
;
68 // ImageResourceFetchers schedule via DownloadImage.
69 ImageResourceFetcherList image_fetchers_
;
71 DISALLOW_COPY_AND_ASSIGN(ImageLoadingHelper
);
74 } // namespace content
76 #endif // CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_