diff options
Diffstat (limited to 'chrome/browser/speech')
5 files changed, 59 insertions, 37 deletions
diff --git a/chrome/browser/speech/speech_recognition_bubble.cc b/chrome/browser/speech/speech_recognition_bubble.cc index fa31bb3..7e4dea4 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,11 @@ SpeechRecognitionBubble::FactoryMethod SpeechRecognitionBubble::factory_ = NULL; const int SpeechRecognitionBubble::kBubbleTargetOffsetX = 10; SpeechRecognitionBubble* SpeechRecognitionBubble::Create( - WebContents* web_contents, Delegate* delegate, + 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 +135,21 @@ 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) + int render_process_id, int render_view_id) : weak_factory_(this), animation_step_(0), display_mode_(DISPLAY_MODE_RECORDING), - web_contents_(web_contents), + render_process_id_(render_process_id), + render_view_id_(render_view_id), scale_(1.0f) { + 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(); @@ -263,7 +270,7 @@ void SpeechRecognitionBubbleBase::SetInputVolume(float volume, } WebContents* SpeechRecognitionBubbleBase::GetWebContents() { - return web_contents_; + return tab_util::GetWebContentsByID(render_process_id_, render_view_id_); } void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { diff --git a/chrome/browser/speech/speech_recognition_bubble.h b/chrome/browser/speech/speech_recognition_bubble.h index 6ca5a73..96a805e 100644 --- a/chrome/browser/speech/speech_recognition_bubble.h +++ b/chrome/browser/speech/speech_recognition_bubble.h @@ -57,17 +57,21 @@ class SpeechRecognitionBubble { // Factory method to create new instances. // Creates the bubble, call |Show| to display it on screen. - // |web_contents| is the WebContents hosting the page. + // |render_process_id| and |render_view_id| is used to extract the + // correct WebContents. // |element_rect| is the display bounds of the html element requesting speech // recognition (in page coordinates). - static SpeechRecognitionBubble* Create(content::WebContents* web_contents, - Delegate* delegate, - const gfx::Rect& element_rect); + static SpeechRecognitionBubble* Create( + int render_process_id, + int render_view_id, + Delegate* delegate, + const gfx::Rect& element_rect); // This is implemented by platform specific code to create the underlying // bubble window. Not to be called directly by users of this class. static SpeechRecognitionBubble* CreateNativeBubble( - content::WebContents* web_contents, + int render_process_id, + int render_view_id, Delegate* delegate, const gfx::Rect& element_rect); @@ -135,7 +139,7 @@ class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble { DISPLAY_MODE_MESSAGE }; - explicit SpeechRecognitionBubbleBase(content::WebContents* web_contents); + SpeechRecognitionBubbleBase(int render_process_id, int render_view_id); virtual ~SpeechRecognitionBubbleBase(); // SpeechRecognitionBubble methods @@ -179,8 +183,11 @@ class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble { scoped_ptr<SkBitmap> mic_image_; // A temporary buffer image used in creating the above mic image. scoped_ptr<SkBitmap> buffer_image_; - // WebContents in which this this bubble gets displayed. - content::WebContents* web_contents_; + + // Content in which this bubble gets displayed. + int render_process_id_; + int render_view_id_; + // The current image displayed in the bubble's icon widget. gfx::ImageSkia icon_image_; // The scale factor used for the web-contents. diff --git a/chrome/browser/speech/speech_recognition_bubble_browsertest.cc b/chrome/browser/speech/speech_recognition_bubble_browsertest.cc index edc5160..dcb35f4 100644 --- a/chrome/browser/speech/speech_recognition_bubble_browsertest.cc +++ b/chrome/browser/speech/speech_recognition_bubble_browsertest.cc @@ -7,6 +7,9 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/test/base/in_process_browser_test.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/rect.h" @@ -24,26 +27,35 @@ class SpeechRecognitionBubbleTest : public SpeechRecognitionBubbleDelegate, IN_PROC_BROWSER_TEST_F(SpeechRecognitionBubbleTest, CreateAndDestroy) { gfx::Rect element_rect(100, 100, 100, 100); + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); scoped_ptr<SpeechRecognitionBubble> bubble(SpeechRecognitionBubble::Create( - browser()->tab_strip_model()->GetActiveWebContents(), - this, element_rect)); + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID(), + this, element_rect)); EXPECT_TRUE(bubble.get()); } IN_PROC_BROWSER_TEST_F(SpeechRecognitionBubbleTest, ShowAndDestroy) { gfx::Rect element_rect(100, 100, 100, 100); + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); scoped_ptr<SpeechRecognitionBubble> bubble(SpeechRecognitionBubble::Create( - browser()->tab_strip_model()->GetActiveWebContents(), - this, element_rect)); + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID(), + this, element_rect)); EXPECT_TRUE(bubble.get()); bubble->Show(); } IN_PROC_BROWSER_TEST_F(SpeechRecognitionBubbleTest, ShowAndHide) { gfx::Rect element_rect(100, 100, 100, 100); + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); scoped_ptr<SpeechRecognitionBubble> bubble(SpeechRecognitionBubble::Create( - browser()->tab_strip_model()->GetActiveWebContents(), - this, element_rect)); + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID(), + this, element_rect)); EXPECT_TRUE(bubble.get()); bubble->Show(); bubble->Hide(); @@ -51,9 +63,12 @@ IN_PROC_BROWSER_TEST_F(SpeechRecognitionBubbleTest, ShowAndHide) { IN_PROC_BROWSER_TEST_F(SpeechRecognitionBubbleTest, ShowAndHideTwice) { gfx::Rect element_rect(100, 100, 100, 100); + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); scoped_ptr<SpeechRecognitionBubble> bubble(SpeechRecognitionBubble::Create( - browser()->tab_strip_model()->GetActiveWebContents(), - this, element_rect)); + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID(), + this, element_rect)); EXPECT_TRUE(bubble.get()); bubble->Show(); bubble->Hide(); diff --git a/chrome/browser/speech/speech_recognition_bubble_controller.cc b/chrome/browser/speech/speech_recognition_bubble_controller.cc index ff7aadd..ede3858 100644 --- a/chrome/browser/speech/speech_recognition_bubble_controller.cc +++ b/chrome/browser/speech/speech_recognition_bubble_controller.cc @@ -168,8 +168,7 @@ void SpeechRecognitionBubbleController::ProcessRequestInUiThread( switch (request.type) { case REQUEST_CREATE: bubble_.reset(SpeechRecognitionBubble::Create( - tab_util::GetWebContentsByID(request.render_process_id, - request.render_view_id), + request.render_process_id, request.render_view_id, this, request.element_rect)); if (!bubble_.get()) { diff --git a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc index f1380c9..8e4f0c9 100644 --- a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc +++ b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc @@ -11,10 +11,13 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/testing_profile.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/rect.h" + using content::BrowserThread; using content::WebContents; @@ -30,10 +33,9 @@ class MockSpeechRecognitionBubble : public SpeechRecognitionBubbleBase { BUBBLE_TEST_CLICK_TRY_AGAIN, }; - MockSpeechRecognitionBubble(WebContents* web_contents, - Delegate* delegate, - const gfx::Rect&) - : SpeechRecognitionBubbleBase(web_contents) { + MockSpeechRecognitionBubble(int render_process_id, int render_view_id, + Delegate* delegate, const gfx::Rect&) + : SpeechRecognitionBubbleBase(render_process_id, render_view_id) { VLOG(1) << "MockSpeechRecognitionBubble created"; base::MessageLoop::current()->PostTask( FROM_HERE, base::Bind(&InvokeDelegate, delegate)); @@ -141,15 +143,7 @@ class SpeechRecognitionBubbleControllerTest base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&ActivateBubble)); - // The |web_contents| parameter would be NULL since the dummy session id - // passed to CreateBubble would not have matched any active tab. So get a - // real WebContents pointer from the test fixture and pass that, because - // the bubble controller registers for tab close notifications which need - // a valid WebContents. - web_contents = - test_fixture_->browser()->tab_strip_model()->GetActiveWebContents(); - return new MockSpeechRecognitionBubble(web_contents, delegate, - element_rect); + return new MockSpeechRecognitionBubble(0, 0, delegate, element_rect); } protected: |