Fields Summary |
---|
private static UrlInterceptHandlerGears | instanceSingleton instance. |
private static final String | LOG_TAGDebug logging tag. |
private static final int | BUFFER_SIZEBuffer size for reading/writing streams. |
private static boolean | logEnabledEnable/disable all logging in this class. |
public static final int | HEADERS_MAP_INDEX_KEYThe unmodified (case-sensitive) key in the headers map is the
same index as used by HttpRequestAndroid. |
public static final int | HEADERS_MAP_INDEX_VALUEThe associated value in the headers map is the same index as
used by HttpRequestAndroid. |
Methods Summary |
---|
public static void | enableLogging(boolean on)Turn on/off logging in this class.
logEnabled = on;
|
public static android.webkit.gears.UrlInterceptHandlerGears | getInstance()Get the singleton instance.
return instance;
|
public android.webkit.PluginData | getPluginData(java.lang.String url, java.util.Map requestHeaders)Given an URL, returns a PluginData instance which contains the
response for the request. This implements the UrlInterceptHandler
interface.
// Thankfully the browser does call us with case-sensitive
// headers. We just need to map it case-insensitive.
Map<String, String[]> lowercaseRequestHeaders =
new HashMap<String, String[]>();
Iterator<Map.Entry<String, String>> requestHeadersIt =
requestHeaders.entrySet().iterator();
while (requestHeadersIt.hasNext()) {
Map.Entry<String, String> entry = requestHeadersIt.next();
String key = entry.getKey();
String mapValue[] = { key, entry.getValue() };
lowercaseRequestHeaders.put(key.toLowerCase(), mapValue);
}
ServiceResponse response = getServiceResponse(url, lowercaseRequestHeaders);
if (response == null) {
// No result for this URL.
return null;
}
return new PluginData(response.getInputStream(),
response.getContentLength(),
response.getResponseHeaders(),
response.getStatusCode());
|
public android.webkit.gears.UrlInterceptHandlerGears$ServiceResponse | getServiceResponse(java.lang.String url, java.util.Map requestHeaders)Given an URL, returns a CacheResult and headers which contain the
response for the request.
if (!url.startsWith("http://") && !url.startsWith("https://")) {
// Don't know how to service non-HTTP URLs
return null;
}
// Call the native handler to craft a response for this URL.
return nativeService(new ServiceRequest(url, requestHeaders));
|
private void | log(java.lang.String str)Convenience debug function. Calls the Android logging
mechanism. logEnabled is not a constant, so if the string
evaluation is potentially expensive, the caller also needs to
check it.
if (logEnabled) {
Log.i(LOG_TAG, str);
}
|
private static native android.webkit.gears.UrlInterceptHandlerGears$ServiceResponse | nativeService(android.webkit.gears.UrlInterceptHandlerGears$ServiceRequest request)Native method which handles the bulk of the request in LocalServer.
|
public synchronized void | register()Register the singleton instance with the browser's interception
mechanism.
UrlInterceptRegistry.registerHandler(this);
|
public android.webkit.CacheManager.CacheResult | service(java.lang.String url, java.util.Map headers)Given an URL, returns the CacheResult which contains the
surrogate response for the request, or null if the handler is
not interested.
throw new UnsupportedOperationException("unimplemented");
|
public synchronized void | unregister()Unregister the singleton instance from the browser's interception
mechanism.
UrlInterceptRegistry.unregisterHandler(this);
|