FileDocCategorySizeDatePackage
PluginContentLoader.javaAPI DocAndroid 1.5 API3831Wed May 06 22:41:56 BST 2009android.webkit

PluginContentLoader

public class PluginContentLoader extends StreamLoader
This class is a concrete implementation of StreamLoader that uses a PluginData object as the source for the stream.

Fields Summary
private PluginData
mData
Constructors Summary
PluginContentLoader(LoadListener loadListener, PluginData data)
Constructs a PluginDataLoader for use when loading content from a plugin.

param
loadListener LoadListener to pass the content to
param
data PluginData used as the source for the content.

        super(loadListener);
        mData = data;
    
Methods Summary
protected voidbuildHeaders(android.net.http.Headers headers)

        // Crate a CharArrayBuffer with an arbitrary initial capacity.
        CharArrayBuffer buffer = new CharArrayBuffer(100);
        Iterator<Map.Entry<String, String[]>> responseHeadersIt =
                mData.getHeaders().entrySet().iterator();
        while (responseHeadersIt.hasNext()) {
            Map.Entry<String, String[]> entry = responseHeadersIt.next();
            // Headers.parseHeader() expects lowercase keys, so keys
            // such as "Accept-Ranges" will fail to parse.
            //
            // UrlInterceptHandler instances supply a mapping of
            // lowercase key to [ unmodified key, value ], so for
            // Headers.parseHeader() to succeed, we need to construct
            // a string using the key (i.e. entry.getKey()) and the
            // element denoting the header value in the
            // [ unmodified key, value ] pair (i.e. entry.getValue()[1).
            //
            // The reason why UrlInterceptHandler instances supply such a
            // mapping in the first place is historical. Early versions of
            // the Gears plugin used java.net.HttpURLConnection, which always
            // returned headers names as capitalized strings. When these were
            // fed back into webkit, they failed to parse.
            //
            // Mewanwhile, Gears was modified to use Apache HTTP library
            // instead, so this design is now obsolete. Changing it however,
            // would require changes to the Gears C++ codebase and QA-ing and
            // submitting a new binary to the Android tree. Given the
            // timelines for the next Android release, we will not do this
            // for now.
            //
            // TODO: fix C++ Gears to remove the need for this
            // design.
            String keyValue = entry.getKey() + ": " + entry.getValue()[1];
            buffer.ensureCapacity(keyValue.length());
            buffer.append(keyValue);
            // Parse it into the header container.
            headers.parseHeader(buffer);
            // Clear the buffer
            buffer.clear();
        }
    
protected booleansetupStreamAndSendStatus()

        mDataStream = mData.getInputStream();
        mContentLength = mData.getContentLength();
        mHandler.status(1, 1, mData.getStatusCode(), "OK");
        return true;