michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsQtNetworkManager.h" michael@0: #include "nsQtNetworkLinkService.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIObserverService.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsString.h" michael@0: #include "mozilla/Services.h" michael@0: #include "nsCRT.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsQtNetworkLinkService, michael@0: nsINetworkLinkService, michael@0: nsIObserver) michael@0: michael@0: nsQtNetworkLinkService::nsQtNetworkLinkService() michael@0: { michael@0: } michael@0: michael@0: nsQtNetworkLinkService::~nsQtNetworkLinkService() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtNetworkLinkService::GetIsLinkUp(bool* aIsUp) michael@0: { michael@0: *aIsUp = nsQtNetworkManager::get()->isOnline(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtNetworkLinkService::GetLinkStatusKnown(bool* aIsKnown) michael@0: { michael@0: *aIsKnown = nsQtNetworkManager::get()->isOnline(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtNetworkLinkService::GetLinkType(uint32_t *aLinkType) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aLinkType); michael@0: michael@0: // XXX This function has not yet been implemented for this platform michael@0: *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtNetworkLinkService::Observe(nsISupports* aSubject, michael@0: const char* aTopic, michael@0: const char16_t* aData) michael@0: { michael@0: if (!strcmp(aTopic, "xpcom-shutdown")) { michael@0: Shutdown(); michael@0: nsQtNetworkManager::get()->destroy(); michael@0: } michael@0: michael@0: if (!strcmp(aTopic, "browser-lastwindow-close-granted")) { michael@0: Shutdown(); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsQtNetworkLinkService::Init(void) michael@0: { michael@0: nsCOMPtr observerService = michael@0: mozilla::services::GetObserverService(); michael@0: if (!observerService) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: nsQtNetworkManager::create(); michael@0: nsresult rv; michael@0: michael@0: rv = observerService->AddObserver(this, "xpcom-shutdown", false); michael@0: if (NS_FAILED(rv)) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: rv = observerService->AddObserver(this, "browser-lastwindow-close-granted", false); michael@0: if (NS_FAILED(rv)) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsQtNetworkLinkService::Shutdown() michael@0: { michael@0: nsQtNetworkManager::get()->closeSession(); michael@0: return NS_OK; michael@0: }