blob: f21e2b42a1022cc12aa5438cbd655e104ac18ea2 [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
Patrick Scottc12544a2010-11-11 13:16:44 -050019import java.io.InputStream;
20
21/**
Steve Block938d2fb2012-02-21 02:10:10 +000022 * Encapsulates a resource response. Applications can return an instance of this
23 * class from {@link WebViewClient#shouldInterceptRequest} to provide a custom
24 * response when the WebView requests a particular resource.
Patrick Scottc12544a2010-11-11 13:16:44 -050025 */
26public class WebResourceResponse {
Patrick Scottc12544a2010-11-11 13:16:44 -050027 // Accessed by jni, do not rename without modifying the jni code.
28 private String mMimeType;
29 private String mEncoding;
30 private InputStream mInputStream;
31
32 /**
Steve Block938d2fb2012-02-21 02:10:10 +000033 * Constructs a resource response with the given MIME type, encoding, and
34 * input stream. Callers must implement
35 * {@link InputStream#read(byte[]) InputStream.read(byte[])} for the input
36 * stream.
Steve Block4e584df2012-04-24 23:12:47 +010037 *
38 * @param mimeType the resource response's MIME type, for example text/html
39 * @param encoding the resource response's encoding
40 * @param data the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -050041 */
42 public WebResourceResponse(String mimeType, String encoding,
43 InputStream data) {
44 mMimeType = mimeType;
45 mEncoding = encoding;
46 mInputStream = data;
47 }
48
49 /**
Steve Block938d2fb2012-02-21 02:10:10 +000050 * Sets the resource response's MIME type, for example text/html.
Steve Block4e584df2012-04-24 23:12:47 +010051 *
52 * @param mimeType the resource response's MIME type
Patrick Scottc12544a2010-11-11 13:16:44 -050053 */
54 public void setMimeType(String mimeType) {
55 mMimeType = mimeType;
56 }
57
58 /**
Steve Block938d2fb2012-02-21 02:10:10 +000059 * Gets the resource response's MIME type.
Steve Block4e584df2012-04-24 23:12:47 +010060 *
61 * @return the resource response's MIME type
Patrick Scottc12544a2010-11-11 13:16:44 -050062 */
63 public String getMimeType() {
64 return mMimeType;
65 }
66
67 /**
Steve Block938d2fb2012-02-21 02:10:10 +000068 * Sets the resource response's encoding, for example UTF-8. This is used
69 * to decode the data from the input stream.
Steve Block4e584df2012-04-24 23:12:47 +010070 *
71 * @param encoding the resource response's encoding
Patrick Scottc12544a2010-11-11 13:16:44 -050072 */
73 public void setEncoding(String encoding) {
74 mEncoding = encoding;
75 }
76
77 /**
Steve Block938d2fb2012-02-21 02:10:10 +000078 * Gets the resource response's encoding.
Steve Block4e584df2012-04-24 23:12:47 +010079 *
80 * @return the resource response's encoding
Patrick Scottc12544a2010-11-11 13:16:44 -050081 */
82 public String getEncoding() {
83 return mEncoding;
84 }
85
86 /**
Steve Block938d2fb2012-02-21 02:10:10 +000087 * Sets the input stream that provides the resource respone's data. Callers
88 * must implement {@link InputStream#read(byte[]) InputStream.read(byte[])}.
Steve Block4e584df2012-04-24 23:12:47 +010089 *
90 * @param data the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -050091 */
92 public void setData(InputStream data) {
93 mInputStream = data;
94 }
95
96 /**
Steve Block938d2fb2012-02-21 02:10:10 +000097 * Gets the input stream that provides the resource respone's data.
Steve Block4e584df2012-04-24 23:12:47 +010098 *
99 * @return the input stream that provides the resource response's data
Patrick Scottc12544a2010-11-11 13:16:44 -0500100 */
101 public InputStream getData() {
102 return mInputStream;
103 }
Patrick Scottc12544a2010-11-11 13:16:44 -0500104}