Chromium Code Reviews| 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/fetchers/multi_resolution_image_resource_fetcher.h" | 5 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "net/base/mime_util.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 12 #include "webkit/glue/image_decoder.h" | 14 #include "webkit/glue/image_decoder.h" |
| 13 | 15 |
| 14 using WebKit::WebFrame; | 16 using WebKit::WebFrame; |
| 15 using WebKit::WebURLRequest; | 17 using WebKit::WebURLRequest; |
| 16 using WebKit::WebURLResponse; | 18 using WebKit::WebURLResponse; |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 37 if (!fetcher_->completed()) | 39 if (!fetcher_->completed()) |
| 38 fetcher_->Cancel(); | 40 fetcher_->Cancel(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void MultiResolutionImageResourceFetcher::OnURLFetchComplete( | 43 void MultiResolutionImageResourceFetcher::OnURLFetchComplete( |
| 42 const WebURLResponse& response, | 44 const WebURLResponse& response, |
| 43 const std::string& data) { | 45 const std::string& data) { |
| 44 std::vector<SkBitmap> bitmaps; | 46 std::vector<SkBitmap> bitmaps; |
| 45 if (!response.isNull()) { | 47 if (!response.isNull()) { |
| 46 http_status_code_ = response.httpStatusCode(); | 48 http_status_code_ = response.httpStatusCode(); |
| 47 if (http_status_code_ == 200) { | 49 std::string mime_type = UTF16ToUTF8(response.mimeType()); |
| 50 if (http_status_code_ == 200 || (net::IsSupportedImageMimeType(mime_type) && | |
|
Nico
2013/06/04 18:01:20
This will now also let through a partially downloa
| |
| 51 data.size() > 0)) { | |
| 48 // Request succeeded, try to convert it to an image. | 52 // Request succeeded, try to convert it to an image. |
| 49 bitmaps = webkit_glue::ImageDecoder::DecodeAll( | 53 bitmaps = webkit_glue::ImageDecoder::DecodeAll( |
| 50 reinterpret_cast<const unsigned char*>(data.data()), data.size()); | 54 reinterpret_cast<const unsigned char*>(data.data()), data.size()); |
| 51 } | 55 } |
| 52 } // else case: | 56 } // else case: |
| 53 // If we get here, it means no image from server or couldn't decode the | 57 // If we get here, it means no image from server or couldn't decode the |
| 54 // response as an image. The delegate will see an empty vector. | 58 // response as an image. The delegate will see an empty vector. |
| 55 | 59 |
| 56 // Take a reference to the callback as running the callback may lead to our | 60 // Take a reference to the callback as running the callback may lead to our |
| 57 // destruction. | 61 // destruction. |
| 58 Callback callback = callback_; | 62 Callback callback = callback_; |
| 59 callback.Run(this, bitmaps); | 63 callback.Run(this, bitmaps); |
| 60 } | 64 } |
| 61 | 65 |
| 62 } // namespace content | 66 } // namespace content |
| OLD | NEW |