| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/webrtc/webrtc_internals_message_handler.h" | 5 #include "content/browser/media/webrtc/webrtc_internals_message_handler.h" |
| 6 | 6 |
| 7 #include "content/browser/media/webrtc/webrtc_internals.h" | 7 #include "content/browser/media/webrtc/webrtc_internals.h" |
| 8 #include "content/common/media/peer_connection_tracker_messages.h" | 8 #include "content/common/media/peer_connection_tracker_messages.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_ui.h" | 13 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() { | 18 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() |
| 19 WebRTCInternals::GetInstance()->AddObserver(this); | 19 : WebRTCInternalsMessageHandler(WebRTCInternals::GetInstance()) {} |
| 20 |
| 21 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler( |
| 22 WebRTCInternals* webrtc_internals) |
| 23 : webrtc_internals_(webrtc_internals) { |
| 24 webrtc_internals_->AddObserver(this); |
| 20 } | 25 } |
| 21 | 26 |
| 22 WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() { | 27 WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() { |
| 23 WebRTCInternals::GetInstance()->RemoveObserver(this); | 28 webrtc_internals_->RemoveObserver(this); |
| 24 } | 29 } |
| 25 | 30 |
| 26 void WebRTCInternalsMessageHandler::RegisterMessages() { | 31 void WebRTCInternalsMessageHandler::RegisterMessages() { |
| 27 web_ui()->RegisterMessageCallback("getAllStats", | 32 web_ui()->RegisterMessageCallback("getAllStats", |
| 28 base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats, | 33 base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats, |
| 29 base::Unretained(this))); | 34 base::Unretained(this))); |
| 30 | 35 |
| 31 web_ui()->RegisterMessageCallback("enableAudioDebugRecordings", | 36 web_ui()->RegisterMessageCallback("enableAudioDebugRecordings", |
| 32 base::Bind( | 37 base::Bind( |
| 33 &WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled, | 38 &WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 for (RenderProcessHost::iterator i( | 82 for (RenderProcessHost::iterator i( |
| 78 content::RenderProcessHost::AllHostsIterator()); | 83 content::RenderProcessHost::AllHostsIterator()); |
| 79 !i.IsAtEnd(); i.Advance()) { | 84 !i.IsAtEnd(); i.Advance()) { |
| 80 i.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats()); | 85 i.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats()); |
| 81 } | 86 } |
| 82 } | 87 } |
| 83 | 88 |
| 84 void WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled( | 89 void WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled( |
| 85 bool enable, const base::ListValue* /* unused_list */) { | 90 bool enable, const base::ListValue* /* unused_list */) { |
| 86 if (enable) { | 91 if (enable) { |
| 87 WebRTCInternals::GetInstance()->EnableAudioDebugRecordings( | 92 webrtc_internals_->EnableAudioDebugRecordings(web_ui()->GetWebContents()); |
| 88 web_ui()->GetWebContents()); | |
| 89 } else { | 93 } else { |
| 90 WebRTCInternals::GetInstance()->DisableAudioDebugRecordings(); | 94 webrtc_internals_->DisableAudioDebugRecordings(); |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 void WebRTCInternalsMessageHandler::OnSetEventLogRecordingsEnabled( | 98 void WebRTCInternalsMessageHandler::OnSetEventLogRecordingsEnabled( |
| 95 bool enable, | 99 bool enable, |
| 96 const base::ListValue* /* unused_list */) { | 100 const base::ListValue* /* unused_list */) { |
| 97 if (enable) { | 101 if (enable) { |
| 98 WebRTCInternals::GetInstance()->EnableEventLogRecordings( | 102 webrtc_internals_->EnableEventLogRecordings(web_ui()->GetWebContents()); |
| 99 web_ui()->GetWebContents()); | |
| 100 } else { | 103 } else { |
| 101 WebRTCInternals::GetInstance()->DisableEventLogRecordings(); | 104 webrtc_internals_->DisableEventLogRecordings(); |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void WebRTCInternalsMessageHandler::OnDOMLoadDone( | 108 void WebRTCInternalsMessageHandler::OnDOMLoadDone( |
| 106 const base::ListValue* /* unused_list */) { | 109 const base::ListValue* /* unused_list */) { |
| 107 WebRTCInternals::GetInstance()->UpdateObserver(this); | 110 webrtc_internals_->UpdateObserver(this); |
| 108 | 111 |
| 109 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) { | 112 if (webrtc_internals_->IsAudioDebugRecordingsEnabled()) { |
| 110 RenderFrameHost* host = GetWebRTCInternalsHost(); | 113 RenderFrameHost* host = GetWebRTCInternalsHost(); |
| 111 if (!host) | 114 if (!host) |
| 112 return; | 115 return; |
| 113 | 116 |
| 114 std::vector<const base::Value*> args_vector; | 117 std::vector<const base::Value*> args_vector; |
| 115 base::string16 script = | 118 base::string16 script = |
| 116 WebUI::GetJavascriptCall("setAudioDebugRecordingsEnabled", args_vector); | 119 WebUI::GetJavascriptCall("setAudioDebugRecordingsEnabled", args_vector); |
| 117 host->ExecuteJavaScript(script); | 120 host->ExecuteJavaScript(script); |
| 118 } | 121 } |
| 119 } | 122 } |
| 120 | 123 |
| 121 void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command, | 124 void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command, |
| 122 const base::Value* args) { | 125 const base::Value* args) { |
| 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 126 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 124 | 127 |
| 125 RenderFrameHost* host = GetWebRTCInternalsHost(); | 128 RenderFrameHost* host = GetWebRTCInternalsHost(); |
| 126 if (!host) | 129 if (!host) |
| 127 return; | 130 return; |
| 128 | 131 |
| 129 std::vector<const base::Value*> args_vector; | 132 std::vector<const base::Value*> args_vector; |
| 130 if (args) | 133 if (args) |
| 131 args_vector.push_back(args); | 134 args_vector.push_back(args); |
| 132 | 135 |
| 133 base::string16 update = WebUI::GetJavascriptCall(command, args_vector); | 136 base::string16 update = WebUI::GetJavascriptCall(command, args_vector); |
| 134 host->ExecuteJavaScript(update); | 137 host->ExecuteJavaScript(update); |
| 135 } | 138 } |
| 136 | 139 |
| 137 } // namespace content | 140 } // namespace content |
| OLD | NEW |