Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / media / webrtc_internals_message_handler.cc
blob8bfae991c06fee37f244ed0fcfa6e3656fe250d5
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"
15 namespace content {
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("enableAecRecording",
31 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled,
32 base::Unretained(this), true));
34 web_ui()->RegisterMessageCallback("disableAecRecording",
35 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled,
36 base::Unretained(this), false));
38 web_ui()->RegisterMessageCallback("finishedDOMLoad",
39 base::Bind(&WebRTCInternalsMessageHandler::OnDOMLoadDone,
40 base::Unretained(this)));
43 void WebRTCInternalsMessageHandler::OnGetAllStats(
44 const base::ListValue* /* unused_list */) {
45 for (RenderProcessHost::iterator i(
46 content::RenderProcessHost::AllHostsIterator());
47 !i.IsAtEnd(); i.Advance()) {
48 i.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats());
52 void WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled(
53 bool enable, const base::ListValue* /* unused_list */) {
54 if (enable)
55 WebRTCInternals::GetInstance()->EnableAecDump(web_ui()->GetWebContents());
56 else
57 WebRTCInternals::GetInstance()->DisableAecDump();
60 void WebRTCInternalsMessageHandler::OnDOMLoadDone(
61 const base::ListValue* /* unused_list */) {
62 WebRTCInternals::GetInstance()->UpdateObserver(this);
64 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) {
65 std::vector<const base::Value*> args_vector;
66 base::string16 script = WebUI::GetJavascriptCall("setAecRecordingEnabled",
67 args_vector);
68 RenderFrameHost* host = web_ui()->GetWebContents()->GetMainFrame();
69 if (host)
70 host->ExecuteJavaScript(script);
74 void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command,
75 const base::Value* args) {
76 DCHECK_CURRENTLY_ON(BrowserThread::UI);
77 std::vector<const base::Value*> args_vector;
78 if (args)
79 args_vector.push_back(args);
80 base::string16 update = WebUI::GetJavascriptCall(command, args_vector);
82 RenderFrameHost* host = web_ui()->GetWebContents()->GetMainFrame();
83 if (host)
84 host->ExecuteJavaScript(update);
87 } // namespace content