michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:set ts=4 sw=4 cindent et: */ 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 "mozilla/DebugOnly.h" michael@0: michael@0: #include "nsIOService.h" michael@0: #include "nsIProtocolHandler.h" michael@0: #include "nsIFileProtocolHandler.h" michael@0: #include "nscore.h" michael@0: #include "nsIURI.h" michael@0: #include "prprf.h" michael@0: #include "nsIErrorService.h" michael@0: #include "netCore.h" michael@0: #include "nsIObserverService.h" michael@0: #include "nsIPrefService.h" michael@0: #include "nsXPCOM.h" michael@0: #include "nsIProxiedProtocolHandler.h" michael@0: #include "nsIProxyInfo.h" michael@0: #include "nsEscape.h" michael@0: #include "nsNetCID.h" michael@0: #include "nsCRT.h" michael@0: #include "nsSimpleNestedURI.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIConsoleService.h" michael@0: #include "nsIUploadChannel2.h" michael@0: #include "nsXULAppAPI.h" michael@0: #include "nsIProtocolProxyCallback.h" michael@0: #include "nsICancelable.h" michael@0: #include "nsINetworkLinkService.h" michael@0: #include "nsPISocketTransportService.h" michael@0: #include "nsAsyncRedirectVerifyHelper.h" michael@0: #include "nsURLHelper.h" michael@0: #include "nsPIDNSService.h" michael@0: #include "nsIProtocolProxyService2.h" michael@0: #include "MainThreadUtils.h" michael@0: michael@0: #if defined(XP_WIN) michael@0: #include "nsNativeConnectionHelper.h" michael@0: #endif michael@0: michael@0: using namespace mozilla; michael@0: michael@0: #define PORT_PREF_PREFIX "network.security.ports." michael@0: #define PORT_PREF(x) PORT_PREF_PREFIX x michael@0: #define AUTODIAL_PREF "network.autodial-helper.enabled" michael@0: #define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status" michael@0: michael@0: // Nb: these have been misnomers since bug 715770 removed the buffer cache. michael@0: // "network.segment.count" and "network.segment.size" would be better names, michael@0: // but the old names are still used to preserve backward compatibility. michael@0: #define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count" michael@0: #define NECKO_BUFFER_CACHE_SIZE_PREF "network.buffer.cache.size" michael@0: michael@0: #define MAX_RECURSION_COUNT 50 michael@0: michael@0: nsIOService* gIOService = nullptr; michael@0: static bool gHasWarnedUploadChannel2; michael@0: michael@0: // A general port blacklist. Connections to these ports will not be allowed unless michael@0: // the protocol overrides. michael@0: // michael@0: // TODO: I am sure that there are more ports to be added. michael@0: // This cut is based on the classic mozilla codebase michael@0: michael@0: int16_t gBadPortList[] = { michael@0: 1, // tcpmux michael@0: 7, // echo michael@0: 9, // discard michael@0: 11, // systat michael@0: 13, // daytime michael@0: 15, // netstat michael@0: 17, // qotd michael@0: 19, // chargen michael@0: 20, // ftp-data michael@0: 21, // ftp-cntl michael@0: 22, // ssh michael@0: 23, // telnet michael@0: 25, // smtp michael@0: 37, // time michael@0: 42, // name michael@0: 43, // nicname michael@0: 53, // domain michael@0: 77, // priv-rjs michael@0: 79, // finger michael@0: 87, // ttylink michael@0: 95, // supdup michael@0: 101, // hostriame michael@0: 102, // iso-tsap michael@0: 103, // gppitnp michael@0: 104, // acr-nema michael@0: 109, // pop2 michael@0: 110, // pop3 michael@0: 111, // sunrpc michael@0: 113, // auth michael@0: 115, // sftp michael@0: 117, // uucp-path michael@0: 119, // nntp michael@0: 123, // NTP michael@0: 135, // loc-srv / epmap michael@0: 139, // netbios michael@0: 143, // imap2 michael@0: 179, // BGP michael@0: 389, // ldap michael@0: 465, // smtp+ssl michael@0: 512, // print / exec michael@0: 513, // login michael@0: 514, // shell michael@0: 515, // printer michael@0: 526, // tempo michael@0: 530, // courier michael@0: 531, // Chat michael@0: 532, // netnews michael@0: 540, // uucp michael@0: 556, // remotefs michael@0: 563, // nntp+ssl michael@0: 587, // michael@0: 601, // michael@0: 636, // ldap+ssl michael@0: 993, // imap+ssl michael@0: 995, // pop3+ssl michael@0: 2049, // nfs michael@0: 4045, // lockd michael@0: 6000, // x11 michael@0: 0, // This MUST be zero so that we can populating the array michael@0: }; michael@0: michael@0: static const char kProfileChangeNetTeardownTopic[] = "profile-change-net-teardown"; michael@0: static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore"; michael@0: static const char kProfileDoChange[] = "profile-do-change"; michael@0: michael@0: // Necko buffer defaults michael@0: uint32_t nsIOService::gDefaultSegmentSize = 4096; michael@0: uint32_t nsIOService::gDefaultSegmentCount = 24; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: nsIOService::nsIOService() michael@0: : mOffline(true) michael@0: , mOfflineForProfileChange(false) michael@0: , mManageOfflineStatus(false) michael@0: , mSettingOffline(false) michael@0: , mSetOfflineValue(false) michael@0: , mShutdown(false) michael@0: , mNetworkLinkServiceInitialized(false) michael@0: , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY) michael@0: , mAutoDialEnabled(false) michael@0: { michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::Init() michael@0: { michael@0: nsresult rv; michael@0: michael@0: // We need to get references to the DNS service so that we can shut it michael@0: // down later. If we wait until the nsIOService is being shut down, michael@0: // GetService will fail at that point. michael@0: michael@0: mDNSService = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING("failed to get DNS service"); michael@0: return rv; michael@0: } michael@0: michael@0: // XXX hack until xpidl supports error info directly (bug 13423) michael@0: nsCOMPtr errorService = do_GetService(NS_ERRORSERVICE_CONTRACTID); michael@0: if (errorService) { michael@0: errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_NETWORK, NECKO_MSGS_URL); michael@0: } michael@0: else michael@0: NS_WARNING("failed to get error service"); michael@0: michael@0: // setup our bad port list stuff michael@0: for(int i=0; gBadPortList[i]; i++) michael@0: mRestrictedPortList.AppendElement(gBadPortList[i]); michael@0: michael@0: // Further modifications to the port list come from prefs michael@0: nsCOMPtr prefBranch; michael@0: GetPrefBranch(getter_AddRefs(prefBranch)); michael@0: if (prefBranch) { michael@0: prefBranch->AddObserver(PORT_PREF_PREFIX, this, true); michael@0: prefBranch->AddObserver(AUTODIAL_PREF, this, true); michael@0: prefBranch->AddObserver(MANAGE_OFFLINE_STATUS_PREF, this, true); michael@0: prefBranch->AddObserver(NECKO_BUFFER_CACHE_COUNT_PREF, this, true); michael@0: prefBranch->AddObserver(NECKO_BUFFER_CACHE_SIZE_PREF, this, true); michael@0: PrefsChanged(prefBranch); michael@0: } michael@0: michael@0: // Register for profile change notifications michael@0: nsCOMPtr observerService = michael@0: mozilla::services::GetObserverService(); michael@0: if (observerService) { michael@0: observerService->AddObserver(this, kProfileChangeNetTeardownTopic, true); michael@0: observerService->AddObserver(this, kProfileChangeNetRestoreTopic, true); michael@0: observerService->AddObserver(this, kProfileDoChange, true); michael@0: observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true); michael@0: observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true); michael@0: } michael@0: else michael@0: NS_WARNING("failed to get observer service"); michael@0: michael@0: gIOService = this; michael@0: michael@0: InitializeNetworkLinkService(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: nsIOService::~nsIOService() michael@0: { michael@0: gIOService = nullptr; michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::InitializeSocketTransportService() michael@0: { michael@0: nsresult rv = NS_OK; michael@0: michael@0: if (!mSocketTransportService) { michael@0: mSocketTransportService = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING("failed to get socket transport service"); michael@0: } michael@0: } michael@0: michael@0: if (mSocketTransportService) { michael@0: rv = mSocketTransportService->Init(); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service init failed"); michael@0: mSocketTransportService->SetAutodialEnabled(mAutoDialEnabled); michael@0: mSocketTransportService->SetOffline(false); michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::InitializeNetworkLinkService() michael@0: { michael@0: nsresult rv = NS_OK; michael@0: michael@0: if (mNetworkLinkServiceInitialized) michael@0: return rv; michael@0: michael@0: if (!NS_IsMainThread()) { michael@0: NS_WARNING("Network link service should be created on main thread"); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: // go into managed mode if we can, and chrome process michael@0: if (XRE_GetProcessType() == GeckoProcessType_Default) michael@0: { michael@0: mNetworkLinkService = do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv); michael@0: } michael@0: michael@0: if (mNetworkLinkService) { michael@0: mNetworkLinkServiceInitialized = true; michael@0: } michael@0: else { michael@0: // We can't really determine if the machine has a usable network connection, michael@0: // so let's cross our fingers! michael@0: mManageOfflineStatus = false; michael@0: } michael@0: michael@0: michael@0: if (mManageOfflineStatus) michael@0: TrackNetworkLinkStatusForOffline(); michael@0: else michael@0: SetOffline(false); michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: nsIOService* michael@0: nsIOService::GetInstance() { michael@0: if (!gIOService) { michael@0: gIOService = new nsIOService(); michael@0: if (!gIOService) michael@0: return nullptr; michael@0: NS_ADDREF(gIOService); michael@0: michael@0: nsresult rv = gIOService->Init(); michael@0: if (NS_FAILED(rv)) { michael@0: NS_RELEASE(gIOService); michael@0: return nullptr; michael@0: } michael@0: return gIOService; michael@0: } michael@0: NS_ADDREF(gIOService); michael@0: return gIOService; michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(nsIOService, michael@0: nsIIOService, michael@0: nsIIOService2, michael@0: nsINetUtil, michael@0: nsISpeculativeConnect, michael@0: nsIObserver, michael@0: nsISupportsWeakReference) michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: nsresult michael@0: nsIOService::AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan, michael@0: uint32_t flags, michael@0: nsAsyncRedirectVerifyHelper *helper) michael@0: { michael@0: nsCOMPtr sink = michael@0: do_GetService(NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID); michael@0: if (sink) { michael@0: nsresult rv = helper->DelegateOnChannelRedirect(sink, oldChan, michael@0: newChan, flags); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: } michael@0: michael@0: // Finally, our category michael@0: nsCOMArray entries; michael@0: mChannelEventSinks.GetEntries(entries); michael@0: int32_t len = entries.Count(); michael@0: for (int32_t i = 0; i < len; ++i) { michael@0: nsresult rv = helper->DelegateOnChannelRedirect(entries[i], oldChan, michael@0: newChan, flags); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::CacheProtocolHandler(const char *scheme, nsIProtocolHandler *handler) michael@0: { michael@0: for (unsigned int i=0; i factoryPtr = do_QueryInterface(handler, &rv); michael@0: if (!factoryPtr) michael@0: { michael@0: // Don't cache handlers that don't support weak reference as michael@0: // there is real danger of a circular reference. michael@0: #ifdef DEBUG_dp michael@0: printf("DEBUG: %s protcol handler doesn't support weak ref. Not cached.\n", scheme); michael@0: #endif /* DEBUG_dp */ michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mWeakHandler[i] = do_GetWeakReference(handler); michael@0: return NS_OK; michael@0: } michael@0: } michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::GetCachedProtocolHandler(const char *scheme, nsIProtocolHandler **result, uint32_t start, uint32_t end) michael@0: { michael@0: uint32_t len = end - start - 1; michael@0: for (unsigned int i=0; i protocol handler mapping, avoiding the string manipulation michael@0: // and service manager stuff michael@0: michael@0: rv = GetCachedProtocolHandler(scheme, result); michael@0: if (NS_SUCCEEDED(rv)) michael@0: return rv; michael@0: michael@0: bool externalProtocol = false; michael@0: nsCOMPtr prefBranch; michael@0: GetPrefBranch(getter_AddRefs(prefBranch)); michael@0: if (prefBranch) { michael@0: nsAutoCString externalProtocolPref("network.protocol-handler.external."); michael@0: externalProtocolPref += scheme; michael@0: rv = prefBranch->GetBoolPref(externalProtocolPref.get(), &externalProtocol); michael@0: if (NS_FAILED(rv)) { michael@0: externalProtocol = false; michael@0: } michael@0: } michael@0: michael@0: if (!externalProtocol) { michael@0: nsAutoCString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX); michael@0: contractID += scheme; michael@0: ToLowerCase(contractID); michael@0: michael@0: rv = CallGetService(contractID.get(), result); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: CacheProtocolHandler(scheme, *result); michael@0: return rv; michael@0: } michael@0: michael@0: #ifdef MOZ_X11 michael@0: // check to see whether GVFS can handle this URI scheme. if it can michael@0: // create a nsIURI for the "scheme:", then we assume it has support for michael@0: // the requested protocol. otherwise, we failover to using the default michael@0: // protocol handler. michael@0: michael@0: rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"moz-gio", michael@0: result); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: nsAutoCString spec(scheme); michael@0: spec.Append(':'); michael@0: michael@0: nsIURI *uri; michael@0: rv = (*result)->NewURI(spec, nullptr, nullptr, &uri); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: NS_RELEASE(uri); michael@0: return rv; michael@0: } michael@0: michael@0: NS_RELEASE(*result); michael@0: } michael@0: michael@0: // check to see whether GnomeVFS can handle this URI scheme. if it can michael@0: // create a nsIURI for the "scheme:", then we assume it has support for michael@0: // the requested protocol. otherwise, we failover to using the default michael@0: // protocol handler. michael@0: michael@0: // XXX should this be generalized into something that searches a michael@0: // category? (see bug 234714) michael@0: michael@0: rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"moz-gnomevfs", michael@0: result); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: nsAutoCString spec(scheme); michael@0: spec.Append(':'); michael@0: michael@0: nsIURI *uri; michael@0: rv = (*result)->NewURI(spec, nullptr, nullptr, &uri); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: NS_RELEASE(uri); michael@0: return rv; michael@0: } michael@0: michael@0: NS_RELEASE(*result); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: // Okay we don't have a protocol handler to handle this url type, so use michael@0: // the default protocol handler. This will cause urls to get dispatched michael@0: // out to the OS ('cause we can't do anything with them) when we try to michael@0: // read from a channel created by the default protocol handler. michael@0: michael@0: rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", michael@0: result); michael@0: if (NS_FAILED(rv)) michael@0: return NS_ERROR_UNKNOWN_PROTOCOL; michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::ExtractScheme(const nsACString &inURI, nsACString &scheme) michael@0: { michael@0: return net_ExtractURLScheme(inURI, nullptr, nullptr, &scheme); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::GetProtocolFlags(const char* scheme, uint32_t *flags) michael@0: { michael@0: nsCOMPtr handler; michael@0: nsresult rv = GetProtocolHandler(scheme, getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: rv = handler->GetProtocolFlags(flags); michael@0: return rv; michael@0: } michael@0: michael@0: class AutoIncrement michael@0: { michael@0: public: michael@0: AutoIncrement(uint32_t *var) : mVar(var) michael@0: { michael@0: ++*var; michael@0: } michael@0: ~AutoIncrement() michael@0: { michael@0: --*mVar; michael@0: } michael@0: private: michael@0: uint32_t *mVar; michael@0: }; michael@0: michael@0: nsresult michael@0: nsIOService::NewURI(const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, nsIURI **result) michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "wrong thread"); michael@0: michael@0: static uint32_t recursionCount = 0; michael@0: if (recursionCount >= MAX_RECURSION_COUNT) michael@0: return NS_ERROR_MALFORMED_URI; michael@0: AutoIncrement inc(&recursionCount); michael@0: michael@0: nsAutoCString scheme; michael@0: nsresult rv = ExtractScheme(aSpec, scheme); michael@0: if (NS_FAILED(rv)) { michael@0: // then aSpec is relative michael@0: if (!aBaseURI) michael@0: return NS_ERROR_MALFORMED_URI; michael@0: michael@0: rv = aBaseURI->GetScheme(scheme); michael@0: if (NS_FAILED(rv)) return rv; michael@0: } michael@0: michael@0: // now get the handler for this scheme michael@0: nsCOMPtr handler; michael@0: rv = GetProtocolHandler(scheme.get(), getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return handler->NewURI(aSpec, aCharset, aBaseURI, result); michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::NewFileURI(nsIFile *file, nsIURI **result) michael@0: { michael@0: nsresult rv; michael@0: NS_ENSURE_ARG_POINTER(file); michael@0: michael@0: nsCOMPtr handler; michael@0: michael@0: rv = GetProtocolHandler("file", getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: nsCOMPtr fileHandler( do_QueryInterface(handler, &rv) ); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return fileHandler->NewFileURI(file, result); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result) michael@0: { michael@0: return NewChannelFromURIWithProxyFlags(aURI, nullptr, 0, result); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::NewChannelFromURIWithProxyFlags(nsIURI *aURI, michael@0: nsIURI *aProxyURI, michael@0: uint32_t aProxyFlags, michael@0: nsIChannel **result) michael@0: { michael@0: nsresult rv; michael@0: NS_ENSURE_ARG_POINTER(aURI); michael@0: michael@0: nsAutoCString scheme; michael@0: rv = aURI->GetScheme(scheme); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr handler; michael@0: rv = GetProtocolHandler(scheme.get(), getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: uint32_t protoFlags; michael@0: rv = handler->GetProtocolFlags(&protoFlags); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr pph = do_QueryInterface(handler); michael@0: if (pph) michael@0: rv = pph->NewProxiedChannel(aURI, nullptr, aProxyFlags, aProxyURI, result); michael@0: else michael@0: rv = handler->NewChannel(aURI, result); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: // Some extensions override the http protocol handler and provide their own michael@0: // implementation. The channels returned from that implementation doesn't michael@0: // seem to always implement the nsIUploadChannel2 interface, presumably michael@0: // because it's a new interface. michael@0: // Eventually we should remove this and simply require that http channels michael@0: // implement the new interface. michael@0: // See bug 529041 michael@0: if (!gHasWarnedUploadChannel2 && scheme.EqualsLiteral("http")) { michael@0: nsCOMPtr uploadChannel2 = do_QueryInterface(*result); michael@0: if (!uploadChannel2) { michael@0: nsCOMPtr consoleService = michael@0: do_GetService(NS_CONSOLESERVICE_CONTRACTID); michael@0: if (consoleService) { michael@0: consoleService->LogStringMessage(NS_LITERAL_STRING( michael@0: "Http channel implementation doesn't support nsIUploadChannel2. An extension has supplied a non-functional http protocol handler. This will break behavior and in future releases not work at all." michael@0: ).get()); michael@0: } michael@0: gHasWarnedUploadChannel2 = true; michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::NewChannel(const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, nsIChannel **result) michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr uri; michael@0: rv = NewURI(aSpec, aCharset, aBaseURI, getter_AddRefs(uri)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return NewChannelFromURI(uri, result); michael@0: } michael@0: michael@0: bool michael@0: nsIOService::IsLinkUp() michael@0: { michael@0: InitializeNetworkLinkService(); michael@0: michael@0: if (!mNetworkLinkService) { michael@0: // We cannot decide, assume the link is up michael@0: return true; michael@0: } michael@0: michael@0: bool isLinkUp; michael@0: nsresult rv; michael@0: rv = mNetworkLinkService->GetIsLinkUp(&isLinkUp); michael@0: if (NS_FAILED(rv)) { michael@0: return true; michael@0: } michael@0: michael@0: return isLinkUp; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::GetOffline(bool *offline) michael@0: { michael@0: *offline = mOffline; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::SetOffline(bool offline) michael@0: { michael@0: // When someone wants to go online (!offline) after we got XPCOM shutdown michael@0: // throw ERROR_NOT_AVAILABLE to prevent return to online state. michael@0: if ((mShutdown || mOfflineForProfileChange) && !offline) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: // SetOffline() may re-enter while it's shutting down services. michael@0: // If that happens, save the most recent value and it will be michael@0: // processed when the first SetOffline() call is done bringing michael@0: // down the service. michael@0: mSetOfflineValue = offline; michael@0: if (mSettingOffline) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: mSettingOffline = true; michael@0: michael@0: nsCOMPtr observerService = michael@0: mozilla::services::GetObserverService(); michael@0: michael@0: NS_ASSERTION(observerService, "The observer service should not be null"); michael@0: michael@0: if (XRE_GetProcessType() == GeckoProcessType_Default) { michael@0: if (observerService) { michael@0: (void)observerService->NotifyObservers(nullptr, michael@0: NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, offline ? michael@0: MOZ_UTF16("true") : michael@0: MOZ_UTF16("false")); michael@0: } michael@0: } michael@0: michael@0: nsIIOService *subject = static_cast(this); michael@0: while (mSetOfflineValue != mOffline) { michael@0: offline = mSetOfflineValue; michael@0: michael@0: if (offline && !mOffline) { michael@0: NS_NAMED_LITERAL_STRING(offlineString, NS_IOSERVICE_OFFLINE); michael@0: mOffline = true; // indicate we're trying to shutdown michael@0: michael@0: // don't care if notifications fail michael@0: if (observerService) michael@0: observerService->NotifyObservers(subject, michael@0: NS_IOSERVICE_GOING_OFFLINE_TOPIC, michael@0: offlineString.get()); michael@0: michael@0: if (mDNSService) michael@0: mDNSService->SetOffline(true); michael@0: michael@0: if (mSocketTransportService) michael@0: mSocketTransportService->SetOffline(true); michael@0: michael@0: if (observerService) michael@0: observerService->NotifyObservers(subject, michael@0: NS_IOSERVICE_OFFLINE_STATUS_TOPIC, michael@0: offlineString.get()); michael@0: } michael@0: else if (!offline && mOffline) { michael@0: // go online michael@0: if (mDNSService) { michael@0: mDNSService->SetOffline(false); michael@0: DebugOnly rv = mDNSService->Init(); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed"); michael@0: } michael@0: InitializeSocketTransportService(); michael@0: mOffline = false; // indicate success only AFTER we've michael@0: // brought up the services michael@0: michael@0: // trigger a PAC reload when we come back online michael@0: if (mProxyService) michael@0: mProxyService->ReloadPAC(); michael@0: michael@0: // don't care if notification fails michael@0: if (observerService) michael@0: observerService->NotifyObservers(subject, michael@0: NS_IOSERVICE_OFFLINE_STATUS_TOPIC, michael@0: NS_LITERAL_STRING(NS_IOSERVICE_ONLINE).get()); michael@0: } michael@0: } michael@0: michael@0: // Don't notify here, as the above notifications (if used) suffice. michael@0: if ((mShutdown || mOfflineForProfileChange) && mOffline) { michael@0: // be sure to try and shutdown both (even if the first fails)... michael@0: // shutdown dns service first, because it has callbacks for socket transport michael@0: if (mDNSService) { michael@0: DebugOnly rv = mDNSService->Shutdown(); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service shutdown failed"); michael@0: } michael@0: if (mSocketTransportService) { michael@0: DebugOnly rv = mSocketTransportService->Shutdown(); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service shutdown failed"); michael@0: } michael@0: } michael@0: michael@0: mSettingOffline = false; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::AllowPort(int32_t inPort, const char *scheme, bool *_retval) michael@0: { michael@0: int16_t port = inPort; michael@0: if (port == -1) { michael@0: *_retval = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: if (port == 0) { michael@0: *_retval = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // first check to see if the port is in our blacklist: michael@0: int32_t badPortListCnt = mRestrictedPortList.Length(); michael@0: for (int i=0; i handler; michael@0: nsresult rv = GetProtocolHandler(scheme, getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: // let the protocol handler decide michael@0: return handler->AllowPort(port, scheme, _retval); michael@0: } michael@0: } michael@0: michael@0: *_retval = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: void michael@0: nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref) michael@0: { michael@0: if (!prefs) return; michael@0: michael@0: // Look for extra ports to block michael@0: if (!pref || strcmp(pref, PORT_PREF("banned")) == 0) michael@0: ParsePortList(prefs, PORT_PREF("banned"), false); michael@0: michael@0: // ...as well as previous blocks to remove. michael@0: if (!pref || strcmp(pref, PORT_PREF("banned.override")) == 0) michael@0: ParsePortList(prefs, PORT_PREF("banned.override"), true); michael@0: michael@0: if (!pref || strcmp(pref, AUTODIAL_PREF) == 0) { michael@0: bool enableAutodial = false; michael@0: nsresult rv = prefs->GetBoolPref(AUTODIAL_PREF, &enableAutodial); michael@0: // If pref not found, default to disabled. michael@0: mAutoDialEnabled = enableAutodial; michael@0: if (NS_SUCCEEDED(rv)) { michael@0: if (mSocketTransportService) michael@0: mSocketTransportService->SetAutodialEnabled(enableAutodial); michael@0: } michael@0: } michael@0: michael@0: if (!pref || strcmp(pref, MANAGE_OFFLINE_STATUS_PREF) == 0) { michael@0: bool manage; michael@0: if (mNetworkLinkServiceInitialized && michael@0: NS_SUCCEEDED(prefs->GetBoolPref(MANAGE_OFFLINE_STATUS_PREF, michael@0: &manage))) michael@0: SetManageOfflineStatus(manage); michael@0: } michael@0: michael@0: if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_COUNT_PREF) == 0) { michael@0: int32_t count; michael@0: if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_COUNT_PREF, michael@0: &count))) michael@0: /* check for bogus values and default if we find such a value */ michael@0: if (count > 0) michael@0: gDefaultSegmentCount = count; michael@0: } michael@0: michael@0: if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_SIZE_PREF) == 0) { michael@0: int32_t size; michael@0: if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_SIZE_PREF, michael@0: &size))) michael@0: /* check for bogus values and default if we find such a value michael@0: * the upper limit here is arbitrary. having a 1mb segment size michael@0: * is pretty crazy. if you remove this, consider adding some michael@0: * integer rollover test. michael@0: */ michael@0: if (size > 0 && size < 1024*1024) michael@0: gDefaultSegmentSize = size; michael@0: NS_WARN_IF_FALSE( (!(size & (size - 1))) , "network segment size is not a power of 2!"); michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsIOService::ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove) michael@0: { michael@0: nsXPIDLCString portList; michael@0: michael@0: // Get a pref string and chop it up into a list of ports. michael@0: prefBranch->GetCharPref(pref, getter_Copies(portList)); michael@0: if (portList) { michael@0: nsTArray portListArray; michael@0: ParseString(portList, ',', portListArray); michael@0: uint32_t index; michael@0: for (index=0; index < portListArray.Length(); index++) { michael@0: portListArray[index].StripWhitespace(); michael@0: int32_t portBegin, portEnd; michael@0: michael@0: if (PR_sscanf(portListArray[index].get(), "%d-%d", &portBegin, &portEnd) == 2) { michael@0: if ((portBegin < 65536) && (portEnd < 65536)) { michael@0: int32_t curPort; michael@0: if (remove) { michael@0: for (curPort=portBegin; curPort <= portEnd; curPort++) michael@0: mRestrictedPortList.RemoveElement(curPort); michael@0: } else { michael@0: for (curPort=portBegin; curPort <= portEnd; curPort++) michael@0: mRestrictedPortList.AppendElement(curPort); michael@0: } michael@0: } michael@0: } else { michael@0: nsresult aErrorCode; michael@0: int32_t port = portListArray[index].ToInteger(&aErrorCode); michael@0: if (NS_SUCCEEDED(aErrorCode) && port < 65536) { michael@0: if (remove) michael@0: mRestrictedPortList.RemoveElement(port); michael@0: else michael@0: mRestrictedPortList.AppendElement(port); michael@0: } michael@0: } michael@0: michael@0: } michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsIOService::GetPrefBranch(nsIPrefBranch **result) michael@0: { michael@0: *result = nullptr; michael@0: CallGetService(NS_PREFSERVICE_CONTRACTID, result); michael@0: } michael@0: michael@0: // nsIObserver interface michael@0: NS_IMETHODIMP michael@0: nsIOService::Observe(nsISupports *subject, michael@0: const char *topic, michael@0: const char16_t *data) michael@0: { michael@0: if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { michael@0: nsCOMPtr prefBranch = do_QueryInterface(subject); michael@0: if (prefBranch) michael@0: PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get()); michael@0: } michael@0: else if (!strcmp(topic, kProfileChangeNetTeardownTopic)) { michael@0: if (!mOffline) { michael@0: mOfflineForProfileChange = true; michael@0: SetOffline(true); michael@0: } michael@0: } michael@0: else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) { michael@0: if (mOfflineForProfileChange) { michael@0: mOfflineForProfileChange = false; michael@0: if (!mManageOfflineStatus || michael@0: NS_FAILED(TrackNetworkLinkStatusForOffline())) { michael@0: SetOffline(false); michael@0: } michael@0: } michael@0: } michael@0: else if (!strcmp(topic, kProfileDoChange)) { michael@0: if (data && NS_LITERAL_STRING("startup").Equals(data)) { michael@0: // Lazy initialization of network link service (see bug 620472) michael@0: InitializeNetworkLinkService(); michael@0: // Set up the initilization flag regardless the actuall result. michael@0: // If we fail here, we will fail always on. michael@0: mNetworkLinkServiceInitialized = true; michael@0: // And now reflect the preference setting michael@0: nsCOMPtr prefBranch; michael@0: GetPrefBranch(getter_AddRefs(prefBranch)); michael@0: PrefsChanged(prefBranch, MANAGE_OFFLINE_STATUS_PREF); michael@0: } michael@0: } michael@0: else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { michael@0: // Remember we passed XPCOM shutdown notification to prevent any michael@0: // changes of the offline status from now. We must not allow going michael@0: // online after this point. michael@0: mShutdown = true; michael@0: michael@0: SetOffline(true); michael@0: michael@0: // Break circular reference. michael@0: mProxyService = nullptr; michael@0: } michael@0: else if (!strcmp(topic, NS_NETWORK_LINK_TOPIC)) { michael@0: if (!mOfflineForProfileChange && mManageOfflineStatus) { michael@0: TrackNetworkLinkStatusForOffline(); michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: // nsINetUtil interface michael@0: NS_IMETHODIMP michael@0: nsIOService::ParseContentType(const nsACString &aTypeHeader, michael@0: nsACString &aCharset, michael@0: bool *aHadCharset, michael@0: nsACString &aContentType) michael@0: { michael@0: net_ParseContentType(aTypeHeader, aContentType, aCharset, aHadCharset); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::ProtocolHasFlags(nsIURI *uri, michael@0: uint32_t flags, michael@0: bool *result) michael@0: { michael@0: NS_ENSURE_ARG(uri); michael@0: michael@0: *result = false; michael@0: nsAutoCString scheme; michael@0: nsresult rv = uri->GetScheme(scheme); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: uint32_t protocolFlags; michael@0: rv = GetProtocolFlags(scheme.get(), &protocolFlags); michael@0: michael@0: if (NS_SUCCEEDED(rv)) { michael@0: *result = (protocolFlags & flags) == flags; michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::URIChainHasFlags(nsIURI *uri, michael@0: uint32_t flags, michael@0: bool *result) michael@0: { michael@0: nsresult rv = ProtocolHasFlags(uri, flags, result); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: if (*result) { michael@0: return rv; michael@0: } michael@0: michael@0: // Dig deeper into the chain. Note that this is not a do/while loop to michael@0: // avoid the extra addref/release on |uri| in the common (non-nested) case. michael@0: nsCOMPtr nestedURI = do_QueryInterface(uri); michael@0: while (nestedURI) { michael@0: nsCOMPtr innerURI; michael@0: rv = nestedURI->GetInnerURI(getter_AddRefs(innerURI)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: rv = ProtocolHasFlags(innerURI, flags, result); michael@0: michael@0: if (*result) { michael@0: return rv; michael@0: } michael@0: michael@0: nestedURI = do_QueryInterface(innerURI); michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::ToImmutableURI(nsIURI* uri, nsIURI** result) michael@0: { michael@0: if (!uri) { michael@0: *result = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult rv = NS_EnsureSafeToReturn(uri, result); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: NS_TryToSetImmutable(*result); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::NewSimpleNestedURI(nsIURI* aURI, nsIURI** aResult) michael@0: { michael@0: NS_ENSURE_ARG(aURI); michael@0: michael@0: nsCOMPtr safeURI; michael@0: nsresult rv = NS_EnsureSafeToReturn(aURI, getter_AddRefs(safeURI)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: NS_IF_ADDREF(*aResult = new nsSimpleNestedURI(safeURI)); michael@0: return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::SetManageOfflineStatus(bool aManage) { michael@0: nsresult rv = NS_OK; michael@0: michael@0: // SetManageOfflineStatus must throw when we fail to go from non-managed michael@0: // to managed. Usually because there is no link monitoring service michael@0: // available. Failure to do this switch is detected by a failure of michael@0: // TrackNetworkLinkStatusForOffline(). When there is no network link michael@0: // available during call to InitializeNetworkLinkService(), application is michael@0: // put to offline mode. And when we change mMangeOfflineStatus to false michael@0: // on the next line we get stuck on being offline even though the link michael@0: // becomes later available. michael@0: bool wasManaged = mManageOfflineStatus; michael@0: mManageOfflineStatus = aManage; michael@0: michael@0: InitializeNetworkLinkService(); michael@0: michael@0: if (mManageOfflineStatus && !wasManaged) { michael@0: rv = TrackNetworkLinkStatusForOffline(); michael@0: if (NS_FAILED(rv)) michael@0: mManageOfflineStatus = false; michael@0: } michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::GetManageOfflineStatus(bool* aManage) { michael@0: *aManage = mManageOfflineStatus; michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsIOService::TrackNetworkLinkStatusForOffline() michael@0: { michael@0: NS_ASSERTION(mManageOfflineStatus, michael@0: "Don't call this unless we're managing the offline status"); michael@0: if (!mNetworkLinkService) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: if (mShutdown) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: // check to make sure this won't collide with Autodial michael@0: if (mSocketTransportService) { michael@0: bool autodialEnabled = false; michael@0: mSocketTransportService->GetAutodialEnabled(&autodialEnabled); michael@0: // If autodialing-on-link-down is enabled, check if the OS auto dial michael@0: // option is set to always autodial. If so, then we are michael@0: // always up for the purposes of offline management. michael@0: if (autodialEnabled) { michael@0: #if defined(XP_WIN) michael@0: // On Windows, we should first check with the OS michael@0: // to see if autodial is enabled. If it is michael@0: // enabled then we are allowed to manage the michael@0: // offline state. michael@0: if(nsNativeConnectionHelper::IsAutodialEnabled()) michael@0: return SetOffline(false); michael@0: #else michael@0: return SetOffline(false); michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: bool isUp; michael@0: nsresult rv = mNetworkLinkService->GetIsLinkUp(&isUp); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: return SetOffline(!isUp); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::EscapeString(const nsACString& aString, michael@0: uint32_t aEscapeType, michael@0: nsACString& aResult) michael@0: { michael@0: NS_ENSURE_ARG_MAX(aEscapeType, 4); michael@0: michael@0: nsAutoCString stringCopy(aString); michael@0: nsCString result; michael@0: michael@0: if (!NS_Escape(stringCopy, result, (nsEscapeMask) aEscapeType)) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: aResult.Assign(result); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::EscapeURL(const nsACString &aStr, michael@0: uint32_t aFlags, nsACString &aResult) michael@0: { michael@0: aResult.Truncate(); michael@0: NS_EscapeURL(aStr.BeginReading(), aStr.Length(), michael@0: aFlags | esc_AlwaysCopy, aResult); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::UnescapeString(const nsACString &aStr, michael@0: uint32_t aFlags, nsACString &aResult) michael@0: { michael@0: aResult.Truncate(); michael@0: NS_UnescapeURL(aStr.BeginReading(), aStr.Length(), michael@0: aFlags | esc_AlwaysCopy, aResult); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::ExtractCharsetFromContentType(const nsACString &aTypeHeader, michael@0: nsACString &aCharset, michael@0: int32_t *aCharsetStart, michael@0: int32_t *aCharsetEnd, michael@0: bool *aHadCharset) michael@0: { michael@0: nsAutoCString ignored; michael@0: net_ParseContentType(aTypeHeader, ignored, aCharset, aHadCharset, michael@0: aCharsetStart, aCharsetEnd); michael@0: if (*aHadCharset && *aCharsetStart == *aCharsetEnd) { michael@0: *aHadCharset = false; michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: // nsISpeculativeConnect michael@0: class IOServiceProxyCallback MOZ_FINAL : public nsIProtocolProxyCallback michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIPROTOCOLPROXYCALLBACK michael@0: michael@0: IOServiceProxyCallback(nsIInterfaceRequestor *aCallbacks, michael@0: nsIOService *aIOService) michael@0: : mCallbacks(aCallbacks) michael@0: , mIOService(aIOService) michael@0: { } michael@0: michael@0: private: michael@0: nsRefPtr mCallbacks; michael@0: nsRefPtr mIOService; michael@0: }; michael@0: michael@0: NS_IMPL_ISUPPORTS(IOServiceProxyCallback, nsIProtocolProxyCallback) michael@0: michael@0: NS_IMETHODIMP michael@0: IOServiceProxyCallback::OnProxyAvailable(nsICancelable *request, nsIChannel *channel, michael@0: nsIProxyInfo *pi, nsresult status) michael@0: { michael@0: // Checking proxy status for speculative connect michael@0: nsAutoCString type; michael@0: if (NS_SUCCEEDED(status) && pi && michael@0: NS_SUCCEEDED(pi->GetType(type)) && michael@0: !type.EqualsLiteral("direct")) { michael@0: // proxies dont do speculative connect michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsCOMPtr uri; michael@0: nsresult rv = channel->GetURI(getter_AddRefs(uri)); michael@0: if (NS_FAILED(rv)) michael@0: return NS_OK; michael@0: michael@0: nsAutoCString scheme; michael@0: rv = uri->GetScheme(scheme); michael@0: if (NS_FAILED(rv)) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr handler; michael@0: rv = mIOService->GetProtocolHandler(scheme.get(), michael@0: getter_AddRefs(handler)); michael@0: if (NS_FAILED(rv)) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr speculativeHandler = michael@0: do_QueryInterface(handler); michael@0: if (!speculativeHandler) michael@0: return NS_OK; michael@0: michael@0: speculativeHandler->SpeculativeConnect(uri, michael@0: mCallbacks); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsIOService::SpeculativeConnect(nsIURI *aURI, michael@0: nsIInterfaceRequestor *aCallbacks) michael@0: { michael@0: // Check for proxy information. If there is a proxy configured then a michael@0: // speculative connect should not be performed because the potential michael@0: // reward is slim with tcp peers closely located to the browser. michael@0: nsresult rv; michael@0: nsCOMPtr pps = michael@0: do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID, &rv); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr channel; michael@0: rv = NewChannelFromURI(aURI, getter_AddRefs(channel)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr cancelable; michael@0: nsRefPtr callback = michael@0: new IOServiceProxyCallback(aCallbacks, this); michael@0: return pps->AsyncResolve(channel, 0, callback, getter_AddRefs(cancelable)); michael@0: }