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

Unified Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc

Issue 2785193002: Restrict the amount of text shown in dialogs. (Closed)
Patch Set: Created 3 years, 9 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/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
diff --git a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
index 82b1781d9220090608f3cd250c16b6902be03c4e..76ac346a9786cbd6c6369d1357373f1ed4366985 100644
--- a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
+++ b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
@@ -18,6 +18,7 @@
#include "components/app_modal/javascript_dialog_manager.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
+#include "ui/gfx/text_elider.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper);
@@ -151,13 +152,28 @@ void JavaScriptDialogTabHelper::RunJavaScriptDialog(
DismissalCause::SUBSEQUENT_DIALOG_SHOWN);
}
+ // Enforce sane sizes. ElideRectangleString breaks horizontally, which isn't
+ // strictly needed, but it restricts the vertical size, which is crucial.
+ // This gives about 2000 characters, which is about the same as the
+ // AppModalDialogManager provides, but allows no more than 24 lines.
+ const int kMessageTextMaxRows = 24;
+ const int kMessageTextMaxCols = 80;
+ const size_t kDefaultPromptMaxSize = 2000;
+ base::string16 truncated_message_text;
+ gfx::ElideRectangleString(message_text, kMessageTextMaxRows,
+ kMessageTextMaxCols, false,
+ &truncated_message_text);
+ base::string16 truncated_default_prompt_text;
+ gfx::ElideString(default_prompt_text, kDefaultPromptMaxSize,
+ &truncated_default_prompt_text);
+
base::string16 title =
AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url);
dialog_callback_ = callback;
dialog_type_ = dialog_type;
dialog_ = JavaScriptDialog::Create(
parent_web_contents, alerting_web_contents, title, dialog_type,
- message_text, default_prompt_text,
+ truncated_message_text, truncated_default_prompt_text,
base::Bind(&JavaScriptDialogTabHelper::OnDialogClosed,
base::Unretained(this), callback));
« 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