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