Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 0 : 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 : }
22 0 : if (NS_WARN_IF(NS_FAILED(mTransport->EnableDataNotification()))) {
23 0 : return NS_ERROR_NOT_AVAILABLE;
24 : }
25 0 : return NS_OK;
26 : }
27 :
28 : nsresult
29 0 : PresentationContentSessionInfo::Send(const nsAString& aData)
30 : {
31 0 : if (!mTransport) {
32 0 : return NS_ERROR_NOT_AVAILABLE;
33 : }
34 :
35 0 : return mTransport->Send(aData);
36 : }
37 :
38 : nsresult
39 0 : PresentationContentSessionInfo::SendBinaryMsg(const nsACString& aData)
40 : {
41 0 : if (NS_WARN_IF(!mTransport)) {
42 0 : return NS_ERROR_NOT_AVAILABLE;
43 : }
44 :
45 0 : return mTransport->SendBinaryMsg(aData);
46 : }
47 :
48 : nsresult
49 0 : PresentationContentSessionInfo::SendBlob(nsIDOMBlob* aBlob)
50 : {
51 0 : if (NS_WARN_IF(!mTransport)) {
52 0 : return NS_ERROR_NOT_AVAILABLE;
53 : }
54 :
55 0 : return mTransport->SendBlob(aBlob);
56 : }
57 :
58 : nsresult
59 0 : PresentationContentSessionInfo::Close(nsresult aReason)
60 : {
61 0 : if (!mTransport) {
62 0 : return NS_ERROR_NOT_AVAILABLE;
63 : }
64 :
65 0 : return mTransport->Close(aReason);
66 : }
67 :
68 : // nsIPresentationSessionTransportCallback
69 : NS_IMETHODIMP
70 0 : PresentationContentSessionInfo::NotifyTransportReady()
71 : {
72 : // do nothing since |onSessionTransport| implies this
73 0 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : PresentationContentSessionInfo::NotifyTransportClosed(nsresult aReason)
78 : {
79 0 : MOZ_ASSERT(NS_IsMainThread());
80 :
81 : // Nullify |mTransport| here so it won't try to re-close |mTransport| in
82 : // potential subsequent |Shutdown| calls.
83 0 : mTransport = nullptr;
84 : 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 : }
89 0 : return static_cast<PresentationIPCService*>(service.get())->
90 0 : NotifyTransportClosed(mSessionId, mRole, aReason);
91 : }
92 :
93 : NS_IMETHODIMP
94 0 : PresentationContentSessionInfo::NotifyData(const nsACString& aData,
95 : bool aIsBinary)
96 : {
97 0 : MOZ_ASSERT(NS_IsMainThread());
98 :
99 : 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 : }
104 0 : return static_cast<PresentationIPCService*>(service.get())->
105 0 : NotifyMessage(mSessionId, aData, aIsBinary);
106 : }
107 :
108 : } // namespace dom
109 : } // namespace mozilla
|