Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsQtNetworkManager.h" |
michael@0 | 6 | #include "nsQtNetworkLinkService.h" |
michael@0 | 7 | #include "nsCOMPtr.h" |
michael@0 | 8 | #include "nsIObserverService.h" |
michael@0 | 9 | #include "nsServiceManagerUtils.h" |
michael@0 | 10 | #include "nsString.h" |
michael@0 | 11 | #include "mozilla/Services.h" |
michael@0 | 12 | #include "nsCRT.h" |
michael@0 | 13 | |
michael@0 | 14 | NS_IMPL_ISUPPORTS(nsQtNetworkLinkService, |
michael@0 | 15 | nsINetworkLinkService, |
michael@0 | 16 | nsIObserver) |
michael@0 | 17 | |
michael@0 | 18 | nsQtNetworkLinkService::nsQtNetworkLinkService() |
michael@0 | 19 | { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | nsQtNetworkLinkService::~nsQtNetworkLinkService() |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMETHODIMP |
michael@0 | 27 | nsQtNetworkLinkService::GetIsLinkUp(bool* aIsUp) |
michael@0 | 28 | { |
michael@0 | 29 | *aIsUp = nsQtNetworkManager::get()->isOnline(); |
michael@0 | 30 | return NS_OK; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | NS_IMETHODIMP |
michael@0 | 34 | nsQtNetworkLinkService::GetLinkStatusKnown(bool* aIsKnown) |
michael@0 | 35 | { |
michael@0 | 36 | *aIsKnown = nsQtNetworkManager::get()->isOnline(); |
michael@0 | 37 | return NS_OK; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | NS_IMETHODIMP |
michael@0 | 41 | nsQtNetworkLinkService::GetLinkType(uint32_t *aLinkType) |
michael@0 | 42 | { |
michael@0 | 43 | NS_ENSURE_ARG_POINTER(aLinkType); |
michael@0 | 44 | |
michael@0 | 45 | // XXX This function has not yet been implemented for this platform |
michael@0 | 46 | *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NS_IMETHODIMP |
michael@0 | 51 | nsQtNetworkLinkService::Observe(nsISupports* aSubject, |
michael@0 | 52 | const char* aTopic, |
michael@0 | 53 | const char16_t* aData) |
michael@0 | 54 | { |
michael@0 | 55 | if (!strcmp(aTopic, "xpcom-shutdown")) { |
michael@0 | 56 | Shutdown(); |
michael@0 | 57 | nsQtNetworkManager::get()->destroy(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | if (!strcmp(aTopic, "browser-lastwindow-close-granted")) { |
michael@0 | 61 | Shutdown(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | return NS_OK; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | nsresult |
michael@0 | 68 | nsQtNetworkLinkService::Init(void) |
michael@0 | 69 | { |
michael@0 | 70 | nsCOMPtr<nsIObserverService> observerService = |
michael@0 | 71 | mozilla::services::GetObserverService(); |
michael@0 | 72 | if (!observerService) { |
michael@0 | 73 | return NS_ERROR_FAILURE; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | nsQtNetworkManager::create(); |
michael@0 | 77 | nsresult rv; |
michael@0 | 78 | |
michael@0 | 79 | rv = observerService->AddObserver(this, "xpcom-shutdown", false); |
michael@0 | 80 | if (NS_FAILED(rv)) { |
michael@0 | 81 | return NS_ERROR_FAILURE; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | rv = observerService->AddObserver(this, "browser-lastwindow-close-granted", false); |
michael@0 | 85 | if (NS_FAILED(rv)) { |
michael@0 | 86 | return NS_ERROR_FAILURE; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | return NS_OK; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | nsresult |
michael@0 | 94 | nsQtNetworkLinkService::Shutdown() |
michael@0 | 95 | { |
michael@0 | 96 | nsQtNetworkManager::get()->closeSession(); |
michael@0 | 97 | return NS_OK; |
michael@0 | 98 | } |