| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | |
| 6 | |
| 7 #include "base/compiler_specific.h" | |
| 8 | |
| 9 MSVC_PUSH_WARNING_LEVEL(0); | |
| 10 #include "ImageSourceSkia.h" | |
| 11 MSVC_POP_WARNING(); | |
| 12 #undef LOG | |
| 13 | |
| 14 #include "webkit/glue/image_resource_fetcher.h" | 5 #include "webkit/glue/image_resource_fetcher.h" |
| 15 | 6 |
| 16 #include "base/gfx/size.h" | 7 #include "base/gfx/size.h" |
| 17 #include "webkit/glue/image_decoder.h" | 8 #include "webkit/glue/image_decoder.h" |
| 18 #include "webkit/glue/webview_impl.h" | 9 #include "webkit/glue/webframe.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 | 11 |
| 12 namespace webkit_glue { |
| 13 |
| 21 ImageResourceFetcher::ImageResourceFetcher( | 14 ImageResourceFetcher::ImageResourceFetcher( |
| 22 WebViewImpl* web_view, | 15 const GURL& image_url, |
| 16 WebFrame* frame, |
| 23 int id, | 17 int id, |
| 24 const GURL& image_url, | 18 int image_size, |
| 25 int image_size) | 19 Callback* callback) |
| 26 : web_view_(web_view), | 20 : callback_(callback), |
| 27 id_(id), | 21 id_(id), |
| 28 image_url_(image_url), | 22 image_url_(image_url), |
| 29 image_size_(image_size) { | 23 image_size_(image_size) { |
| 30 fetcher_.reset(new ResourceFetcher(image_url, | 24 fetcher_.reset(new ResourceFetcher( |
| 31 web_view->main_frame()->frame(), | 25 image_url, frame, |
| 32 this)); | 26 NewCallback(this, &ImageResourceFetcher::OnURLFetchComplete))); |
| 33 } | 27 } |
| 34 | 28 |
| 35 ImageResourceFetcher::~ImageResourceFetcher() { | 29 ImageResourceFetcher::~ImageResourceFetcher() { |
| 36 if (!fetcher_->completed()) | 30 if (!fetcher_->completed()) |
| 37 fetcher_->Cancel(); | 31 fetcher_->Cancel(); |
| 38 } | 32 } |
| 39 | 33 |
| 40 void ImageResourceFetcher::OnURLFetchComplete( | 34 void ImageResourceFetcher::OnURLFetchComplete( |
| 41 const WebCore::ResourceResponse& response, | 35 const WebKit::WebURLResponse& response, |
| 42 const std::string& data) { | 36 const std::string& data) { |
| 43 SkBitmap image; | 37 SkBitmap bitmap; |
| 44 bool errored = false; | 38 if (!response.isNull() && response.httpStatusCode() == 200) { |
| 45 if (response.isNull()) { | |
| 46 errored = true; | |
| 47 } else if (response.httpStatusCode() == 200) { | |
| 48 // Request succeeded, try to convert it to an image. | 39 // Request succeeded, try to convert it to an image. |
| 49 webkit_glue::ImageDecoder decoder(gfx::Size(image_size_, image_size_)); | 40 ImageDecoder decoder(gfx::Size(image_size_, image_size_)); |
| 50 image = decoder.Decode( | 41 bitmap = decoder.Decode( |
| 51 reinterpret_cast<const unsigned char*>(data.data()), data.size()); | 42 reinterpret_cast<const unsigned char*>(data.data()), data.size()); |
| 52 } // else case: | 43 } // else case: |
| 53 // If we get here, it means no image from server or couldn't decode the | 44 // If we get here, it means no image from server or couldn't decode the |
| 54 // response as an image. Need to notify the webview though, otherwise the | 45 // response as an image. The delegate will see a null image, indicating |
| 55 // browser will keep trying to download favicon (when this is used to | 46 // that an error occurred. |
| 56 // download the favicon). | 47 callback_->Run(this, bitmap); |
| 57 web_view_->ImageResourceDownloadDone(this, errored, image); | |
| 58 } | 48 } |
| 49 |
| 50 } // namespace webkit_glue |
| OLD | NEW |