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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/js_modal_dialog.cc
diff --git a/chrome/browser/js_modal_dialog.cc b/chrome/browser/js_modal_dialog.cc
index 5eb66a8ac02773a1c0f4387213b4199b5d4d5c10..2bfb8c852f6b6c82d48a89913b46571dd1aa389b 100644
--- a/chrome/browser/js_modal_dialog.cc
+++ b/chrome/browser/js_modal_dialog.cc
@@ -4,12 +4,21 @@
#include "chrome/browser/js_modal_dialog.h"
+#include "base/string_util.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
#include "ipc/ipc_message.h"
+namespace {
+
+// The maximum sizes of various texts passed to us from javascript.
+const int kMessageTextMaxSize = 3000;
+const int kDefaultPromptTextSize = 2000;
+
+} // namespace
+
JavaScriptAppModalDialog::JavaScriptAppModalDialog(
JavaScriptMessageBoxClient* client,
const std::wstring& title,
@@ -28,6 +37,12 @@ JavaScriptAppModalDialog::JavaScriptAppModalDialog(
display_suppress_checkbox_(display_suppress_checkbox),
is_before_unload_dialog_(is_before_unload_dialog),
reply_msg_(reply_msg) {
+ // We trim the various parts of the message dialog because otherwise we can
+ // overflow the message dialog (and crash/hang the GTK+ version).
+ ElideString(message_text, kMessageTextMaxSize, &message_text_);
+ ElideString(default_prompt_text, kDefaultPromptTextSize,
+ &default_prompt_text_);
+
DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL));
InitNotifications();
}
« 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