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

Side by Side Diff: chrome/browser/ui/app_modal_dialogs/js_modal_dialog.cc

Issue 7096016: Remove JS dialog dependency from content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now a tc delegate Created 9 years, 6 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/app_modal_dialogs/js_modal_dialog.h" 5 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_shutdown.h" 9 #include "chrome/browser/browser_shutdown.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
(...skipping 30 matching lines...) Expand all
41 void EnforceMaxTextSize(const string16& in_string, string16* out_string) { 41 void EnforceMaxTextSize(const string16& in_string, string16* out_string) {
42 ui::ElideString(in_string, kMessageTextMaxSize, out_string); 42 ui::ElideString(in_string, kMessageTextMaxSize, out_string);
43 } 43 }
44 void EnforceMaxPromptSize(const string16& in_string, string16* out_string) { 44 void EnforceMaxPromptSize(const string16& in_string, string16* out_string) {
45 ui::ElideString(in_string, kDefaultPromptMaxSize, out_string); 45 ui::ElideString(in_string, kDefaultPromptMaxSize, out_string);
46 } 46 }
47 #endif 47 #endif
48 48
49 } // namespace 49 } // namespace
50 50
51 ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData()
52 : suppress_javascript_messages_(false) {
53 }
54
51 JavaScriptAppModalDialog::JavaScriptAppModalDialog( 55 JavaScriptAppModalDialog::JavaScriptAppModalDialog(
52 JavaScriptAppModalDialogDelegate* delegate, 56 content::JavaScriptDialogDelegate* delegate,
53 const std::wstring& title, 57 ChromeJavaScriptDialogExtraData* extra_data,
58 const string16& title,
54 int dialog_flags, 59 int dialog_flags,
55 const std::wstring& message_text, 60 const string16& message_text,
56 const std::wstring& default_prompt_text, 61 const string16& default_prompt_text,
57 bool display_suppress_checkbox, 62 bool display_suppress_checkbox,
58 bool is_before_unload_dialog, 63 bool is_before_unload_dialog,
59 IPC::Message* reply_msg) 64 IPC::Message* reply_msg)
60 : AppModalDialog(delegate->AsTabContents(), title), 65 : AppModalDialog(delegate->AsTabContents(), title),
61 delegate_(delegate), 66 delegate_(delegate),
67 extra_data_(extra_data),
62 extension_host_(delegate->AsExtensionHost()), 68 extension_host_(delegate->AsExtensionHost()),
63 dialog_flags_(dialog_flags), 69 dialog_flags_(dialog_flags),
64 display_suppress_checkbox_(display_suppress_checkbox), 70 display_suppress_checkbox_(display_suppress_checkbox),
65 is_before_unload_dialog_(is_before_unload_dialog), 71 is_before_unload_dialog_(is_before_unload_dialog),
66 reply_msg_(reply_msg), 72 reply_msg_(reply_msg),
67 use_override_prompt_text_(false) { 73 use_override_prompt_text_(false) {
68 string16 elided_text; 74 EnforceMaxTextSize(message_text, &message_text_);
69 EnforceMaxTextSize(WideToUTF16(message_text), &elided_text); 75 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
70 message_text_ = UTF16ToWide(elided_text);
71 EnforceMaxPromptSize(WideToUTF16Hack(default_prompt_text),
72 &default_prompt_text_);
73 76
74 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); 77 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL));
75 InitNotifications(); 78 InitNotifications();
76 } 79 }
77 80
78 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { 81 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
79 } 82 }
80 83
81 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { 84 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() {
82 gfx::NativeWindow parent_window = tab_contents_ ? 85 gfx::NativeWindow parent_window = delegate_->GetDialogRootWindow();
83 tab_contents_->GetMessageBoxRootWindow() :
84 extension_host_->GetMessageBoxRootWindow();
85 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, 86 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this,
86 parent_window); 87 parent_window);
87 } 88 }
88 89
89 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { 90 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() {
90 return true; 91 return true;
91 } 92 }
92 93
93 void JavaScriptAppModalDialog::Observe(NotificationType type, 94 void JavaScriptAppModalDialog::Observe(NotificationType type,
94 const NotificationSource& source, 95 const NotificationSource& source,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 browser_shutdown::SetTryingToQuit(false); 136 browser_shutdown::SetTryingToQuit(false);
136 137
137 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame 138 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame
138 // will receive its activation messages before this dialog receives 139 // will receive its activation messages before this dialog receives
139 // WM_DESTROY. The parent frame would then try to activate any modal dialogs 140 // WM_DESTROY. The parent frame would then try to activate any modal dialogs
140 // that were still open in the ModalDialogQueue, which would send activation 141 // that were still open in the ModalDialogQueue, which would send activation
141 // back to this one. The framework should be improved to handle this, so this 142 // back to this one. The framework should be improved to handle this, so this
142 // is a temporary workaround. 143 // is a temporary workaround.
143 CompleteDialog(); 144 CompleteDialog();
144 145
145 NotifyDelegate(false, L"", suppress_js_messages); 146 NotifyDelegate(false, string16(), suppress_js_messages);
146 } 147 }
147 148
148 void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text, 149 void JavaScriptAppModalDialog::OnAccept(const string16& prompt_text,
149 bool suppress_js_messages) { 150 bool suppress_js_messages) {
150 std::wstring prompt_text_to_use = prompt_text; 151 string16 prompt_text_to_use = prompt_text;
151 // This is only for testing. 152 // This is only for testing.
152 if (use_override_prompt_text_) 153 if (use_override_prompt_text_)
153 prompt_text_to_use = UTF16ToWideHack(override_prompt_text_); 154 prompt_text_to_use = override_prompt_text_;
154 155
155 CompleteDialog(); 156 CompleteDialog();
156 NotifyDelegate(true, prompt_text_to_use, suppress_js_messages); 157 NotifyDelegate(true, prompt_text_to_use, suppress_js_messages);
157 } 158 }
158 159
159 void JavaScriptAppModalDialog::OnClose() { 160 void JavaScriptAppModalDialog::OnClose() {
160 NotifyDelegate(false, L"", false); 161 NotifyDelegate(false, string16(), false);
161 } 162 }
162 163
163 void JavaScriptAppModalDialog::SetOverridePromptText( 164 void JavaScriptAppModalDialog::SetOverridePromptText(
164 const string16& override_prompt_text) { 165 const string16& override_prompt_text) {
165 override_prompt_text_ = override_prompt_text; 166 override_prompt_text_ = override_prompt_text;
166 use_override_prompt_text_ = true; 167 use_override_prompt_text_ = true;
167 } 168 }
168 169
169 void JavaScriptAppModalDialog::NotifyDelegate(bool success, 170 void JavaScriptAppModalDialog::NotifyDelegate(bool success,
170 const std::wstring& prompt_text, 171 const string16& user_input,
171 bool suppress_js_messages) { 172 bool suppress_js_messages) {
172 if (skip_this_dialog_) 173 if (skip_this_dialog_)
173 return; 174 return;
174 175
175 delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text); 176 delegate_->OnDialogClosed(reply_msg_, success, user_input);
176 if (suppress_js_messages) 177
177 delegate_->SetSuppressMessageBoxes(true); 178 extra_data_->last_javascript_message_dismissal_ = base::TimeTicks::Now();
179 extra_data_->suppress_javascript_messages_ = suppress_js_messages;
178 180
179 // On Views, we can end up coming through this code path twice :(. 181 // On Views, we can end up coming through this code path twice :(.
180 // See crbug.com/63732. 182 // See crbug.com/63732.
181 skip_this_dialog_ = true; 183 skip_this_dialog_ = true;
182 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698