-
Notifications
You must be signed in to change notification settings - Fork 17
/
0003-Add-socks5-proxy-and-jni.patch
373 lines (346 loc) · 17.8 KB
/
0003-Add-socks5-proxy-and-jni.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
components/cronet/BUILD.gn | 21 +++++++++++++++++++++
components/cronet/android/cronet_context_adapter.cc | 10 ++++++++++
components/cronet/android/cronet_context_adapter.h | 8 ++++++++
components/cronet/android/cronet_library_loader.cc | 11 +++++++++++
.../chromium/net/impl/CronetUrlRequestContext.java | 8 ++++++++
.../cronet_sample_apk/CronetSampleActivity.java | 3 ++-
components/cronet/cronet_context.cc | 13 +++++++++++++
components/cronet/cronet_context.h | 2 ++
components/cronet/cronet_global_state.h | 4 ++++
components/cronet/cronet_global_state_stubs.cc | 7 +++++++
components/cronet/ios/cronet_global_state_ios.mm | 5 +++++
components/cronet/native/engine.cc | 7 +++++++
components/cronet/native/sample/main.cc | 1 +
.../external_intents/ExternalNavigationHandler.java | 3 +++
net/proxy_resolution/proxy_config_service.cc | 17 +++++++++++++++++
net/proxy_resolution/proxy_config_service.h | 4 ++++
16 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/components/cronet/BUILD.gn b/components/cronet/BUILD.gn
index c616b514868f5..92350cf3b4b77 100644
--- a/components/cronet/BUILD.gn
+++ b/components/cronet/BUILD.gn
@@ -100,6 +100,27 @@ if (is_android) {
testonly = true
deps = [ "//components/cronet/android:cronet_package_android" ]
}
+ executable("cronet_sample") {
+ testonly = true
+ sources = [
+ "native/sample/main.cc",
+ "native/sample/sample_executor.cc",
+ "native/sample/sample_executor.h",
+ "native/sample/sample_url_request_callback.cc",
+ "native/sample/sample_url_request_callback.h",
+
+ "cronet_global_state_stubs.cc",
+ ]
+ deps = [
+ "//base",
+ "//net",
+ "//components/cronet/native:cronet_native_headers",
+ "//components/cronet/native:cronet_native_impl",
+ ]
+ if ((is_linux || is_chromeos) && !is_component_build) {
+ public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
+ }
+ }
} else if (is_ios) {
group("cronet_package") {
deps = [ "//components/cronet/ios:cronet_package_ios" ]
diff --git a/components/cronet/android/cronet_context_adapter.cc b/components/cronet/android/cronet_context_adapter.cc
index 99fc5f16ae2ac..dfd1ea05b3e1c 100644
--- a/components/cronet/android/cronet_context_adapter.cc
+++ b/components/cronet/android/cronet_context_adapter.cc
@@ -103,6 +103,16 @@ void CronetContextAdapter::InitRequestContextOnInitThread(
context_->InitRequestContextOnInitThread();
}
+void CronetContextAdapter::InitRequestContextOnInitThreadWithUri(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& jcaller,
+ const JavaParamRef<jstring>& juri) {
+ jcronet_url_request_context_.Reset(env, jcaller);
+ std::string uri(
+ base::android::ConvertJavaStringToUTF8(env, juri));
+ context_->InitRequestContextOnInitThreadWithUri(uri);
+}
+
void CronetContextAdapter::ConfigureNetworkQualityEstimatorForTesting(
JNIEnv* env,
const JavaParamRef<jobject>& jcaller,
diff --git a/components/cronet/android/cronet_context_adapter.h b/components/cronet/android/cronet_context_adapter.h
index 6c256da0a28ce..57478fe7d4044 100644
--- a/components/cronet/android/cronet_context_adapter.h
+++ b/components/cronet/android/cronet_context_adapter.h
@@ -51,6 +51,11 @@ class CronetContextAdapter : public CronetContext::Callback {
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);
+ void InitRequestContextOnInitThreadWithUri(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jcaller,
+ const base::android::JavaParamRef<jstring>& juri);
+
// Releases all resources for the request context and deletes the object.
// Blocks until network thread is destroyed after running all pending tasks.
void Destroy(JNIEnv* env,
@@ -99,6 +104,9 @@ class CronetContextAdapter : public CronetContext::Callback {
// Called on init Java thread to initialize URLRequestContext.
void InitRequestContextOnInitThread();
+ // Called on init Java thread to initialize URLRequestContext.
+ void InitRequestContextOnInitThreadWithUri(const base::android::JavaParamRef<jstring>& juri);
+
// Configures the network quality estimator to observe requests to localhost,
// to use smaller responses when estimating throughput, and to disable the
// device offline checks when computing the effective connection type or when
diff --git a/components/cronet/android/cronet_library_loader.cc b/components/cronet/android/cronet_library_loader.cc
index f25be3bfe8146..486eb7c7a990d 100644
--- a/components/cronet/android/cronet_library_loader.cc
+++ b/components/cronet/android/cronet_library_loader.cc
@@ -182,6 +182,17 @@ std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
return service;
}
+std::unique_ptr<net::ProxyConfigService> CreateFixedProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, base::StringPiece uri) {
+ std::unique_ptr<net::ProxyConfigService> service =
+ net::ProxyConfigService::CreateFixedSystemProxyConfigService(
+ io_task_runner, uri);
+ //net::ProxyConfigServiceAndroid* android_proxy_config_service =
+ // static_cast<net::ProxyConfigServiceAndroid*>(service.get());
+ //android_proxy_config_service->set_exclude_pac_url(true);
+ return service;
+}
+
// Creates a proxy resolution service appropriate for this platform.
std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService(
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
diff --git a/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java
index 2ff07ccada289..d3cf3bd77c417 100644
--- a/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java
+++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java
@@ -234,8 +234,13 @@ public class CronetUrlRequestContext extends CronetEngineBase {
// mUrlRequestContextAdapter is guaranteed to exist until
// initialization on init and network threads completes and
// initNetworkThread is called back on network thread.
+ if (builder.getEnvoyUrl() != null && builder.getEnvoyUrl().startsWith("socks5://")) {
+ CronetUrlRequestContextJni.get().initRequestContextOnInitThreadWithUri(
+ mUrlRequestContextAdapter, CronetUrlRequestContext.this, builder.getEnvoyUrl());
+ } else {
CronetUrlRequestContextJni.get().initRequestContextOnInitThread(
mUrlRequestContextAdapter, CronetUrlRequestContext.this);
+ }
}
}
});
@@ -826,6 +831,9 @@ public class CronetUrlRequestContext extends CronetEngineBase {
@NativeClassQualifiedName("CronetContextAdapter")
void initRequestContextOnInitThread(long nativePtr, CronetUrlRequestContext caller);
+ @NativeClassQualifiedName("CronetContextAdapter")
+ void initRequestContextOnInitThreadWithUri(long nativePtr, CronetUrlRequestContext caller, String uri);
+
@NativeClassQualifiedName("CronetContextAdapter")
void configureNetworkQualityEstimatorForTesting(long nativePtr,
CronetUrlRequestContext caller, boolean useLocalHostRequests,
diff --git a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
index 9538b5072539a..399b4b9be683e 100644
--- a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
+++ b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
@@ -125,7 +125,8 @@ public class CronetSampleActivity extends Activity {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(this);
myBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
.enableHttp2(true)
- .setEnvoyUrl("https://example.com/enovy_path/")
+ //.setEnvoyUrl("https://example.com/enovy_path/")
+ .setEnvoyUrl("socks5://127.0.0.1:1080")
.enableQuic(true);
mCronetEngine = myBuilder.build();
diff --git a/components/cronet/cronet_context.cc b/components/cronet/cronet_context.cc
index 1597f77bcbd92..3ca9ebdd35fa7 100644
--- a/components/cronet/cronet_context.cc
+++ b/components/cronet/cronet_context.cc
@@ -244,6 +244,19 @@ CronetContext::NetworkTasks::~NetworkTasks() {
net::NetworkChangeNotifier::RemoveNetworkObserver(this);
}
+void CronetContext::InitRequestContextOnInitThreadWithUri(base::StringPiece uri) {
+ DCHECK(OnInitThread());
+ auto proxy_config_service =
+ cronet::CreateFixedProxyConfigService(GetNetworkTaskRunner(), uri);
+ g_net_log.Get().EnsureInitializedOnInitThread();
+ GetNetworkTaskRunner()->PostTask(
+ FROM_HERE,
+ base::BindOnce(&CronetContext::NetworkTasks::Initialize,
+ base::Unretained(network_tasks_), GetNetworkTaskRunner(),
+ GetFileThread()->task_runner(),
+ std::move(proxy_config_service)));
+}
+
void CronetContext::InitRequestContextOnInitThread() {
DCHECK(OnInitThread());
// Cannot create this inside Initialize because Android requires this to be
diff --git a/components/cronet/cronet_context.h b/components/cronet/cronet_context.h
index 4570cd1938fb8..15d86089c074d 100644
--- a/components/cronet/cronet_context.h
+++ b/components/cronet/cronet_context.h
@@ -111,6 +111,8 @@ class CronetContext {
// Blocks until network thread is destroyed after running all pending tasks.
virtual ~CronetContext();
+ void InitRequestContextOnInitThreadWithUri(base::StringPiece uri);
+
// Called on init thread to initialize URLRequestContext.
void InitRequestContextOnInitThread();
diff --git a/components/cronet/cronet_global_state.h b/components/cronet/cronet_global_state.h
index 327a6cb424265..894221e95dab3 100644
--- a/components/cronet/cronet_global_state.h
+++ b/components/cronet/cronet_global_state.h
@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include "base/memory/scoped_refptr.h"
+#include "base/strings/string_piece.h"
#include "base/task/sequenced_task_runner.h"
namespace net {
@@ -33,6 +34,9 @@ void PostTaskToInitThread(const base::Location& posted_from,
// idempotent, and must complete initialization before returning.
void EnsureInitialized();
+std::unique_ptr<net::ProxyConfigService> CreateFixedProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, base::StringPiece uri);
+
// Creates a proxy config service appropriate for this platform that fetches the
// system proxy settings. Cronet will call this API only after a prior call
// to EnsureInitialized() has returned.
diff --git a/components/cronet/cronet_global_state_stubs.cc b/components/cronet/cronet_global_state_stubs.cc
index d110cae3e4c3b..f21a80af437ff 100644
--- a/components/cronet/cronet_global_state_stubs.cc
+++ b/components/cronet/cronet_global_state_stubs.cc
@@ -8,6 +8,7 @@
#include "base/at_exit.h"
#include "base/feature_list.h"
+#include "base/strings/string_piece.h"
#include "base/task/thread_pool.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
@@ -60,6 +61,12 @@ void PostTaskToInitThread(const base::Location& posted_from,
InitTaskRunner()->PostTask(posted_from, std::move(task));
}
+std::unique_ptr<net::ProxyConfigService> CreateFixedProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, base::StringPiece uri) {
+ return net::ProxyConfigService::CreateFixedSystemProxyConfigService(
+ io_task_runner, uri);
+}
+
std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
return net::ProxyConfigService::CreateSystemProxyConfigService(
diff --git a/components/cronet/ios/cronet_global_state_ios.mm b/components/cronet/ios/cronet_global_state_ios.mm
index 3e215097596d4..ac789f02f77fb 100644
--- a/components/cronet/ios/cronet_global_state_ios.mm
+++ b/components/cronet/ios/cronet_global_state_ios.mm
@@ -72,6 +72,11 @@ std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
return nullptr;
}
+std::unique_ptr<net::ProxyConfigService> CreateFixedProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, base::StringPiece uri) {
+ return nullptr;
+}
+
std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService(
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
net::NetLog* net_log) {
diff --git a/components/cronet/native/engine.cc b/components/cronet/native/engine.cc
index d6ea7f8c8e3e0..a4e93b23c5b3f 100644
--- a/components/cronet/native/engine.cc
+++ b/components/cronet/native/engine.cc
@@ -200,9 +200,16 @@ Cronet_RESULT Cronet_EngineImpl::StartWithParams(
// @VisibleForTesting (as the only external use will be in a test).
// Initialize context on the init thread.
+ if (params->envoy_url.rfind("socks5://", 0) != 0) {
cronet::PostTaskToInitThread(
FROM_HERE, base::BindOnce(&CronetContext::InitRequestContextOnInitThread,
base::Unretained(context_.get())));
+ } else {
+ cronet::PostTaskToInitThread(
+ FROM_HERE,
+ base::BindOnce(&CronetContext::InitRequestContextOnInitThreadWithUri,
+ base::Unretained(context_.get()), params->envoy_url));
+ }
return CheckResult(Cronet_RESULT_SUCCESS);
}
diff --git a/components/cronet/native/sample/main.cc b/components/cronet/native/sample/main.cc
index f69f8e5d3cd49..ffdb1a37fd629 100644
--- a/components/cronet/native/sample/main.cc
+++ b/components/cronet/native/sample/main.cc
@@ -35,6 +35,7 @@ Cronet_EnginePtr CreateCronetEngine() {
"envoy://"
"?url=https%3A%2F%2Fexample.com%2Fenvoy_path%2F%3Fk1%3Dv1&header_Host="
"subdomain.example.com&address=1.2.3.4&disabled_cipher_suites=0xc024,0xc02f");
+ Cronet_EngineParams_envoy_url_set(engine_params, "socks5://127.0.0.1:1080");
Cronet_EngineParams_enable_quic_set(engine_params, true);
diff --git a/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java b/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java
index 630d1696c5322..d2b2f26be3311 100644
--- a/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java
+++ b/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java
@@ -979,6 +979,8 @@ public class ExternalNavigationHandler {
}
private boolean externalIntentRequestsDisabledForUrl(ExternalNavigationParams params) {
+ return true;
+ /*
// TODO(changwan): check if we need to handle URL even when external intent is off.
if (CommandLine.getInstance().hasSwitch(
ExternalIntentsSwitches.DISABLE_EXTERNAL_INTENT_REQUESTS)) {
@@ -991,6 +993,7 @@ public class ExternalNavigationHandler {
return true;
}
return false;
+ */
}
/**
diff --git a/net/proxy_resolution/proxy_config_service.cc b/net/proxy_resolution/proxy_config_service.cc
index 27544e1a2952d..073996ae20d3f 100644
--- a/net/proxy_resolution/proxy_config_service.cc
+++ b/net/proxy_resolution/proxy_config_service.cc
@@ -10,7 +10,9 @@
#include "base/memory/scoped_refptr.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
+#include "net/base/proxy_string_util.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
+#include "net/proxy_resolution/proxy_config_service_fixed.h"
#if BUILDFLAG(IS_WIN)
#include "net/proxy_resolution/win/proxy_config_service_win.h"
@@ -90,6 +92,21 @@ class ProxyConfigServiceDirect : public ProxyConfigService {
} // namespace
+
+std::unique_ptr<ProxyConfigService>
+ProxyConfigService::CreateFixedSystemProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& main_task_runner, base::StringPiece uri) {
+ ProxyConfig raw_proxy_config;
+ raw_proxy_config.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
+ raw_proxy_config.proxy_rules().single_proxies.SetSingleProxyServer(ProxyUriToProxyServer(uri, ProxyServer::SCHEME_SOCKS5));
+#if (!defined(OS_WIN) && !defined(OS_LINUX)) || defined(OS_CHROMEOS)
+ ProxyConfigWithAnnotation proxy_config = ProxyConfigWithAnnotation(raw_proxy_config, NO_TRAFFIC_ANNOTATION_YET);
+#else
+ ProxyConfigWithAnnotation proxy_config = ProxyConfigWithAnnotation(raw_proxy_config, kSystemProxyConfigTrafficAnnotation);
+#endif
+ return std::make_unique<ProxyConfigServiceFixed>(proxy_config);
+}
+
// static
std::unique_ptr<ProxyConfigService>
ProxyConfigService::CreateSystemProxyConfigService(
diff --git a/net/proxy_resolution/proxy_config_service.h b/net/proxy_resolution/proxy_config_service.h
index d2681d46311cf..ddd938d66d6f0 100644
--- a/net/proxy_resolution/proxy_config_service.h
+++ b/net/proxy_resolution/proxy_config_service.h
@@ -8,6 +8,7 @@
#include <memory>
#include "base/memory/ref_counted.h"
+#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
namespace base {
@@ -75,6 +76,9 @@ class NET_EXPORT ProxyConfigService {
// consumer of the ProxyConfigService will live.
static std::unique_ptr<ProxyConfigService> CreateSystemProxyConfigService(
scoped_refptr<base::SequencedTaskRunner> main_task_runner);
+
+ static std::unique_ptr<ProxyConfigService> CreateFixedSystemProxyConfigService(
+ const scoped_refptr<base::SequencedTaskRunner>& main_task_runner, base::StringPiece uri);
};
} // namespace net