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/renderer/media/rtc_dtmf_sender_handler.h" 6 7 #include <string> 8 9 #include "base/logging.h" 10 #include "base/strings/utf_string_conversions.h" 11 12 using webrtc::DtmfSenderInterface; 13 14 namespace content { 15 16 RtcDtmfSenderHandler::RtcDtmfSenderHandler(DtmfSenderInterface* dtmf_sender) 17 : dtmf_sender_(dtmf_sender), 18 webkit_client_(NULL) { 19 DVLOG(1) << "::ctor"; 20 dtmf_sender_->RegisterObserver(this); 21 } 22 23 RtcDtmfSenderHandler::~RtcDtmfSenderHandler() { 24 DVLOG(1) << "::dtor"; 25 dtmf_sender_->UnregisterObserver(); 26 } 27 28 void RtcDtmfSenderHandler::setClient( 29 WebKit::WebRTCDTMFSenderHandlerClient* client) { 30 webkit_client_ = client; 31 } 32 33 WebKit::WebString RtcDtmfSenderHandler::currentToneBuffer() { 34 return UTF8ToUTF16(dtmf_sender_->tones()); 35 } 36 37 bool RtcDtmfSenderHandler::canInsertDTMF() { 38 return dtmf_sender_->CanInsertDtmf(); 39 } 40 41 bool RtcDtmfSenderHandler::insertDTMF(const WebKit::WebString& tones, 42 long duration, 43 long interToneGap) { 44 std::string utf8_tones = UTF16ToUTF8(tones); 45 return dtmf_sender_->InsertDtmf(utf8_tones, static_cast<int>(duration), 46 static_cast<int>(interToneGap)); 47 } 48 49 void RtcDtmfSenderHandler::OnToneChange(const std::string& tone) { 50 if (!webkit_client_) { 51 LOG(ERROR) << "WebRTCDTMFSenderHandlerClient not set."; 52 return; 53 } 54 webkit_client_->didPlayTone(UTF8ToUTF16(tone)); 55 } 56 57 } // namespace content 58 59