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

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: Review comments 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) {
128 WebContents* web_contents =
129 tab_util::GetWebContentsByID(render_process_id, render_view_id);
130
127 if (factory_) 131 if (factory_)
128 return (*factory_)(web_contents, delegate, element_rect); 132 return (*factory_)(web_contents, delegate, element_rect);
129 133
130 // Has the tab already closed before bubble create request was processed? 134 // Has the tab already closed before bubble create request was processed?
131 if (!web_contents) 135 if (!web_contents)
132 return NULL; 136 return NULL;
133 137
134 return CreateNativeBubble(web_contents, delegate, element_rect); 138 return CreateNativeBubble(render_process_id, render_view_id,
139 delegate, element_rect);
135 } 140 }
136 141
137 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( 142 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase(
138 WebContents* web_contents) 143 int render_process_id, int render_view_id)
139 : weak_factory_(this), 144 : weak_factory_(this),
140 animation_step_(0), 145 animation_step_(0),
141 display_mode_(DISPLAY_MODE_RECORDING), 146 display_mode_(DISPLAY_MODE_RECORDING),
142 web_contents_(web_contents), 147 render_process_id_(render_process_id),
148 render_view_id_(render_view_id),
143 scale_(1.0f) { 149 scale_(1.0f) {
150 WebContents* web_contents = GetWebContents();
144 gfx::NativeView view = 151 gfx::NativeView view =
145 web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL; 152 web_contents ? web_contents->GetView()->GetNativeView() : NULL;
146 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); 153 gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
147 gfx::Display display = screen->GetDisplayNearestWindow(view); 154 gfx::Display display = screen->GetDisplayNearestWindow(view);
148 scale_ = display.device_scale_factor(); 155 scale_ = display.device_scale_factor();
149 156
150 const gfx::ImageSkiaRep& rep = 157 const gfx::ImageSkiaRep& rep =
151 g_images.Get().mic_empty()->GetRepresentation(scale_); 158 g_images.Get().mic_empty()->GetRepresentation(scale_);
152 mic_image_.reset(new SkBitmap()); 159 mic_image_.reset(new SkBitmap());
153 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, 160 mic_image_->setConfig(SkBitmap::kARGB_8888_Config,
154 rep.pixel_width(), rep.pixel_height()); 161 rep.pixel_width(), rep.pixel_height());
155 mic_image_->allocPixels(); 162 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(), 263 g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(),
257 0, 0); 264 0, 0);
258 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); 265 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume);
259 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); 266 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume);
260 267
261 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_)); 268 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_));
262 SetImage(image); 269 SetImage(image);
263 } 270 }
264 271
265 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { 272 WebContents* SpeechRecognitionBubbleBase::GetWebContents() {
266 return web_contents_; 273 return tab_util::GetWebContentsByID(render_process_id_, render_view_id_);
267 } 274 }
268 275
269 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { 276 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) {
270 icon_image_ = image; 277 icon_image_ = image;
271 UpdateImage(); 278 UpdateImage();
272 } 279 }
273 280
274 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { 281 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() {
275 return icon_image_; 282 return icon_image_;
276 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698