• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 package org.chromium.android_webview;
6 
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9 import org.chromium.base.VisibleForTesting;
10 
11 import java.io.InputStream;
12 import java.util.Map;
13 
14 /**
15  * The response information that is to be returned for a particular resource fetch.
16  */
17 @JNINamespace("android_webview")
18 public class AwWebResourceResponse {
19     private String mMimeType;
20     private String mCharset;
21     private InputStream mData;
22     private int mStatusCode;
23     private String mReasonPhrase;
24     private String[] mResponseHeaderNames;
25     private String[] mResponseHeaderValues;
26 
AwWebResourceResponse(String mimeType, String encoding, InputStream data)27     public AwWebResourceResponse(String mimeType, String encoding, InputStream data) {
28         mMimeType = mimeType;
29         mCharset = encoding;
30         mData = data;
31     }
32 
AwWebResourceResponse(String mimeType, String encoding, InputStream data, int statusCode, String reasonPhrase, Map<String, String> responseHeaders)33     public AwWebResourceResponse(String mimeType, String encoding, InputStream data,
34             int statusCode, String reasonPhrase, Map<String, String> responseHeaders) {
35         this(mimeType, encoding, data);
36 
37         mStatusCode = statusCode;
38         mReasonPhrase = reasonPhrase;
39 
40         if (responseHeaders != null) {
41             mResponseHeaderNames = new String[responseHeaders.size()];
42             mResponseHeaderValues = new String[responseHeaders.size()];
43             int i = 0;
44             for (Map.Entry<String, String> entry : responseHeaders.entrySet()) {
45                 mResponseHeaderNames[i] = entry.getKey();
46                 mResponseHeaderValues[i] = entry.getValue();
47                 i++;
48             }
49         }
50     }
51 
52     @VisibleForTesting
53     @CalledByNative
getMimeType()54     public String getMimeType() {
55         return mMimeType;
56     }
57 
58     @CalledByNative
getCharset()59     private String getCharset() {
60         return mCharset;
61     }
62 
63     @VisibleForTesting
64     @CalledByNative
getData()65     public InputStream getData() {
66         return mData;
67     }
68 
69     @CalledByNative
getStatusCode()70     private int getStatusCode() {
71         return mStatusCode;
72     }
73 
74     @CalledByNative
getReasonPhrase()75     private String getReasonPhrase() {
76         return mReasonPhrase;
77     }
78 
79     @CalledByNative
getResponseHeaderNames()80     private String[] getResponseHeaderNames() {
81         return mResponseHeaderNames;
82     }
83 
84     @CalledByNative
getResponseHeaderValues()85     private String[] getResponseHeaderValues() {
86         return mResponseHeaderValues;
87     }
88 }
89