From 3a1ebba4426fd0206d63988b0d037b5d746bb5d6 Mon Sep 17 00:00:00 2001 From: Garrett Casto Date: Tue, 6 Jan 2015 14:00:24 -0800 Subject: Merge to branch 2214 [Password Generation] Hide popup if view can not be created. Fixes a crash. BUG=439618 Review URL: https://codereview.chromium.org/811563004 Cr-Commit-Position: refs/heads/master@{#309323} (cherry picked from commit 978e1ba2dcd2e4b7667b8831b2784b466ea28c87) Review URL: https://codereview.chromium.org/842503002 Cr-Commit-Position: refs/branch-heads/2214@{#390} Cr-Branched-From: 03655fd3f6d72165dc3c9bd2c89807305316fe6c-refs/heads/master@{#303346} --- .../password_generation_popup_controller_impl.cc | 7 +++++++ .../password_generation_popup_view_browsertest.cc | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc b/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc index 05f7f98..07d6da0 100644 --- a/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc +++ b/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc @@ -182,6 +182,13 @@ void PasswordGenerationPopupControllerImpl::Show(bool display_password) { if (!view_) { view_ = PasswordGenerationPopupView::Create(this); + + // Treat popup as being hidden if creation fails. + if (!view_) { + Hide(); + return; + } + CalculateBounds(); view_->Show(); } else { diff --git a/chrome/browser/ui/autofill/password_generation_popup_view_browsertest.cc b/chrome/browser/ui/autofill/password_generation_popup_view_browsertest.cc index 67bcc37..21c74ad 100644 --- a/chrome/browser/ui/autofill/password_generation_popup_view_browsertest.cc +++ b/chrome/browser/ui/autofill/password_generation_popup_view_browsertest.cc @@ -39,13 +39,12 @@ class TestPasswordGenerationPopupController : class PasswordGenerationPopupViewTest : public InProcessBrowserTest { public: - void SetUpOnMainThread() override { - gfx::NativeView native_view = - browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView(); + content::WebContents* GetWebContents() { + return browser()->tab_strip_model()->GetActiveWebContents(); + } - controller_ = - new TestPasswordGenerationPopupController( - browser()->tab_strip_model()->GetActiveWebContents(), native_view); + gfx::NativeView GetNativeView() { + return GetWebContents()->GetNativeView(); } scoped_ptr GetViewTester() { @@ -62,6 +61,8 @@ class PasswordGenerationPopupViewTest : public InProcessBrowserTest { // editing dialog doesn't crash. IN_PROC_BROWSER_TEST_F(PasswordGenerationPopupViewTest, MouseMovementInEditingPopup) { + controller_ = new autofill::TestPasswordGenerationPopupController( + GetWebContents(), GetNativeView()); controller_->Show(false /* display_password */); gfx::Point center_point = @@ -72,6 +73,15 @@ IN_PROC_BROWSER_TEST_F(PasswordGenerationPopupViewTest, // Deletes |controller_|. controller_->HideAndDestroy(); } + +// Verify that we calling Show() with an invalid container does not crash. +// Regression test for crbug.com/439618. +IN_PROC_BROWSER_TEST_F(PasswordGenerationPopupViewTest, + InvalidContainerView) { + controller_ = new autofill::TestPasswordGenerationPopupController( + GetWebContents(), NULL); + controller_->Show(true /* display password */); +} #endif } // namespace autofill -- cgit v1.1