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

Side by Side Diff: components/app_modal/javascript_dialog_manager.cc

Issue 1714573002: Remove the ability of webpages to specify strings for the onbeforeunload dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | components/app_modal_strings.grdp » ('j') | components/app_modal_strings.grdp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/app_modal/javascript_dialog_manager.h" 5 #include "components/app_modal/javascript_dialog_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 default_prompt_text, 157 default_prompt_text,
158 ShouldDisplaySuppressCheckbox(extra_data), 158 ShouldDisplaySuppressCheckbox(extra_data),
159 false, // is_before_unload_dialog 159 false, // is_before_unload_dialog
160 false, // is_reload 160 false, // is_reload
161 base::Bind(&JavaScriptDialogManager::OnDialogClosed, 161 base::Bind(&JavaScriptDialogManager::OnDialogClosed,
162 base::Unretained(this), web_contents, callback))); 162 base::Unretained(this), web_contents, callback)));
163 } 163 }
164 164
165 void JavaScriptDialogManager::RunBeforeUnloadDialog( 165 void JavaScriptDialogManager::RunBeforeUnloadDialog(
166 content::WebContents* web_contents, 166 content::WebContents* web_contents,
167 const base::string16& message_text, 167 const base::string16& /* message_text */,
168 bool is_reload, 168 bool is_reload,
169 const DialogClosedCallback& callback) { 169 const DialogClosedCallback& callback) {
170 ChromeJavaScriptDialogExtraData* extra_data = 170 ChromeJavaScriptDialogExtraData* extra_data =
171 &javascript_dialog_extra_data_ 171 &javascript_dialog_extra_data_
172 [JavaScriptAppModalDialog::GetSerializedOriginForWebContents( 172 [JavaScriptAppModalDialog::GetSerializedOriginForWebContents(
173 web_contents)]; 173 web_contents)];
174 174
175 if (extra_data->suppress_javascript_messages_) { 175 if (extra_data->suppress_javascript_messages_) {
176 // If a site harassed the user enough for them to put it on mute, then it 176 // If a site harassed the user enough for them to put it on mute, then it
177 // lost its privilege to deny unloading. 177 // lost its privilege to deny unloading.
178 callback.Run(true, base::string16()); 178 callback.Run(true, base::string16());
179 return; 179 return;
180 } 180 }
181 181
182 // Build the dialog message. We explicitly do _not_ allow the webpage to
183 // specify the contents of this dialog, because most of the time nowadays it's
184 // used for scams.
185 //
186 // This does not violate the spec. Per
187 // https://html.spec.whatwg.org/#prompt-to-unload-a-document, step 7:
188 //
189 // "The prompt shown by the user agent may include the string of the
190 // returnValue attribute, or some leading subset thereof."
191 //
192 // The prompt MAY include the string. It doesn't any more. Scam web page
193 // authors have abused this, so we're taking away the toys from everyone. This
194 // is why we can't have nice things.
195
182 const base::string16 title = l10n_util::GetStringUTF16(is_reload ? 196 const base::string16 title = l10n_util::GetStringUTF16(is_reload ?
183 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE); 197 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE);
184 const base::string16 footer = l10n_util::GetStringUTF16(is_reload ? 198 const base::string16 message = l10n_util::GetStringUTF16(
185 IDS_BEFORERELOAD_MESSAGEBOX_FOOTER : IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); 199 is_reload ? IDS_BEFORERELOAD_MESSAGEBOX_MESSAGE
186 200 : IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE);
187 base::string16 full_message =
188 message_text + base::ASCIIToUTF16("\n\n") + footer;
189 201
190 extensions_client_->OnDialogOpened(web_contents); 202 extensions_client_->OnDialogOpened(web_contents);
191 203
192 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 204 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
193 web_contents, 205 web_contents,
194 &javascript_dialog_extra_data_, 206 &javascript_dialog_extra_data_,
195 title, 207 title,
196 content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, 208 content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
197 full_message, 209 message,
198 base::string16(), // default_prompt_text 210 base::string16(), // default_prompt_text
199 ShouldDisplaySuppressCheckbox(extra_data), 211 ShouldDisplaySuppressCheckbox(extra_data),
200 true, // is_before_unload_dialog 212 true, // is_before_unload_dialog
201 is_reload, 213 is_reload,
202 base::Bind(&JavaScriptDialogManager::OnDialogClosed, 214 base::Bind(&JavaScriptDialogManager::OnDialogClosed,
203 base::Unretained(this), web_contents, callback))); 215 base::Unretained(this), web_contents, callback)));
204 } 216 }
205 217
206 bool JavaScriptDialogManager::HandleJavaScriptDialog( 218 bool JavaScriptDialogManager::HandleJavaScriptDialog(
207 content::WebContents* web_contents, 219 content::WebContents* web_contents,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // lazy background page after the dialog closes. (Dialogs are closed before 307 // lazy background page after the dialog closes. (Dialogs are closed before
296 // their WebContents is destroyed so |web_contents| is still valid here.) 308 // their WebContents is destroyed so |web_contents| is still valid here.)
297 extensions_client_->OnDialogClosed(web_contents); 309 extensions_client_->OnDialogClosed(web_contents);
298 310
299 last_close_time_ = base::TimeTicks::Now(); 311 last_close_time_ = base::TimeTicks::Now();
300 312
301 callback.Run(success, user_input); 313 callback.Run(success, user_input);
302 } 314 }
303 315
304 } // namespace app_modal 316 } // namespace app_modal
OLDNEW
« no previous file with comments | « no previous file | components/app_modal_strings.grdp » ('j') | components/app_modal_strings.grdp » ('J')

Powered by Google App Engine
This is Rietveld 408576698