/src/mozilla-central/dom/presentation/ipc/PresentationContentSessionInfo.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 "nsServiceManagerUtils.h" |
8 | | #include "PresentationContentSessionInfo.h" |
9 | | #include "PresentationIPCService.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | NS_IMPL_ISUPPORTS(PresentationContentSessionInfo, |
15 | | nsIPresentationSessionTransportCallback); |
16 | | |
17 | | nsresult |
18 | 0 | PresentationContentSessionInfo::Init() { |
19 | 0 | if (NS_WARN_IF(NS_FAILED(mTransport->SetCallback(this)))) { |
20 | 0 | return NS_ERROR_NOT_AVAILABLE; |
21 | 0 | } |
22 | 0 | if (NS_WARN_IF(NS_FAILED(mTransport->EnableDataNotification()))) { |
23 | 0 | return NS_ERROR_NOT_AVAILABLE; |
24 | 0 | } |
25 | 0 | return NS_OK; |
26 | 0 | } |
27 | | |
28 | | nsresult |
29 | | PresentationContentSessionInfo::Send(const nsAString& aData) |
30 | 0 | { |
31 | 0 | if (!mTransport) { |
32 | 0 | return NS_ERROR_NOT_AVAILABLE; |
33 | 0 | } |
34 | 0 | |
35 | 0 | return mTransport->Send(aData); |
36 | 0 | } |
37 | | |
38 | | nsresult |
39 | | PresentationContentSessionInfo::SendBinaryMsg(const nsACString& aData) |
40 | 0 | { |
41 | 0 | if (NS_WARN_IF(!mTransport)) { |
42 | 0 | return NS_ERROR_NOT_AVAILABLE; |
43 | 0 | } |
44 | 0 | |
45 | 0 | return mTransport->SendBinaryMsg(aData); |
46 | 0 | } |
47 | | |
48 | | nsresult |
49 | | PresentationContentSessionInfo::SendBlob(Blob* aBlob) |
50 | 0 | { |
51 | 0 | if (NS_WARN_IF(!mTransport)) { |
52 | 0 | return NS_ERROR_NOT_AVAILABLE; |
53 | 0 | } |
54 | 0 | |
55 | 0 | return mTransport->SendBlob(aBlob); |
56 | 0 | } |
57 | | |
58 | | nsresult |
59 | | PresentationContentSessionInfo::Close(nsresult aReason) |
60 | 0 | { |
61 | 0 | if (!mTransport) { |
62 | 0 | return NS_ERROR_NOT_AVAILABLE; |
63 | 0 | } |
64 | 0 | |
65 | 0 | return mTransport->Close(aReason); |
66 | 0 | } |
67 | | |
68 | | // nsIPresentationSessionTransportCallback |
69 | | NS_IMETHODIMP |
70 | | PresentationContentSessionInfo::NotifyTransportReady() |
71 | 0 | { |
72 | 0 | // do nothing since |onSessionTransport| implies this |
73 | 0 | return NS_OK; |
74 | 0 | } |
75 | | |
76 | | NS_IMETHODIMP |
77 | | PresentationContentSessionInfo::NotifyTransportClosed(nsresult aReason) |
78 | 0 | { |
79 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
80 | 0 |
|
81 | 0 | // Nullify |mTransport| here so it won't try to re-close |mTransport| in |
82 | 0 | // potential subsequent |Shutdown| calls. |
83 | 0 | mTransport = nullptr; |
84 | 0 | nsCOMPtr<nsIPresentationService> service = |
85 | 0 | do_GetService(PRESENTATION_SERVICE_CONTRACTID); |
86 | 0 | if (NS_WARN_IF(!service)) { |
87 | 0 | return NS_ERROR_NOT_AVAILABLE; |
88 | 0 | } |
89 | 0 | return static_cast<PresentationIPCService*>(service.get())-> |
90 | 0 | NotifyTransportClosed(mSessionId, mRole, aReason); |
91 | 0 | } |
92 | | |
93 | | NS_IMETHODIMP |
94 | | PresentationContentSessionInfo::NotifyData(const nsACString& aData, |
95 | | bool aIsBinary) |
96 | 0 | { |
97 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
98 | 0 |
|
99 | 0 | nsCOMPtr<nsIPresentationService> service = |
100 | 0 | do_GetService(PRESENTATION_SERVICE_CONTRACTID); |
101 | 0 | if (NS_WARN_IF(!service)) { |
102 | 0 | return NS_ERROR_NOT_AVAILABLE; |
103 | 0 | } |
104 | 0 | return static_cast<PresentationIPCService*>(service.get())-> |
105 | 0 | NotifyMessage(mSessionId, aData, aIsBinary); |
106 | 0 | } |
107 | | |
108 | | } // namespace dom |
109 | | } // namespace mozilla |