Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLStreamHandler.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLStreamHandler.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLStreamHandler.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e571a4d0dca168eaf6cec8e7e99909326869357f |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLStreamHandler.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 org.chromium.net.UrlRequestContext; |
| + |
| +import java.io.IOException; |
| +import java.net.Proxy; |
| +import java.net.URL; |
| +import java.net.URLConnection; |
| +import java.net.URLStreamHandler; |
| + |
| +/** |
| + * An {@code URLStreamHandler} that handles http and https connections. |
| + */ |
| +public class CronetHttpURLStreamHandler extends URLStreamHandler { |
| + |
| + private final UrlRequestContext mUrlRequestContext; |
| + |
| + public CronetHttpURLStreamHandler(UrlRequestContext urlRequestContext) { |
| + mUrlRequestContext = urlRequestContext; |
| + } |
| + |
| + /** |
| + * Establishes a new connection to the resource specified by the URL u. |
| + */ |
| + @Override |
| + protected URLConnection openConnection(URL u) throws IOException { |
|
mmenke
2014/11/18 15:53:52
nit: u -> url
xunjieli
2014/11/18 18:13:36
Done.
|
| + String protocol = u.getProtocol(); |
| + if ("http".equals(protocol) || "https".equals(protocol)) { |
| + return new CronetHttpURLConnection(u, mUrlRequestContext); |
| + } |
| + throw new UnsupportedOperationException( |
| + "Unexpected protocol:" + protocol); |
| + } |
| + |
| + /** |
| + * Establishes a new connection to the resource specified by the URL u |
| + * using the given proxy. |
| + */ |
| + @Override |
| + protected URLConnection openConnection(URL u, Proxy proxy) { |
| + throw new UnsupportedOperationException(); |
| + } |
| +} |