Bug 1565004 - Add nsINetworkLinkService.vpnDetected r=mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D52168

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-11-20 14:33:11 +00:00
parent 510357cec1
commit eb905c9af5
6 changed files with 35 additions and 1 deletions

View File

@ -56,6 +56,11 @@ interface nsINetworkLinkService : nsISupports
* The list of DNS suffixes for the currently active network interfaces.
*/
readonly attribute Array<ACString> dnsSuffixList;
/**
* Whether a VPN was detected on at least one active network interface.
*/
readonly attribute boolean vpnDetected;
};
%{C++

View File

@ -152,6 +152,11 @@ nsAndroidNetworkLinkService::GetDnsSuffixList(
return NS_OK;
}
NS_IMETHODIMP
nsAndroidNetworkLinkService::GetVpnDetected(bool* aHasVPN) {
return NS_ERROR_NOT_IMPLEMENTED;
}
void nsAndroidNetworkLinkService::OnNetworkChanged() {
if (mozilla::StaticPrefs::network_notify_changed()) {
if (!mNetworkChangeTime.IsNull()) {

View File

@ -68,6 +68,11 @@ nsNetworkLinkService::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
return NS_OK;
}
NS_IMETHODIMP
nsNetworkLinkService::GetVpnDetected(bool* aHasVPN) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNetworkLinkService::Observe(nsISupports* subject, const char* topic,
const char16_t* data) {

View File

@ -118,6 +118,9 @@ nsNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
return NS_OK;
}
NS_IMETHODIMP
nsNetworkLinkService::GetVpnDetected(bool* aHasVPN) { return NS_ERROR_NOT_IMPLEMENTED; }
// Note that this function is copied from xpcom/io/nsLocalFileUnix.cpp.
static nsresult CFStringReftoUTF8(CFStringRef aInStrRef, nsACString& aOutStr) {
// first see if the conversion would succeed and find the length of the result

View File

@ -66,6 +66,7 @@ nsNotifyAddrListener::nsNotifyAddrListener()
mMutex("nsNotifyAddrListener::mMutex"),
mCheckEvent(nullptr),
mShutdown(false),
mFoundVPN(false),
mIPInterfaceChecksum(0),
mCoalescingActive(false) {}
@ -114,6 +115,12 @@ nsNotifyAddrListener::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
return NS_OK;
}
NS_IMETHODIMP
nsNotifyAddrListener::GetVpnDetected(bool* aHasVPN) {
*aHasVPN = mFoundVPN;
return NS_OK;
}
//
// Hash the sorted network ids
//
@ -438,7 +445,7 @@ nsNotifyAddrListener::CheckAdaptersAddresses(void) {
ULONG sumAll = 0;
nsTArray<nsCString> dnsSuffixList;
mFoundVPN = false;
if (ret == ERROR_SUCCESS) {
bool linkUp = false;
ULONG sum = 0;
@ -451,6 +458,11 @@ nsNotifyAddrListener::CheckAdaptersAddresses(void) {
continue;
}
if (adapter->IfType == IF_TYPE_PPP) {
LOG(("VPN connection found"));
mFoundVPN = true;
}
sum <<= 2;
// Add chars from AdapterName to the checksum.
for (int i = 0; adapter->AdapterName[i]; ++i) {

View File

@ -15,6 +15,7 @@
#include "nsThreadUtils.h"
#include "nsThreadPool.h"
#include "nsCOMPtr.h"
#include "mozilla/Atomics.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Mutex.h"
#include "mozilla/SHA1.h"
@ -71,6 +72,9 @@ class nsNotifyAddrListener : public nsINetworkLinkService,
// set true when mCheckEvent means shutdown
bool mShutdown;
// If a VPN was detected on at least one active network interface.
mozilla::Atomic<bool, mozilla::MemoryOrdering::Relaxed> mFoundVPN;
// This is a checksum of various meta data for all network interfaces
// considered UP at last check.
ULONG mIPInterfaceChecksum;