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. 4 5 #include "content/browser/media/webrtc_internals_message_handler.h" 6 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" 14 15 namespace content { 16 17 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() { 18 WebRTCInternals::GetInstance()->AddObserver(this); 19 } 20 21 WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() { 22 WebRTCInternals::GetInstance()->RemoveObserver(this); 23 } 24 25 void WebRTCInternalsMessageHandler::RegisterMessages() { 26 web_ui()->RegisterMessageCallback("getAllStats", 27 base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats, 28 base::Unretained(this))); 29 30 web_ui()->RegisterMessageCallback("enableAecRecording", 31 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled, 32 base::Unretained(this), true)); 33 34 web_ui()->RegisterMessageCallback("disableAecRecording", 35 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled, 36 base::Unretained(this), false)); 37 38 web_ui()->RegisterMessageCallback("finishedDOMLoad", 39 base::Bind(&WebRTCInternalsMessageHandler::OnDOMLoadDone, 40 base::Unretained(this))); 41 } 42 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()); 49 } 50 } 51 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(); 58 } 59 60 void WebRTCInternalsMessageHandler::OnDOMLoadDone( 61 const base::ListValue* /* unused_list */) { 62 WebRTCInternals::GetInstance()->UpdateObserver(this); 63 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); 71 } 72 } 73 74 void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command, 75 const base::Value* args) { 76 DCHECK(BrowserThread::CurrentlyOn(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); 81 82 RenderFrameHost* host = web_ui()->GetWebContents()->GetMainFrame(); 83 if (host) 84 host->ExecuteJavaScript(update); 85 } 86 87 } // namespace content 88