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

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: 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 <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(WebContents* test_web_contents,
316 Delegate* delegate,
317 const gfx::Rect& element_rect);
318 SpeechRecognitionBubbleImpl(int render_process_id, int render_view_id,
316 Delegate* delegate, 319 Delegate* delegate,
317 const gfx::Rect& element_rect); 320 const gfx::Rect& element_rect);
318 virtual ~SpeechRecognitionBubbleImpl(); 321 virtual ~SpeechRecognitionBubbleImpl();
319 322
320 // SpeechRecognitionBubble methods. 323 // SpeechRecognitionBubble methods.
321 virtual void Show() OVERRIDE; 324 virtual void Show() OVERRIDE;
322 virtual void Hide() OVERRIDE; 325 virtual void Hide() OVERRIDE;
323 326
324 // SpeechRecognitionBubbleBase methods. 327 // SpeechRecognitionBubbleBase methods.
325 virtual void UpdateLayout() OVERRIDE; 328 virtual void UpdateLayout() OVERRIDE;
326 virtual void UpdateImage() OVERRIDE; 329 virtual void UpdateImage() OVERRIDE;
327 330
328 private: 331 private:
329 Delegate* delegate_; 332 Delegate* delegate_;
330 SpeechRecognitionBubbleView* bubble_; 333 SpeechRecognitionBubbleView* bubble_;
331 gfx::Rect element_rect_; 334 gfx::Rect element_rect_;
332 335
333 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleImpl); 336 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleImpl);
334 }; 337 };
335 338
336 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl( 339 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl(
337 WebContents* web_contents, Delegate* delegate, 340 WebContents* test_web_contents, Delegate* delegate,
338 const gfx::Rect& element_rect) 341 const gfx::Rect& element_rect)
339 : SpeechRecognitionBubbleBase(web_contents), 342 : SpeechRecognitionBubbleBase(test_web_contents),
340 delegate_(delegate), 343 delegate_(delegate),
341 bubble_(NULL), 344 bubble_(NULL),
342 element_rect_(element_rect) { 345 element_rect_(element_rect) {
346 }
347
348 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl(
349 int render_process_id, int render_view_id, Delegate* delegate,
350 const gfx::Rect& element_rect)
351 : SpeechRecognitionBubbleBase(render_process_id, render_view_id),
352 delegate_(delegate),
353 bubble_(NULL),
354 element_rect_(element_rect) {
343 } 355 }
344 356
345 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() { 357 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() {
346 if (bubble_) { 358 if (bubble_) {
347 bubble_->set_notify_delegate_on_activation_change(false); 359 bubble_->set_notify_delegate_on_activation_change(false);
348 bubble_->GetWidget()->Close(); 360 bubble_->GetWidget()->Close();
349 } 361 }
350 } 362 }
351 363
352 void SpeechRecognitionBubbleImpl::Show() { 364 void SpeechRecognitionBubbleImpl::Show() {
365 WebContents* web_contents = GetWebContents();
366 if (!web_contents)
367 return;
368
353 if (!bubble_) { 369 if (!bubble_) {
354 views::View* icon = NULL; 370 views::View* icon = NULL;
355 371
356 // Anchor to the location bar, in case |element_rect| is offscreen. 372 // Anchor to the location bar, in case |element_rect| is offscreen.
357 WebContents* web_contents = GetWebContents();
358 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 373 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
359 if (browser) { 374 if (browser) {
360 BrowserView* browser_view = 375 BrowserView* browser_view =
361 BrowserView::GetBrowserViewForBrowser(browser); 376 BrowserView::GetBrowserViewForBrowser(browser);
362 icon = browser_view->GetLocationBarView() ? 377 icon = browser_view->GetLocationBarView() ?
363 browser_view->GetLocationBarView()->GetLocationBarAnchor() : NULL; 378 browser_view->GetLocationBarView()->GetLocationBarAnchor() : NULL;
364 } 379 }
365 380
366 bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_, 381 bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_,
367 web_contents); 382 web_contents);
368 383
369 if (!icon) { 384 if (!icon) {
370 // We dont't have an icon to attach to. Manually specify the web contents 385 // We dont't have an icon to attach to. Manually specify the web contents
371 // window as the parent. 386 // window as the parent.
372 bubble_->set_parent_window( 387 bubble_->set_parent_window(
373 web_contents->GetView()->GetTopLevelNativeWindow()); 388 web_contents->GetView()->GetTopLevelNativeWindow());
374 } 389 }
375 390
376 views::BubbleDelegateView::CreateBubble(bubble_); 391 views::BubbleDelegateView::CreateBubble(bubble_);
377 UpdateLayout(); 392 UpdateLayout();
378 } 393 }
379 bubble_->GetWidget()->Show(); 394 bubble_->GetWidget()->Show();
380 } 395 }
381 396
382 void SpeechRecognitionBubbleImpl::Hide() { 397 void SpeechRecognitionBubbleImpl::Hide() {
383 if (bubble_) 398 if (bubble_ && GetWebContents())
384 bubble_->GetWidget()->Hide(); 399 bubble_->GetWidget()->Hide();
385 } 400 }
386 401
387 void SpeechRecognitionBubbleImpl::UpdateLayout() { 402 void SpeechRecognitionBubbleImpl::UpdateLayout() {
388 if (bubble_) 403 if (bubble_ && GetWebContents())
389 bubble_->UpdateLayout(display_mode(), message_text(), icon_image()); 404 bubble_->UpdateLayout(display_mode(), message_text(), icon_image());
390 } 405 }
391 406
392 void SpeechRecognitionBubbleImpl::UpdateImage() { 407 void SpeechRecognitionBubbleImpl::UpdateImage() {
393 if (bubble_) 408 if (bubble_ && GetWebContents())
394 bubble_->SetImage(icon_image()); 409 bubble_->SetImage(icon_image());
395 } 410 }
396 411
397 } // namespace 412 } // namespace
398 413
399 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( 414 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
400 WebContents* web_contents, 415 WebContents* test_web_contents,
401 SpeechRecognitionBubble::Delegate* delegate, 416 SpeechRecognitionBubble::Delegate* delegate,
402 const gfx::Rect& element_rect) { 417 const gfx::Rect& element_rect) {
403 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); 418 return new SpeechRecognitionBubbleImpl(test_web_contents, delegate,
419 element_rect);
404 } 420 }
421
422 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
423 int render_process_id, int render_view_id,
424 SpeechRecognitionBubble::Delegate* delegate,
425 const gfx::Rect& element_rect) {
426 return new SpeechRecognitionBubbleImpl(render_process_id, render_view_id,
427 delegate, element_rect);
428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698