OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_PROVIDER_H_ |
| 6 #define CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_PROVIDER_H_ |
| 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/id_map.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "content/child/worker_task_runner.h" |
| 12 #include "content/common/service_port_service.mojom.h" |
| 13 #include "third_party/WebKit/public/platform/modules/navigator_services/WebServi
cePortProvider.h" |
| 14 |
| 15 class GURL; |
| 16 |
| 17 namespace base { |
| 18 class SingleThreadTaskRunner; |
| 19 } |
| 20 |
| 21 namespace blink { |
| 22 class WebServicePortProviderClient; |
| 23 class WebString; |
| 24 } |
| 25 |
| 26 namespace IPC { |
| 27 class Message; |
| 28 } |
| 29 |
| 30 namespace content { |
| 31 class ServiceRegistry; |
| 32 struct TransferredMessagePort; |
| 33 |
| 34 // Main entry point for the navigator.services API in a child process. This |
| 35 // implementes the blink API and passes calls on to the browser process, as |
| 36 // well as receives events from the browser process to pass back on to blink. |
| 37 // One instance of this class is created for each ServicePortCollection, the |
| 38 // instance lives on the worker thread it is associated with, and is |
| 39 // conceptually owned by the ServicePortCollection in blink. Refcounted because |
| 40 // some operations might require asynchronous operations that require this class |
| 41 // to potentially stick around for a bit longer after a ServicePortCollection is |
| 42 // destroyed. |
| 43 // Uses mojo to communicate with the browser process. |
| 44 class ServicePortProvider |
| 45 : public blink::WebServicePortProvider, |
| 46 public ServicePortServiceClient, |
| 47 public base::RefCountedThreadSafe<ServicePortProvider> { |
| 48 public: |
| 49 ServicePortProvider( |
| 50 blink::WebServicePortProviderClient* client, |
| 51 const scoped_refptr<base::SingleThreadTaskRunner>& main_loop); |
| 52 |
| 53 // WebServicePortProvider implementation. |
| 54 virtual void destroy(); |
| 55 virtual void connect(const blink::WebURL& target_url, |
| 56 const blink::WebString& origin, |
| 57 blink::WebServicePortConnectCallbacks* callbacks); |
| 58 virtual void postMessage(blink::WebServicePortID port_id, |
| 59 const blink::WebString& message, |
| 60 blink::WebMessagePortChannelArray* channels); |
| 61 virtual void closePort(blink::WebServicePortID port_id); |
| 62 |
| 63 // ServicePortServiceClient implementation. |
| 64 void PostMessage(int32_t port_id, |
| 65 const mojo::String& message, |
| 66 mojo::Array<MojoTransferredMessagePortPtr> ports, |
| 67 mojo::Array<int32_t> new_routing_ids) override; |
| 68 |
| 69 private: |
| 70 ~ServicePortProvider() override; |
| 71 friend class base::RefCountedThreadSafe<ServicePortProvider>; |
| 72 |
| 73 void PostMessageToBrowser(int port_id, |
| 74 const base::string16& message, |
| 75 const std::vector<TransferredMessagePort> ports); |
| 76 |
| 77 void OnConnectResult( |
| 78 scoped_ptr<blink::WebServicePortConnectCallbacks> callbacks, |
| 79 ServicePortConnectResult result, |
| 80 int32_t port_id); |
| 81 |
| 82 blink::WebServicePortProviderClient* client_; |
| 83 |
| 84 // Helper method that returns an initialized ServicePortServicePtr. |
| 85 ServicePortServicePtr& GetServicePortServicePtr(); |
| 86 mojo::Binding<ServicePortServiceClient> binding_; |
| 87 |
| 88 ServicePortServicePtr service_port_service_; |
| 89 |
| 90 scoped_refptr<base::SingleThreadTaskRunner> main_loop_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(ServicePortProvider); |
| 93 }; |
| 94 |
| 95 } // namespace content |
| 96 |
| 97 #endif // CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_PROVIDER_H_ |
OLD | NEW |