| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_FAVICON_HELPER_H_ | 5 #ifndef CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_ |
| 6 #define CONTENT_RENDERER_FAVICON_HELPER_H_ | 6 #define CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/memory/scoped_vector.h" | 11 #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" | 12 #include "content/public/renderer/render_view_observer.h" |
| 16 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 17 | 14 |
| 18 class SkBitmap; | 15 class SkBitmap; |
| 19 | 16 |
| 20 namespace content { | |
| 21 struct FaviconURL; | |
| 22 } | |
| 23 | |
| 24 namespace webkit_glue { | 17 namespace webkit_glue { |
| 25 class MultiResolutionImageResourceFetcher; | 18 class MultiResolutionImageResourceFetcher; |
| 26 } | 19 } |
| 27 | 20 |
| 28 namespace content { | 21 namespace content { |
| 29 | 22 |
| 30 struct FaviconURL; | 23 // This class deals with image downloading. |
| 31 | 24 // One instance of ImageLoadingHelper is owned by RenderView. |
| 32 // This class deals with favicon downloading. | 25 class ImageLoadingHelper : public RenderViewObserver { |
| 33 // There is one FaviconHelper per RenderView, which is owned by the RenderView. | |
| 34 class FaviconHelper : public RenderViewObserver { | |
| 35 public: | 26 public: |
| 36 explicit FaviconHelper(RenderView* render_view); | 27 explicit ImageLoadingHelper(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 | 28 |
| 42 private: | 29 private: |
| 43 virtual ~FaviconHelper(); | 30 virtual ~ImageLoadingHelper(); |
| 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 | 31 |
| 49 // Message handler. | 32 // Message handler. |
| 50 void OnDownloadFavicon(int id, | 33 void OnDownloadImage(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, | 34 const GURL& image_url, |
| 66 bool is_favicon, | 35 bool is_favicon, |
| 67 int image_size); | 36 int image_size); |
| 68 | 37 |
| 69 // This callback is triggered when DownloadFavicon completes, either | 38 // Requests to download an image. When done, the ImageLoadingHelper |
| 70 // succesfully or with a failure. See DownloadFavicon for more | 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, |
| 48 bool is_favicon, |
| 49 int image_size); |
| 50 |
| 51 // This callback is triggered when DownloadImage completes, either |
| 52 // succesfully or with a failure. See DownloadImage for more |
| 71 // details. | 53 // details. |
| 72 void DidDownloadFavicon( | 54 void DidDownloadImage( |
| 73 int requested_size, | 55 int requested_size, |
| 74 webkit_glue::MultiResolutionImageResourceFetcher* fetcher, | 56 webkit_glue::MultiResolutionImageResourceFetcher* fetcher, |
| 75 const std::vector<SkBitmap>& images); | 57 const std::vector<SkBitmap>& images); |
| 76 | 58 |
| 77 // Decodes a data: URL image or returns an empty image in case of failure. | 59 // Decodes a data: URL image or returns an empty image in case of failure. |
| 78 SkBitmap ImageFromDataUrl(const GURL&) const; | 60 SkBitmap ImageFromDataUrl(const GURL&) const; |
| 79 | 61 |
| 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. | 62 // RenderViewObserver implementation. |
| 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 63 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 87 virtual void DidStopLoading() OVERRIDE; | |
| 88 | 64 |
| 89 typedef ScopedVector<webkit_glue::MultiResolutionImageResourceFetcher> | 65 typedef ScopedVector<webkit_glue::MultiResolutionImageResourceFetcher> |
| 90 ImageResourceFetcherList; | 66 ImageResourceFetcherList; |
| 91 | 67 |
| 92 // ImageResourceFetchers schedule via DownloadImage. | 68 // ImageResourceFetchers schedule via DownloadImage. |
| 93 ImageResourceFetcherList image_fetchers_; | 69 ImageResourceFetcherList image_fetchers_; |
| 94 | 70 |
| 95 // The set of flags which have been sent to DidChangeIcon but not yet | 71 DISALLOW_COPY_AND_ASSIGN(ImageLoadingHelper); |
| 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 }; | 72 }; |
| 103 | 73 |
| 104 } // namespace content | 74 } // namespace content |
| 105 | 75 |
| 106 #endif // CONTENT_RENDERER_FAVICON_HELPER_H_ | 76 #endif // CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_ |
| 77 |
| OLD | NEW |