Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: content/renderer/fetchers/image_resource_fetcher.cc

Issue 140823010: ResourceFetcher: Add POST support and the ability to set headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Gack Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/image_resource_fetcher.h" 5 #include "content/renderer/fetchers/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/debug/crash_logging.h" 9 #include "base/debug/crash_logging.h"
10 #include "content/child/image_decoder.h" 10 #include "content/child/image_decoder.h"
(...skipping 13 matching lines...) Expand all
24 const GURL& image_url, 24 const GURL& image_url,
25 WebFrame* frame, 25 WebFrame* frame,
26 int id, 26 int id,
27 int image_size, 27 int image_size,
28 WebURLRequest::TargetType target_type, 28 WebURLRequest::TargetType target_type,
29 const Callback& callback) 29 const Callback& callback)
30 : callback_(callback), 30 : callback_(callback),
31 id_(id), 31 id_(id),
32 image_url_(image_url), 32 image_url_(image_url),
33 image_size_(image_size) { 33 image_size_(image_size) {
34 fetcher_.reset(ResourceFetcher::Create( 34 fetcher_.reset(ResourceFetcher::Create(image_url));
35 image_url, frame, target_type, 35 fetcher_->Start(frame, target_type,
36 base::Bind(&ImageResourceFetcher::OnURLFetchComplete, 36 base::Bind(&ImageResourceFetcher::OnURLFetchComplete,
37 base::Unretained(this)))); 37 base::Unretained(this)));
38 38
39 // Set subresource URL for crash reporting. 39 // Set subresource URL for crash reporting.
40 base::debug::SetCrashKeyValue("subresource_url", image_url.spec()); 40 base::debug::SetCrashKeyValue("subresource_url", image_url.spec());
41 } 41 }
42 42
43 ImageResourceFetcher::~ImageResourceFetcher() { 43 ImageResourceFetcher::~ImageResourceFetcher() {
44 } 44 }
45 45
46 void ImageResourceFetcher::OnURLFetchComplete( 46 void ImageResourceFetcher::OnURLFetchComplete(
47 const WebURLResponse& response, 47 const WebURLResponse& response,
48 const std::string& data) { 48 const std::string& data) {
49 SkBitmap bitmap; 49 SkBitmap bitmap;
50 if (!response.isNull() && response.httpStatusCode() == 200) { 50 if (!response.isNull() && response.httpStatusCode() == 200) {
51 // Request succeeded, try to convert it to an image. 51 // Request succeeded, try to convert it to an image.
52 ImageDecoder decoder(gfx::Size(image_size_, image_size_)); 52 ImageDecoder decoder(gfx::Size(image_size_, image_size_));
53 bitmap = decoder.Decode( 53 bitmap = decoder.Decode(
54 reinterpret_cast<const unsigned char*>(data.data()), data.size()); 54 reinterpret_cast<const unsigned char*>(data.data()), data.size());
55 } // else case: 55 } // else case:
56 // If we get here, it means no image from server or couldn't decode the 56 // If we get here, it means no image from server or couldn't decode the
57 // response as an image. The delegate will see a null image, indicating 57 // response as an image. The delegate will see a null image, indicating
58 // that an error occurred. 58 // that an error occurred.
59 59
60 // 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
61 // destruction. 61 // destruction.
62 Callback callback = callback_; 62 Callback callback = callback_;
63 callback.Run(this, bitmap); 63 callback.Run(this, bitmap);
64 } 64 }
65 65
66 } // namespace content 66 } // namespace content
OLDNEW
« no previous file with comments | « content/public/renderer/resource_fetcher.h ('k') | content/renderer/fetchers/multi_resolution_image_resource_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698