nsresult nsExtProtocolChannel::OpenURL() { nsresult rv = NS_ERROR_FAILURE; nsCOMPtr<nsIExternalProtocolService> extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); if (extProtService) { #ifdef DEBUG nsAutoCString urlScheme; mUrl->GetScheme(urlScheme); bool haveHandler = false; extProtService->ExternalProtocolHandlerExists(urlScheme.get(), &haveHandler); NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support the protocol?"); #endif nsCOMPtr<nsIInterfaceRequestor> aggCallbacks; rv = NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup, getter_AddRefs(aggCallbacks)); if (NS_FAILED(rv)) { goto finish; } rv = extProtService->LoadURI(mUrl, aggCallbacks); if (NS_SUCCEEDED(rv)) { // despite success, we need to abort this channel, at the very least // to make it clear to the caller that no on{Start,Stop}Request // should be expected. rv = NS_ERROR_NO_CONTENT; } } finish: mCallbacks = 0; return rv; }
nsresult nsExtProtocolChannel::OpenURL() { nsresult rv = NS_ERROR_FAILURE; nsCOMPtr<nsIExternalProtocolService> extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); if (extProtService) { #ifdef DEBUG nsAutoCString urlScheme; mUrl->GetScheme(urlScheme); bool haveHandler = false; extProtService->ExternalProtocolHandlerExists(urlScheme.get(), &haveHandler); NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support the protocol?"); #endif nsCOMPtr<nsIInterfaceRequestor> aggCallbacks; rv = NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup, getter_AddRefs(aggCallbacks)); if (NS_FAILED(rv)) { goto finish; } rv = extProtService->LoadURI(mUrl, aggCallbacks); if (NS_SUCCEEDED(rv) && mListener) { Cancel(NS_ERROR_NO_CONTENT); RefPtr<nsExtProtocolChannel> self = this; nsCOMPtr<nsIStreamListener> listener = mListener; MessageLoop::current()->PostTask( NS_NewRunnableFunction( "nsExtProtocolChannel::OpenURL", [self, listener]() { listener->OnStartRequest(self, nullptr); listener->OnStopRequest(self, nullptr, self->mStatus); })); } } finish: mCallbacks = nullptr; mListener = nullptr; return rv; }