| OLD | NEW |
| 1 // Copyright (c) 2013 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 #include "content/renderer/image_loading_helper.h" | 5 #include "content/renderer/image_loading_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/child/image_decoder.h" |
| 9 #include "content/common/image_messages.h" | 10 #include "content/common/image_messages.h" |
| 10 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 12 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" | 13 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" |
| 13 #include "net/base/data_url.h" | 14 #include "net/base/data_url.h" |
| 14 #include "skia/ext/image_operations.h" | 15 #include "skia/ext/image_operations.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 16 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 16 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
| 17 #include "third_party/WebKit/public/web/WebFrame.h" | 18 #include "third_party/WebKit/public/web/WebFrame.h" |
| 18 #include "third_party/WebKit/public/web/WebView.h" | 19 #include "third_party/WebKit/public/web/WebView.h" |
| 19 #include "ui/gfx/favicon_size.h" | 20 #include "ui/gfx/favicon_size.h" |
| 20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 21 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
| 22 #include "webkit/glue/image_decoder.h" | |
| 23 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
| 24 | 24 |
| 25 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
| 26 using WebKit::WebVector; | 26 using WebKit::WebVector; |
| 27 using WebKit::WebURL; | 27 using WebKit::WebURL; |
| 28 using WebKit::WebURLRequest; | 28 using WebKit::WebURLRequest; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Proportionally resizes the |image| to fit in a box of size | 32 // Proportionally resizes the |image| to fit in a box of size |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (iter != image_fetchers_.end()) { | 163 if (iter != image_fetchers_.end()) { |
| 164 image_fetchers_.weak_erase(iter); | 164 image_fetchers_.weak_erase(iter); |
| 165 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 165 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 SkBitmap ImageLoadingHelper::ImageFromDataUrl(const GURL& url) const { | 169 SkBitmap ImageLoadingHelper::ImageFromDataUrl(const GURL& url) const { |
| 170 std::string mime_type, char_set, data; | 170 std::string mime_type, char_set, data; |
| 171 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 171 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 172 // Decode the image using WebKit's image decoder. | 172 // Decode the image using WebKit's image decoder. |
| 173 webkit_glue::ImageDecoder decoder( | 173 ImageDecoder decoder(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); |
| 174 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | |
| 175 const unsigned char* src_data = | 174 const unsigned char* src_data = |
| 176 reinterpret_cast<const unsigned char*>(&data[0]); | 175 reinterpret_cast<const unsigned char*>(&data[0]); |
| 177 | 176 |
| 178 return decoder.Decode(src_data, data.size()); | 177 return decoder.Decode(src_data, data.size()); |
| 179 } | 178 } |
| 180 return SkBitmap(); | 179 return SkBitmap(); |
| 181 } | 180 } |
| 182 | 181 |
| 183 bool ImageLoadingHelper::OnMessageReceived(const IPC::Message& message) { | 182 bool ImageLoadingHelper::OnMessageReceived(const IPC::Message& message) { |
| 184 bool handled = true; | 183 bool handled = true; |
| 185 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) | 184 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) |
| 186 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) | 185 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) |
| 187 IPC_MESSAGE_UNHANDLED(handled = false) | 186 IPC_MESSAGE_UNHANDLED(handled = false) |
| 188 IPC_END_MESSAGE_MAP() | 187 IPC_END_MESSAGE_MAP() |
| 189 | 188 |
| 190 return handled; | 189 return handled; |
| 191 } | 190 } |
| 192 | 191 |
| 193 } // namespace content | 192 } // namespace content |
| OLD | NEW |