Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / renderer / extensions / cast_streaming_native_handler.h
blobf468186e16302de3d4e0f32c63258e2ad7d867a6
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.
5 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
8 #include <map>
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"
16 class CastRtpStream;
17 class CastUdpTransport;
19 namespace base {
20 class BinaryValue;
21 class DictionaryValue;
24 namespace extensions {
26 // Native code that handle chrome.webrtc custom bindings.
27 class CastStreamingNativeHandler : public ObjectBackedNativeHandler {
28 public:
29 explicit CastStreamingNativeHandler(ScriptContext* context);
30 virtual ~CastStreamingNativeHandler();
32 private:
33 void CreateCastSession(
34 const v8::FunctionCallbackInfo<v8::Value>& args);
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);
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);
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);
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);
64 void CallStartCallback(int stream_id);
65 void CallStopCallback(int stream_id);
66 void CallErrorCallback(int stream_id, const std::string& message);
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);
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;
78 int last_transport_id_;
80 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap;
81 RtpStreamMap rtp_stream_map_;
83 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap;
84 UdpTransportMap udp_transport_map_;
86 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_;
88 extensions::ScopedPersistent<v8::Function> create_callback_;
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_;
96 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler);
99 } // namespace extensions
101 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_