diff options
author | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 04:08:54 +0000 |
---|---|---|
committer | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 04:08:54 +0000 |
commit | beb440cea06ba40683a755d14dd5dbf9d11baadf (patch) | |
tree | 79b805ed76621b38c5682033a3fbab9dc0a6f8a8 /chrome/browser/app_modal_dialog.cc | |
parent | da3b971ec3cababd149b5cd6a7a9d021bfdd96b4 (diff) | |
download | chromium_src-beb440cea06ba40683a755d14dd5dbf9d11baadf.zip chromium_src-beb440cea06ba40683a755d14dd5dbf9d11baadf.tar.gz chromium_src-beb440cea06ba40683a755d14dd5dbf9d11baadf.tar.bz2 |
Implement window.alert() and its cousins for extensions.
Second try, now with fixed observer.
BUG=12126
TEST=put a window.prompt() in a background page, a browser action, and a page action.
Make sure it gets the result back correctly. Also make sure it still works when
called from a web page.
Review URL: http://codereview.chromium.org/373006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_modal_dialog.cc')
-rw-r--r-- | chrome/browser/app_modal_dialog.cc | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/chrome/browser/app_modal_dialog.cc b/chrome/browser/app_modal_dialog.cc index 8abf78e..258eb19 100644 --- a/chrome/browser/app_modal_dialog.cc +++ b/chrome/browser/app_modal_dialog.cc @@ -10,7 +10,7 @@ #include "chrome/common/notification_type.h" #include "ipc/ipc_message.h" -AppModalDialog::AppModalDialog(TabContents* tab_contents, +AppModalDialog::AppModalDialog(JavaScriptMessageBoxClient* client, const std::wstring& title, int dialog_flags, const std::wstring& message_text, @@ -19,7 +19,8 @@ AppModalDialog::AppModalDialog(TabContents* tab_contents, bool is_before_unload_dialog, IPC::Message* reply_msg) : dialog_(NULL), - tab_contents_(tab_contents), + client_(client), + skip_this_dialog_(false), title_(title), dialog_flags_(dialog_flags), message_text_(message_text), @@ -33,21 +34,16 @@ AppModalDialog::AppModalDialog(TabContents* tab_contents, void AppModalDialog::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (!tab_contents_) + if (skip_this_dialog_) return; - if (type == NotificationType::NAV_ENTRY_COMMITTED && - Source<NavigationController>(source).ptr() == - &tab_contents_->controller()) - tab_contents_ = NULL; - - if (type == NotificationType::TAB_CONTENTS_DESTROYED && - Source<TabContents>(source).ptr() == - static_cast<TabContents*>(tab_contents_)) - tab_contents_ = NULL; - - if (!tab_contents_) - CloseModalDialog(); + // We only observe our NavigationController for NAV_ENTRY_COMMITTED and our + // TabContents for TAB_CONTENTS_DESTROYED, both of which indicate that we + // should ignore this dialog. Also clear the client for good measure, since + // it's now invalid. + skip_this_dialog_ = true; + client_ = NULL; + CloseModalDialog(); } void AppModalDialog::SendCloseNotification() { @@ -58,24 +54,29 @@ void AppModalDialog::SendCloseNotification() { } void AppModalDialog::InitNotifications() { - // Make sure we get navigation notifications so we know when our parent - // contents will disappear or navigate to a different page. - registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, - NotificationService::AllSources()); + // Make sure we get relevant navigation notifications so we know when our + // parent contents will disappear or navigate to a different page. + TabContents* tab_contents = client_->AsTabContents(); + if (tab_contents) { + registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents->controller())); + registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents)); + } } void AppModalDialog::ShowModalDialog() { // If the TabContents that created this dialog navigated away before this // dialog became visible, simply show the next dialog if any. - if (!tab_contents_) { + if (skip_this_dialog_) { Singleton<AppModalDialogQueue>()->ShowNextDialog(); delete this; return; } + TabContents* tab_contents = client_->AsTabContents(); + if (tab_contents) + tab_contents->Activate(); - tab_contents_->Activate(); CreateAndShowDialog(); NotificationService::current()->Notify( @@ -86,16 +87,15 @@ void AppModalDialog::ShowModalDialog() { void AppModalDialog::OnCancel() { // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame - // will receive it's activation messages before this dialog receives + // will receive its activation messages before this dialog receives // WM_DESTROY. The parent frame would then try to activate any modal dialogs // that were still open in the ModalDialogQueue, which would send activation // back to this one. The framework should be improved to handle this, so this // is a temporary workaround. Singleton<AppModalDialogQueue>()->ShowNextDialog(); - if (tab_contents_) { - tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, false, - std::wstring()); + if (!skip_this_dialog_) { + client_->OnMessageBoxClosed(reply_msg_, false, std::wstring()); } SendCloseNotification(); @@ -105,12 +105,10 @@ void AppModalDialog::OnAccept(const std::wstring& prompt_text, bool suppress_js_messages) { Singleton<AppModalDialogQueue>()->ShowNextDialog(); - if (tab_contents_) { - tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, true, - prompt_text); - + if (!skip_this_dialog_) { + client_->OnMessageBoxClosed(reply_msg_, true, prompt_text); if (suppress_js_messages) - tab_contents()->set_suppress_javascript_messages(true); + client_->SetSuppressMessageBoxes(true); } SendCloseNotification(); |