-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71f7279
commit 2f329ac
Showing
79 changed files
with
3,077 additions
and
747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
android/java/org/chromium/chrome/browser/vpn/BraveVpnServiceFactoryAndroid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.vpn; | ||
|
||
import org.jni_zero.JNINamespace; | ||
import org.jni_zero.NativeMethods; | ||
|
||
import org.chromium.brave_vpn.mojom.ServiceHandler; | ||
import org.chromium.chrome.browser.profiles.Profile; | ||
import org.chromium.mojo.bindings.ConnectionErrorHandler; | ||
import org.chromium.mojo.bindings.Interface; | ||
import org.chromium.mojo.bindings.Interface.Proxy.Handler; | ||
import org.chromium.mojo.system.MessagePipeHandle; | ||
import org.chromium.mojo.system.impl.CoreImpl; | ||
|
||
@JNINamespace("chrome::android") | ||
public class BraveVpnServiceFactoryAndroid { | ||
private static final Object sLock = new Object(); | ||
private static BraveVpnServiceFactoryAndroid sInstance; | ||
|
||
public static BraveVpnServiceFactoryAndroid getInstance() { | ||
synchronized (sLock) { | ||
if (sInstance == null) { | ||
sInstance = new BraveVpnServiceFactoryAndroid(); | ||
} | ||
} | ||
return sInstance; | ||
} | ||
|
||
private BraveVpnServiceFactoryAndroid() {} | ||
|
||
public ServiceHandler getVpnService( | ||
Profile profile, ConnectionErrorHandler connectionErrorHandler) { | ||
if (profile == null) { | ||
return null; | ||
} | ||
long nativeHandle = | ||
BraveVpnServiceFactoryAndroidJni.get().getInterfaceToVpnService(profile); | ||
if (nativeHandle == -1) { | ||
return null; | ||
} | ||
MessagePipeHandle handle = wrapNativeHandle(nativeHandle); | ||
ServiceHandler serviceHandler = ServiceHandler.MANAGER.attachProxy(handle, 0); | ||
Handler handler = ((Interface.Proxy) serviceHandler).getProxyHandler(); | ||
handler.setErrorHandler(connectionErrorHandler); | ||
|
||
return serviceHandler; | ||
} | ||
|
||
private MessagePipeHandle wrapNativeHandle(long nativeHandle) { | ||
return CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle(); | ||
} | ||
|
||
@NativeMethods | ||
interface Natives { | ||
long getInterfaceToVpnService(Profile profile); | ||
} | ||
} |
Oops, something went wrong.