2012-05-21 04:12:37 -07:00
|
|
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
2010-08-30 23:23:35 -07:00
|
|
|
|
2011-04-08 01:32:00 -07:00
|
|
|
#include "nsQtNetworkManager.h"
|
2010-08-30 23:23:35 -07:00
|
|
|
#include "nsQtNetworkLinkService.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "mozilla/Services.h"
|
2011-07-10 15:24:05 -07:00
|
|
|
#include "nsCRT.h"
|
2010-08-30 23:23:35 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsQtNetworkLinkService,
|
|
|
|
nsINetworkLinkService,
|
|
|
|
nsIObserver)
|
2010-08-30 23:23:35 -07:00
|
|
|
|
|
|
|
nsQtNetworkLinkService::nsQtNetworkLinkService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsQtNetworkLinkService::~nsQtNetworkLinkService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsQtNetworkLinkService::GetIsLinkUp(bool* aIsUp)
|
2010-08-30 23:23:35 -07:00
|
|
|
{
|
2011-05-07 01:27:13 -07:00
|
|
|
*aIsUp = nsQtNetworkManager::get()->isOnline();
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsQtNetworkLinkService::GetLinkStatusKnown(bool* aIsKnown)
|
2010-08-30 23:23:35 -07:00
|
|
|
{
|
2011-05-07 01:27:13 -07:00
|
|
|
*aIsKnown = nsQtNetworkManager::get()->isOnline();
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsQtNetworkLinkService::GetLinkType(uint32_t *aLinkType)
|
2011-07-10 15:24:05 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLinkType);
|
|
|
|
|
|
|
|
// XXX This function has not yet been implemented for this platform
|
|
|
|
*aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-30 23:23:35 -07:00
|
|
|
nsQtNetworkLinkService::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aData)
|
2010-08-30 23:23:35 -07:00
|
|
|
{
|
2011-04-08 01:32:00 -07:00
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
Shutdown();
|
2011-05-07 01:27:13 -07:00
|
|
|
nsQtNetworkManager::get()->destroy();
|
2011-04-08 01:32:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "browser-lastwindow-close-granted")) {
|
2010-08-30 23:23:35 -07:00
|
|
|
Shutdown();
|
2011-04-08 01:32:00 -07:00
|
|
|
}
|
2010-08-30 23:23:35 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsQtNetworkLinkService::Init(void)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
2011-04-08 01:32:00 -07:00
|
|
|
if (!observerService) {
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-04-08 01:32:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 01:27:13 -07:00
|
|
|
nsQtNetworkManager::create();
|
2011-04-08 01:32:00 -07:00
|
|
|
nsresult rv;
|
2010-08-30 23:23:35 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = observerService->AddObserver(this, "xpcom-shutdown", false);
|
2011-04-08 01:32:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-04-08 01:32:00 -07:00
|
|
|
}
|
2010-08-30 23:23:35 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = observerService->AddObserver(this, "browser-lastwindow-close-granted", false);
|
2011-04-08 01:32:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-04-08 01:32:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-30 23:23:35 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsQtNetworkLinkService::Shutdown()
|
|
|
|
{
|
2011-05-07 01:27:13 -07:00
|
|
|
nsQtNetworkManager::get()->closeSession();
|
2010-08-30 23:23:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|