Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/app_modal_dialog.cc

Issue 373006: Implement window.alert() and its cousins for extensions.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_modal_dialog.h ('k') | chrome/browser/app_modal_dialog_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 12
13 AppModalDialog::AppModalDialog(TabContents* tab_contents, 13 AppModalDialog::AppModalDialog(JavaScriptMessageBoxClient* client,
14 const std::wstring& title, 14 const std::wstring& title,
15 int dialog_flags, 15 int dialog_flags,
16 const std::wstring& message_text, 16 const std::wstring& message_text,
17 const std::wstring& default_prompt_text, 17 const std::wstring& default_prompt_text,
18 bool display_suppress_checkbox, 18 bool display_suppress_checkbox,
19 bool is_before_unload_dialog, 19 bool is_before_unload_dialog,
20 IPC::Message* reply_msg) 20 IPC::Message* reply_msg)
21 : dialog_(NULL), 21 : dialog_(NULL),
22 tab_contents_(tab_contents), 22 client_(client),
23 skip_this_dialog_(false),
23 title_(title), 24 title_(title),
24 dialog_flags_(dialog_flags), 25 dialog_flags_(dialog_flags),
25 message_text_(message_text), 26 message_text_(message_text),
26 default_prompt_text_(default_prompt_text), 27 default_prompt_text_(default_prompt_text),
27 display_suppress_checkbox_(display_suppress_checkbox), 28 display_suppress_checkbox_(display_suppress_checkbox),
28 is_before_unload_dialog_(is_before_unload_dialog), 29 is_before_unload_dialog_(is_before_unload_dialog),
29 reply_msg_(reply_msg) { 30 reply_msg_(reply_msg) {
30 InitNotifications(); 31 InitNotifications();
31 } 32 }
32 33
33 void AppModalDialog::Observe(NotificationType type, 34 void AppModalDialog::Observe(NotificationType type,
34 const NotificationSource& source, 35 const NotificationSource& source,
35 const NotificationDetails& details) { 36 const NotificationDetails& details) {
36 if (!tab_contents_) 37 if (skip_this_dialog_)
37 return; 38 return;
38 39
39 if (type == NotificationType::NAV_ENTRY_COMMITTED && 40 // We only observe our NavigationController for NAV_ENTRY_COMMITTED and our
40 Source<NavigationController>(source).ptr() == 41 // TabContents for TAB_CONTENTS_DESTROYED, both of which indicate that we
41 &tab_contents_->controller()) 42 // should ignore this dialog. Also clear the client for good measure, since
42 tab_contents_ = NULL; 43 // it's now invalid.
43 44 skip_this_dialog_ = true;
44 if (type == NotificationType::TAB_CONTENTS_DESTROYED && 45 client_ = NULL;
45 Source<TabContents>(source).ptr() == 46 CloseModalDialog();
46 static_cast<TabContents*>(tab_contents_))
47 tab_contents_ = NULL;
48
49 if (!tab_contents_)
50 CloseModalDialog();
51 } 47 }
52 48
53 void AppModalDialog::SendCloseNotification() { 49 void AppModalDialog::SendCloseNotification() {
54 NotificationService::current()->Notify( 50 NotificationService::current()->Notify(
55 NotificationType::APP_MODAL_DIALOG_CLOSED, 51 NotificationType::APP_MODAL_DIALOG_CLOSED,
56 Source<AppModalDialog>(this), 52 Source<AppModalDialog>(this),
57 NotificationService::NoDetails()); 53 NotificationService::NoDetails());
58 } 54 }
59 55
60 void AppModalDialog::InitNotifications() { 56 void AppModalDialog::InitNotifications() {
61 // Make sure we get navigation notifications so we know when our parent 57 // Make sure we get relevant navigation notifications so we know when our
62 // contents will disappear or navigate to a different page. 58 // parent contents will disappear or navigate to a different page.
63 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 59 TabContents* tab_contents = client_->AsTabContents();
64 NotificationService::AllSources()); 60 if (tab_contents) {
65 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 61 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
66 NotificationService::AllSources()); 62 Source<NavigationController>(&tab_contents->controller()));
63 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
64 Source<TabContents>(tab_contents));
65 }
67 } 66 }
68 67
69 void AppModalDialog::ShowModalDialog() { 68 void AppModalDialog::ShowModalDialog() {
70 // If the TabContents that created this dialog navigated away before this 69 // If the TabContents that created this dialog navigated away before this
71 // dialog became visible, simply show the next dialog if any. 70 // dialog became visible, simply show the next dialog if any.
72 if (!tab_contents_) { 71 if (skip_this_dialog_) {
73 Singleton<AppModalDialogQueue>()->ShowNextDialog(); 72 Singleton<AppModalDialogQueue>()->ShowNextDialog();
74 delete this; 73 delete this;
75 return; 74 return;
76 } 75 }
76 TabContents* tab_contents = client_->AsTabContents();
77 if (tab_contents)
78 tab_contents->Activate();
77 79
78 tab_contents_->Activate();
79 CreateAndShowDialog(); 80 CreateAndShowDialog();
80 81
81 NotificationService::current()->Notify( 82 NotificationService::current()->Notify(
82 NotificationType::APP_MODAL_DIALOG_SHOWN, 83 NotificationType::APP_MODAL_DIALOG_SHOWN,
83 Source<AppModalDialog>(this), 84 Source<AppModalDialog>(this),
84 NotificationService::NoDetails()); 85 NotificationService::NoDetails());
85 } 86 }
86 87
87 void AppModalDialog::OnCancel() { 88 void AppModalDialog::OnCancel() {
88 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame 89 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame
89 // will receive it's activation messages before this dialog receives 90 // will receive its activation messages before this dialog receives
90 // WM_DESTROY. The parent frame would then try to activate any modal dialogs 91 // WM_DESTROY. The parent frame would then try to activate any modal dialogs
91 // that were still open in the ModalDialogQueue, which would send activation 92 // that were still open in the ModalDialogQueue, which would send activation
92 // back to this one. The framework should be improved to handle this, so this 93 // back to this one. The framework should be improved to handle this, so this
93 // is a temporary workaround. 94 // is a temporary workaround.
94 Singleton<AppModalDialogQueue>()->ShowNextDialog(); 95 Singleton<AppModalDialogQueue>()->ShowNextDialog();
95 96
96 if (tab_contents_) { 97 if (!skip_this_dialog_) {
97 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, false, 98 client_->OnMessageBoxClosed(reply_msg_, false, std::wstring());
98 std::wstring());
99 } 99 }
100 100
101 SendCloseNotification(); 101 SendCloseNotification();
102 } 102 }
103 103
104 void AppModalDialog::OnAccept(const std::wstring& prompt_text, 104 void AppModalDialog::OnAccept(const std::wstring& prompt_text,
105 bool suppress_js_messages) { 105 bool suppress_js_messages) {
106 Singleton<AppModalDialogQueue>()->ShowNextDialog(); 106 Singleton<AppModalDialogQueue>()->ShowNextDialog();
107 107
108 if (tab_contents_) { 108 if (!skip_this_dialog_) {
109 tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, true, 109 client_->OnMessageBoxClosed(reply_msg_, true, prompt_text);
110 prompt_text);
111
112 if (suppress_js_messages) 110 if (suppress_js_messages)
113 tab_contents()->set_suppress_javascript_messages(true); 111 client_->SetSuppressMessageBoxes(true);
114 } 112 }
115 113
116 SendCloseNotification(); 114 SendCloseNotification();
117 } 115 }
118 116
119 void AppModalDialog::OnClose() { 117 void AppModalDialog::OnClose() {
120 SendCloseNotification(); 118 SendCloseNotification();
121 } 119 }
OLDNEW
« no previous file with comments | « chrome/browser/app_modal_dialog.h ('k') | chrome/browser/app_modal_dialog_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698