| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_input_bubble_controller.h" | 5 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/tab_contents/tab_util.h" | 9 #include "chrome/browser/tab_contents/tab_util.h" |
| 10 #include "chrome/common/notification_registrar.h" | 10 #include "chrome/common/notification_registrar.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 element_rect); | 45 element_rect); |
| 46 if (!bubble) // could be null if tab or display rect were invalid. | 46 if (!bubble) // could be null if tab or display rect were invalid. |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 bubbles_[caller_id] = bubble; | 49 bubbles_[caller_id] = bubble; |
| 50 | 50 |
| 51 UpdateTabContentsSubscription(caller_id, BUBBLE_ADDED); | 51 UpdateTabContentsSubscription(caller_id, BUBBLE_ADDED); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SpeechInputBubbleController::CloseBubble(int caller_id) { | 54 void SpeechInputBubbleController::CloseBubble(int caller_id) { |
| 55 ProcessRequestInUiThread(caller_id, REQUEST_CLOSE, string16(), 0); | 55 ProcessRequestInUiThread(caller_id, REQUEST_CLOSE, string16(), 0, 0); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void SpeechInputBubbleController::SetBubbleRecordingMode(int caller_id) { | 58 void SpeechInputBubbleController::SetBubbleRecordingMode(int caller_id) { |
| 59 ProcessRequestInUiThread(caller_id, REQUEST_SET_RECORDING_MODE, | 59 ProcessRequestInUiThread(caller_id, REQUEST_SET_RECORDING_MODE, |
| 60 string16(), 0); | 60 string16(), 0, 0); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SpeechInputBubbleController::SetBubbleRecognizingMode(int caller_id) { | 63 void SpeechInputBubbleController::SetBubbleRecognizingMode(int caller_id) { |
| 64 ProcessRequestInUiThread(caller_id, REQUEST_SET_RECOGNIZING_MODE, | 64 ProcessRequestInUiThread(caller_id, REQUEST_SET_RECOGNIZING_MODE, |
| 65 string16(), 0); | 65 string16(), 0, 0); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SpeechInputBubbleController::SetBubbleInputVolume(int caller_id, | 68 void SpeechInputBubbleController::SetBubbleInputVolume(int caller_id, |
| 69 float volume) { | 69 float volume, |
| 70 float noise_volume) { |
| 70 ProcessRequestInUiThread(caller_id, REQUEST_SET_INPUT_VOLUME, string16(), | 71 ProcessRequestInUiThread(caller_id, REQUEST_SET_INPUT_VOLUME, string16(), |
| 71 volume); | 72 volume, noise_volume); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void SpeechInputBubbleController::SetBubbleMessage(int caller_id, | 75 void SpeechInputBubbleController::SetBubbleMessage(int caller_id, |
| 75 const string16& text) { | 76 const string16& text) { |
| 76 ProcessRequestInUiThread(caller_id, REQUEST_SET_MESSAGE, text, 0); | 77 ProcessRequestInUiThread(caller_id, REQUEST_SET_MESSAGE, text, 0, 0); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void SpeechInputBubbleController::UpdateTabContentsSubscription( | 80 void SpeechInputBubbleController::UpdateTabContentsSubscription( |
| 80 int caller_id, ManageSubscriptionAction action) { | 81 int caller_id, ManageSubscriptionAction action) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 | 83 |
| 83 // If there are any other bubbles existing for the same TabContents, we would | 84 // If there are any other bubbles existing for the same TabContents, we would |
| 84 // have subscribed to tab close notifications on their behalf and we need to | 85 // have subscribed to tab close notifications on their behalf and we need to |
| 85 // stay registered. So we don't change the subscription in such cases. | 86 // stay registered. So we don't change the subscription in such cases. |
| 86 TabContents* tab_contents = bubbles_[caller_id]->tab_contents(); | 87 TabContents* tab_contents = bubbles_[caller_id]->tab_contents(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } else { | 125 } else { |
| 125 ++iter; | 126 ++iter; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 } else { | 129 } else { |
| 129 NOTREACHED() << "Unknown notification"; | 130 NOTREACHED() << "Unknown notification"; |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 void SpeechInputBubbleController::ProcessRequestInUiThread( | 134 void SpeechInputBubbleController::ProcessRequestInUiThread( |
| 134 int caller_id, RequestType type, const string16& text, float volume) { | 135 int caller_id, RequestType type, const string16& text, float volume, |
| 136 float noise_volume) { |
| 135 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 137 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 136 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( | 138 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( |
| 137 this, &SpeechInputBubbleController::ProcessRequestInUiThread, | 139 this, &SpeechInputBubbleController::ProcessRequestInUiThread, |
| 138 caller_id, type, text, volume)); | 140 caller_id, type, text, volume, noise_volume)); |
| 139 return; | 141 return; |
| 140 } | 142 } |
| 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 142 // The bubble may have been closed before we got a chance to process this | 144 // The bubble may have been closed before we got a chance to process this |
| 143 // request. So check before proceeding. | 145 // request. So check before proceeding. |
| 144 if (!bubbles_.count(caller_id)) | 146 if (!bubbles_.count(caller_id)) |
| 145 return; | 147 return; |
| 146 | 148 |
| 147 bool change_active_bubble = (type == REQUEST_SET_RECORDING_MODE || | 149 bool change_active_bubble = (type == REQUEST_SET_RECORDING_MODE || |
| 148 type == REQUEST_SET_MESSAGE); | 150 type == REQUEST_SET_MESSAGE); |
| 149 if (change_active_bubble) { | 151 if (change_active_bubble) { |
| 150 if (current_bubble_caller_id_ && current_bubble_caller_id_ != caller_id) | 152 if (current_bubble_caller_id_ && current_bubble_caller_id_ != caller_id) |
| 151 bubbles_[current_bubble_caller_id_]->Hide(); | 153 bubbles_[current_bubble_caller_id_]->Hide(); |
| 152 current_bubble_caller_id_ = caller_id; | 154 current_bubble_caller_id_ = caller_id; |
| 153 } | 155 } |
| 154 | 156 |
| 155 SpeechInputBubble* bubble = bubbles_[caller_id]; | 157 SpeechInputBubble* bubble = bubbles_[caller_id]; |
| 156 switch (type) { | 158 switch (type) { |
| 157 case REQUEST_SET_RECORDING_MODE: | 159 case REQUEST_SET_RECORDING_MODE: |
| 158 bubble->SetRecordingMode(); | 160 bubble->SetRecordingMode(); |
| 159 break; | 161 break; |
| 160 case REQUEST_SET_RECOGNIZING_MODE: | 162 case REQUEST_SET_RECOGNIZING_MODE: |
| 161 bubble->SetRecognizingMode(); | 163 bubble->SetRecognizingMode(); |
| 162 break; | 164 break; |
| 163 case REQUEST_SET_MESSAGE: | 165 case REQUEST_SET_MESSAGE: |
| 164 bubble->SetMessage(text); | 166 bubble->SetMessage(text); |
| 165 break; | 167 break; |
| 166 case REQUEST_SET_INPUT_VOLUME: | 168 case REQUEST_SET_INPUT_VOLUME: |
| 167 bubble->SetInputVolume(volume); | 169 bubble->SetInputVolume(volume, noise_volume); |
| 168 break; | 170 break; |
| 169 case REQUEST_CLOSE: | 171 case REQUEST_CLOSE: |
| 170 if (current_bubble_caller_id_ == caller_id) | 172 if (current_bubble_caller_id_ == caller_id) |
| 171 current_bubble_caller_id_ = 0; | 173 current_bubble_caller_id_ = 0; |
| 172 UpdateTabContentsSubscription(caller_id, BUBBLE_REMOVED); | 174 UpdateTabContentsSubscription(caller_id, BUBBLE_REMOVED); |
| 173 delete bubble; | 175 delete bubble; |
| 174 bubbles_.erase(caller_id); | 176 bubbles_.erase(caller_id); |
| 175 break; | 177 break; |
| 176 default: | 178 default: |
| 177 NOTREACHED(); | 179 NOTREACHED(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 void SpeechInputBubbleController::InvokeDelegateButtonClicked( | 215 void SpeechInputBubbleController::InvokeDelegateButtonClicked( |
| 214 int caller_id, SpeechInputBubble::Button button) { | 216 int caller_id, SpeechInputBubble::Button button) { |
| 215 delegate_->InfoBubbleButtonClicked(caller_id, button); | 217 delegate_->InfoBubbleButtonClicked(caller_id, button); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void SpeechInputBubbleController::InvokeDelegateFocusChanged(int caller_id) { | 220 void SpeechInputBubbleController::InvokeDelegateFocusChanged(int caller_id) { |
| 219 delegate_->InfoBubbleFocusChanged(caller_id); | 221 delegate_->InfoBubbleFocusChanged(caller_id); |
| 220 } | 222 } |
| 221 | 223 |
| 222 } // namespace speech_input | 224 } // namespace speech_input |
| OLD | NEW |