diff options
Diffstat (limited to 'android_webview/java')
9 files changed, 180 insertions, 66 deletions
diff --git a/android_webview/java/DEPS b/android_webview/java/DEPS index a6c4c30e89..d04003daa7 100644 --- a/android_webview/java/DEPS +++ b/android_webview/java/DEPS @@ -2,4 +2,5 @@ include_rules = [ "+content/public/android/java", "+components/navigation_interception/android/java", "+components/web_contents_delegate_android/android/java", + "+media/base/android/java", ] diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java index 7044cb77fc..15c5edbb9a 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java +++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java @@ -5,13 +5,16 @@ package org.chromium.android_webview; import android.content.Context; +import android.util.Log; import org.chromium.base.PathUtils; import org.chromium.base.ThreadUtils; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.BrowserStartupController; +import org.chromium.media.MediaDrmBridge; +import java.util.UUID; /** * Wrapper for the steps needed to initialize the java and native sides of webview chromium. @@ -50,10 +53,25 @@ public abstract class AwBrowserProcess { try { BrowserStartupController.get(context).startBrowserProcessesSync( BrowserStartupController.MAX_RENDERERS_SINGLE_PROCESS); + initializePlatformKeySystem(); } catch (ProcessInitException e) { throw new RuntimeException("Cannot initialize WebView", e); } } }); } + + private static void initializePlatformKeySystem() { + String[] mappings = AwResource.getConfigKeySystemUuidMapping(); + for (String mapping : mappings) { + try { + String fragments[] = mapping.split(","); + String keySystem = fragments[0].trim(); + UUID uuid = UUID.fromString(fragments[1]); + MediaDrmBridge.addKeySystemUuidMapping(keySystem, uuid); + } catch (java.lang.RuntimeException e) { + Log.e(TAG, "Can't parse key-system mapping: " + mapping); + } + } + } } diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 98a1d1c79b..340e18cc61 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -252,7 +252,7 @@ public class AwContents { private CleanupReference mCleanupReference; //-------------------------------------------------------------------------------------------- - private class IoThreadClientImpl implements AwContentsIoThreadClient { + private class IoThreadClientImpl extends AwContentsIoThreadClient { // All methods are called on the IO thread. @Override @@ -261,21 +261,22 @@ public class AwContents { } @Override - public InterceptedRequestData shouldInterceptRequest(final String url, - boolean isMainFrame) { - InterceptedRequestData interceptedRequestData; + public AwWebResourceResponse shouldInterceptRequest( + AwContentsClient.ShouldInterceptRequestParams params) { + String url = params.url; + AwWebResourceResponse awWebResourceResponse; // Return the response directly if the url is default video poster url. - interceptedRequestData = mDefaultVideoPosterRequestHandler.shouldInterceptRequest(url); - if (interceptedRequestData != null) return interceptedRequestData; + awWebResourceResponse = mDefaultVideoPosterRequestHandler.shouldInterceptRequest(url); + if (awWebResourceResponse != null) return awWebResourceResponse; - interceptedRequestData = mContentsClient.shouldInterceptRequest(url); + awWebResourceResponse = mContentsClient.shouldInterceptRequest(params); - if (interceptedRequestData == null) { + if (awWebResourceResponse == null) { mContentsClient.getCallbackHelper().postOnLoadResource(url); } - if (isMainFrame && interceptedRequestData != null && - interceptedRequestData.getData() == null) { + if (params.isMainFrame && awWebResourceResponse != null && + awWebResourceResponse.getData() == null) { // In this case the intercepted URLRequest job will simulate an empty response // which doesn't trigger the onReceivedError callback. For WebViewClassic // compatibility we synthesize that callback. http://crbug.com/180950 @@ -283,7 +284,7 @@ public class AwContents { ErrorCodeConversionHelper.ERROR_UNKNOWN, null /* filled in by the glue layer */, url); } - return interceptedRequestData; + return awWebResourceResponse; } @Override diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java index 4b952831af..5c41d62cfd 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java @@ -10,6 +10,7 @@ import android.graphics.Picture; import android.net.http.SslError; import android.os.Looper; import android.os.Message; +import android.util.ArrayMap; import android.view.KeyEvent; import android.view.View; import android.webkit.ConsoleMessage; @@ -148,13 +149,30 @@ public abstract class AwContentsClient { public boolean capture; } + /** + * Parameters for the {@link AwContentsClient#shouldInterceptRequest} method. + */ + public static class ShouldInterceptRequestParams { + // Url of the request. + public String url; + // Is this for the main frame or a child iframe? + public boolean isMainFrame; + // Was a gesture associated with the request? Don't trust can easily be spoofed. + public boolean hasUserGesture; + // Method used (GET/POST/OPTIONS) + public String method; + // Headers that would have been sent to server. + public ArrayMap<String, String> requestHeaders; + } + public abstract void getVisitedHistory(ValueCallback<String[]> callback); public abstract void doUpdateVisitedHistory(String url, boolean isReload); public abstract void onProgressChanged(int progress); - public abstract InterceptedRequestData shouldInterceptRequest(String url); + public abstract AwWebResourceResponse shouldInterceptRequest( + ShouldInterceptRequestParams params); public abstract boolean shouldOverrideKeyEvent(KeyEvent event); diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadClient.java index fe59d2bbf8..087e01714c 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadClient.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsIoThreadClient.java @@ -4,6 +4,9 @@ package org.chromium.android_webview; +import android.util.ArrayMap; + +import org.chromium.android_webview.AwContentsClient; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; @@ -14,29 +17,48 @@ import org.chromium.base.JNINamespace; * provided functionality. */ @JNINamespace("android_webview") -public interface AwContentsIoThreadClient { +public abstract class AwContentsIoThreadClient { @CalledByNative - public int getCacheMode(); + public abstract int getCacheMode(); @CalledByNative - public InterceptedRequestData shouldInterceptRequest(String url, boolean isMainFrame); + public abstract boolean shouldBlockContentUrls(); @CalledByNative - public boolean shouldBlockContentUrls(); + public abstract boolean shouldBlockFileUrls(); @CalledByNative - public boolean shouldBlockFileUrls(); + public abstract boolean shouldBlockNetworkLoads(); @CalledByNative - public boolean shouldBlockNetworkLoads(); + public abstract boolean shouldAcceptThirdPartyCookies(); @CalledByNative - public boolean shouldAcceptThirdPartyCookies(); + public abstract void onDownloadStart(String url, String userAgent, + String contentDisposition, String mimeType, long contentLength); @CalledByNative - public void onDownloadStart(String url, String userAgent, - String contentDisposition, String mimeType, long contentLength); + public abstract void newLoginRequest(String realm, String account, String args); + + public abstract AwWebResourceResponse shouldInterceptRequest( + AwContentsClient.ShouldInterceptRequestParams params); + + // Protected methods --------------------------------------------------------------------------- @CalledByNative - public void newLoginRequest(String realm, String account, String args); + protected AwWebResourceResponse shouldInterceptRequest(String url, boolean isMainFrame, + boolean hasUserGesture, String method, String[] requestHeaderNames, + String[] requestHeaderValues) { + AwContentsClient.ShouldInterceptRequestParams params = + new AwContentsClient.ShouldInterceptRequestParams(); + params.url = url; + params.isMainFrame = isMainFrame; + params.hasUserGesture = hasUserGesture; + params.method = method; + params.requestHeaders = new ArrayMap<String, String>(requestHeaderNames.length); + for (int i = 0; i < requestHeaderNames.length; ++i) { + params.requestHeaders.put(requestHeaderNames[i], requestHeaderValues[i]); + } + return shouldInterceptRequest(params); + } } diff --git a/android_webview/java/src/org/chromium/android_webview/AwResource.java b/android_webview/java/src/org/chromium/android_webview/AwResource.java index ee658e4f24..3b3b3265f4 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwResource.java +++ b/android_webview/java/src/org/chromium/android_webview/AwResource.java @@ -35,6 +35,9 @@ public class AwResource { // String resource ID for the default text encoding to use. private static int STRING_DEFAULT_TEXT_ENCODING; + // Array resource ID for the configuration of platform specific key-systems. + private static int STRING_ARRAY_CONFIG_KEY_SYSTEM_UUID_MAPPING; + // The embedder should inject a Resources object that will be used // to resolve Resource IDs into the actual resources. private static Resources sResources; @@ -59,6 +62,10 @@ public class AwResource { STRING_DEFAULT_TEXT_ENCODING = encoding; } + public static void setConfigKeySystemUuidMapping(int config) { + STRING_ARRAY_CONFIG_KEY_SYSTEM_UUID_MAPPING = config; + } + @CalledByNative public static String getDefaultTextEncoding() { return getResource(STRING_DEFAULT_TEXT_ENCODING, TYPE_STRING); @@ -74,6 +81,11 @@ public class AwResource { return getResource(RAW_LOAD_ERROR, TYPE_RAW); } + public static String[] getConfigKeySystemUuidMapping() { + // No need to cache, since this should be called only once. + return sResources.getStringArray(STRING_ARRAY_CONFIG_KEY_SYSTEM_UUID_MAPPING); + } + private static String getResource(int resid, int type) { assert resid != 0; assert sResources != null; diff --git a/android_webview/java/src/org/chromium/android_webview/AwWebResourceResponse.java b/android_webview/java/src/org/chromium/android_webview/AwWebResourceResponse.java new file mode 100644 index 0000000000..1b861c01b4 --- /dev/null +++ b/android_webview/java/src/org/chromium/android_webview/AwWebResourceResponse.java @@ -0,0 +1,83 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.android_webview; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; + +import java.io.InputStream; +import java.util.Map; + +/** + * The response information that is to be returned for a particular resource fetch. + */ +@JNINamespace("android_webview") +public class AwWebResourceResponse { + private String mMimeType; + private String mCharset; + private InputStream mData; + private int mStatusCode; + private String mReasonPhrase; + private String[] mResponseHeaderNames; + private String[] mResponseHeaderValues; + + public AwWebResourceResponse(String mimeType, String encoding, InputStream data) { + mMimeType = mimeType; + mCharset = encoding; + mData = data; + } + + public AwWebResourceResponse(String mimeType, String encoding, InputStream data, + int statusCode, String reasonPhrase, Map<String, String> responseHeaders) { + this(mimeType, encoding, data); + + mStatusCode = statusCode; + mReasonPhrase = reasonPhrase; + + mResponseHeaderNames = new String[responseHeaders.size()]; + mResponseHeaderValues = new String[responseHeaders.size()]; + int i = 0; + for (Map.Entry<String, String> entry : responseHeaders.entrySet()) { + mResponseHeaderNames[i] = entry.getKey(); + mResponseHeaderValues[i] = entry.getValue(); + i++; + } + } + + @CalledByNative + public String getMimeType() { + return mMimeType; + } + + @CalledByNative + public String getCharset() { + return mCharset; + } + + @CalledByNative + public InputStream getData() { + return mData; + } + + @CalledByNative + public int getStatusCode() { + return mStatusCode; + } + + @CalledByNative + public String getReasonPhrase() { + return mReasonPhrase; + } + + @CalledByNative + public String[] getResponseHeaderNames() { + return mResponseHeaderNames; + } + + @CalledByNative + public String[] getResponseHeaderValues() { + return mResponseHeaderValues; + } +} diff --git a/android_webview/java/src/org/chromium/android_webview/DefaultVideoPosterRequestHandler.java b/android_webview/java/src/org/chromium/android_webview/DefaultVideoPosterRequestHandler.java index df2290abb4..aaed9f8ec4 100644 --- a/android_webview/java/src/org/chromium/android_webview/DefaultVideoPosterRequestHandler.java +++ b/android_webview/java/src/org/chromium/android_webview/DefaultVideoPosterRequestHandler.java @@ -81,14 +81,14 @@ public class DefaultVideoPosterRequestHandler { * Used to get the image if the url is mDefaultVideoPosterURL. * * @param url the url requested - * @return InterceptedRequestData which caller can get the image if the url is + * @return AwWebResourceResponse which caller can get the image if the url is * the default video poster URL, otherwise null is returned. */ - public InterceptedRequestData shouldInterceptRequest(final String url) { + public AwWebResourceResponse shouldInterceptRequest(final String url) { if (!mDefaultVideoPosterURL.equals(url)) return null; try { - return new InterceptedRequestData("image/png", null, getInputStream(mContentClient)); + return new AwWebResourceResponse("image/png", null, getInputStream(mContentClient)); } catch (IOException e) { Log.e(TAG, null, e); return null; diff --git a/android_webview/java/src/org/chromium/android_webview/InterceptedRequestData.java b/android_webview/java/src/org/chromium/android_webview/InterceptedRequestData.java deleted file mode 100644 index 78f9382015..0000000000 --- a/android_webview/java/src/org/chromium/android_webview/InterceptedRequestData.java +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.android_webview; - -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; - -import java.io.InputStream; - -/** - * The response information that is to be returned for a particular resource fetch. - */ -@JNINamespace("android_webview") -public class InterceptedRequestData { - private String mMimeType; - private String mCharset; - private InputStream mData; - - public InterceptedRequestData(String mimeType, String encoding, InputStream data) { - mMimeType = mimeType; - mCharset = encoding; - mData = data; - } - - @CalledByNative - public String getMimeType() { - return mMimeType; - } - - @CalledByNative - public String getCharset() { - return mCharset; - } - - @CalledByNative - public InputStream getData() { - return mData; - } -} |