PluginData.java revision 4df2423a947bcd3f024cc3d3a1a315a8dc428598
1/* 2 * Copyright (C) 2009 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 java.io.InputStream; 20import java.util.Map; 21 22/** 23 * This class encapsulates the content generated by a plugin. The 24 * data itself is meant to be loaded into webkit via the 25 * PluginContentLoader class, which needs to be able to construct an 26 * HTTP response. For this, it needs a stream with the response body, 27 * the length of the body, the response headers, and the response 28 * status code. The PluginData class is the container for all these 29 * parts. 30 * 31 */ 32public final class PluginData { 33 /** 34 * The content stream. 35 */ 36 private InputStream mStream; 37 /** 38 * The content length. 39 */ 40 private long mContentLength; 41 /** 42 * The associated HTTP response headers stored as a map of 43 * lowercase header name to [ unmodified header name, header value]. 44 * TODO: This design was always a hack. Remove (involves updating 45 * the Gears C++ side). 46 */ 47 private Map<String, String[]> mHeaders; 48 49 /** 50 * The index of the header value in the above mapping. 51 */ 52 private int mHeaderValueIndex; 53 /** 54 * The associated HTTP response code. 55 */ 56 private int mStatusCode; 57 58 /** 59 * Creates a PluginData instance. 60 * 61 * @param stream The stream that supplies content for the plugin. 62 * @param length The length of the plugin content. 63 * @param headers The response headers. Map of 64 * lowercase header name to [ unmodified header name, header value] 65 * @param length The HTTP response status code. 66 */ 67 public PluginData( 68 InputStream stream, 69 long length, 70 Map<String, String[]> headers, 71 int code) { 72 mStream = stream; 73 mContentLength = length; 74 mHeaders = headers; 75 mStatusCode = code; 76 } 77 78 /** 79 * Returns the input stream that contains the plugin content. 80 * 81 * @return An InputStream instance with the plugin content. 82 */ 83 public InputStream getInputStream() { 84 return mStream; 85 } 86 87 /** 88 * Returns the length of the plugin content. 89 * 90 * @return the length of the plugin content. 91 */ 92 public long getContentLength() { 93 return mContentLength; 94 } 95 96 /** 97 * Returns the HTTP response headers associated with the plugin 98 * content. 99 * 100 * @return A Map<String, String[]> containing all headers. The 101 * mapping is 'lowercase header name' to ['unmodified header 102 * name', header value]. 103 */ 104 public Map<String, String[]> getHeaders() { 105 return mHeaders; 106 } 107 108 /** 109 * Returns the HTTP status code for the response. 110 * 111 * @return The HTTP statue code, e.g 200. 112 */ 113 public int getStatusCode() { 114 return mStatusCode; 115 } 116} 117