netwerk/protocol/rtsp/RtspHandler.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/rtsp/RtspHandler.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "RtspChannelChild.h"
    1.11 +#include "RtspChannelParent.h"
    1.12 +#include "RtspHandler.h"
    1.13 +#include "nsILoadGroup.h"
    1.14 +#include "nsIInterfaceRequestor.h"
    1.15 +#include "nsIURI.h"
    1.16 +#include "nsAutoPtr.h"
    1.17 +#include "nsStandardURL.h"
    1.18 +#include "mozilla/net/NeckoChild.h"
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace net {
    1.22 +
    1.23 +NS_IMPL_ISUPPORTS(RtspHandler, nsIProtocolHandler)
    1.24 +
    1.25 +//-----------------------------------------------------------------------------
    1.26 +// RtspHandler::nsIProtocolHandler
    1.27 +//-----------------------------------------------------------------------------
    1.28 +
    1.29 +NS_IMETHODIMP
    1.30 +RtspHandler::GetScheme(nsACString &aScheme)
    1.31 +{
    1.32 +  aScheme.AssignLiteral("rtsp");
    1.33 +  return NS_OK;
    1.34 +}
    1.35 +
    1.36 +NS_IMETHODIMP
    1.37 +RtspHandler::GetDefaultPort(int32_t *aDefaultPort)
    1.38 +{
    1.39 +  *aDefaultPort = kDefaultRtspPort;
    1.40 +  return NS_OK;
    1.41 +}
    1.42 +
    1.43 +NS_IMETHODIMP
    1.44 +RtspHandler::GetProtocolFlags(uint32_t *aProtocolFlags)
    1.45 +{
    1.46 +  *aProtocolFlags = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT |
    1.47 +    URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE | URI_SYNC_LOAD_IS_OK;
    1.48 +
    1.49 +  return NS_OK;
    1.50 +}
    1.51 +
    1.52 +NS_IMETHODIMP
    1.53 +RtspHandler::NewURI(const nsACString & aSpec,
    1.54 +                    const char *aOriginCharset,
    1.55 +                    nsIURI *aBaseURI, nsIURI **aResult)
    1.56 +{
    1.57 +  int32_t port;
    1.58 +
    1.59 +  nsresult rv = GetDefaultPort(&port);
    1.60 +  NS_ENSURE_SUCCESS(rv, rv);
    1.61 +
    1.62 +  nsRefPtr<nsStandardURL> url = new nsStandardURL();
    1.63 +  rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY, port, aSpec,
    1.64 +                 aOriginCharset, aBaseURI);
    1.65 +  NS_ENSURE_SUCCESS(rv, rv);
    1.66 +
    1.67 +  url.forget(aResult);
    1.68 +  return NS_OK;
    1.69 +}
    1.70 +
    1.71 +NS_IMETHODIMP
    1.72 +RtspHandler::NewChannel(nsIURI *aURI, nsIChannel **aResult)
    1.73 +{
    1.74 +  bool isRtsp = false;
    1.75 +  nsRefPtr<nsBaseChannel> rtspChannel;
    1.76 +
    1.77 +  nsresult rv = aURI->SchemeIs("rtsp", &isRtsp);
    1.78 +  NS_ENSURE_SUCCESS(rv, rv);
    1.79 +  NS_ENSURE_TRUE(isRtsp, NS_ERROR_UNEXPECTED);
    1.80 +
    1.81 +  if (IsNeckoChild()) {
    1.82 +    rtspChannel = new RtspChannelChild(aURI);
    1.83 +  } else {
    1.84 +    rtspChannel = new RtspChannelParent(aURI);
    1.85 +  }
    1.86 +
    1.87 +  rv = rtspChannel->Init();
    1.88 +  NS_ENSURE_SUCCESS(rv, rv);
    1.89 +
    1.90 +  rtspChannel.forget(aResult);
    1.91 +  return NS_OK;
    1.92 +}
    1.93 +
    1.94 +NS_IMETHODIMP
    1.95 +RtspHandler::AllowPort(int32_t port, const char *scheme, bool *aResult)
    1.96 +{
    1.97 +  // Do not override any blacklisted ports.
    1.98 +  *aResult = false;
    1.99 +  return NS_OK;
   1.100 +}
   1.101 +
   1.102 +} // namespace net
   1.103 +} // namespace mozilla

mercurial