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

Side by Side Diff: chrome/browser/ui/views/speech_recognition_bubble_views.cc

Issue 148343008: Speech Recognition API: Safeguarding against page closes during startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 int width = cancel_->GetPreferredSize().width(); 305 int width = cancel_->GetPreferredSize().width();
306 cancel_->SetBounds(x + (available_width - width) / 2, y, width, 306 cancel_->SetBounds(x + (available_width - width) / 2, y, width,
307 control_height); 307 control_height);
308 } 308 }
309 } 309 }
310 } 310 }
311 311
312 // Implementation of SpeechRecognitionBubble. 312 // Implementation of SpeechRecognitionBubble.
313 class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase { 313 class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase {
314 public: 314 public:
315 SpeechRecognitionBubbleImpl(WebContents* web_contents, 315 SpeechRecognitionBubbleImpl(int render_process_id, int render_view_id,
316 Delegate* delegate, 316 Delegate* delegate,
317 const gfx::Rect& element_rect); 317 const gfx::Rect& element_rect);
318 virtual ~SpeechRecognitionBubbleImpl(); 318 virtual ~SpeechRecognitionBubbleImpl();
319 319
320 // SpeechRecognitionBubble methods. 320 // SpeechRecognitionBubble methods.
321 virtual void Show() OVERRIDE; 321 virtual void Show() OVERRIDE;
322 virtual void Hide() OVERRIDE; 322 virtual void Hide() OVERRIDE;
323 323
324 // SpeechRecognitionBubbleBase methods. 324 // SpeechRecognitionBubbleBase methods.
325 virtual void UpdateLayout() OVERRIDE; 325 virtual void UpdateLayout() OVERRIDE;
326 virtual void UpdateImage() OVERRIDE; 326 virtual void UpdateImage() OVERRIDE;
327 327
328 private: 328 private:
329 Delegate* delegate_; 329 Delegate* delegate_;
330 SpeechRecognitionBubbleView* bubble_; 330 SpeechRecognitionBubbleView* bubble_;
331 gfx::Rect element_rect_; 331 gfx::Rect element_rect_;
332 332
333 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleImpl); 333 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleImpl);
334 }; 334 };
335 335
336 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl( 336 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl(
337 WebContents* web_contents, Delegate* delegate, 337 int render_process_id, int render_view_id, Delegate* delegate,
338 const gfx::Rect& element_rect) 338 const gfx::Rect& element_rect)
339 : SpeechRecognitionBubbleBase(web_contents), 339 : SpeechRecognitionBubbleBase(render_process_id, render_view_id),
340 delegate_(delegate), 340 delegate_(delegate),
341 bubble_(NULL), 341 bubble_(NULL),
342 element_rect_(element_rect) { 342 element_rect_(element_rect) {
343 } 343 }
344 344
345 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() { 345 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() {
346 if (bubble_) { 346 if (bubble_) {
347 bubble_->set_notify_delegate_on_activation_change(false); 347 bubble_->set_notify_delegate_on_activation_change(false);
348 bubble_->GetWidget()->Close(); 348 bubble_->GetWidget()->Close();
349 } 349 }
350 } 350 }
351 351
352 void SpeechRecognitionBubbleImpl::Show() { 352 void SpeechRecognitionBubbleImpl::Show() {
353 WebContents* web_contents = GetWebContents();
354 if (!web_contents)
355 return;
356
353 if (!bubble_) { 357 if (!bubble_) {
354 views::View* icon = NULL; 358 views::View* icon = NULL;
355 359
356 // Anchor to the location bar, in case |element_rect| is offscreen. 360 // Anchor to the location bar, in case |element_rect| is offscreen.
357 WebContents* web_contents = GetWebContents();
358 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 361 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
359 if (browser) { 362 if (browser) {
360 BrowserView* browser_view = 363 BrowserView* browser_view =
361 BrowserView::GetBrowserViewForBrowser(browser); 364 BrowserView::GetBrowserViewForBrowser(browser);
362 icon = browser_view->GetLocationBarView() ? 365 icon = browser_view->GetLocationBarView() ?
363 browser_view->GetLocationBarView()->GetLocationBarAnchor() : NULL; 366 browser_view->GetLocationBarView()->GetLocationBarAnchor() : NULL;
364 } 367 }
365 368
366 bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_, 369 bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_,
367 web_contents); 370 web_contents);
368 371
369 if (!icon) { 372 if (!icon) {
370 // We dont't have an icon to attach to. Manually specify the web contents 373 // We dont't have an icon to attach to. Manually specify the web contents
371 // window as the parent. 374 // window as the parent.
372 bubble_->set_parent_window( 375 bubble_->set_parent_window(
373 web_contents->GetView()->GetTopLevelNativeWindow()); 376 web_contents->GetView()->GetTopLevelNativeWindow());
374 } 377 }
375 378
376 views::BubbleDelegateView::CreateBubble(bubble_); 379 views::BubbleDelegateView::CreateBubble(bubble_);
377 UpdateLayout(); 380 UpdateLayout();
378 } 381 }
379 bubble_->GetWidget()->Show(); 382 bubble_->GetWidget()->Show();
380 } 383 }
381 384
382 void SpeechRecognitionBubbleImpl::Hide() { 385 void SpeechRecognitionBubbleImpl::Hide() {
383 if (bubble_) 386 WebContents* web_contents = GetWebContents();
387 if (bubble_ && web_contents)
Primiano Tucci (use gerrit) 2014/02/10 21:43:37 nit: You could fit all in one line, without the we
tommi (sloooow) - chröme 2014/02/10 22:32:53 +1 that also avoids calling GetWebContents if bubb
Tommy Widenflycht 2014/02/12 11:35:43 Done.
Tommy Widenflycht 2014/02/12 11:35:43 Done.
384 bubble_->GetWidget()->Hide(); 388 bubble_->GetWidget()->Hide();
385 } 389 }
386 390
387 void SpeechRecognitionBubbleImpl::UpdateLayout() { 391 void SpeechRecognitionBubbleImpl::UpdateLayout() {
388 if (bubble_) 392 WebContents* web_contents = GetWebContents();
393 if (bubble_ && web_contents)
389 bubble_->UpdateLayout(display_mode(), message_text(), icon_image()); 394 bubble_->UpdateLayout(display_mode(), message_text(), icon_image());
390 } 395 }
391 396
392 void SpeechRecognitionBubbleImpl::UpdateImage() { 397 void SpeechRecognitionBubbleImpl::UpdateImage() {
393 if (bubble_) 398 WebContents* web_contents = GetWebContents();
399 if (bubble_ && web_contents)
394 bubble_->SetImage(icon_image()); 400 bubble_->SetImage(icon_image());
395 } 401 }
396 402
397 } // namespace 403 } // namespace
398 404
399 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( 405 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
400 WebContents* web_contents, 406 int render_process_id, int render_view_id,
401 SpeechRecognitionBubble::Delegate* delegate, 407 SpeechRecognitionBubble::Delegate* delegate,
402 const gfx::Rect& element_rect) { 408 const gfx::Rect& element_rect) {
403 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); 409 return new SpeechRecognitionBubbleImpl(render_process_id, render_view_id,
410 delegate, element_rect);
404 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698