exclude PluginsFieldTrialTest.NoPrefLeftBehind from valgrind bot
[chromium-blink-merge.git] / android_webview / browser / aw_web_resource_response.cc
blob44f2aa87abdc9d2a3ea170d1c7c3cfc6d400cac5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "android_webview/browser/aw_web_resource_response.h"
7 #include "android_webview/browser/input_stream.h"
8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "net/http/http_response_headers.h"
12 namespace android_webview {
14 namespace {
16 class StreamReaderJobDelegateImpl
17 : public AndroidStreamReaderURLRequestJob::Delegate {
18 public:
19 StreamReaderJobDelegateImpl(
20 scoped_ptr<AwWebResourceResponse> aw_web_resource_response)
21 : aw_web_resource_response_(aw_web_resource_response.Pass()) {
22 DCHECK(aw_web_resource_response_);
25 scoped_ptr<InputStream> OpenInputStream(JNIEnv* env,
26 const GURL& url) override {
27 return aw_web_resource_response_->GetInputStream(env).Pass();
30 void OnInputStreamOpenFailed(net::URLRequest* request,
31 bool* restart) override {
32 *restart = false;
35 bool GetMimeType(JNIEnv* env,
36 net::URLRequest* request,
37 android_webview::InputStream* stream,
38 std::string* mime_type) override {
39 return aw_web_resource_response_->GetMimeType(env, mime_type);
42 bool GetCharset(JNIEnv* env,
43 net::URLRequest* request,
44 android_webview::InputStream* stream,
45 std::string* charset) override {
46 return aw_web_resource_response_->GetCharset(env, charset);
49 void AppendResponseHeaders(JNIEnv* env,
50 net::HttpResponseHeaders* headers) override {
51 int status_code;
52 std::string reason_phrase;
53 if (aw_web_resource_response_->GetStatusInfo(
54 env, &status_code, &reason_phrase)) {
55 std::string status_line("HTTP/1.1 ");
56 status_line.append(base::IntToString(status_code));
57 status_line.append(" ");
58 status_line.append(reason_phrase);
59 headers->ReplaceStatusLine(status_line);
61 aw_web_resource_response_->GetResponseHeaders(env, headers);
64 private:
65 scoped_ptr<AwWebResourceResponse> aw_web_resource_response_;
68 } // namespace
70 // static
71 net::URLRequestJob* AwWebResourceResponse::CreateJobFor(
72 scoped_ptr<AwWebResourceResponse> aw_web_resource_response,
73 net::URLRequest* request,
74 net::NetworkDelegate* network_delegate) {
75 DCHECK(aw_web_resource_response);
76 DCHECK(request);
77 DCHECK(network_delegate);
79 return new AndroidStreamReaderURLRequestJob(
80 request,
81 network_delegate,
82 make_scoped_ptr(
83 new StreamReaderJobDelegateImpl(aw_web_resource_response.Pass())));
86 } // namespace android_webview