[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / renderer / favicon_helper.h
blobacce5082ec2eabacb6fd0d94c3418ff6bcd21d21
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_
8 #include <string>
9 #include <vector>
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"
16 class SkBitmap;
18 namespace content {
19 struct FaviconURL;
22 namespace webkit_glue {
23 class MultiResolutionImageResourceFetcher;
26 namespace content {
28 struct FaviconURL;
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 {
33 public:
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);
40 private:
41 virtual ~FaviconHelper();
43 // Message handler.
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
57 // details.
58 void DidDownloadFavicon(
59 int requested_size,
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,
68 int32 page_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_