blob: b7171eebfb3f08852ad258ba4ed0acda0aa6b169 [file] [log] [blame]
Patrick Scottc12544a2010-11-11 13:16:44 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
19import android.net.http.Headers;
20
21import java.io.InputStream;
22
23/**
Steve Block938d2fb2012-02-21 02:10:10 +000024 * Encapsulates a resource response. Applications can return an instance of this
25 * class from {@link WebViewClient#shouldInterceptRequest} to provide a custom
26 * response when the WebView requests a particular resource.
Patrick Scottc12544a2010-11-11 13:16:44 -050027 */
28public class WebResourceResponse {
Patrick Scottc12544a2010-11-11 13:16:44 -050029 // Accessed by jni, do not rename without modifying the jni code.
30 private String mMimeType;
31 private String mEncoding;
32 private InputStream mInputStream;
33
34 /**
Steve Block938d2fb2012-02-21 02:10:10 +000035 * Constructs a resource response with the given MIME type, encoding, and
36 * input stream. Callers must implement
37 * {@link InputStream#read(byte[]) InputStream.read(byte[])} for the input
38 * stream.
Steve Block4e584df2012-04-24 23:12:47 +010039 *
40 * @param mimeType the resource response's MIME type, for example text/html
41 * @param encoding the resource response's encoding
42 * @param data the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -050043 */
44 public WebResourceResponse(String mimeType, String encoding,
45 InputStream data) {
46 mMimeType = mimeType;
47 mEncoding = encoding;
48 mInputStream = data;
49 }
50
51 /**
Steve Block938d2fb2012-02-21 02:10:10 +000052 * Sets the resource response's MIME type, for example text/html.
Steve Block4e584df2012-04-24 23:12:47 +010053 *
54 * @param mimeType the resource response's MIME type
Patrick Scottc12544a2010-11-11 13:16:44 -050055 */
56 public void setMimeType(String mimeType) {
57 mMimeType = mimeType;
58 }
59
60 /**
Steve Block938d2fb2012-02-21 02:10:10 +000061 * Gets the resource response's MIME type.
Steve Block4e584df2012-04-24 23:12:47 +010062 *
63 * @return the resource response's MIME type
Patrick Scottc12544a2010-11-11 13:16:44 -050064 */
65 public String getMimeType() {
66 return mMimeType;
67 }
68
69 /**
Steve Block938d2fb2012-02-21 02:10:10 +000070 * Sets the resource response's encoding, for example UTF-8. This is used
71 * to decode the data from the input stream.
Steve Block4e584df2012-04-24 23:12:47 +010072 *
73 * @param encoding the resource response's encoding
Patrick Scottc12544a2010-11-11 13:16:44 -050074 */
75 public void setEncoding(String encoding) {
76 mEncoding = encoding;
77 }
78
79 /**
Steve Block938d2fb2012-02-21 02:10:10 +000080 * Gets the resource response's encoding.
Steve Block4e584df2012-04-24 23:12:47 +010081 *
82 * @return the resource response's encoding
Patrick Scottc12544a2010-11-11 13:16:44 -050083 */
84 public String getEncoding() {
85 return mEncoding;
86 }
87
88 /**
Steve Block938d2fb2012-02-21 02:10:10 +000089 * Sets the input stream that provides the resource respone's data. Callers
90 * must implement {@link InputStream#read(byte[]) InputStream.read(byte[])}.
Steve Block4e584df2012-04-24 23:12:47 +010091 *
92 * @param data the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -050093 */
94 public void setData(InputStream data) {
95 mInputStream = data;
96 }
97
98 /**
Steve Block938d2fb2012-02-21 02:10:10 +000099 * Gets the input stream that provides the resource respone's data.
Steve Block4e584df2012-04-24 23:12:47 +0100100 *
101 * @return the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -0500102 */
103 public InputStream getData() {
104 return mInputStream;
105 }
Patrick Scottc12544a2010-11-11 13:16:44 -0500106}