OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_RENDERER_FAVICON_HELPER_H_ | |
6 #define CONTENT_RENDERER_FAVICON_HELPER_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/linked_ptr.h" | |
12 #include "base/memory/scoped_vector.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "content/public/common/content_constants.h" | |
15 #include "content/public/renderer/render_view_observer.h" | |
16 #include "googleurl/src/gurl.h" | |
17 | |
18 class SkBitmap; | |
19 | |
20 namespace content { | |
21 struct FaviconURL; | |
22 } | |
23 | |
24 namespace webkit_glue { | |
25 class MultiResolutionImageResourceFetcher; | |
26 } | |
27 | |
28 namespace content { | |
29 | |
30 struct FaviconURL; | |
31 | |
32 // This class deals with favicon downloading. | |
33 // There is one FaviconHelper per RenderView, which is owned by the RenderView. | |
34 class FaviconHelper : public RenderViewObserver { | |
35 public: | |
36 explicit FaviconHelper(RenderView* render_view); | |
37 | |
38 // Send a message that the favicon has changed. | |
39 void DidChangeIcon(WebKit::WebFrame* frame, | |
40 WebKit::WebIconURL::Type icon_type); | |
41 | |
42 private: | |
43 virtual ~FaviconHelper(); | |
44 | |
45 // Start processing the icon change. This done async from DidChangeIcon in | |
46 // case there are several calls to DidChangeIcon in a row. | |
47 void ProcessDidChangeIcon(); | |
48 | |
49 // Message handler. | |
50 void OnDownloadFavicon(int id, | |
51 const GURL& image_url, | |
52 bool is_favicon, | |
53 int image_size); | |
54 | |
55 // Requests to download a favicon image. When done, the RenderView | |
56 // is notified by way of DidDownloadFavicon. Returns true if the | |
57 // request was successfully started, false otherwise. id is used to | |
58 // uniquely identify the request and passed back to the | |
59 // DidDownloadFavicon method. If the image is a favicon, cookies are | |
60 // not sent and not accepted during download. | |
61 // If the image has multiple frames, the | |
62 // frame whose size is image_size is returned. If the image doesn't | |
63 // have a frame at the specified size, the first is returned. | |
64 bool DownloadFavicon(int id, | |
65 const GURL& image_url, | |
66 bool is_favicon, | |
67 int image_size); | |
68 | |
69 // This callback is triggered when DownloadFavicon completes, either | |
70 // succesfully or with a failure. See DownloadFavicon for more | |
71 // details. | |
72 void DidDownloadFavicon( | |
73 int requested_size, | |
74 webkit_glue::MultiResolutionImageResourceFetcher* fetcher, | |
75 const std::vector<SkBitmap>& images); | |
76 | |
77 // Decodes a data: URL image or returns an empty image in case of failure. | |
78 SkBitmap ImageFromDataUrl(const GURL&) const; | |
79 | |
80 // Send a message to update the favicon URL for a page. | |
81 void SendUpdateFaviconURL(int32 routing_id, | |
82 int32 page_id, | |
83 const std::vector<FaviconURL>& urls); | |
84 | |
85 // RenderViewObserver implementation. | |
86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
87 virtual void DidStopLoading() OVERRIDE; | |
88 | |
89 typedef ScopedVector<webkit_glue::MultiResolutionImageResourceFetcher> | |
90 ImageResourceFetcherList; | |
91 | |
92 // ImageResourceFetchers schedule via DownloadImage. | |
93 ImageResourceFetcherList image_fetchers_; | |
94 | |
95 // The set of flags which have been sent to DidChangeIcon but not yet | |
96 // processed. | |
97 WebKit::WebIconURL::Type icon_types_changed_; | |
98 | |
99 base::WeakPtrFactory<FaviconHelper> weak_ptr_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(FaviconHelper); | |
102 }; | |
103 | |
104 } // namespace content | |
105 | |
106 #endif // CONTENT_RENDERER_FAVICON_HELPER_H_ | |
OLD | NEW |