/src/mozilla-central/dom/presentation/PresentationTransportBuilderConstructor.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 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 "PresentationTransportBuilderConstructor.h" |
8 | | |
9 | | #include "nsComponentManagerUtils.h" |
10 | | #include "nsIPresentationControlChannel.h" |
11 | | #include "nsIPresentationSessionTransport.h" |
12 | | #include "nsXULAppAPI.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | NS_IMPL_ISUPPORTS(DummyPresentationTransportBuilderConstructor, |
18 | | nsIPresentationTransportBuilderConstructor) |
19 | | |
20 | | NS_IMETHODIMP |
21 | | DummyPresentationTransportBuilderConstructor::CreateTransportBuilder( |
22 | | uint8_t aType, |
23 | | nsIPresentationSessionTransportBuilder** aRetval) |
24 | 0 | { |
25 | 0 | MOZ_ASSERT(false, "Unexpected to be invoked."); |
26 | 0 | return NS_OK; |
27 | 0 | } |
28 | | |
29 | | /* static */ already_AddRefed<nsIPresentationTransportBuilderConstructor> |
30 | | PresentationTransportBuilderConstructor::Create() |
31 | 0 | { |
32 | 0 | nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor; |
33 | 0 | if (XRE_IsContentProcess()) { |
34 | 0 | constructor = new DummyPresentationTransportBuilderConstructor(); |
35 | 0 | } else { |
36 | 0 | constructor = new PresentationTransportBuilderConstructor(); |
37 | 0 | } |
38 | 0 |
|
39 | 0 | return constructor.forget(); |
40 | 0 | } |
41 | | |
42 | | NS_IMETHODIMP |
43 | | PresentationTransportBuilderConstructor::CreateTransportBuilder( |
44 | | uint8_t aType, |
45 | | nsIPresentationSessionTransportBuilder** aRetval) |
46 | 0 | { |
47 | 0 | if (NS_WARN_IF(!aRetval)) { |
48 | 0 | return NS_ERROR_INVALID_ARG; |
49 | 0 | } |
50 | 0 | |
51 | 0 | *aRetval = nullptr; |
52 | 0 |
|
53 | 0 | if (NS_WARN_IF(aType != nsIPresentationChannelDescription::TYPE_TCP && |
54 | 0 | aType != nsIPresentationChannelDescription::TYPE_DATACHANNEL)) { |
55 | 0 | return NS_ERROR_INVALID_ARG; |
56 | 0 | } |
57 | 0 | |
58 | 0 | if (XRE_IsContentProcess()) { |
59 | 0 | MOZ_ASSERT(false, |
60 | 0 | "CreateTransportBuilder can only be invoked in parent process."); |
61 | 0 | return NS_ERROR_FAILURE; |
62 | 0 | } |
63 | 0 |
|
64 | 0 | nsCOMPtr<nsIPresentationSessionTransportBuilder> builder; |
65 | 0 | if (aType == nsIPresentationChannelDescription::TYPE_TCP) { |
66 | 0 | builder = |
67 | 0 | do_CreateInstance(PRESENTATION_TCP_SESSION_TRANSPORT_CONTRACTID); |
68 | 0 | } else { |
69 | 0 | builder = |
70 | 0 | do_CreateInstance("@mozilla.org/presentation/datachanneltransportbuilder;1"); |
71 | 0 | } |
72 | 0 |
|
73 | 0 | if (NS_WARN_IF(!builder)) { |
74 | 0 | return NS_ERROR_DOM_OPERATION_ERR; |
75 | 0 | } |
76 | 0 | |
77 | 0 | builder.forget(aRetval); |
78 | 0 | return NS_OK; |
79 | 0 | } |
80 | | |
81 | | } // namespace dom |
82 | | } // namespace mozilla |