Skip to content

Commit

Permalink
Don't activate tabs showing tab modal dialogs.
Browse files Browse the repository at this point in the history
BUG=768475,768900,769351
TEST=as in bugs

Change-Id: I1fb3244db8883e059e927e84ecca09dd3591f75d
Reviewed-on: https://chromium-review.googlesource.com/687811
Reviewed-by: Mike Wittman <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Sidney San Martín <[email protected]>
Commit-Queue: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#512585}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Oct 30, 2017
1 parent 0626323 commit 7154fd0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 45 deletions.
44 changes: 0 additions & 44 deletions chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,50 +831,6 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
ASSERT_EQ(popup_browser, chrome::FindLastActive());
}

IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderViaHTTPAuth) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
GURL url(
embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html"));
HostContentSettingsMapFactory::GetForProfile(browser()->profile())
->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), CONTENT_SETTING_ALLOW);

NavigateAndCheckPopupShown(url, ExpectPopup);

Browser* popup_browser = chrome::FindLastActive();
ASSERT_NE(popup_browser, browser());

// Showing an http auth dialog will raise the tab over the popup.
LoginPromptBrowserTestObserver observer;
content::NavigationController* controller = &tab->GetController();
observer.Register(content::Source<content::NavigationController>(controller));
{
#if !defined(OS_MACOSX)
// Mac doesn't activate the browser during modal dialogs, see
// https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter raised_waiter(browser());
#endif
WindowedAuthNeededObserver auth_needed_observer(controller);
tab->GetMainFrame()->ExecuteJavaScriptForTests(
base::UTF8ToUTF16("var f = document.createElement('iframe'); f.src = "
"'/auth-basic'; document.body.appendChild(f);"));
auth_needed_observer.Wait();
ASSERT_FALSE(observer.handlers().empty());
#if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser())
raised_waiter.WaitForActivation();
#endif
}

{
ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
LoginHandler* handler = *observer.handlers().begin();
handler->CancelAuth();
waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive());
}
}

// Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab.
IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class WebContentsModalDialogHostCocoa
// web_modal::ModalDialogHost:
gfx::NativeView GetHostView() const override;
gfx::Point GetDialogPosition(const gfx::Size& size) override;
bool ShouldActivateDialog() const override;
void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
return gfx::Point();
}

bool WebContentsModalDialogHostCocoa::ShouldActivateDialog() const {
return [[sheet_controller_ parentWindow] isMainWindow];
}

void WebContentsModalDialogHostCocoa::AddObserver(
web_modal::ModalDialogHostObserver* observer) {
NOTREACHED();
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/views/frame/browser_view_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class BrowserViewLayout::WebContentsModalDialogHostViews
return gfx::Point(middle_x - size.width() / 2, top);
}

bool ShouldActivateDialog() const override {
views::Widget* widget = browser_view_layout_->browser_view_->GetWidget();
return widget->IsActive();
}

gfx::Size GetMaximumDialogSize() override {
views::View* view = browser_view_layout_->contents_container_;
gfx::Rect content_area = view->ConvertRectToWidget(view->GetLocalBounds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void NativeWebContentsModalDialogManagerViews::Show() {
}
#endif
ShowWidget(widget);
Focus();
if (host_->ShouldActivateDialog())
Focus();

#if defined(USE_AURA)
// TODO(pkotwicz): Control the z-order of the constrained dialog via
Expand Down
4 changes: 4 additions & 0 deletions components/web_modal/modal_dialog_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ ModalDialogHostObserver::~ModalDialogHostObserver() {
ModalDialogHost::~ModalDialogHost() {
}

bool ModalDialogHost::ShouldActivateDialog() const {
return true;
}

} // namespace web_modal
2 changes: 2 additions & 0 deletions components/web_modal/modal_dialog_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ModalDialogHost {
virtual gfx::NativeView GetHostView() const = 0;
// Gets the position for the dialog in coordinates relative to the host view.
virtual gfx::Point GetDialogPosition(const gfx::Size& size) = 0;
// Returns whether a dialog currently about to be shown should be activated.
virtual bool ShouldActivateDialog() const;

// Add/remove observer.
virtual void AddObserver(ModalDialogHostObserver* observer) = 0;
Expand Down

0 comments on commit 7154fd0

Please sign in to comment.