netwerk/protocol/rtsp/RtspHandler.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et tw=80 : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "RtspChannelChild.h"
michael@0 8 #include "RtspChannelParent.h"
michael@0 9 #include "RtspHandler.h"
michael@0 10 #include "nsILoadGroup.h"
michael@0 11 #include "nsIInterfaceRequestor.h"
michael@0 12 #include "nsIURI.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "nsStandardURL.h"
michael@0 15 #include "mozilla/net/NeckoChild.h"
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace net {
michael@0 19
michael@0 20 NS_IMPL_ISUPPORTS(RtspHandler, nsIProtocolHandler)
michael@0 21
michael@0 22 //-----------------------------------------------------------------------------
michael@0 23 // RtspHandler::nsIProtocolHandler
michael@0 24 //-----------------------------------------------------------------------------
michael@0 25
michael@0 26 NS_IMETHODIMP
michael@0 27 RtspHandler::GetScheme(nsACString &aScheme)
michael@0 28 {
michael@0 29 aScheme.AssignLiteral("rtsp");
michael@0 30 return NS_OK;
michael@0 31 }
michael@0 32
michael@0 33 NS_IMETHODIMP
michael@0 34 RtspHandler::GetDefaultPort(int32_t *aDefaultPort)
michael@0 35 {
michael@0 36 *aDefaultPort = kDefaultRtspPort;
michael@0 37 return NS_OK;
michael@0 38 }
michael@0 39
michael@0 40 NS_IMETHODIMP
michael@0 41 RtspHandler::GetProtocolFlags(uint32_t *aProtocolFlags)
michael@0 42 {
michael@0 43 *aProtocolFlags = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT |
michael@0 44 URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE | URI_SYNC_LOAD_IS_OK;
michael@0 45
michael@0 46 return NS_OK;
michael@0 47 }
michael@0 48
michael@0 49 NS_IMETHODIMP
michael@0 50 RtspHandler::NewURI(const nsACString & aSpec,
michael@0 51 const char *aOriginCharset,
michael@0 52 nsIURI *aBaseURI, nsIURI **aResult)
michael@0 53 {
michael@0 54 int32_t port;
michael@0 55
michael@0 56 nsresult rv = GetDefaultPort(&port);
michael@0 57 NS_ENSURE_SUCCESS(rv, rv);
michael@0 58
michael@0 59 nsRefPtr<nsStandardURL> url = new nsStandardURL();
michael@0 60 rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY, port, aSpec,
michael@0 61 aOriginCharset, aBaseURI);
michael@0 62 NS_ENSURE_SUCCESS(rv, rv);
michael@0 63
michael@0 64 url.forget(aResult);
michael@0 65 return NS_OK;
michael@0 66 }
michael@0 67
michael@0 68 NS_IMETHODIMP
michael@0 69 RtspHandler::NewChannel(nsIURI *aURI, nsIChannel **aResult)
michael@0 70 {
michael@0 71 bool isRtsp = false;
michael@0 72 nsRefPtr<nsBaseChannel> rtspChannel;
michael@0 73
michael@0 74 nsresult rv = aURI->SchemeIs("rtsp", &isRtsp);
michael@0 75 NS_ENSURE_SUCCESS(rv, rv);
michael@0 76 NS_ENSURE_TRUE(isRtsp, NS_ERROR_UNEXPECTED);
michael@0 77
michael@0 78 if (IsNeckoChild()) {
michael@0 79 rtspChannel = new RtspChannelChild(aURI);
michael@0 80 } else {
michael@0 81 rtspChannel = new RtspChannelParent(aURI);
michael@0 82 }
michael@0 83
michael@0 84 rv = rtspChannel->Init();
michael@0 85 NS_ENSURE_SUCCESS(rv, rv);
michael@0 86
michael@0 87 rtspChannel.forget(aResult);
michael@0 88 return NS_OK;
michael@0 89 }
michael@0 90
michael@0 91 NS_IMETHODIMP
michael@0 92 RtspHandler::AllowPort(int32_t port, const char *scheme, bool *aResult)
michael@0 93 {
michael@0 94 // Do not override any blacklisted ports.
michael@0 95 *aResult = false;
michael@0 96 return NS_OK;
michael@0 97 }
michael@0 98
michael@0 99 } // namespace net
michael@0 100 } // namespace mozilla

mercurial