Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set ts=4 sw=4 sts=4 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 "DataChannelChild.h"
8 :
9 : #include "mozilla/Unused.h"
10 : #include "mozilla/dom/ContentChild.h"
11 : #include "mozilla/net/NeckoChild.h"
12 :
13 : namespace mozilla {
14 : namespace net {
15 :
16 44 : NS_IMPL_ISUPPORTS_INHERITED(DataChannelChild, nsDataChannel, nsIChildChannel)
17 :
18 4 : DataChannelChild::DataChannelChild(nsIURI* aURI)
19 : : nsDataChannel(aURI)
20 4 : , mIPCOpen(false)
21 : {
22 4 : }
23 :
24 8 : DataChannelChild::~DataChannelChild()
25 : {
26 12 : }
27 :
28 : NS_IMETHODIMP
29 0 : DataChannelChild::ConnectParent(uint32_t aId)
30 : {
31 : mozilla::dom::ContentChild* cc =
32 0 : static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager());
33 0 : if (cc->IsShuttingDown()) {
34 0 : return NS_ERROR_FAILURE;
35 : }
36 :
37 0 : if (!gNeckoChild->SendPDataChannelConstructor(this, aId)) {
38 0 : return NS_ERROR_FAILURE;
39 : }
40 :
41 : // IPC now has a ref to us.
42 0 : AddIPDLReference();
43 0 : return NS_OK;
44 : }
45 :
46 : NS_IMETHODIMP
47 0 : DataChannelChild::CompleteRedirectSetup(nsIStreamListener *aListener,
48 : nsISupports *aContext)
49 : {
50 : nsresult rv;
51 0 : if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) {
52 0 : MOZ_ASSERT(!aContext, "aContext should be null!");
53 0 : rv = AsyncOpen2(aListener);
54 : }
55 : else {
56 0 : rv = AsyncOpen(aListener, aContext);
57 : }
58 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
59 0 : return rv;
60 : }
61 :
62 0 : if (mIPCOpen) {
63 0 : Unused << Send__delete__(this);
64 : }
65 0 : return NS_OK;
66 : }
67 :
68 : void
69 0 : DataChannelChild::AddIPDLReference()
70 : {
71 0 : AddRef();
72 0 : mIPCOpen = true;
73 0 : }
74 :
75 : void
76 0 : DataChannelChild::ActorDestroy(ActorDestroyReason why)
77 : {
78 0 : MOZ_ASSERT(mIPCOpen);
79 0 : mIPCOpen = false;
80 0 : Release();
81 0 : }
82 :
83 : } // namespace net
84 : } // namespace mozilla
|