netwerk/protocol/rtsp/RtspHandler.cpp

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

mercurial