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

Side by Side Diff: chrome/browser/speech/speech_recognition_bubble.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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_view.h" 12 #include "content/public/browser/web_contents_view.h"
12 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
17 #include "ui/gfx/image/image_skia_operations.h" 18 #include "ui/gfx/image/image_skia_operations.h"
18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
19 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 116
116 base::LazyInstance<SpeechRecognitionBubbleImages> g_images = 117 base::LazyInstance<SpeechRecognitionBubbleImages> g_images =
117 LAZY_INSTANCE_INITIALIZER; 118 LAZY_INSTANCE_INITIALIZER;
118 119
119 } // namespace 120 } // namespace
120 121
121 SpeechRecognitionBubble::FactoryMethod SpeechRecognitionBubble::factory_ = NULL; 122 SpeechRecognitionBubble::FactoryMethod SpeechRecognitionBubble::factory_ = NULL;
122 const int SpeechRecognitionBubble::kBubbleTargetOffsetX = 10; 123 const int SpeechRecognitionBubble::kBubbleTargetOffsetX = 10;
123 124
124 SpeechRecognitionBubble* SpeechRecognitionBubble::Create( 125 SpeechRecognitionBubble* SpeechRecognitionBubble::Create(
125 WebContents* web_contents, Delegate* delegate, 126 int render_process_id, int render_view_id, Delegate* delegate,
126 const gfx::Rect& element_rect) { 127 const gfx::Rect& element_rect) {
127 if (factory_) 128
128 return (*factory_)(web_contents, delegate, element_rect); 129 WebContents* web_contents =
130 tab_util::GetWebContentsByID(render_process_id, render_view_id);
129 131
130 // Has the tab already closed before bubble create request was processed? 132 // Has the tab already closed before bubble create request was processed?
131 if (!web_contents) 133 if (!web_contents)
132 return NULL; 134 return NULL;
133 135
134 return CreateNativeBubble(web_contents, delegate, element_rect); 136 if (factory_)
137 return (*factory_)(web_contents, delegate, element_rect);
138
139 return CreateNativeBubble(render_process_id, render_view_id,
140 delegate, element_rect);
135 } 141 }
136 142
137 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( 143 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase(
138 WebContents* web_contents) 144 int render_process_id, int render_view_id)
139 : weak_factory_(this), 145 : weak_factory_(this),
140 animation_step_(0), 146 animation_step_(0),
141 display_mode_(DISPLAY_MODE_RECORDING), 147 display_mode_(DISPLAY_MODE_RECORDING),
142 web_contents_(web_contents), 148 render_process_id_(render_process_id),
149 render_view_id_(render_view_id),
143 scale_(1.0f) { 150 scale_(1.0f) {
151 WebContents* web_contents = GetWebContents();
152 DCHECK(web_contents);
tommi (sloooow) - chröme 2014/02/10 22:32:53 nit: since you check web_contents immediately afte
144 gfx::NativeView view = 153 gfx::NativeView view =
145 web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL; 154 web_contents ? web_contents->GetView()->GetNativeView() : NULL;
146 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); 155 gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
147 gfx::Display display = screen->GetDisplayNearestWindow(view); 156 gfx::Display display = screen->GetDisplayNearestWindow(view);
148 scale_ = display.device_scale_factor(); 157 scale_ = display.device_scale_factor();
149 158
150 const gfx::ImageSkiaRep& rep = 159 const gfx::ImageSkiaRep& rep =
151 g_images.Get().mic_empty()->GetRepresentation(scale_); 160 g_images.Get().mic_empty()->GetRepresentation(scale_);
152 mic_image_.reset(new SkBitmap()); 161 mic_image_.reset(new SkBitmap());
153 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, 162 mic_image_->setConfig(SkBitmap::kARGB_8888_Config,
154 rep.pixel_width(), rep.pixel_height()); 163 rep.pixel_width(), rep.pixel_height());
155 mic_image_->allocPixels(); 164 mic_image_->allocPixels();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(), 265 g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(),
257 0, 0); 266 0, 0);
258 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); 267 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume);
259 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); 268 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume);
260 269
261 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_)); 270 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_));
262 SetImage(image); 271 SetImage(image);
263 } 272 }
264 273
265 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { 274 WebContents* SpeechRecognitionBubbleBase::GetWebContents() {
266 return web_contents_; 275 return tab_util::GetWebContentsByID(render_process_id_, render_view_id_);
267 } 276 }
268 277
269 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { 278 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) {
270 icon_image_ = image; 279 icon_image_ = image;
271 UpdateImage(); 280 UpdateImage();
272 } 281 }
273 282
274 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { 283 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() {
275 return icon_image_; 284 return icon_image_;
276 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698