• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
7 
8 #include <map>
9 
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "extensions/renderer/object_backed_native_handler.h"
13 #include "extensions/renderer/scoped_persistent.h"
14 #include "v8/include/v8.h"
15 
16 class CastRtpStream;
17 class CastUdpTransport;
18 
19 namespace base {
20 class BinaryValue;
21 class DictionaryValue;
22 }
23 
24 namespace extensions {
25 
26 // Native code that handle chrome.webrtc custom bindings.
27 class CastStreamingNativeHandler : public ObjectBackedNativeHandler {
28  public:
29   explicit CastStreamingNativeHandler(ScriptContext* context);
30   virtual ~CastStreamingNativeHandler();
31 
32  private:
33   void CreateCastSession(
34       const v8::FunctionCallbackInfo<v8::Value>& args);
35 
36   void DestroyCastRtpStream(
37       const v8::FunctionCallbackInfo<v8::Value>& args);
38   void CreateParamsCastRtpStream(
39       const v8::FunctionCallbackInfo<v8::Value>& args);
40   void GetSupportedParamsCastRtpStream(
41       const v8::FunctionCallbackInfo<v8::Value>& args);
42   void StartCastRtpStream(
43       const v8::FunctionCallbackInfo<v8::Value>& args);
44   void StopCastRtpStream(
45       const v8::FunctionCallbackInfo<v8::Value>& args);
46 
47   void DestroyCastUdpTransport(
48       const v8::FunctionCallbackInfo<v8::Value>& args);
49   void SetDestinationCastUdpTransport(
50       const v8::FunctionCallbackInfo<v8::Value>& args);
51   void StopCastUdpTransport(
52       const v8::FunctionCallbackInfo<v8::Value>& args);
53 
54   void ToggleLogging(const v8::FunctionCallbackInfo<v8::Value>& args);
55   void GetRawEvents(const v8::FunctionCallbackInfo<v8::Value>& args);
56   void GetStats(const v8::FunctionCallbackInfo<v8::Value>& args);
57 
58   // Helper method to call the v8 callback function after a session is
59   // created.
60   void CallCreateCallback(scoped_ptr<CastRtpStream> stream1,
61                           scoped_ptr<CastRtpStream> stream2,
62                           scoped_ptr<CastUdpTransport> udp_transport);
63 
64   void CallStartCallback(int stream_id);
65   void CallStopCallback(int stream_id);
66   void CallErrorCallback(int stream_id, const std::string& message);
67 
68   void CallGetRawEventsCallback(int transport_id,
69                                 scoped_ptr<base::BinaryValue> raw_events);
70   void CallGetStatsCallback(int transport_id,
71                             scoped_ptr<base::DictionaryValue> stats);
72 
73   // Gets the RTP stream or UDP transport indexed by an ID.
74   // If not found, returns NULL and throws a V8 exception.
75   CastRtpStream* GetRtpStreamOrThrow(int stream_id) const;
76   CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const;
77 
78   int last_transport_id_;
79 
80   typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap;
81   RtpStreamMap rtp_stream_map_;
82 
83   typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap;
84   UdpTransportMap udp_transport_map_;
85 
86   base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_;
87 
88   extensions::ScopedPersistent<v8::Function> create_callback_;
89 
90   typedef std::map<int,
91                    linked_ptr<extensions::ScopedPersistent<v8::Function> > >
92       RtpStreamCallbackMap;
93   RtpStreamCallbackMap get_raw_events_callbacks_;
94   RtpStreamCallbackMap get_stats_callbacks_;
95 
96   DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler);
97 };
98 
99 }  // namespace extensions
100 
101 #endif  // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
102