OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/renderer/favicon_helper.h" | 5 #include "content/renderer/favicon_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "content/common/icon_messages.h" | 10 #include "content/common/icon_messages.h" |
| 11 #include "content/public/common/content_constants.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "net/base/data_url.h" | 13 #include "net/base/data_url.h" |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
17 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
18 #include "ui/gfx/favicon_size.h" | 19 #include "ui/gfx/favicon_size.h" |
19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
20 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ToFaviconType(icon_urls[i].iconType()))); | 79 ToFaviconType(icon_urls[i].iconType()))); |
79 } | 80 } |
80 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); | 81 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); |
81 } | 82 } |
82 | 83 |
83 FaviconHelper::~FaviconHelper() { | 84 FaviconHelper::~FaviconHelper() { |
84 } | 85 } |
85 | 86 |
86 void FaviconHelper::OnDownloadFavicon(int id, | 87 void FaviconHelper::OnDownloadFavicon(int id, |
87 const GURL& image_url, | 88 const GURL& image_url, |
| 89 DownloadImageType image_type, |
88 int image_size) { | 90 int image_size) { |
89 std::vector<SkBitmap> result_images; | 91 std::vector<SkBitmap> result_images; |
90 if (image_url.SchemeIs("data")) { | 92 if (image_url.SchemeIs("data")) { |
91 SkBitmap data_image = ImageFromDataUrl(image_url); | 93 SkBitmap data_image = ImageFromDataUrl(image_url); |
92 if (!data_image.empty()) | 94 if (!data_image.empty()) |
93 result_images.push_back(data_image); | 95 result_images.push_back(data_image); |
94 } else { | 96 } else { |
95 if (DownloadFavicon(id, image_url, image_size)) { | 97 if (DownloadFavicon(id, image_url, image_type, image_size)) { |
96 // Will complete asynchronously via FaviconHelper::DidDownloadFavicon | 98 // Will complete asynchronously via FaviconHelper::DidDownloadFavicon |
97 return; | 99 return; |
98 } | 100 } |
99 } | 101 } |
100 | 102 |
101 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), | 103 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), |
102 id, | 104 id, |
103 image_url, | 105 image_url, |
104 image_size, | 106 image_size, |
105 result_images)); | 107 result_images)); |
106 } | 108 } |
107 | 109 |
108 bool FaviconHelper::DownloadFavicon(int id, | 110 bool FaviconHelper::DownloadFavicon(int id, |
109 const GURL& image_url, | 111 const GURL& image_url, |
| 112 DownloadImageType image_type, |
110 int image_size) { | 113 int image_size) { |
111 // Make sure webview was not shut down. | 114 // Make sure webview was not shut down. |
112 if (!render_view()->GetWebView()) | 115 if (!render_view()->GetWebView()) |
113 return false; | 116 return false; |
114 // Create an image resource fetcher and assign it with a call back object. | 117 // Create an image resource fetcher and assign it with a call back object. |
| 118 WebURLRequest::TargetType target_type; |
| 119 switch (image_type) { |
| 120 case DOWNLOAD_FAVICON: |
| 121 target_type = WebURLRequest::TargetIsFavicon; |
| 122 break; |
| 123 case DOWNLOAD_OTHER: |
| 124 target_type = WebURLRequest::TargetIsImage; |
| 125 break; |
| 126 default: |
| 127 NOTREACHED(); |
| 128 } |
| 129 |
115 image_fetchers_.push_back(new MultiResolutionImageResourceFetcher( | 130 image_fetchers_.push_back(new MultiResolutionImageResourceFetcher( |
116 image_url, render_view()->GetWebView()->mainFrame(), id, | 131 image_url, |
117 WebURLRequest::TargetIsFavicon, | 132 render_view()->GetWebView()->mainFrame(), |
| 133 id, |
| 134 target_type, |
118 base::Bind(&FaviconHelper::DidDownloadFavicon, | 135 base::Bind(&FaviconHelper::DidDownloadFavicon, |
119 base::Unretained(this), image_size))); | 136 base::Unretained(this), image_size))); |
120 return true; | 137 return true; |
121 } | 138 } |
122 | 139 |
123 void FaviconHelper::DidDownloadFavicon( | 140 void FaviconHelper::DidDownloadFavicon( |
124 int requested_size, | 141 int requested_size, |
125 MultiResolutionImageResourceFetcher* fetcher, | 142 MultiResolutionImageResourceFetcher* fetcher, |
126 const std::vector<SkBitmap>& images) { | 143 const std::vector<SkBitmap>& images) { |
127 // Notify requester of image download status. | 144 // Notify requester of image download status. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 std::vector<FaviconURL> urls; | 199 std::vector<FaviconURL> urls; |
183 for (size_t i = 0; i < icon_urls.size(); i++) { | 200 for (size_t i = 0; i < icon_urls.size(); i++) { |
184 WebURL url = icon_urls[i].iconURL(); | 201 WebURL url = icon_urls[i].iconURL(); |
185 if (!url.isEmpty()) | 202 if (!url.isEmpty()) |
186 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); | 203 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); |
187 } | 204 } |
188 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); | 205 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); |
189 } | 206 } |
190 | 207 |
191 } // namespace content | 208 } // namespace content |
OLD | NEW |