1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_CONTENT_BROWSER_PEPPER_HOST_FACTORY_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_CONTENT_BROWSER_PEPPER_HOST_FACTORY_H_
7 
8 #include <memory>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "mojo/public/cpp/bindings/pending_receiver.h"
14 #include "mojo/public/cpp/bindings/pending_remote.h"
15 #include "mojo/public/cpp/system/data_pipe.h"
16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/host/host_factory.h"
18 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h"
19 #include "services/network/public/mojom/tcp_socket.mojom.h"
20 
21 namespace ppapi {
22 class PpapiPermissions;
23 }
24 
25 namespace content {
26 
27 class BrowserPpapiHostImpl;
28 
29 class ContentBrowserPepperHostFactory : public ppapi::host::HostFactory {
30  public:
31   // Non-owning pointer to the filter must outlive this class.
32   explicit ContentBrowserPepperHostFactory(BrowserPpapiHostImpl* host);
33 
34   ~ContentBrowserPepperHostFactory() override;
35 
36   std::unique_ptr<ppapi::host::ResourceHost> CreateResourceHost(
37       ppapi::host::PpapiHost* host,
38       PP_Resource resource,
39       PP_Instance instance,
40       const IPC::Message& message) override;
41 
42   // Creates ResourceHost for already accepted TCP |socket|. In the case of
43   // failure returns wrapped NULL.
44   std::unique_ptr<ppapi::host::ResourceHost> CreateAcceptedTCPSocket(
45       PP_Instance instance,
46       ppapi::TCPSocketVersion version,
47       mojo::PendingRemote<network::mojom::TCPConnectedSocket> connected_socket,
48       mojo::PendingReceiver<network::mojom::SocketObserver>
49           socket_observer_receiver,
50       mojo::ScopedDataPipeConsumerHandle receive_stream,
51       mojo::ScopedDataPipeProducerHandle send_stream);
52 
53  private:
54   std::unique_ptr<ppapi::host::ResourceHost> CreateNewTCPSocket(
55       PP_Instance instance,
56       PP_Resource resource,
57       ppapi::TCPSocketVersion version);
58 
59   const ppapi::PpapiPermissions& GetPermissions() const;
60 
61   // Non-owning pointer.
62   BrowserPpapiHostImpl* host_;
63 
64   DISALLOW_COPY_AND_ASSIGN(ContentBrowserPepperHostFactory);
65 };
66 
67 }  // namespace content
68 
69 #endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_CONTENT_BROWSER_PEPPER_HOST_FACTORY_H_
70