OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.os.AsyncTask; | 8 import android.os.AsyncTask; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 public DefaultVideoPosterRequestHandler(AwContentsClient contentClient) { | 75 public DefaultVideoPosterRequestHandler(AwContentsClient contentClient) { |
76 mDefaultVideoPosterURL = generateDefaulVideoPosterURL(); | 76 mDefaultVideoPosterURL = generateDefaulVideoPosterURL(); |
77 mContentClient = contentClient; | 77 mContentClient = contentClient; |
78 } | 78 } |
79 | 79 |
80 /** | 80 /** |
81 * Used to get the image if the url is mDefaultVideoPosterURL. | 81 * Used to get the image if the url is mDefaultVideoPosterURL. |
82 * | 82 * |
83 * @param url the url requested | 83 * @param url the url requested |
84 * @return InterceptedRequestData which caller can get the image if the url
is | 84 * @return AwWebResourceResponse which caller can get the image if the url i
s |
85 * the default video poster URL, otherwise null is returned. | 85 * the default video poster URL, otherwise null is returned. |
86 */ | 86 */ |
87 public InterceptedRequestData shouldInterceptRequest(final String url) { | 87 public AwWebResourceResponse shouldInterceptRequest(final String url) { |
88 if (!mDefaultVideoPosterURL.equals(url)) return null; | 88 if (!mDefaultVideoPosterURL.equals(url)) return null; |
89 | 89 |
90 try { | 90 try { |
91 return new InterceptedRequestData("image/png", null, getInputStream(
mContentClient)); | 91 return new AwWebResourceResponse("image/png", null, getInputStream(m
ContentClient)); |
92 } catch (IOException e) { | 92 } catch (IOException e) { |
93 Log.e(TAG, null, e); | 93 Log.e(TAG, null, e); |
94 return null; | 94 return null; |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 public String getDefaultVideoPosterURL() { | 98 public String getDefaultVideoPosterURL() { |
99 return mDefaultVideoPosterURL; | 99 return mDefaultVideoPosterURL; |
100 } | 100 } |
101 | 101 |
102 /** | 102 /** |
103 * @return a unique URL which has little chance to be used by application. | 103 * @return a unique URL which has little chance to be used by application. |
104 */ | 104 */ |
105 private static String generateDefaulVideoPosterURL() { | 105 private static String generateDefaulVideoPosterURL() { |
106 Random randomGenerator = new Random(); | 106 Random randomGenerator = new Random(); |
107 String path = String.valueOf(randomGenerator.nextLong()); | 107 String path = String.valueOf(randomGenerator.nextLong()); |
108 // The scheme of this URL should be kept in sync with kAndroidWebViewVid
eoPosterScheme | 108 // The scheme of this URL should be kept in sync with kAndroidWebViewVid
eoPosterScheme |
109 // on the native side (see android_webview/common/url_constants.h) | 109 // on the native side (see android_webview/common/url_constants.h) |
110 return "android-webview-video-poster:default_video_poster/" + path; | 110 return "android-webview-video-poster:default_video_poster/" + path; |
111 } | 111 } |
112 } | 112 } |
OLD | NEW |