Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: chrome/browser/ui/gtk/speech_recognition_bubble_gtk.cc

Issue 148343008: Speech Recognition API: Safeguarding against page closes during startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "chrome/browser/speech/speech_recognition_bubble.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
(...skipping 30 matching lines...) Expand all
41 const GdkColor& kLabelTextColor = ui::kGdkBlack; 41 const GdkColor& kLabelTextColor = ui::kGdkBlack;
42 42
43 // Implementation of SpeechRecognitionBubble for GTK. This shows a speech 43 // Implementation of SpeechRecognitionBubble for GTK. This shows a speech
44 // recognition bubble on screen. 44 // recognition bubble on screen.
45 class SpeechRecognitionBubbleGtk : public SpeechRecognitionBubbleBase, 45 class SpeechRecognitionBubbleGtk : public SpeechRecognitionBubbleBase,
46 public BubbleDelegateGtk { 46 public BubbleDelegateGtk {
47 public: 47 public:
48 SpeechRecognitionBubbleGtk(WebContents* web_contents, 48 SpeechRecognitionBubbleGtk(WebContents* web_contents,
49 Delegate* delegate, 49 Delegate* delegate,
50 const gfx::Rect& element_rect); 50 const gfx::Rect& element_rect);
51 SpeechRecognitionBubbleGtk(int render_process_id, int render_view_id,
52 Delegate* delegate,
53 const gfx::Rect& element_rect);
51 virtual ~SpeechRecognitionBubbleGtk(); 54 virtual ~SpeechRecognitionBubbleGtk();
52 55
53 private: 56 private:
54 // SpeechRecognitionBubbleBase: 57 // SpeechRecognitionBubbleBase:
55 virtual void Show() OVERRIDE; 58 virtual void Show() OVERRIDE;
56 virtual void Hide() OVERRIDE; 59 virtual void Hide() OVERRIDE;
57 virtual void UpdateLayout() OVERRIDE; 60 virtual void UpdateLayout() OVERRIDE;
58 virtual void UpdateImage() OVERRIDE; 61 virtual void UpdateImage() OVERRIDE;
59 62
60 // BubbleDelegateGtk: 63 // BubbleDelegateGtk:
(...skipping 27 matching lines...) Expand all
88 element_rect_(element_rect), 91 element_rect_(element_rect),
89 did_invoke_close_(false), 92 did_invoke_close_(false),
90 label_(NULL), 93 label_(NULL),
91 cancel_button_(NULL), 94 cancel_button_(NULL),
92 try_again_button_(NULL), 95 try_again_button_(NULL),
93 icon_(NULL), 96 icon_(NULL),
94 icon_container_(NULL), 97 icon_container_(NULL),
95 mic_settings_(NULL) { 98 mic_settings_(NULL) {
96 } 99 }
97 100
101 SpeechRecognitionBubbleGtk::SpeechRecognitionBubbleGtk(
102 int render_process_id, int render_view_id, Delegate* delegate,
103 const gfx::Rect& element_rect)
104 : SpeechRecognitionBubbleBase(render_process_id, render_process_id),
105 delegate_(delegate),
106 bubble_(NULL),
107 element_rect_(element_rect),
108 did_invoke_close_(false),
109 label_(NULL),
110 cancel_button_(NULL),
111 try_again_button_(NULL),
112 icon_(NULL),
113 icon_container_(NULL),
114 mic_settings_(NULL) {
115 }
116
98 SpeechRecognitionBubbleGtk::~SpeechRecognitionBubbleGtk() { 117 SpeechRecognitionBubbleGtk::~SpeechRecognitionBubbleGtk() {
99 // The |Close| call below invokes our |BubbleClosing| method. Since we were 118 // The |Close| call below invokes our |BubbleClosing| method. Since we were
100 // destroyed by the caller we don't need to call them back, hence set this 119 // destroyed by the caller we don't need to call them back, hence set this
101 // flag here. 120 // flag here.
102 did_invoke_close_ = true; 121 did_invoke_close_ = true;
103 Hide(); 122 Hide();
104 } 123 }
105 124
106 void SpeechRecognitionBubbleGtk::OnCancelClicked(GtkWidget* widget) { 125 void SpeechRecognitionBubbleGtk::OnCancelClicked(GtkWidget* widget) {
107 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); 126 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL);
108 } 127 }
109 128
110 void SpeechRecognitionBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { 129 void SpeechRecognitionBubbleGtk::OnTryAgainClicked(GtkWidget* widget) {
111 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); 130 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN);
112 } 131 }
113 132
114 void SpeechRecognitionBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { 133 void SpeechRecognitionBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) {
115 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); 134 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings();
116 Hide(); 135 Hide();
117 } 136 }
118 137
119 void SpeechRecognitionBubbleGtk::Show() { 138 void SpeechRecognitionBubbleGtk::Show() {
120 if (bubble_) 139 if (bubble_ || !GetWebContents())
121 return; // Nothing further to do since the bubble is already visible. 140 return; // Nothing further to do since the bubble is already visible.
122 141
123 // We use a vbox to arrange the controls (label, image, button bar) vertically 142 // We use a vbox to arrange the controls (label, image, button bar) vertically
124 // and the button bar is a hbox holding the 2 buttons (try again and cancel). 143 // and the button bar is a hbox holding the 2 buttons (try again and cancel).
125 // To get horizontal space around them we place this vbox with padding in a 144 // To get horizontal space around them we place this vbox with padding in a
126 // GtkAlignment below. 145 // GtkAlignment below.
127 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); 146 GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
128 147
129 // The icon with a some padding on the left and right. 148 // The icon with a some padding on the left and right.
130 icon_container_ = gtk_alignment_new(0, 0, 0, 0); 149 icon_container_ = gtk_alignment_new(0, 0, 0, 0);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 content, 219 content,
201 BubbleGtk::ANCHOR_TOP_LEFT, 220 BubbleGtk::ANCHOR_TOP_LEFT,
202 BubbleGtk::POPUP_WINDOW | BubbleGtk::GRAB_INPUT, 221 BubbleGtk::POPUP_WINDOW | BubbleGtk::GRAB_INPUT,
203 theme_provider, 222 theme_provider,
204 this); 223 this);
205 224
206 UpdateLayout(); 225 UpdateLayout();
207 } 226 }
208 227
209 void SpeechRecognitionBubbleGtk::Hide() { 228 void SpeechRecognitionBubbleGtk::Hide() {
210 if (bubble_) 229 if (bubble_ && GetWebContents())
211 bubble_->Close(); 230 bubble_->Close();
212 } 231 }
213 232
214 void SpeechRecognitionBubbleGtk::UpdateLayout() { 233 void SpeechRecognitionBubbleGtk::UpdateLayout() {
215 if (!bubble_) 234 if (!bubble_ || !GetWebContents())
216 return; 235 return;
217 236
218 if (display_mode() == DISPLAY_MODE_MESSAGE) { 237 if (display_mode() == DISPLAY_MODE_MESSAGE) {
219 // Message text and the Try Again + Cancel buttons are visible, hide the 238 // Message text and the Try Again + Cancel buttons are visible, hide the
220 // icon. 239 // icon.
221 gtk_label_set_text(GTK_LABEL(label_), 240 gtk_label_set_text(GTK_LABEL(label_),
222 base::UTF16ToUTF8(message_text()).c_str()); 241 base::UTF16ToUTF8(message_text()).c_str());
223 gtk_widget_show(label_); 242 gtk_widget_show(label_);
224 gtk_widget_show(try_again_button_); 243 gtk_widget_show(try_again_button_);
225 if (mic_settings_) 244 if (mic_settings_)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 310 }
292 311
293 } // namespace 312 } // namespace
294 313
295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( 314 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
296 WebContents* web_contents, 315 WebContents* web_contents,
297 Delegate* delegate, 316 Delegate* delegate,
298 const gfx::Rect& element_rect) { 317 const gfx::Rect& element_rect) {
299 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect); 318 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect);
300 } 319 }
320
321 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
322 int render_process_id, int render_view_id,
323 SpeechRecognitionBubble::Delegate* delegate,
324 const gfx::Rect& element_rect) {
325 return new SpeechRecognitionBubbleGtk(render_process_id, render_view_id,
326 delegate, element_rect);
327 }
328
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698