• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "libcef/browser/speech_recognition_manager_delegate.h"
6 
7 #include <set>
8 #include <string>
9 
10 #include "libcef/common/cef_switches.h"
11 
12 #include "base/bind.h"
13 #include "base/command_line.h"
14 #include "base/task/post_task.h"
15 #include "content/public/browser/browser_task_traits.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/speech_recognition_manager.h"
24 #include "content/public/browser/speech_recognition_session_context.h"
25 #include "content/public/browser/web_contents.h"
26 
27 using content::BrowserThread;
28 using content::SpeechRecognitionManager;
29 using content::WebContents;
30 
CefSpeechRecognitionManagerDelegate()31 CefSpeechRecognitionManagerDelegate ::CefSpeechRecognitionManagerDelegate() {
32   const base::CommandLine* command_line =
33       base::CommandLine::ForCurrentProcess();
34   filter_profanities_ =
35       command_line->HasSwitch(switches::kEnableProfanityFilter);
36 }
37 
~CefSpeechRecognitionManagerDelegate()38 CefSpeechRecognitionManagerDelegate ::~CefSpeechRecognitionManagerDelegate() {}
39 
OnRecognitionStart(int session_id)40 void CefSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {}
41 
OnAudioStart(int session_id)42 void CefSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {}
43 
OnEnvironmentEstimationComplete(int session_id)44 void CefSpeechRecognitionManagerDelegate::OnEnvironmentEstimationComplete(
45     int session_id) {}
46 
OnSoundStart(int session_id)47 void CefSpeechRecognitionManagerDelegate::OnSoundStart(int session_id) {}
48 
OnSoundEnd(int session_id)49 void CefSpeechRecognitionManagerDelegate::OnSoundEnd(int session_id) {}
50 
OnAudioEnd(int session_id)51 void CefSpeechRecognitionManagerDelegate::OnAudioEnd(int session_id) {}
52 
OnRecognitionResults(int session_id,const std::vector<blink::mojom::SpeechRecognitionResultPtr> & result)53 void CefSpeechRecognitionManagerDelegate::OnRecognitionResults(
54     int session_id,
55     const std::vector<blink::mojom::SpeechRecognitionResultPtr>& result) {}
56 
OnRecognitionError(int session_id,const blink::mojom::SpeechRecognitionError & error)57 void CefSpeechRecognitionManagerDelegate::OnRecognitionError(
58     int session_id,
59     const blink::mojom::SpeechRecognitionError& error) {}
60 
OnAudioLevelsChange(int session_id,float volume,float noise_volume)61 void CefSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
62     int session_id,
63     float volume,
64     float noise_volume) {}
65 
OnRecognitionEnd(int session_id)66 void CefSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {}
67 
CheckRecognitionIsAllowed(int session_id,base::OnceCallback<void (bool ask_user,bool is_allowed)> callback)68 void CefSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
69     int session_id,
70     base::OnceCallback<void(bool ask_user, bool is_allowed)> callback) {
71   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
72 
73   const content::SpeechRecognitionSessionContext& context =
74       SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
75 
76   // Make sure that initiators properly set the |render_process_id| field.
77   DCHECK_NE(context.render_process_id, 0);
78 
79   base::PostTask(FROM_HERE, {content::BrowserThread::IO},
80                  base::BindOnce(std::move(callback), false, true));
81 }
82 
83 content::SpeechRecognitionEventListener*
GetEventListener()84 CefSpeechRecognitionManagerDelegate::GetEventListener() {
85   return this;
86 }
87 
FilterProfanities(int render_process_id)88 bool CefSpeechRecognitionManagerDelegate::FilterProfanities(
89     int render_process_id) {
90   return filter_profanities_;
91 }
92