| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/app_modal_dialog.h" | 5 #include "chrome/browser/app_modal_dialog.h" |
| 6 | 6 |
| 7 #include "chrome/browser/app_modal_dialog_queue.h" | 7 #include "chrome/browser/app_modal_dialog_queue.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
| 9 #include "chrome/common/notification_service.h" | 9 #include "chrome/common/notification_service.h" |
| 10 #include "chrome/common/notification_type.h" | 10 #include "chrome/common/notification_type.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 if (type == NotificationType::TAB_CONTENTS_DESTROYED && | 44 if (type == NotificationType::TAB_CONTENTS_DESTROYED && |
| 45 Source<TabContents>(source).ptr() == | 45 Source<TabContents>(source).ptr() == |
| 46 static_cast<TabContents*>(tab_contents_)) | 46 static_cast<TabContents*>(tab_contents_)) |
| 47 tab_contents_ = NULL; | 47 tab_contents_ = NULL; |
| 48 | 48 |
| 49 if (!tab_contents_) | 49 if (!tab_contents_) |
| 50 CloseModalDialog(); | 50 CloseModalDialog(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void AppModalDialog::SendCloseNotification() { |
| 54 NotificationService::current()->Notify( |
| 55 NotificationType::APP_MODAL_DIALOG_CLOSED, |
| 56 Source<AppModalDialog>(this), |
| 57 NotificationService::NoDetails()); |
| 58 } |
| 59 |
| 53 void AppModalDialog::InitNotifications() { | 60 void AppModalDialog::InitNotifications() { |
| 54 // Make sure we get navigation notifications so we know when our parent | 61 // Make sure we get navigation notifications so we know when our parent |
| 55 // contents will disappear or navigate to a different page. | 62 // contents will disappear or navigate to a different page. |
| 56 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 63 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 57 NotificationService::AllSources()); | 64 NotificationService::AllSources()); |
| 58 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 65 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 59 NotificationService::AllSources()); | 66 NotificationService::AllSources()); |
| 60 } | 67 } |
| 61 | 68 |
| 62 void AppModalDialog::ShowModalDialog() { | 69 void AppModalDialog::ShowModalDialog() { |
| 63 // If the TabContents that created this dialog navigated away before this | 70 // If the TabContents that created this dialog navigated away before this |
| 64 // dialog became visible, simply show the next dialog if any. | 71 // dialog became visible, simply show the next dialog if any. |
| 65 if (!tab_contents_) { | 72 if (!tab_contents_) { |
| 66 Singleton<AppModalDialogQueue>()->ShowNextDialog(); | 73 Singleton<AppModalDialogQueue>()->ShowNextDialog(); |
| 67 delete this; | 74 delete this; |
| 68 return; | 75 return; |
| 69 } | 76 } |
| 70 | 77 |
| 71 tab_contents_->Activate(); | 78 tab_contents_->Activate(); |
| 72 CreateAndShowDialog(); | 79 CreateAndShowDialog(); |
| 80 |
| 81 NotificationService::current()->Notify( |
| 82 NotificationType::APP_MODAL_DIALOG_SHOWN, |
| 83 Source<AppModalDialog>(this), |
| 84 NotificationService::NoDetails()); |
| 73 } | 85 } |
| 74 | 86 |
| 75 void AppModalDialog::OnCancel() { | 87 void AppModalDialog::OnCancel() { |
| 76 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame | 88 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame |
| 77 // will receive it's activation messages before this dialog receives | 89 // will receive it's activation messages before this dialog receives |
| 78 // WM_DESTROY. The parent frame would then try to activate any modal dialogs | 90 // WM_DESTROY. The parent frame would then try to activate any modal dialogs |
| 79 // that were still open in the ModalDialogQueue, which would send activation | 91 // that were still open in the ModalDialogQueue, which would send activation |
| 80 // back to this one. The framework should be improved to handle this, so this | 92 // back to this one. The framework should be improved to handle this, so this |
| 81 // is a temporary workaround. | 93 // is a temporary workaround. |
| 82 Singleton<AppModalDialogQueue>()->ShowNextDialog(); | 94 Singleton<AppModalDialogQueue>()->ShowNextDialog(); |
| 83 | 95 |
| 84 if (tab_contents_) { | 96 if (tab_contents_) { |
| 85 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, false, | 97 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, false, |
| 86 std::wstring()); | 98 std::wstring()); |
| 87 } | 99 } |
| 100 |
| 101 SendCloseNotification(); |
| 88 } | 102 } |
| 89 | 103 |
| 90 void AppModalDialog::OnAccept(const std::wstring& prompt_text, | 104 void AppModalDialog::OnAccept(const std::wstring& prompt_text, |
| 91 bool suppress_js_messages) { | 105 bool suppress_js_messages) { |
| 92 Singleton<AppModalDialogQueue>()->ShowNextDialog(); | 106 Singleton<AppModalDialogQueue>()->ShowNextDialog(); |
| 93 | 107 |
| 94 if (tab_contents_) { | 108 if (tab_contents_) { |
| 95 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, true, | 109 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, true, |
| 96 prompt_text); | 110 prompt_text); |
| 97 | 111 |
| 98 if (suppress_js_messages) | 112 if (suppress_js_messages) |
| 99 tab_contents()->set_suppress_javascript_messages(true); | 113 tab_contents()->set_suppress_javascript_messages(true); |
| 100 } | 114 } |
| 115 |
| 116 SendCloseNotification(); |
| 101 } | 117 } |
| 102 | 118 |
| 103 void AppModalDialog::OnClose() { | 119 void AppModalDialog::OnClose() { |
| 104 if (tab_contents_) { | 120 if (tab_contents_) { |
| 105 tab_contents_->OnJavaScriptMessageBoxWindowDestroyed(); | 121 tab_contents_->OnJavaScriptMessageBoxWindowDestroyed(); |
| 106 } | 122 } |
| 123 |
| 124 SendCloseNotification(); |
| 107 } | 125 } |
| OLD | NEW |