Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / media / rtc_dtmf_sender_handler.cc
blob23c5cc18f88b3e30d351243cd4aaf60329eba8ba
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"
7 #include <string>
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
12 using webrtc::DtmfSenderInterface;
14 namespace content {
16 RtcDtmfSenderHandler::RtcDtmfSenderHandler(DtmfSenderInterface* dtmf_sender)
17 : dtmf_sender_(dtmf_sender),
18 webkit_client_(NULL) {
19 DVLOG(1) << "::ctor";
20 dtmf_sender_->RegisterObserver(this);
23 RtcDtmfSenderHandler::~RtcDtmfSenderHandler() {
24 DVLOG(1) << "::dtor";
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,
42 long duration,
43 long interToneGap) {
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.";
52 return;
54 webkit_client_->didPlayTone(base::UTF8ToUTF16(tone));
57 } // namespace content