1 // Copyright (c) 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 #include "content/browser/media/webrtc_internals_message_handler.h"
7 #include "content/browser/media/webrtc_internals.h"
8 #include "content/common/media/peer_connection_tracker_messages.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_ui.h"
17 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() {
18 WebRTCInternals::GetInstance()->AddObserver(this);
21 WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() {
22 WebRTCInternals::GetInstance()->RemoveObserver(this);
25 void WebRTCInternalsMessageHandler::RegisterMessages() {
26 web_ui()->RegisterMessageCallback("getAllStats",
27 base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats
,
28 base::Unretained(this)));
30 web_ui()->RegisterMessageCallback("enableAudioDebugRecordings",
32 &WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled
,
33 base::Unretained(this),
36 web_ui()->RegisterMessageCallback("disableAudioDebugRecordings",
38 &WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled
,
39 base::Unretained(this),
42 web_ui()->RegisterMessageCallback("finishedDOMLoad",
43 base::Bind(&WebRTCInternalsMessageHandler::OnDOMLoadDone
,
44 base::Unretained(this)));
47 void WebRTCInternalsMessageHandler::OnGetAllStats(
48 const base::ListValue
* /* unused_list */) {
49 for (RenderProcessHost::iterator
i(
50 content::RenderProcessHost::AllHostsIterator());
51 !i
.IsAtEnd(); i
.Advance()) {
52 i
.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats());
56 void WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled(
57 bool enable
, const base::ListValue
* /* unused_list */) {
59 WebRTCInternals::GetInstance()->EnableAudioDebugRecordings(
60 web_ui()->GetWebContents());
62 WebRTCInternals::GetInstance()->DisableAudioDebugRecordings();
66 void WebRTCInternalsMessageHandler::OnDOMLoadDone(
67 const base::ListValue
* /* unused_list */) {
68 WebRTCInternals::GetInstance()->UpdateObserver(this);
70 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) {
71 std::vector
<const base::Value
*> args_vector
;
72 base::string16 script
=
73 WebUI::GetJavascriptCall("setAudioDebugRecordingsEnabled", args_vector
);
74 RenderFrameHost
* host
= web_ui()->GetWebContents()->GetMainFrame();
76 host
->ExecuteJavaScript(script
);
80 void WebRTCInternalsMessageHandler::OnUpdate(const std::string
& command
,
81 const base::Value
* args
) {
82 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
83 std::vector
<const base::Value
*> args_vector
;
85 args_vector
.push_back(args
);
86 base::string16 update
= WebUI::GetJavascriptCall(command
, args_vector
);
88 RenderFrameHost
* host
= web_ui()->GetWebContents()->GetMainFrame();
90 host
->ExecuteJavaScript(update
);
93 } // namespace content