1 // Copyright 2021 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.net; 6 7 import java.io.IOException; 8 import java.io.InputStream; 9 import java.net.Proxy; 10 import java.net.URL; 11 import java.net.URLConnection; 12 13 /** Wrapper class for network requests. */ 14 public final class ChromiumNetworkAdapter { ChromiumNetworkAdapter()15 private ChromiumNetworkAdapter() {} 16 17 /** 18 * Wrapper around URL#openConnection(), with an extra argument for static analysis/privacy 19 * auditing. 20 * 21 * @param url the URL to open connection to. 22 * @param traffic_annotation an object documenting this network request: what it's used for, 23 * what data gets sent, what triggers it, etc. 24 * @return a URLConnection linking to the URL. 25 */ openConnection( URL url, NetworkTrafficAnnotationTag trafficAnnotation)26 public static URLConnection openConnection( 27 URL url, NetworkTrafficAnnotationTag trafficAnnotation) throws IOException { 28 return url.openConnection(); 29 } 30 31 /** 32 * Wrapper around URL#openConnection(Proxy), with an extra argument for static analysis/privacy 33 * auditing. 34 * 35 * @param url the URL to open connection to. 36 * @param proxy the Proxy through which this connection will be made. 37 * @param traffic_annotation an object documenting this network request: what it's used for, 38 * what data gets sent, what triggers it, etc. 39 * @return a URLConnection linking to the URL. 40 */ openConnection( URL url, Proxy proxy, NetworkTrafficAnnotationTag trafficAnnotation)41 public static URLConnection openConnection( 42 URL url, Proxy proxy, NetworkTrafficAnnotationTag trafficAnnotation) 43 throws IOException { 44 return url.openConnection(proxy); 45 } 46 47 /** 48 * Wrapper around URL#openStream(), with an extra argument for static analysis/privacy 49 * auditing. 50 * 51 * @param url the URL to open connection to. 52 * @param traffic_annotation an object documenting this network request: what it's used for, 53 * what data gets sent, what triggers it, etc. 54 * @return an InputStream linking to the URL. 55 */ openStream(URL url, NetworkTrafficAnnotationTag trafficAnnotation)56 public static InputStream openStream(URL url, NetworkTrafficAnnotationTag trafficAnnotation) 57 throws IOException { 58 return url.openStream(); 59 } 60 } 61