| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/renderer/extensions/object_backed_native_handler.h" | 12 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
| 12 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 13 | 14 |
| 14 class CastSendTransport; | 15 class CastSendTransport; |
| 15 class CastUdpTransport; | 16 class CastUdpTransport; |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 class ChromeV8Context; | 20 class ChromeV8Context; |
| 20 | 21 |
| 21 // Native code that handle chrome.webrtc custom bindings. | 22 // Native code that handle chrome.webrtc custom bindings. |
| 22 class WebRtcNativeHandler : public ObjectBackedNativeHandler { | 23 class WebRtcNativeHandler : public ObjectBackedNativeHandler { |
| 23 public: | 24 public: |
| 24 explicit WebRtcNativeHandler(ChromeV8Context* context); | 25 explicit WebRtcNativeHandler(ChromeV8Context* context); |
| 25 virtual ~WebRtcNativeHandler(); | 26 virtual ~WebRtcNativeHandler(); |
| 26 | 27 |
| 27 private: | 28 private: |
| 28 void CreateCastSendTransport( | 29 void CreateCastSession( |
| 29 const v8::FunctionCallbackInfo<v8::Value>& args); | 30 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 31 |
| 30 void DestroyCastSendTransport( | 32 void DestroyCastSendTransport( |
| 31 const v8::FunctionCallbackInfo<v8::Value>& args); | 33 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 32 void CreateParamsCastSendTransport( | 34 void CreateParamsCastSendTransport( |
| 33 const v8::FunctionCallbackInfo<v8::Value>& args); | 35 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 34 void GetCapsCastSendTransport( | 36 void GetCapsCastSendTransport( |
| 35 const v8::FunctionCallbackInfo<v8::Value>& args); | 37 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 36 void StartCastSendTransport( | 38 void StartCastSendTransport( |
| 37 const v8::FunctionCallbackInfo<v8::Value>& args); | 39 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 38 void StopCastSendTransport( | 40 void StopCastSendTransport( |
| 39 const v8::FunctionCallbackInfo<v8::Value>& args); | 41 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 40 | 42 |
| 41 void CreateCastUdpTransport( | |
| 42 const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 43 void DestroyCastUdpTransport( | 43 void DestroyCastUdpTransport( |
| 44 const v8::FunctionCallbackInfo<v8::Value>& args); | 44 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 45 void StartCastUdpTransport( | 45 void StartCastUdpTransport( |
| 46 const v8::FunctionCallbackInfo<v8::Value>& args); | 46 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 47 void StopCastUdpTransport( | 47 void StopCastUdpTransport( |
| 48 const v8::FunctionCallbackInfo<v8::Value>& args); | 48 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 49 | 49 |
| 50 // Helper method to call the v8 callback function after a session is |
| 51 // created. |
| 52 void CallCreateCallback(v8::Handle<v8::Function> function, |
| 53 scoped_ptr<CastSendTransport> stream1, |
| 54 scoped_ptr<CastSendTransport> stream2, |
| 55 scoped_ptr<CastUdpTransport> udp_transport); |
| 56 |
| 50 // Gets the Send or UDP transport indexed by |transport_id|. | 57 // Gets the Send or UDP transport indexed by |transport_id|. |
| 51 // If not found, returns NULL and throws a V8 exception. | 58 // If not found, returns NULL and throws a V8 exception. |
| 52 CastSendTransport* GetSendTransportOrThrow(int transport_id) const; | 59 CastSendTransport* GetSendTransportOrThrow(int transport_id) const; |
| 53 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; | 60 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; |
| 54 | 61 |
| 55 int last_transport_id_; | 62 int last_transport_id_; |
| 56 | 63 |
| 57 typedef std::map<int, linked_ptr<CastSendTransport> > SendTransportMap; | 64 typedef std::map<int, linked_ptr<CastSendTransport> > SendTransportMap; |
| 58 SendTransportMap send_transport_map_; | 65 SendTransportMap send_transport_map_; |
| 59 | 66 |
| 60 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; | 67 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; |
| 61 UdpTransportMap udp_transport_map_; | 68 UdpTransportMap udp_transport_map_; |
| 62 | 69 |
| 70 base::WeakPtrFactory<WebRtcNativeHandler> weak_factory_; |
| 71 |
| 63 DISALLOW_COPY_AND_ASSIGN(WebRtcNativeHandler); | 72 DISALLOW_COPY_AND_ASSIGN(WebRtcNativeHandler); |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 } // namespace extensions | 75 } // namespace extensions |
| 67 | 76 |
| 68 #endif // CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ | 77 #endif // CHROME_RENDERER_EXTENSIONS_WEBRTC_NATIVE_HANDLER_H_ |
| OLD | NEW |