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/common/image_messages.h" | 9 #include "content/common/image_messages.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 fetcher->image_url(), | 88 fetcher->image_url(), |
89 requested_size, | 89 requested_size, |
90 images)); | 90 images)); |
91 | 91 |
92 // Remove the image fetcher from our pending list. We're in the callback from | 92 // Remove the image fetcher from our pending list. We're in the callback from |
93 // MultiResolutionImageResourceFetcher, best to delay deletion. | 93 // MultiResolutionImageResourceFetcher, best to delay deletion. |
94 ImageResourceFetcherList::iterator iter = | 94 ImageResourceFetcherList::iterator iter = |
95 std::find(image_fetchers_.begin(), image_fetchers_.end(), fetcher); | 95 std::find(image_fetchers_.begin(), image_fetchers_.end(), fetcher); |
96 if (iter != image_fetchers_.end()) { | 96 if (iter != image_fetchers_.end()) { |
97 image_fetchers_.weak_erase(iter); | 97 image_fetchers_.weak_erase(iter); |
98 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 98 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 SkBitmap ImageLoadingHelper::ImageFromDataUrl(const GURL& url) const { | 102 SkBitmap ImageLoadingHelper::ImageFromDataUrl(const GURL& url) const { |
103 std::string mime_type, char_set, data; | 103 std::string mime_type, char_set, data; |
104 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 104 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
105 // Decode the image using WebKit's image decoder. | 105 // Decode the image using WebKit's image decoder. |
106 webkit_glue::ImageDecoder decoder( | 106 webkit_glue::ImageDecoder decoder( |
107 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | 107 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); |
108 const unsigned char* src_data = | 108 const unsigned char* src_data = |
109 reinterpret_cast<const unsigned char*>(&data[0]); | 109 reinterpret_cast<const unsigned char*>(&data[0]); |
110 | 110 |
111 return decoder.Decode(src_data, data.size()); | 111 return decoder.Decode(src_data, data.size()); |
112 } | 112 } |
113 return SkBitmap(); | 113 return SkBitmap(); |
114 } | 114 } |
115 | 115 |
116 bool ImageLoadingHelper::OnMessageReceived(const IPC::Message& message) { | 116 bool ImageLoadingHelper::OnMessageReceived(const IPC::Message& message) { |
117 bool handled = true; | 117 bool handled = true; |
118 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) | 118 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) |
119 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) | 119 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) |
120 IPC_MESSAGE_UNHANDLED(handled = false) | 120 IPC_MESSAGE_UNHANDLED(handled = false) |
121 IPC_END_MESSAGE_MAP() | 121 IPC_END_MESSAGE_MAP() |
122 | 122 |
123 return handled; | 123 return handled; |
124 } | 124 } |
125 | 125 |
126 } // namespace content | 126 } // namespace content |
127 | 127 |
OLD | NEW |