summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/HTML5VideoViewProxy.java
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-02-18 12:34:35 +0000
committerBen Murdoch <benm@google.com>2011-02-18 14:37:15 +0000
commit42509799f261c844bf6be66ce630c47bdee620f3 (patch)
treec9d7ad324554d8e56abe6b94910c0bcd4af80f6a /core/java/android/webkit/HTML5VideoViewProxy.java
parent7a2222b2605b52fc24baf6c7df509979cbec8d9b (diff)
Fix crash downloading posters for HTML5 video.
We use the apache HTTP stack to download the poster images for HTML5 video. This will crash if there is no host to use as the "Host" header when making the request. Limit the java poster downloader to just http or https for now. WebKit seems able to display posters over other schemes like file://, but doesn't always get the dimensions right. This fix just stops us crashing. Bug: 3180037 Change-Id: Idf51efda5b9ca1f2fe373c1fdb9c6bb7d5e254c8
Diffstat (limited to 'core/java/android/webkit/HTML5VideoViewProxy.java')
-rw-r--r--core/java/android/webkit/HTML5VideoViewProxy.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index d8f34e05d2fe..3caf3452822b 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -46,6 +46,8 @@ import android.widget.VideoView;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
@@ -344,7 +346,7 @@ class HTML5VideoViewProxy extends Handler
private static RequestQueue mRequestQueue;
private static int mQueueRefCount = 0;
// The poster URL
- private String mUrl;
+ private URL mUrl;
// The proxy we're doing this for.
private final HTML5VideoViewProxy mProxy;
// The poster bytes. We only touch this on the network thread.
@@ -359,14 +361,30 @@ class HTML5VideoViewProxy extends Handler
private Handler mHandler;
public PosterDownloader(String url, HTML5VideoViewProxy proxy) {
- mUrl = url;
+ try {
+ mUrl = new URL(url);
+ } catch (MalformedURLException e) {
+ mUrl = null;
+ }
mProxy = proxy;
mHandler = new Handler();
}
// Start the download. Called on WebCore thread.
public void start() {
retainQueue();
- mRequestHandle = mRequestQueue.queueRequest(mUrl, "GET", null, this, null, 0);
+
+ if (mUrl == null) {
+ return;
+ }
+
+ // Only support downloading posters over http/https.
+ // FIXME: Add support for other schemes. WebKit seems able to load
+ // posters over other schemes e.g. file://, but gets the dimensions wrong.
+ String protocol = mUrl.getProtocol();
+ if ("http".equals(protocol) || "https".equals(protocol)) {
+ mRequestHandle = mRequestQueue.queueRequest(mUrl.toString(), "GET", null,
+ this, null, 0);
+ }
}
// Cancel the download if active and release the queue. Called on WebCore thread.
public void cancelAndReleaseQueue() {
@@ -405,12 +423,16 @@ class HTML5VideoViewProxy extends Handler
cleanup();
} else if (mStatusCode >= 300 && mStatusCode < 400) {
// We have a redirect.
- mUrl = mHeaders.getLocation();
+ try {
+ mUrl = new URL(mHeaders.getLocation());
+ } catch (MalformedURLException e) {
+ mUrl = null;
+ }
if (mUrl != null) {
mHandler.post(new Runnable() {
public void run() {
if (mRequestHandle != null) {
- mRequestHandle.setupRedirect(mUrl, mStatusCode,
+ mRequestHandle.setupRedirect(mUrl.toString(), mStatusCode,
new HashMap<String, String>());
}
}