Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "TCPServerSocketParent.h" |
michael@0 | 6 | #include "nsJSUtils.h" |
michael@0 | 7 | #include "TCPSocketParent.h" |
michael@0 | 8 | #include "mozilla/unused.h" |
michael@0 | 9 | #include "mozilla/AppProcessChecker.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace dom { |
michael@0 | 13 | |
michael@0 | 14 | static void |
michael@0 | 15 | FireInteralError(mozilla::net::PTCPServerSocketParent* aActor, |
michael@0 | 16 | uint32_t aLineNo) |
michael@0 | 17 | { |
michael@0 | 18 | mozilla::unused << |
michael@0 | 19 | aActor->SendCallbackError(NS_LITERAL_STRING("Internal error"), |
michael@0 | 20 | NS_LITERAL_STRING(__FILE__), aLineNo, 0); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | NS_IMPL_CYCLE_COLLECTION(TCPServerSocketParent, mServerSocket, mIntermediary) |
michael@0 | 24 | NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketParent) |
michael@0 | 25 | NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketParent) |
michael@0 | 26 | |
michael@0 | 27 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent) |
michael@0 | 28 | NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketParent) |
michael@0 | 29 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 30 | NS_INTERFACE_MAP_END |
michael@0 | 31 | |
michael@0 | 32 | void |
michael@0 | 33 | TCPServerSocketParent::ReleaseIPDLReference() |
michael@0 | 34 | { |
michael@0 | 35 | MOZ_ASSERT(mIPCOpen); |
michael@0 | 36 | mIPCOpen = false; |
michael@0 | 37 | this->Release(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | void |
michael@0 | 41 | TCPServerSocketParent::AddIPDLReference() |
michael@0 | 42 | { |
michael@0 | 43 | MOZ_ASSERT(!mIPCOpen); |
michael@0 | 44 | mIPCOpen = true; |
michael@0 | 45 | this->AddRef(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | bool |
michael@0 | 49 | TCPServerSocketParent::Init(PNeckoParent* neckoParent, const uint16_t& aLocalPort, |
michael@0 | 50 | const uint16_t& aBacklog, const nsString& aBinaryType) |
michael@0 | 51 | { |
michael@0 | 52 | mNeckoParent = neckoParent; |
michael@0 | 53 | |
michael@0 | 54 | nsresult rv; |
michael@0 | 55 | mIntermediary = do_CreateInstance("@mozilla.org/tcp-socket-intermediary;1", &rv); |
michael@0 | 56 | if (NS_FAILED(rv)) { |
michael@0 | 57 | FireInteralError(this, __LINE__); |
michael@0 | 58 | return true; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | rv = mIntermediary->Listen(this, aLocalPort, aBacklog, aBinaryType, getter_AddRefs(mServerSocket)); |
michael@0 | 62 | if (NS_FAILED(rv) || !mServerSocket) { |
michael@0 | 63 | FireInteralError(this, __LINE__); |
michael@0 | 64 | return true; |
michael@0 | 65 | } |
michael@0 | 66 | return true; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | NS_IMETHODIMP |
michael@0 | 70 | TCPServerSocketParent::SendCallbackAccept(nsITCPSocketParent *socket) |
michael@0 | 71 | { |
michael@0 | 72 | TCPSocketParent* _socket = static_cast<TCPSocketParent*>(socket); |
michael@0 | 73 | PTCPSocketParent* _psocket = static_cast<PTCPSocketParent*>(_socket); |
michael@0 | 74 | |
michael@0 | 75 | _socket->AddIPDLReference(); |
michael@0 | 76 | |
michael@0 | 77 | if (mNeckoParent) { |
michael@0 | 78 | if (mNeckoParent->SendPTCPSocketConstructor(_psocket)) { |
michael@0 | 79 | mozilla::unused << PTCPServerSocketParent::SendCallbackAccept(_psocket); |
michael@0 | 80 | } |
michael@0 | 81 | else { |
michael@0 | 82 | NS_ERROR("Sending data from PTCPSocketParent was failed."); |
michael@0 | 83 | }; |
michael@0 | 84 | } |
michael@0 | 85 | else { |
michael@0 | 86 | NS_ERROR("The member value for NeckoParent is wrong."); |
michael@0 | 87 | } |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | TCPServerSocketParent::SendCallbackError(const nsAString& message, |
michael@0 | 93 | const nsAString& filename, |
michael@0 | 94 | uint32_t lineNumber, |
michael@0 | 95 | uint32_t columnNumber) |
michael@0 | 96 | { |
michael@0 | 97 | mozilla::unused << |
michael@0 | 98 | PTCPServerSocketParent::SendCallbackError(nsString(message), nsString(filename), |
michael@0 | 99 | lineNumber, columnNumber); |
michael@0 | 100 | return NS_OK; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | bool |
michael@0 | 104 | TCPServerSocketParent::RecvClose() |
michael@0 | 105 | { |
michael@0 | 106 | NS_ENSURE_TRUE(mServerSocket, true); |
michael@0 | 107 | mServerSocket->Close(); |
michael@0 | 108 | return true; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | void |
michael@0 | 112 | TCPServerSocketParent::ActorDestroy(ActorDestroyReason why) |
michael@0 | 113 | { |
michael@0 | 114 | if (mServerSocket) { |
michael@0 | 115 | mServerSocket->Close(); |
michael@0 | 116 | mServerSocket = nullptr; |
michael@0 | 117 | } |
michael@0 | 118 | mNeckoParent = nullptr; |
michael@0 | 119 | mIntermediary = nullptr; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | bool |
michael@0 | 123 | TCPServerSocketParent::RecvRequestDelete() |
michael@0 | 124 | { |
michael@0 | 125 | mozilla::unused << Send__delete__(this); |
michael@0 | 126 | return true; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | } // namespace dom |
michael@0 | 130 | } // namespace mozilla |