1 // Copyright (c) 2011 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_FAVICON_HELPER_H_
6 #define CONTENT_RENDERER_FAVICON_HELPER_H_
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "content/public/renderer/render_view_observer.h"
14 #include "googleurl/src/gurl.h"
22 namespace webkit_glue
{
23 class MultiResolutionImageResourceFetcher
;
30 // This class deals with favicon downloading.
31 // There is one FaviconHelper per RenderView, which is owned by the RenderView.
32 class FaviconHelper
: public RenderViewObserver
{
34 explicit FaviconHelper(RenderView
* render_view
);
36 // Sund a message that the favicon has changed.
37 void DidChangeIcon(WebKit::WebFrame
* frame
,
38 WebKit::WebIconURL::Type icon_type
);
41 virtual ~FaviconHelper();
44 void OnDownloadFavicon(int id
, const GURL
& image_url
, int image_size
);
46 // Requests to download a favicon image. When done, the RenderView
47 // is notified by way of DidDownloadFavicon. Returns true if the
48 // request was successfully started, false otherwise. id is used to
49 // uniquely identify the request and passed back to the
50 // DidDownloadFavicon method. If the image has multiple frames, the
51 // frame whose size is image_size is returned. If the image doesn't
52 // have a frame at the specified size, the first is returned.
53 bool DownloadFavicon(int id
, const GURL
& image_url
, int image_size
);
55 // This callback is triggered when DownloadFavicon completes, either
56 // succesfully or with a failure. See DownloadFavicon for more
58 void DidDownloadFavicon(
60 webkit_glue::MultiResolutionImageResourceFetcher
* fetcher
,
61 const std::vector
<SkBitmap
>& images
);
63 // Decodes a data: URL image or returns an empty image in case of failure.
64 SkBitmap
ImageFromDataUrl(const GURL
&) const;
66 // Send a message to update the favicon URL for a page.
67 void SendUpdateFaviconURL(int32 routing_id
,
69 const std::vector
<FaviconURL
>& urls
);
71 // RenderViewObserver implementation.
72 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
73 virtual void DidStopLoading() OVERRIDE
;
75 typedef ScopedVector
<webkit_glue::MultiResolutionImageResourceFetcher
>
76 ImageResourceFetcherList
;
78 // ImageResourceFetchers schedule via DownloadImage.
79 ImageResourceFetcherList image_fetchers_
;
81 DISALLOW_COPY_AND_ASSIGN(FaviconHelper
);
84 } // namespace content
86 #endif // CONTENT_RENDERER_FAVICON_HELPER_H_