| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java
|
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6800a47be11e623d46cdd0eba22898bbc1063e3e
|
| --- /dev/null
|
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java
|
| @@ -0,0 +1,48 @@
|
| +// 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.net.urlconnection;
|
| +
|
| +import android.content.Context;
|
| +
|
| +import org.chromium.net.UrlRequestContext;
|
| +import org.chromium.net.UrlRequestContextConfig;
|
| +
|
| +import java.net.URLStreamHandler;
|
| +import java.net.URLStreamHandlerFactory;
|
| +
|
| +/**
|
| + * An implementation of {@code URLStreamHandlerFactory} to handle http
|
| + * and https traffic.
|
| + */
|
| +public class CronetURLStreamHandlerFactory
|
| + implements URLStreamHandlerFactory {
|
| + private final Context mContext;
|
| + private final UrlRequestContext mRequestContext;
|
| +
|
| + /**
|
| + * Creates a {@link URLStreamHandlerFactory} to handle http and https
|
| + * traffic.
|
| + * @param context application context.
|
| + */
|
| + public CronetURLStreamHandlerFactory(Context context) {
|
| + mContext = context;
|
| + // TODO(xunjieli): have a way to enable customized config.
|
| + UrlRequestContextConfig config = new UrlRequestContextConfig();
|
| + config.enableSPDY(true).enableQUIC(true);
|
| + mRequestContext = UrlRequestContext.createContext(mContext, config);
|
| + }
|
| +
|
| + /**
|
| + * Returns a {@link CronetHttpURLStreamHandler} for http and https, and
|
| + * null for other protocols.
|
| + */
|
| + @Override
|
| + public URLStreamHandler createURLStreamHandler(String protocol) {
|
| + if ("http".equals(protocol) || "https".equals(protocol)) {
|
| + return new CronetHttpURLStreamHandler(mRequestContext);
|
| + }
|
| + return null;
|
| + }
|
| +}
|
|
|