| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/speech/speech_recognition_bubble_controller.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/tab_contents/tab_util.h" | 8 #include "chrome/browser/tab_contents/tab_util.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
| 11 #include "content/public/browser/notification_source.h" | 11 #include "content/public/browser/notification_source.h" |
| 12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 using content::WebContents; | 18 using content::WebContents; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 const int kInvalidSessionId = 0; | 21 const int kInvalidSessionId = 0; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace speech { | 24 namespace speech { |
| 25 | 25 |
| 26 SpeechRecognitionBubbleControllerDelegateForTests* |
| 27 SpeechRecognitionBubbleController::delegate_for_tests_ = NULL; |
| 28 |
| 29 SpeechRecognitionBubbleController* |
| 30 SpeechRecognitionBubbleController::instance_for_tests_ = NULL; |
| 31 |
| 32 void SpeechRecognitionBubbleController::SetDelegateForTests( |
| 33 DelegateForTests* delegate_for_tests) { |
| 34 delegate_for_tests_ = delegate_for_tests; |
| 35 } |
| 36 |
| 37 SpeechRecognitionBubbleController* |
| 38 SpeechRecognitionBubbleController::GetInstanceForTests() { |
| 39 return instance_for_tests_; |
| 40 } |
| 41 |
| 26 SpeechRecognitionBubbleController::SpeechRecognitionBubbleController( | 42 SpeechRecognitionBubbleController::SpeechRecognitionBubbleController( |
| 27 Delegate* delegate) | 43 Delegate* delegate) |
| 28 : delegate_(delegate), | 44 : delegate_(delegate), |
| 29 current_bubble_session_id_(kInvalidSessionId), | 45 current_bubble_session_id_(kInvalidSessionId), |
| 30 current_bubble_render_process_id_(0), | 46 current_bubble_render_process_id_(0), |
| 31 current_bubble_render_view_id_(0), | 47 current_bubble_render_view_id_(0), |
| 32 last_request_issued_(REQUEST_CLOSE) { | 48 last_request_issued_(REQUEST_CLOSE) { |
| 49 instance_for_tests_ = this; |
| 33 } | 50 } |
| 34 | 51 |
| 35 SpeechRecognitionBubbleController::~SpeechRecognitionBubbleController() { | 52 SpeechRecognitionBubbleController::~SpeechRecognitionBubbleController() { |
| 36 DCHECK_EQ(kInvalidSessionId, current_bubble_session_id_); | 53 DCHECK_EQ(kInvalidSessionId, current_bubble_session_id_); |
| 54 instance_for_tests_ = NULL; |
| 37 } | 55 } |
| 38 | 56 |
| 39 void SpeechRecognitionBubbleController::CreateBubble( | 57 void SpeechRecognitionBubbleController::CreateBubble( |
| 40 int session_id, | 58 int session_id, |
| 41 int render_process_id, | 59 int render_process_id, |
| 42 int render_view_id, | 60 int render_view_id, |
| 43 const gfx::Rect& element_rect) { | 61 const gfx::Rect& element_rect) { |
| 44 current_bubble_session_id_ = session_id; | 62 current_bubble_session_id_ = session_id; |
| 45 current_bubble_render_process_id_ = render_process_id; | 63 current_bubble_render_process_id_ = render_process_id; |
| 46 current_bubble_render_view_id_ = render_view_id; | 64 current_bubble_render_view_id_ = render_view_id; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Could be null if tab or display rect were invalid. | 169 // Could be null if tab or display rect were invalid. |
| 152 // Simulate the cancel button being clicked to inform the delegate. | 170 // Simulate the cancel button being clicked to inform the delegate. |
| 153 BrowserThread::PostTask( | 171 BrowserThread::PostTask( |
| 154 BrowserThread::IO, FROM_HERE, base::Bind( | 172 BrowserThread::IO, FROM_HERE, base::Bind( |
| 155 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, | 173 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, |
| 156 this, SpeechRecognitionBubble::BUTTON_CANCEL)); | 174 this, SpeechRecognitionBubble::BUTTON_CANCEL)); |
| 157 return; | 175 return; |
| 158 } | 176 } |
| 159 bubble_->Show(); | 177 bubble_->Show(); |
| 160 bubble_->SetWarmUpMode(); | 178 bubble_->SetWarmUpMode(); |
| 179 if (delegate_for_tests_) |
| 180 delegate_for_tests_->BubbleCreated(); |
| 161 break; | 181 break; |
| 162 case REQUEST_SET_RECORDING_MODE: | 182 case REQUEST_SET_RECORDING_MODE: |
| 163 DCHECK(bubble_.get()); | 183 DCHECK(bubble_.get()); |
| 164 bubble_->SetRecordingMode(); | 184 bubble_->SetRecordingMode(); |
| 185 if (delegate_for_tests_) |
| 186 delegate_for_tests_->BubbleSwitchedToRecordingMode(); |
| 165 break; | 187 break; |
| 166 case REQUEST_SET_RECOGNIZING_MODE: | 188 case REQUEST_SET_RECOGNIZING_MODE: |
| 167 DCHECK(bubble_.get()); | 189 DCHECK(bubble_.get()); |
| 168 bubble_->SetRecognizingMode(); | 190 bubble_->SetRecognizingMode(); |
| 191 if (delegate_for_tests_) |
| 192 delegate_for_tests_->BubbleSwitchedToRecognizingMode(); |
| 169 break; | 193 break; |
| 170 case REQUEST_SET_MESSAGE: | 194 case REQUEST_SET_MESSAGE: |
| 171 DCHECK(bubble_.get()); | 195 DCHECK(bubble_.get()); |
| 172 bubble_->SetMessage(request.message); | 196 bubble_->SetMessage(request.message); |
| 197 if (delegate_for_tests_) |
| 198 delegate_for_tests_->BubbleMessageDisplayed(); |
| 173 break; | 199 break; |
| 174 case REQUEST_SET_INPUT_VOLUME: | 200 case REQUEST_SET_INPUT_VOLUME: |
| 175 DCHECK(bubble_.get()); | 201 DCHECK(bubble_.get()); |
| 176 bubble_->SetInputVolume(request.volume, request.noise_volume); | 202 bubble_->SetInputVolume(request.volume, request.noise_volume); |
| 177 break; | 203 break; |
| 178 case REQUEST_CLOSE: | 204 case REQUEST_CLOSE: |
| 179 bubble_.reset(); | 205 if (bubble_.get()) { |
| 206 bubble_.reset(); |
| 207 if (delegate_for_tests_) |
| 208 delegate_for_tests_->BubbleClosed(); |
| 209 } |
| 180 break; | 210 break; |
| 181 default: | 211 default: |
| 182 NOTREACHED(); | 212 NOTREACHED(); |
| 183 break; | 213 break; |
| 184 } | 214 } |
| 185 } | 215 } |
| 186 | 216 |
| 187 SpeechRecognitionBubbleController::UIRequest::UIRequest(RequestType type_value) | 217 SpeechRecognitionBubbleController::UIRequest::UIRequest(RequestType type_value) |
| 188 : type(type_value), | 218 : type(type_value), |
| 189 volume(0.0F), | 219 volume(0.0F), |
| 190 noise_volume(0.0F), | 220 noise_volume(0.0F), |
| 191 render_process_id(0), | 221 render_process_id(0), |
| 192 render_view_id(0) { | 222 render_view_id(0) { |
| 193 } | 223 } |
| 194 | 224 |
| 195 SpeechRecognitionBubbleController::UIRequest::~UIRequest() { | 225 SpeechRecognitionBubbleController::UIRequest::~UIRequest() { |
| 196 } | 226 } |
| 197 | 227 |
| 198 } // namespace speech | 228 } // namespace speech |
| OLD | NEW |