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_NAVIGATOR_CONNECT_PROVIDER_H_ |
| 6 #define CONTENT_CHILD_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_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 "third_party/WebKit/public/platform/WebNavigatorConnectProvider.h" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace base { |
| 17 class SingleThreadTaskRunner; |
| 18 } |
| 19 |
| 20 namespace blink { |
| 21 template <typename T1, typename T2> |
| 22 class WebCallbacks; |
| 23 class WebMessagePortChannel; |
| 24 class WebString; |
| 25 } |
| 26 |
| 27 namespace IPC { |
| 28 class Message; |
| 29 } |
| 30 |
| 31 namespace content { |
| 32 class ThreadSafeSender; |
| 33 |
| 34 // Main entry point for the navigator.connect API in a child process. This |
| 35 // implements the blink API and passes connect calls on to the browser process. |
| 36 // NavigatorConnectDispatcher receives IPCs from the browser process and passes |
| 37 // them on to the correct thread specific instance of this class. |
| 38 // The ThreadSpecificInstance method will return an instance of this class for |
| 39 // the current thread, or create one if no instance exists yet for this thread. |
| 40 // This class deletes itself if the worker thread it belongs to quits. |
| 41 class NavigatorConnectProvider : public blink::WebNavigatorConnectProvider, |
| 42 public WorkerTaskRunner::Observer { |
| 43 public: |
| 44 NavigatorConnectProvider( |
| 45 ThreadSafeSender* thread_safe_sender, |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& main_loop); |
| 47 ~NavigatorConnectProvider(); |
| 48 |
| 49 // WebNavigatorConnectProvider implementation. |
| 50 virtual void connect(const blink::WebURL& target_url, |
| 51 const blink::WebString& origin, |
| 52 blink::WebMessagePortChannel* port, |
| 53 blink::WebCallbacks<void, void>* callbacks); |
| 54 |
| 55 void OnMessageReceived(const IPC::Message& msg); |
| 56 |
| 57 // |thread_safe_sender| and |main_loop| need to be passed in because if the |
| 58 // call leads to construction they will be needed. |
| 59 static NavigatorConnectProvider* ThreadSpecificInstance( |
| 60 ThreadSafeSender* thread_safe_sender, |
| 61 const scoped_refptr<base::SingleThreadTaskRunner>& main_loop); |
| 62 |
| 63 private: |
| 64 void OnConnectResult(int thread_id, int request_id, bool allow_connect); |
| 65 |
| 66 // WorkerTaskRunner::Observer implementation. |
| 67 void OnWorkerRunLoopStopped() override; |
| 68 |
| 69 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 70 scoped_refptr<base::SingleThreadTaskRunner> main_loop_; |
| 71 typedef blink::WebCallbacks<void, void> ConnectCallback; |
| 72 IDMap<ConnectCallback> requests_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(NavigatorConnectProvider); |
| 75 }; |
| 76 |
| 77 } // namespace content |
| 78 |
| 79 #endif // CONTENT_CHILD_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_PROVIDER_H_ |
OLD | NEW |