Home | History | Annotate | Download | only in extensions
      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 SetOptionsCastUdpTransport(
     52       const v8::FunctionCallbackInfo<v8::Value>& args);
     53   void StopCastUdpTransport(
     54       const v8::FunctionCallbackInfo<v8::Value>& args);
     55 
     56   void ToggleLogging(const v8::FunctionCallbackInfo<v8::Value>& args);
     57   void GetRawEvents(const v8::FunctionCallbackInfo<v8::Value>& args);
     58   void GetStats(const v8::FunctionCallbackInfo<v8::Value>& args);
     59 
     60   // Helper method to call the v8 callback function after a session is
     61   // created.
     62   void CallCreateCallback(scoped_ptr<CastRtpStream> stream1,
     63                           scoped_ptr<CastRtpStream> stream2,
     64                           scoped_ptr<CastUdpTransport> udp_transport);
     65 
     66   void CallStartCallback(int stream_id);
     67   void CallStopCallback(int stream_id);
     68   void CallErrorCallback(int stream_id, const std::string& message);
     69 
     70   void CallGetRawEventsCallback(int transport_id,
     71                                 scoped_ptr<base::BinaryValue> raw_events);
     72   void CallGetStatsCallback(int transport_id,
     73                             scoped_ptr<base::DictionaryValue> stats);
     74 
     75   // Gets the RTP stream or UDP transport indexed by an ID.
     76   // If not found, returns NULL and throws a V8 exception.
     77   CastRtpStream* GetRtpStreamOrThrow(int stream_id) const;
     78   CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const;
     79 
     80   int last_transport_id_;
     81 
     82   typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap;
     83   RtpStreamMap rtp_stream_map_;
     84 
     85   typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap;
     86   UdpTransportMap udp_transport_map_;
     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   base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_;
     97 
     98   DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler);
     99 };
    100 
    101 }  // namespace extensions
    102 
    103 #endif  // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
    104