tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebSocketConnectionBase.h (4451B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set sw=2 ts=8 et ft=cpp : */
      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_net_WebSocketConnectionBase_h
      8 #define mozilla_net_WebSocketConnectionBase_h
      9 
     10 // Architecture view:
     11 //    Parent Process                        Socket Process
     12 //  ┌─────────────────┐         IPC    ┌────────────────────────┐
     13 //  │ WebSocketChannel│          ┌─────►WebSocketConnectionChild│
     14 //  └─────────┬───────┘          │     └─────────┬──────────────┘
     15 //            │                  │               │
     16 // ┌──────────▼───────────────┐  │     ┌─────────▼─────────┐
     17 // │ WebSocketConnectionParent├──┘     │WebSocketConnection│
     18 // └──────────────────────────┘        └─────────┬─────────┘
     19 //                                               │
     20 //                                     ┌─────────▼─────────┐
     21 //                                     │ nsSocketTransport │
     22 //                                     └───────────────────┘
     23 // The main reason that we need WebSocketConnectionBase is that we need to
     24 // encapsulate nsSockTransport, nsSocketOutoutStream, and nsSocketInputStream.
     25 // These three objects only live in socket process, so we provide the necessary
     26 // interfaces in WebSocketConnectionBase and WebSocketConnectionListener for
     27 // reading/writing the real socket.
     28 //
     29 // The output path when WebSocketChannel wants to write data to socket:
     30 // - WebSocketConnectionParent::WriteOutputData
     31 // - WebSocketConnectionParent::SendWriteOutputData
     32 // - WebSocketConnectionChild::RecvWriteOutputData
     33 // - WebSocketConnection::WriteOutputData
     34 // - WebSocketConnection::OnOutputStreamReady (writes data to the real socket)
     35 //
     36 // The input path when data is able to read from the socket
     37 // - WebSocketConnection::OnInputStreamReady
     38 // - WebSocketConnectionChild::OnDataReceived
     39 // - WebSocketConnectionChild::SendOnDataReceived
     40 // - WebSocketConnectionParent::RecvOnDataReceived
     41 // - WebSocketChannel::OnDataReceived
     42 //
     43 // The path that WebSocketConnection is constructed.
     44 // - nsHttpChannel::OnStopRequest
     45 // - HttpConnectionMgrShell::CompleteUpgrade
     46 // - HttpConnectionMgrParent::CompleteUpgrade (we store the
     47 //   nsIHttpUpgradeListener in a table and send an id to socket process)
     48 // - HttpConnectionMgrParent::SendStartWebSocketConnection
     49 // - HttpConnectionMgrChild::RecvStartWebSocketConnection (the listener id is
     50 //   saved in WebSocketConnectionChild and will be used when the socket
     51 //   transport is available)
     52 // - WebSocketConnectionChild::Init (an IPC channel between socket thread in
     53 //   socket process and background thread in parent process is created)
     54 // - nsHttpConnectionMgr::CompleteUpgrade
     55 // - WebSocketConnectionChild::OnTransportAvailable (WebSocketConnection is
     56 //   created)
     57 // - WebSocketConnectionChild::SendOnTransportAvailable
     58 // - WebSocketConnectionParent::RecvOnTransportAvailable
     59 // - WebSocketChannel::OnWebSocketConnectionAvailable
     60 
     61 class nsITransportSecurityInfo;
     62 
     63 namespace mozilla {
     64 namespace net {
     65 
     66 class WebSocketConnectionListener;
     67 
     68 class WebSocketConnectionBase : public nsISupports {
     69 public:
     70  virtual nsresult Init(WebSocketConnectionListener* aListener) = 0;
     71  virtual void GetIoTarget(nsIEventTarget** aTarget) = 0;
     72  virtual void Close() = 0;
     73  virtual nsresult WriteOutputData(const uint8_t* aHdrBuf,
     74                                   uint32_t aHdrBufLength,
     75                                   const uint8_t* aPayloadBuf,
     76                                   uint32_t aPayloadBufLength) = 0;
     77  virtual nsresult StartReading() = 0;
     78  virtual void DrainSocketData() = 0;
     79  virtual nsresult GetSecurityInfo(
     80      nsITransportSecurityInfo** aSecurityInfo) = 0;
     81 };
     82 
     83 }  // namespace net
     84 }  // namespace mozilla
     85 
     86 #endif  // mozilla_net_WebSocketConnectionBase_h