Index: chrome/browser/speech/speech_recognition_bubble.cc |
diff --git a/chrome/browser/speech/speech_recognition_bubble.cc b/chrome/browser/speech/speech_recognition_bubble.cc |
index fa31bb322848043705e75c4cbef3ec230403fd46..533f1f971aff58369b167aec3171e5e8895e964e 100644 |
--- a/chrome/browser/speech/speech_recognition_bubble.cc |
+++ b/chrome/browser/speech/speech_recognition_bubble.cc |
@@ -7,6 +7,7 @@ |
#include "base/bind.h" |
#include "base/lazy_instance.h" |
#include "base/message_loop/message_loop.h" |
+#include "chrome/browser/tab_contents/tab_util.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_view.h" |
#include "grit/generated_resources.h" |
@@ -122,8 +123,22 @@ SpeechRecognitionBubble::FactoryMethod SpeechRecognitionBubble::factory_ = NULL; |
const int SpeechRecognitionBubble::kBubbleTargetOffsetX = 10; |
SpeechRecognitionBubble* SpeechRecognitionBubble::Create( |
- WebContents* web_contents, Delegate* delegate, |
+ WebContents* test_web_contents, |
+ Delegate* delegate, |
const gfx::Rect& element_rect) { |
+ // Has the tab already closed before bubble create request was processed? |
+ if (!test_web_contents) |
+ return NULL; |
+ |
+ return CreateNativeBubble(test_web_contents, delegate, element_rect); |
+} |
+ |
+SpeechRecognitionBubble* SpeechRecognitionBubble::Create( |
+ int render_process_id, int render_view_id, Delegate* delegate, |
+ const gfx::Rect& element_rect) { |
+ WebContents* web_contents = |
+ tab_util::GetWebContentsByID(render_process_id, render_view_id); |
+ |
if (factory_) |
return (*factory_)(web_contents, delegate, element_rect); |
@@ -131,18 +146,44 @@ SpeechRecognitionBubble* SpeechRecognitionBubble::Create( |
if (!web_contents) |
return NULL; |
- return CreateNativeBubble(web_contents, delegate, element_rect); |
+ return CreateNativeBubble(render_process_id, render_view_id, |
+ delegate, element_rect); |
} |
SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( |
- WebContents* web_contents) |
+ WebContents* test_web_contents) |
+ : weak_factory_(this), |
+ animation_step_(0), |
+ display_mode_(DISPLAY_MODE_RECORDING), |
+ test_web_contents_(test_web_contents), |
+ render_process_id_(-1), |
+ render_view_id_(-1), |
+ scale_(1.0f) { |
+ Initialize(); |
+ } |
+ |
+SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( |
+ int render_process_id, int render_view_id) |
: weak_factory_(this), |
animation_step_(0), |
display_mode_(DISPLAY_MODE_RECORDING), |
- web_contents_(web_contents), |
+ test_web_contents_(NULL), |
+ render_process_id_(render_process_id), |
+ render_view_id_(render_view_id), |
scale_(1.0f) { |
+ Initialize(); |
+} |
+ |
+SpeechRecognitionBubbleBase::~SpeechRecognitionBubbleBase() { |
+ // This destructor is added to make sure members such as the scoped_ptr |
+ // get destroyed here and the derived classes don't have to care about such |
+ // member variables which they don't use. |
+} |
+ |
+void SpeechRecognitionBubbleBase::Initialize() { |
+ WebContents* web_contents = GetWebContents(); |
gfx::NativeView view = |
- web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL; |
+ web_contents ? web_contents->GetView()->GetNativeView() : NULL; |
gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
gfx::Display display = screen->GetDisplayNearestWindow(view); |
scale_ = display.device_scale_factor(); |
@@ -160,12 +201,6 @@ SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( |
buffer_image_->allocPixels(); |
} |
-SpeechRecognitionBubbleBase::~SpeechRecognitionBubbleBase() { |
- // This destructor is added to make sure members such as the scoped_ptr |
- // get destroyed here and the derived classes don't have to care about such |
- // member variables which they don't use. |
-} |
- |
void SpeechRecognitionBubbleBase::SetWarmUpMode() { |
weak_factory_.InvalidateWeakPtrs(); |
display_mode_ = DISPLAY_MODE_WARM_UP; |
@@ -263,7 +298,9 @@ void SpeechRecognitionBubbleBase::SetInputVolume(float volume, |
} |
WebContents* SpeechRecognitionBubbleBase::GetWebContents() { |
- return web_contents_; |
+ if (test_web_contents_) |
+ return test_web_contents_; |
+ return tab_util::GetWebContentsByID(render_process_id_, render_view_id_); |
} |
void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { |