1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/system/qt/nsQtNetworkLinkService.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsQtNetworkManager.h" 1.9 +#include "nsQtNetworkLinkService.h" 1.10 +#include "nsCOMPtr.h" 1.11 +#include "nsIObserverService.h" 1.12 +#include "nsServiceManagerUtils.h" 1.13 +#include "nsString.h" 1.14 +#include "mozilla/Services.h" 1.15 +#include "nsCRT.h" 1.16 + 1.17 +NS_IMPL_ISUPPORTS(nsQtNetworkLinkService, 1.18 + nsINetworkLinkService, 1.19 + nsIObserver) 1.20 + 1.21 +nsQtNetworkLinkService::nsQtNetworkLinkService() 1.22 +{ 1.23 +} 1.24 + 1.25 +nsQtNetworkLinkService::~nsQtNetworkLinkService() 1.26 +{ 1.27 +} 1.28 + 1.29 +NS_IMETHODIMP 1.30 +nsQtNetworkLinkService::GetIsLinkUp(bool* aIsUp) 1.31 +{ 1.32 + *aIsUp = nsQtNetworkManager::get()->isOnline(); 1.33 + return NS_OK; 1.34 +} 1.35 + 1.36 +NS_IMETHODIMP 1.37 +nsQtNetworkLinkService::GetLinkStatusKnown(bool* aIsKnown) 1.38 +{ 1.39 + *aIsKnown = nsQtNetworkManager::get()->isOnline(); 1.40 + return NS_OK; 1.41 +} 1.42 + 1.43 +NS_IMETHODIMP 1.44 +nsQtNetworkLinkService::GetLinkType(uint32_t *aLinkType) 1.45 +{ 1.46 + NS_ENSURE_ARG_POINTER(aLinkType); 1.47 + 1.48 + // XXX This function has not yet been implemented for this platform 1.49 + *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; 1.50 + return NS_OK; 1.51 +} 1.52 + 1.53 +NS_IMETHODIMP 1.54 +nsQtNetworkLinkService::Observe(nsISupports* aSubject, 1.55 + const char* aTopic, 1.56 + const char16_t* aData) 1.57 +{ 1.58 + if (!strcmp(aTopic, "xpcom-shutdown")) { 1.59 + Shutdown(); 1.60 + nsQtNetworkManager::get()->destroy(); 1.61 + } 1.62 + 1.63 + if (!strcmp(aTopic, "browser-lastwindow-close-granted")) { 1.64 + Shutdown(); 1.65 + } 1.66 + 1.67 + return NS_OK; 1.68 +} 1.69 + 1.70 +nsresult 1.71 +nsQtNetworkLinkService::Init(void) 1.72 +{ 1.73 + nsCOMPtr<nsIObserverService> observerService = 1.74 + mozilla::services::GetObserverService(); 1.75 + if (!observerService) { 1.76 + return NS_ERROR_FAILURE; 1.77 + } 1.78 + 1.79 + nsQtNetworkManager::create(); 1.80 + nsresult rv; 1.81 + 1.82 + rv = observerService->AddObserver(this, "xpcom-shutdown", false); 1.83 + if (NS_FAILED(rv)) { 1.84 + return NS_ERROR_FAILURE; 1.85 + } 1.86 + 1.87 + rv = observerService->AddObserver(this, "browser-lastwindow-close-granted", false); 1.88 + if (NS_FAILED(rv)) { 1.89 + return NS_ERROR_FAILURE; 1.90 + } 1.91 + 1.92 + 1.93 + return NS_OK; 1.94 +} 1.95 + 1.96 +nsresult 1.97 +nsQtNetworkLinkService::Shutdown() 1.98 +{ 1.99 + nsQtNetworkManager::get()->closeSession(); 1.100 + return NS_OK; 1.101 +}