From 106c901495fac4d0a09656144e37c6c5abe7a6e0 Mon Sep 17 00:00:00 2001 From: "cpu@google.com" Date: Tue, 14 Apr 2009 19:50:26 +0000 Subject: Clamp text size in js message box dialogs - Long text peg cpu at 100% for a couple of minutes for the UI thread - Now with extra protection for OnUnload() BUG=8863 TEST=existing ui tests suffice. Review URL: http://codereview.chromium.org/73043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13693 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/jsmessage_box_handler.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc index f4dc238..551cf4b 100644 --- a/chrome/browser/jsmessage_box_handler.cc +++ b/chrome/browser/jsmessage_box_handler.cc @@ -19,6 +19,16 @@ namespace { +const size_t kMaxReasonableTextLength = 2048; + +// In some platforms, the underlying processing of humongous strings takes too +// long and thus make the UI thread unresponsive. +std::wstring MakeTextSafe(const std::wstring& text) { + if (text.size() > kMaxReasonableTextLength) + return text.substr(0, kMaxReasonableTextLength) + L"\x2026"; + return text; +} + std::wstring GetWindowTitle(WebContents* web_contents, const GURL& frame_url, int dialog_flags) { bool is_alert = (dialog_flags == MessageBox::kIsJavascriptAlert); @@ -61,7 +71,7 @@ void RunJavascriptMessageBox(WebContents* web_contents, #if defined(OS_WIN) || defined(OS_LINUX) AppModalDialogQueue::AddDialog(new AppModalDialog(web_contents, title, - dialog_flags, message_text, default_prompt_text, + dialog_flags, MakeTextSafe(message_text), default_prompt_text, display_suppress_checkbox, false, reply_msg)); #else NOTIMPLEMENTED(); @@ -77,8 +87,8 @@ void RunBeforeUnloadDialog(WebContents* web_contents, #if defined(OS_WIN) || defined(OS_LINUX) AppModalDialogQueue::AddDialog(new AppModalDialog( web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), - MessageBox::kIsJavascriptConfirm, message_text, std::wstring(), false, - true, reply_msg)); + MessageBox::kIsJavascriptConfirm, MakeTextSafe(message_text), + std::wstring(), false, true, reply_msg)); #else NOTIMPLEMENTED(); #endif -- cgit v1.1