diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 19:50:26 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 19:50:26 +0000 |
commit | 106c901495fac4d0a09656144e37c6c5abe7a6e0 (patch) | |
tree | df0b346c84d886d75654b22e916cf5999da0a2f1 /chrome/browser/jsmessage_box_handler.cc | |
parent | 2674971542ef049b13ddad5dc1ac77fa9b16f498 (diff) | |
download | chromium_src-106c901495fac4d0a09656144e37c6c5abe7a6e0.zip chromium_src-106c901495fac4d0a09656144e37c6c5abe7a6e0.tar.gz chromium_src-106c901495fac4d0a09656144e37c6c5abe7a6e0.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/jsmessage_box_handler.cc')
-rw-r--r-- | chrome/browser/jsmessage_box_handler.cc | 16 |
1 files changed, 13 insertions, 3 deletions
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 |