Chromium Code Reviews| 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..51de36a18693da58e1cd5d493945b0458527d5bb |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java |
| @@ -0,0 +1,47 @@ |
| +// 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 {@code URLStreamHandlerFactory} to handle http and https |
| + * traffic. |
| + * @param context application context. |
| + */ |
| + public CronetURLStreamHandlerFactory(Context context) { |
| + mContext = context; |
| + UrlRequestContextConfig config = new UrlRequestContextConfig(); |
|
mef
2014/11/25 23:04:23
I suppose we should allow embedder to somehow supp
xunjieli
2014/11/26 16:11:55
Acknowledged. Yes, we need to have a way to do tha
|
| + config.enableSPDY(true).enableQUIC(true); |
| + |
| + mRequestContext = UrlRequestContext.createContext(mContext, config); |
| + } |
| + |
| + /** |
| + * Returns null for protocols other than http and https. |
|
mef
2014/11/25 23:04:22
nit: need better wording (e.g. what does it do for
xunjieli
2014/11/26 16:11:55
Done.
|
| + */ |
| + @Override |
| + public URLStreamHandler createURLStreamHandler(String protocol) { |
| + if ("http".equals(protocol) || "https".equals(protocol)) { |
| + return new CronetHttpURLStreamHandler(mRequestContext); |
| + } |
| + return null; |
| + } |
| +} |