53 #include <sbFileUtils.h>
57 #include <nsAutoPtr.h>
58 #include <nsIChannel.h>
59 #include <nsIIOService.h>
60 #include <nsIPropertyBag2.h>
79 static PRLogModuleInfo* gHTTPMediaItemDownloaderLog = nsnull;
80 #define TRACE(args) PR_LOG(gHTTPMediaItemDownloaderLog, PR_LOG_DEBUG, args)
81 #define LOG(args) PR_LOG(gHTTPMediaItemDownloaderLog, PR_LOG_WARN, args)
83 #define __FUNCTION__ __PRETTY_FUNCTION__
121 TRACE((
"%s 0x%08x 0x%08x", __FUNCTION__, aMediaItem, aTargetLibrary));
124 NS_ENSURE_ARG_POINTER(aMediaItem);
125 NS_ENSURE_ARG_POINTER(retval);
131 nsCOMPtr<nsIURI> contentSrc;
132 rv = aMediaItem->GetContentSrc(getter_AddRefs(contentSrc));
133 NS_ENSURE_SUCCESS(rv, rv);
136 NS_ENSURE_SUCCESS(rv, rv);
139 nsCAutoString scheme;
140 rv = mainThreadContentSrc->GetScheme(scheme);
141 NS_ENSURE_SUCCESS(rv, rv);
144 if (scheme.Equals(
"http") || scheme.Equals(
"https"))
161 sbHTTPMediaItemDownloader::GetDownloadSize(
sbIMediaItem* aMediaItem,
165 TRACE((
"%s 0x%08x 0x%08x", __FUNCTION__, aMediaItem, aTargetLibrary));
168 NS_ENSURE_ARG_POINTER(aMediaItem);
174 nsCOMPtr<nsIURI> contentSrc;
175 rv = aMediaItem->GetContentSrc(getter_AddRefs(contentSrc));
176 NS_ENSURE_SUCCESS(rv, rv);
179 nsCOMPtr<nsIIOService>
181 NS_ENSURE_SUCCESS(rv, rv);
184 nsCOMPtr<nsIChannel> channel;
185 rv = ioService->NewChannelFromURI(contentSrc, getter_AddRefs(channel));
186 NS_ENSURE_SUCCESS(rv, rv);
189 NS_ENSURE_SUCCESS(rv, rv);
192 nsCOMPtr<nsIInputStream> inputStream;
193 rv = mainThreadChannel->Open(getter_AddRefs(inputStream));
194 NS_ENSURE_SUCCESS(rv, rv);
195 sbAutoInputStream autoInputStream(inputStream);
199 PRBool gotContentLength = PR_FALSE;
200 nsCOMPtr<nsIPropertyBag2>
202 if (NS_SUCCEEDED(rv)) {
203 rv = properties->GetPropertyAsUint64(NS_LITERAL_STRING(
"content-length"),
205 if (NS_SUCCEEDED(rv))
206 gotContentLength = PR_TRUE;
208 if (!gotContentLength) {
209 PRInt32 contentLength32;
210 rv = mainThreadChannel->GetContentLength(&contentLength32);
211 NS_ENSURE_SUCCESS(rv, rv);
212 contentLength = contentLength32;
230 sbHTTPMediaItemDownloader::CreateDownloadJob
235 TRACE((
"%s 0x%08x 0x%08x", __FUNCTION__, aMediaItem, aTargetLibrary));
238 NS_ENSURE_ARG_POINTER(aMediaItem);
244 nsRefPtr<sbHTTPMediaItemDownloadJob> job;
248 NS_ENSURE_SUCCESS(rv, rv);
276 if (!gHTTPMediaItemDownloaderLog) {
277 gHTTPMediaItemDownloaderLog =
278 PR_NewLogModule(
"sbHTTPMediaItemDownloader");
282 TRACE((
"%s[%.8x]", __FUNCTION__,
this));
293 TRACE((
"%s[%.8x]", __FUNCTION__,
this));
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
sbMainThreadQueryInterface do_MainThreadQueryInterface(nsISupports *aSupports, nsresult *aResult=nsnull)
BogusChannel prototype contentLength
Media library abstraction.