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/renderer/media/rtc_dtmf_sender_handler.h"
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
12 using webrtc::DtmfSenderInterface
;
16 RtcDtmfSenderHandler::RtcDtmfSenderHandler(DtmfSenderInterface
* dtmf_sender
)
17 : dtmf_sender_(dtmf_sender
),
18 webkit_client_(NULL
) {
20 dtmf_sender_
->RegisterObserver(this);
23 RtcDtmfSenderHandler::~RtcDtmfSenderHandler() {
25 dtmf_sender_
->UnregisterObserver();
28 void RtcDtmfSenderHandler::setClient(
29 blink::WebRTCDTMFSenderHandlerClient
* client
) {
30 webkit_client_
= client
;
33 blink::WebString
RtcDtmfSenderHandler::currentToneBuffer() {
34 return base::UTF8ToUTF16(dtmf_sender_
->tones());
37 bool RtcDtmfSenderHandler::canInsertDTMF() {
38 return dtmf_sender_
->CanInsertDtmf();
41 bool RtcDtmfSenderHandler::insertDTMF(const blink::WebString
& tones
,
44 std::string utf8_tones
= base::UTF16ToUTF8(tones
);
45 return dtmf_sender_
->InsertDtmf(utf8_tones
, static_cast<int>(duration
),
46 static_cast<int>(interToneGap
));
49 void RtcDtmfSenderHandler::OnToneChange(const std::string
& tone
) {
50 if (!webkit_client_
) {
51 LOG(ERROR
) << "WebRTCDTMFSenderHandlerClient not set.";
54 webkit_client_
->didPlayTone(base::UTF8ToUTF16(tone
));
57 } // namespace content