Commit 32392e97 authored by jam@chromium.org's avatar jam@chromium.org

Fix the browser windows from going in a loop trying to steal focus from each...

Fix the browser windows from going in a loop trying to steal focus from each other when activating a differnet window from the one that has a modal dialog. Instead, activate it in a posttask.

BUG=141650
Review URL: https://chromiumcodereview.appspot.com/10826253

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151211 0039d316-1c4b-4281-b951-d872f2087c98
parent 3a64694f
......@@ -30,11 +30,13 @@
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/speech/extension_api/tts_extension_api.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window_state.h"
......@@ -330,7 +332,8 @@ BrowserView::BrowserView(Browser* browser)
ticker_(0),
#endif
force_location_bar_focus_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)) {
ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) {
browser_->tab_strip_model()->AddObserver(this);
}
......@@ -514,20 +517,6 @@ bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
return false;
}
bool BrowserView::ActivateAppModalDialog() const {
// If another browser is app modal, flash and activate the modal browser.
if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) {
Browser* active_browser = BrowserList::GetLastActive();
if (active_browser && (browser_ != active_browser)) {
active_browser->window()->FlashFrame(true);
active_browser->window()->Activate();
}
AppModalDialogQueue::GetInstance()->ActivateModalDialog();
return true;
}
return false;
}
WebContents* BrowserView::GetActiveWebContents() const {
return chrome::GetActiveWebContents(browser_.get());
}
......@@ -1494,7 +1483,18 @@ bool BrowserView::CanMaximize() const {
}
bool BrowserView::CanActivate() const {
return !ActivateAppModalDialog();
if (!AppModalDialogQueue::GetInstance()->active_dialog())
return true;
// If another browser is app modal, flash and activate the modal browser. This
// has to be done in a post task, otherwise if the user clicked on a window
// that doesn't have the modal dialog the windows keep trying to get the focus
// from each other on Windows. http://crbug.com/141650.
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&BrowserView::ActivateAppModalDialog,
activate_modal_dialog_factory_.GetWeakPtr()));
return false;
}
string16 BrowserView::GetWindowTitle() const {
......@@ -2593,3 +2593,20 @@ bool BrowserView::DoCutCopyPaste(void (content::RenderWidgetHost::*method)()) {
#endif
return false;
}
void BrowserView::ActivateAppModalDialog() const {
// If another browser is app modal, flash and activate the modal browser.
AppModalDialog* active_dialog =
AppModalDialogQueue::GetInstance()->active_dialog();
if (!active_dialog)
return;
Browser* modal_browser =
browser::FindBrowserWithWebContents(active_dialog->web_contents());
if (modal_browser && (browser_ != modal_browser)) {
modal_browser->window()->FlashFrame(true);
modal_browser->window()->Activate();
}
AppModalDialogQueue::GetInstance()->ActivateModalDialog();
}
......@@ -176,11 +176,6 @@ class BrowserView : public BrowserWindow,
// otherwise.
bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
// Shows the next app-modal dialog box, if there is one to be shown, or moves
// an existing showing one to the front. Returns true if one was shown or
// activated, false if none was shown.
bool ActivateAppModalDialog() const;
// Returns the selected WebContents/TabContents. Used by our
// NonClientView's TabIconView::TabContentsProvider implementations.
// TODO(beng): exposing this here is a bit bogus, since it's only used to
......@@ -562,6 +557,10 @@ class BrowserView : public BrowserWindow,
// and returns true if the focus is currently on a WebContent.
bool DoCutCopyPaste(void (content::RenderWidgetHost::*method)());
// Shows the next app-modal dialog box, if there is one to be shown, or moves
// an existing showing one to the front.
void ActivateAppModalDialog() const;
// Last focused view that issued a tab traversal.
int last_focused_view_storage_id_;
......@@ -715,6 +714,8 @@ class BrowserView : public BrowserWindow,
scoped_ptr<SearchViewController> search_view_controller_;
#endif
mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserView);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment