mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 786419 - Part 4 - Have UDP sockets check if the app is offline r=mcmanus
This commit is contained in:
parent
b8934b46be
commit
33d9a1b21d
@ -15,14 +15,58 @@
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "mozilla/net/NeckoCommon.h"
|
||||
#include "mozilla/net/PNeckoParent.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_ISUPPORTS(UDPSocketParent, nsIUDPSocketListener)
|
||||
|
||||
UDPSocketParent::UDPSocketParent()
|
||||
: mIPCOpen(true)
|
||||
{
|
||||
mObserver = new mozilla::net::OfflineObserver(this);
|
||||
}
|
||||
|
||||
UDPSocketParent::~UDPSocketParent()
|
||||
{
|
||||
if (mObserver) {
|
||||
mObserver->RemoveObserver();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
UDPSocketParent::OfflineNotification(nsISupports *aSubject)
|
||||
{
|
||||
nsCOMPtr<nsIAppOfflineInfo> info(do_QueryInterface(aSubject));
|
||||
if (!info) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t targetAppId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
||||
info->GetAppId(&targetAppId);
|
||||
|
||||
// Obtain App ID
|
||||
uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
||||
const PContentParent *content = Manager()->Manager();
|
||||
const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
|
||||
if (browsers.Length() > 0) {
|
||||
TabParent *tab = static_cast<TabParent*>(browsers[0]);
|
||||
appId = tab->OwnAppId();
|
||||
}
|
||||
|
||||
if (appId != targetAppId) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the app is offline, close the socket
|
||||
if (mSocket && NS_IsAppOffline(appId)) {
|
||||
mSocket->Close();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -11,19 +11,20 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
#include "nsIUDPSocketFilter.h"
|
||||
#include "mozilla/net/OfflineObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class UDPSocketParent : public mozilla::net::PUDPSocketParent
|
||||
, public nsIUDPSocketListener
|
||||
, public mozilla::net::DisconnectableParent
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
|
||||
UDPSocketParent() :
|
||||
mIPCOpen(true) {}
|
||||
UDPSocketParent();
|
||||
|
||||
bool Init(const nsACString& aFilter);
|
||||
|
||||
@ -39,6 +40,7 @@ public:
|
||||
const nsCString& aInterface) MOZ_OVERRIDE;
|
||||
virtual bool RecvLeaveMulticast(const nsCString& aMulticastAddress,
|
||||
const nsCString& aInterface) MOZ_OVERRIDE;
|
||||
virtual nsresult OfflineNotification(nsISupports *) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
virtual ~UDPSocketParent();
|
||||
@ -54,6 +56,7 @@ private:
|
||||
bool mIPCOpen;
|
||||
nsCOMPtr<nsIUDPSocket> mSocket;
|
||||
nsCOMPtr<nsIUDPSocketFilter> mFilter;
|
||||
nsRefPtr<mozilla::net::OfflineObserver> mObserver;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user