|
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/. */ |
|
4 |
|
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" |
|
13 |
|
14 NS_IMPL_ISUPPORTS(nsQtNetworkLinkService, |
|
15 nsINetworkLinkService, |
|
16 nsIObserver) |
|
17 |
|
18 nsQtNetworkLinkService::nsQtNetworkLinkService() |
|
19 { |
|
20 } |
|
21 |
|
22 nsQtNetworkLinkService::~nsQtNetworkLinkService() |
|
23 { |
|
24 } |
|
25 |
|
26 NS_IMETHODIMP |
|
27 nsQtNetworkLinkService::GetIsLinkUp(bool* aIsUp) |
|
28 { |
|
29 *aIsUp = nsQtNetworkManager::get()->isOnline(); |
|
30 return NS_OK; |
|
31 } |
|
32 |
|
33 NS_IMETHODIMP |
|
34 nsQtNetworkLinkService::GetLinkStatusKnown(bool* aIsKnown) |
|
35 { |
|
36 *aIsKnown = nsQtNetworkManager::get()->isOnline(); |
|
37 return NS_OK; |
|
38 } |
|
39 |
|
40 NS_IMETHODIMP |
|
41 nsQtNetworkLinkService::GetLinkType(uint32_t *aLinkType) |
|
42 { |
|
43 NS_ENSURE_ARG_POINTER(aLinkType); |
|
44 |
|
45 // XXX This function has not yet been implemented for this platform |
|
46 *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; |
|
47 return NS_OK; |
|
48 } |
|
49 |
|
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 } |
|
59 |
|
60 if (!strcmp(aTopic, "browser-lastwindow-close-granted")) { |
|
61 Shutdown(); |
|
62 } |
|
63 |
|
64 return NS_OK; |
|
65 } |
|
66 |
|
67 nsresult |
|
68 nsQtNetworkLinkService::Init(void) |
|
69 { |
|
70 nsCOMPtr<nsIObserverService> observerService = |
|
71 mozilla::services::GetObserverService(); |
|
72 if (!observerService) { |
|
73 return NS_ERROR_FAILURE; |
|
74 } |
|
75 |
|
76 nsQtNetworkManager::create(); |
|
77 nsresult rv; |
|
78 |
|
79 rv = observerService->AddObserver(this, "xpcom-shutdown", false); |
|
80 if (NS_FAILED(rv)) { |
|
81 return NS_ERROR_FAILURE; |
|
82 } |
|
83 |
|
84 rv = observerService->AddObserver(this, "browser-lastwindow-close-granted", false); |
|
85 if (NS_FAILED(rv)) { |
|
86 return NS_ERROR_FAILURE; |
|
87 } |
|
88 |
|
89 |
|
90 return NS_OK; |
|
91 } |
|
92 |
|
93 nsresult |
|
94 nsQtNetworkLinkService::Shutdown() |
|
95 { |
|
96 nsQtNetworkManager::get()->closeSession(); |
|
97 return NS_OK; |
|
98 } |