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

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

Issue 2486003: Truncate very long javascript alert messages. They can overflow the UI and on Linux cause crashes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: ElideString Created 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/js_modal_dialog.h" 5 #include "chrome/browser/js_modal_dialog.h"
6 6
7 #include "base/string_util.h"
7 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/tab_contents/tab_contents.h" 9 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/common/notification_service.h" 10 #include "chrome/common/notification_service.h"
10 #include "chrome/common/notification_type.h" 11 #include "chrome/common/notification_type.h"
11 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
12 13
14 namespace {
15
16 // The maximum sizes of various texts passed to us from javascript.
17 const int kMessageTextMaxSize = 3000;
18 const int kDefaultPromptTextSize = 2000;
19
20 } // namespace
21
13 JavaScriptAppModalDialog::JavaScriptAppModalDialog( 22 JavaScriptAppModalDialog::JavaScriptAppModalDialog(
14 JavaScriptMessageBoxClient* client, 23 JavaScriptMessageBoxClient* client,
15 const std::wstring& title, 24 const std::wstring& title,
16 int dialog_flags, 25 int dialog_flags,
17 const std::wstring& message_text, 26 const std::wstring& message_text,
18 const std::wstring& default_prompt_text, 27 const std::wstring& default_prompt_text,
19 bool display_suppress_checkbox, 28 bool display_suppress_checkbox,
20 bool is_before_unload_dialog, 29 bool is_before_unload_dialog,
21 IPC::Message* reply_msg) 30 IPC::Message* reply_msg)
22 : AppModalDialog(client->AsTabContents(), title), 31 : AppModalDialog(client->AsTabContents(), title),
23 client_(client), 32 client_(client),
24 extension_host_(client->AsExtensionHost()), 33 extension_host_(client->AsExtensionHost()),
25 dialog_flags_(dialog_flags), 34 dialog_flags_(dialog_flags),
26 message_text_(message_text), 35 message_text_(message_text),
27 default_prompt_text_(default_prompt_text), 36 default_prompt_text_(default_prompt_text),
28 display_suppress_checkbox_(display_suppress_checkbox), 37 display_suppress_checkbox_(display_suppress_checkbox),
29 is_before_unload_dialog_(is_before_unload_dialog), 38 is_before_unload_dialog_(is_before_unload_dialog),
30 reply_msg_(reply_msg) { 39 reply_msg_(reply_msg) {
40 // We trim the various parts of the message dialog because otherwise we can
41 // overflow the message dialog (and crash/hang the GTK+ version).
42 ElideString(message_text, kMessageTextMaxSize, &message_text_);
43 ElideString(default_prompt_text, kDefaultPromptTextSize,
44 &default_prompt_text_);
45
31 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); 46 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL));
32 InitNotifications(); 47 InitNotifications();
33 } 48 }
34 49
35 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { 50 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
36 } 51 }
37 52
38 void JavaScriptAppModalDialog::Observe(NotificationType type, 53 void JavaScriptAppModalDialog::Observe(NotificationType type,
39 const NotificationSource& source, 54 const NotificationSource& source,
40 const NotificationDetails& details) { 55 const NotificationDetails& details) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #if !defined(OS_MACOSX) 132 #if !defined(OS_MACOSX)
118 else if (extension_host_) 133 else if (extension_host_)
119 extension_host_->OnMessageBoxClosed(reply_msg_, false, L""); 134 extension_host_->OnMessageBoxClosed(reply_msg_, false, L"");
120 else 135 else
121 NOTREACHED(); 136 NOTREACHED();
122 #endif 137 #endif
123 } 138 }
124 AppModalDialog::Cleanup(); 139 AppModalDialog::Cleanup();
125 } 140 }
126 141
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698