summaryrefslogtreecommitdiffstats
path: root/content/browser/media/webrtc_internals_message_handler.cc
blob: 2ba75227380b1e358d26efbe206bdb5deefa46fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/media/webrtc_internals_message_handler.h"

#include "content/browser/media/webrtc_internals.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"

namespace content {

WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() {
  WebRTCInternals::GetInstance()->AddObserver(this);
}

WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() {
  WebRTCInternals::GetInstance()->RemoveObserver(this);
}

void WebRTCInternalsMessageHandler::RegisterMessages() {
  web_ui()->RegisterMessageCallback("getAllUpdates",
      base::Bind(&WebRTCInternalsMessageHandler::OnGetAllUpdates,
                 base::Unretained(this)));

  web_ui()->RegisterMessageCallback("getAllStats",
      base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats,
                 base::Unretained(this)));

  web_ui()->RegisterMessageCallback("startRtpRecording",
      base::Bind(&WebRTCInternalsMessageHandler::OnStartRtpRecording,
                 base::Unretained(this)));

  web_ui()->RegisterMessageCallback("stopRtpRecording",
      base::Bind(&WebRTCInternalsMessageHandler::OnStopRtpRecording,
                 base::Unretained(this)));
}

void WebRTCInternalsMessageHandler::OnGetAllUpdates(
    const base::ListValue* list) {
  WebRTCInternals::GetInstance()->SendAllUpdates();
}

void WebRTCInternalsMessageHandler::OnGetAllStats(const base::ListValue* list) {
  for (RenderProcessHost::iterator i(
       content::RenderProcessHost::AllHostsIterator());
       !i.IsAtEnd(); i.Advance()) {
    i.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats());
  }
}

void WebRTCInternalsMessageHandler::OnStartRtpRecording(
    const base::ListValue* list) {
  WebRTCInternals::GetInstance()->StartRtpRecording();
}

void WebRTCInternalsMessageHandler::OnStopRtpRecording(
    const base::ListValue* list) {
  WebRTCInternals::GetInstance()->StopRtpRecording();
}

void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command,
                                            const base::Value* args) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  std::vector<const base::Value*> args_vector;
  args_vector.push_back(args);
  string16 update = WebUI::GetJavascriptCall(command, args_vector);

  RenderViewHost* host = web_ui()->GetWebContents()->GetRenderViewHost();
  if (host)
    host->ExecuteJavascriptInWebFrame(string16(), update);
}

}  // namespace content