diff options
-rw-r--r-- | chrome/browser/app_modal_dialog_delegate.h | 36 | ||||
-rw-r--r-- | chrome/browser/app_modal_dialog_queue.cc | 12 | ||||
-rw-r--r-- | chrome/browser/app_modal_dialog_queue.h | 14 | ||||
-rw-r--r-- | chrome/browser/app_modal_dialog_queue_unittest.cc | 45 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 29 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 4 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler_win.cc | 68 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler_win.h | 21 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 4 | ||||
-rw-r--r-- | chrome/views/app_modal_dialog_delegate.h | 25 | ||||
-rw-r--r-- | chrome/views/views.vcproj | 4 |
11 files changed, 171 insertions, 91 deletions
diff --git a/chrome/browser/app_modal_dialog_delegate.h b/chrome/browser/app_modal_dialog_delegate.h new file mode 100644 index 0000000..0bb546f --- /dev/null +++ b/chrome/browser/app_modal_dialog_delegate.h @@ -0,0 +1,36 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_APP_MODAL_DIALOG_DELEGATE_H_ +#define CHROME_BROWSER_APP_MODAL_DIALOG_DELEGATE_H_ + +#if defined(OS_WIN) +namespace views { +class DialogDelegate; +} +#endif + +class AppModalDialogDelegateTesting { + public: +#if defined(OS_WIN) + virtual views::DialogDelegate* GetDialogDelegate() = 0; +#endif +}; + +// Pure virtual interface for a window which is app modal. +class AppModalDialogDelegate { + public: + // Called by the app modal window queue when it is time to show this window. + virtual void ShowModalDialog() = 0; + + // Called by the app modal window queue to activate the window. + virtual void ActivateModalDialog() = 0; + + // Returns the interface used to control this dialog from testing. Should + // only be used in testing code. + virtual AppModalDialogDelegateTesting* GetTestingInterface() = 0; +}; + +#endif // #ifndef CHROME_BROWSER_APP_MODAL_DIALOG_DELEGATE_H_ + diff --git a/chrome/browser/app_modal_dialog_queue.cc b/chrome/browser/app_modal_dialog_queue.cc index 6646bbc..0fd5dfb 100644 --- a/chrome/browser/app_modal_dialog_queue.cc +++ b/chrome/browser/app_modal_dialog_queue.cc @@ -7,15 +7,14 @@ #include "chrome/browser/browser_list.h" // static -std::queue<views::AppModalDialogDelegate*>* +std::queue<AppModalDialogDelegate*>* AppModalDialogQueue::app_modal_dialog_queue_ = NULL; -views::AppModalDialogDelegate* AppModalDialogQueue::active_dialog_ = NULL; +AppModalDialogDelegate* AppModalDialogQueue::active_dialog_ = NULL; // static -void AppModalDialogQueue::AddDialog(views::AppModalDialogDelegate* dialog) { - DCHECK(dialog->IsModal()); +void AppModalDialogQueue::AddDialog(AppModalDialogDelegate* dialog) { if (!app_modal_dialog_queue_) { - app_modal_dialog_queue_ = new std::queue<views::AppModalDialogDelegate*>; + app_modal_dialog_queue_ = new std::queue<AppModalDialogDelegate*>; ShowModalDialog(dialog); } @@ -41,8 +40,7 @@ void AppModalDialogQueue::ActivateModalDialog() { } // static -void AppModalDialogQueue::ShowModalDialog( - views::AppModalDialogDelegate* dialog) { +void AppModalDialogQueue::ShowModalDialog(AppModalDialogDelegate* dialog) { dialog->ShowModalDialog(); active_dialog_ = dialog; } diff --git a/chrome/browser/app_modal_dialog_queue.h b/chrome/browser/app_modal_dialog_queue.h index ff1b5f5..9101c2e2 100644 --- a/chrome/browser/app_modal_dialog_queue.h +++ b/chrome/browser/app_modal_dialog_queue.h @@ -7,7 +7,7 @@ #include <queue> -#include "chrome/views/app_modal_dialog_delegate.h" +#include "chrome/browser/app_modal_dialog_delegate.h" // Keeps a queue of AppModalDialogDelegates, making sure only one app modal // dialog is shown at a time. @@ -23,7 +23,7 @@ class AppModalDialogQueue { // sloppy app modality. // Note: The AppModalDialogDelegate |dialog| must be window modal before it // can be added as app modal. - static void AddDialog(views::AppModalDialogDelegate* dialog); + static void AddDialog(AppModalDialogDelegate* dialog); // Removes the current dialog in the queue (the one that is being shown). // Shows the next dialog in the queue, if any is present. This does not @@ -45,22 +45,20 @@ class AppModalDialogQueue { } // Accessor for |active_dialog_|. - static views::AppModalDialogDelegate* active_dialog() { - return active_dialog_; - } + static AppModalDialogDelegate* active_dialog() { return active_dialog_; } private: // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. - static void ShowModalDialog(views::AppModalDialogDelegate* dialog); + static void ShowModalDialog(AppModalDialogDelegate* dialog); // Contains all app modal dialogs which are waiting to be shown, with the // currently modal dialog at the front of the queue. - static std::queue<views::AppModalDialogDelegate*>* + static std::queue<AppModalDialogDelegate*>* app_modal_dialog_queue_; // The currently active app-modal dialog box's delegate. NULL if there is no // active app-modal dialog box. - static views::AppModalDialogDelegate* active_dialog_; + static AppModalDialogDelegate* active_dialog_; }; #endif // CHROME_BROWSER_APP_MODAL_DIALOG_QUEUE_H__ diff --git a/chrome/browser/app_modal_dialog_queue_unittest.cc b/chrome/browser/app_modal_dialog_queue_unittest.cc new file mode 100644 index 0000000..6d7210b --- /dev/null +++ b/chrome/browser/app_modal_dialog_queue_unittest.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/basictypes.h" +#include "chrome/browser/app_modal_dialog_delegate.h" +#include "chrome/browser/app_modal_dialog_queue.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class TestModalDialogDelegate : public AppModalDialogDelegate { + public: + TestModalDialogDelegate() {} + virtual ~TestModalDialogDelegate() {} + + // Overridden from AppModalDialogDelegate: + virtual void ShowModalDialog() {} + virtual void ActivateModalDialog() {} + virtual AppModalDialogDelegateTesting* GetTestingInterface() { return NULL; } + + private: + DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate); +}; + +} // namespace + +TEST(AppModalDialogQueueTest, MultipleDialogTest) { + TestModalDialogDelegate modal_dialog1, modal_dialog2; + AppModalDialogQueue::AddDialog(&modal_dialog1); + AppModalDialogQueue::AddDialog(&modal_dialog2); + + EXPECT_TRUE(AppModalDialogQueue::HasActiveDialog()); + EXPECT_EQ(&modal_dialog1, AppModalDialogQueue::active_dialog()); + + AppModalDialogQueue::ShowNextDialog(); + + EXPECT_TRUE(AppModalDialogQueue::HasActiveDialog()); + EXPECT_EQ(&modal_dialog2, AppModalDialogQueue::active_dialog()); + + AppModalDialogQueue::ShowNextDialog(); + + EXPECT_FALSE(AppModalDialogQueue::HasActiveDialog()); + EXPECT_EQ(NULL, AppModalDialogQueue::active_dialog()); +} diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index d5a13d1..29e59b4 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -8,6 +8,7 @@ #include "base/path_service.h" #include "base/thread.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/app_modal_dialog_delegate.h" #include "chrome/browser/app_modal_dialog_queue.h" #include "chrome/browser/automation/automation_provider_list.h" #include "chrome/browser/automation/ui_controls.h" @@ -33,7 +34,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/pref_service.h" -#include "chrome/views/app_modal_dialog_delegate.h" +#include "chrome/views/dialog_delegate.h" #include "chrome/views/window.h" #include "chrome/test/automation/automation_messages.h" #include "net/base/cookie_monster.h" @@ -1162,22 +1163,26 @@ void AutomationProvider::GetBrowserWindowCount(int* window_count) { void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button) { - views::AppModalDialogDelegate* dialog_delegate = - AppModalDialogQueue::active_dialog(); - *showing_dialog = (dialog_delegate != NULL); - if (*showing_dialog) - *dialog_button = dialog_delegate->GetDialogButtons(); - else - *dialog_button = views::DialogDelegate::DIALOGBUTTON_NONE; + *showing_dialog = AppModalDialogQueue::HasActiveDialog(); + *dialog_button = views::DialogDelegate::DIALOGBUTTON_NONE; + if (!*showing_dialog) + return; + + views::DialogDelegate* dialog_delegate = + AppModalDialogQueue::active_dialog()->GetTestingInterface()-> + GetDialogDelegate(); + *dialog_button = dialog_delegate->GetDialogButtons(); } void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { *success = false; + if (!AppModalDialogQueue::HasActiveDialog()) + return; - views::AppModalDialogDelegate* dialog_delegate = - AppModalDialogQueue::active_dialog(); - if (dialog_delegate && - (dialog_delegate->GetDialogButtons() & button) == button) { + views::DialogDelegate* dialog_delegate = + AppModalDialogQueue::active_dialog()->GetTestingInterface()-> + GetDialogDelegate(); + if ((dialog_delegate->GetDialogButtons() & button) == button) { views::DialogClientView* client_view = dialog_delegate->window()->client_view()->AsDialogClientView(); if ((button & views::DialogDelegate::DIALOGBUTTON_OK) == diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index e8ee21e..fea4dea 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -626,6 +626,10 @@ Name="Browser Window" > <File + RelativePath=".\app_modal_dialog_delegate.h" + > + </File> + <File RelativePath=".\app_modal_dialog_queue.cc" > </File> diff --git a/chrome/browser/jsmessage_box_handler_win.cc b/chrome/browser/jsmessage_box_handler_win.cc index 5026e8e..5add577 100644 --- a/chrome/browser/jsmessage_box_handler_win.cc +++ b/chrome/browser/jsmessage_box_handler_win.cc @@ -66,6 +66,45 @@ JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() { } ////////////////////////////////////////////////////////////////////////////// +// JavascriptMessageBoxHandler, views::AppModalDialogDelegate +// implementation: + +void JavascriptMessageBoxHandler::ShowModalDialog() { + // If the WebContents that created this dialog navigated away before this + // dialog became visible, simply show the next dialog if any. + if (!web_contents_) { + AppModalDialogQueue::ShowNextDialog(); + delete this; + return; + } + + web_contents_->Activate(); + HWND root_hwnd = GetAncestor(web_contents_->GetNativeView(), GA_ROOT); + dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this); + dialog_->Show(); +} + +void JavascriptMessageBoxHandler::ActivateModalDialog() { + // Ensure that the dialog is visible and at the top of the z-order. These + // conditions may not be true if the dialog was opened on a different virtual + // desktop to the one the browser window is on. + dialog_->Show(); + dialog_->Activate(); +} + +AppModalDialogDelegateTesting* +JavascriptMessageBoxHandler::GetTestingInterface() { + return this; +} + +/////////////////////////////////////////////////////////////////////////////// +// JavascriptMessageBoxHandler, AppModalDialogDelegateTesting implementation: + +views::DialogDelegate* JavascriptMessageBoxHandler::GetDialogDelegate() { + return this; +} + +////////////////////////////////////////////////////////////////////////////// // JavascriptMessageBoxHandler, views::DialogDelegate implementation: int JavascriptMessageBoxHandler::GetDialogButtons() const { @@ -141,33 +180,6 @@ bool JavascriptMessageBoxHandler::Accept() { return true; } -////////////////////////////////////////////////////////////////////////////// -// JavascriptMessageBoxHandler, views::AppModalDialogDelegate -// implementation: - -void JavascriptMessageBoxHandler::ShowModalDialog() { - // If the WebContents that created this dialog navigated away before this - // dialog became visible, simply show the next dialog if any. - if (!web_contents_) { - AppModalDialogQueue::ShowNextDialog(); - delete this; - return; - } - - web_contents_->Activate(); - HWND root_hwnd = GetAncestor(web_contents_->GetNativeView(), GA_ROOT); - dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this); - dialog_->Show(); -} - -void JavascriptMessageBoxHandler::ActivateModalDialog() { - // Ensure that the dialog is visible and at the top of the z-order. These - // conditions may not be true if the dialog was opened on a different virtual - // desktop to the one the browser window is on. - dialog_->Show(); - dialog_->Activate(); -} - /////////////////////////////////////////////////////////////////////////////// // JavascriptMessageBoxHandler, views::WindowDelegate implementation: @@ -178,7 +190,7 @@ views::View* JavascriptMessageBoxHandler::GetContentsView() { views::View* JavascriptMessageBoxHandler::GetInitiallyFocusedView() { if (message_box_view_->text_box()) return message_box_view_->text_box(); - return views::AppModalDialogDelegate::GetInitiallyFocusedView(); + return views::DialogDelegate::GetInitiallyFocusedView(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/jsmessage_box_handler_win.h b/chrome/browser/jsmessage_box_handler_win.h index bac80dd..9e4804a 100644 --- a/chrome/browser/jsmessage_box_handler_win.h +++ b/chrome/browser/jsmessage_box_handler_win.h @@ -5,11 +5,12 @@ #ifndef CHROME_BROWSER_JSMESSAGE_BOX_HANDLER_WIN_H_ #define CHROME_BROWSER_JSMESSAGE_BOX_HANDLER_WIN_H_ +#include "chrome/browser/app_modal_dialog_delegate.h" #include "chrome/browser/jsmessage_box_handler.h" #include "chrome/common/ipc_message.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -#include "chrome/views/app_modal_dialog_delegate.h" +#include "chrome/views/dialog_delegate.h" class MessageBoxView; class WebContents; @@ -18,8 +19,10 @@ class Window; } class JavascriptMessageBoxHandler - : public views::AppModalDialogDelegate, - public NotificationObserver { + : public AppModalDialogDelegate, + public AppModalDialogDelegateTesting, + public NotificationObserver, + public views::DialogDelegate { public: // Cross-platform code should use RunJavaScriptMessageBox. JavascriptMessageBoxHandler(WebContents* web_contents, @@ -30,6 +33,14 @@ class JavascriptMessageBoxHandler IPC::Message* reply_msg); virtual ~JavascriptMessageBoxHandler(); + // AppModalDialogDelegate Methods: + virtual void ShowModalDialog(); + virtual void ActivateModalDialog(); + virtual AppModalDialogDelegateTesting* GetTestingInterface(); + + // AppModalDialogDelegateTesting Methods: + virtual views::DialogDelegate* GetDialogDelegate(); + // views::DialogDelegate Methods: virtual int GetDialogButtons() const; virtual std::wstring GetWindowTitle() const; @@ -37,10 +48,6 @@ class JavascriptMessageBoxHandler virtual bool Cancel(); virtual bool Accept(); - // views::AppModalDialogDelegate - virtual void ShowModalDialog(); - virtual void ActivateModalDialog(); - // views::WindowDelegate Methods: virtual bool IsModal() const { return true; } virtual views::View* GetContentsView(); diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 969e173..fbc182b 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -375,6 +375,10 @@ Name="browser" > <File + RelativePath="..\..\browser\app_modal_dialog_queue_unittest.cc" + > + </File> + <File RelativePath="..\..\browser\renderer_host\audio_renderer_host_unittest.cc" > </File> diff --git a/chrome/views/app_modal_dialog_delegate.h b/chrome/views/app_modal_dialog_delegate.h deleted file mode 100644 index b8fefb4..0000000 --- a/chrome/views/app_modal_dialog_delegate.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_VIEWS_APP_MODAL_DIALOG_DELEGATE_H__ -#define CHROME_VIEWS_APP_MODAL_DIALOG_DELEGATE_H__ - -#include "chrome/views/dialog_delegate.h" - -namespace views { - -// Pure virtual interface for a window which is app modal. -class AppModalDialogDelegate : public DialogDelegate { - public: - // Called by the app modal window queue when it is time to show this window. - virtual void ShowModalDialog() = 0; - - // Called by the app modal window queue to activate the window. - virtual void ActivateModalDialog() = 0; -}; - -} // namespace views - -#endif // #ifndef CHROME_VIEWS_APP_MODAL_DIALOG_DELEGATE_H__ - diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj index 9656303..845f0eb 100644 --- a/chrome/views/views.vcproj +++ b/chrome/views/views.vcproj @@ -166,10 +166,6 @@ > </File> <File - RelativePath=".\app_modal_dialog_delegate.h" - > - </File> - <File RelativePath=".\background.cc" > </File> |