summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-11 00:15:25 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-11 00:15:25 +0000
commit3413dd8e6353804a0931fc86f842194a6891be90 (patch)
tree037cbe515376483d6bc984bd05bb4c2ee18a420d /chrome
parent9611bb6540f8bd039d60a050733f6e1379e6d7f5 (diff)
downloadchromium_src-3413dd8e6353804a0931fc86f842194a6891be90.zip
chromium_src-3413dd8e6353804a0931fc86f842194a6891be90.tar.gz
chromium_src-3413dd8e6353804a0931fc86f842194a6891be90.tar.bz2
Set an upper limit to the number of characters that can appear in a tooltip string.
B=1368905 Review URL: http://codereview.chromium.org/2409 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/render_widget_host_hwnd.cc10
-rw-r--r--chrome/views/tooltip_manager.cc9
2 files changed, 19 insertions, 0 deletions
diff --git a/chrome/browser/render_widget_host_hwnd.cc b/chrome/browser/render_widget_host_hwnd.cc
index f5f2ed6..346b050 100644
--- a/chrome/browser/render_widget_host_hwnd.cc
+++ b/chrome/browser/render_widget_host_hwnd.cc
@@ -25,6 +25,9 @@
// Tooltips will wrap after this width. Yes, wrap. Imagine that!
static const int kTooltipMaxWidthPixels = 300;
+// Maximum number of characters we allow in a tooltip.
+static const int kMaxTooltipLength = 1024;
+
///////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostHWND, public:
@@ -297,6 +300,13 @@ void RenderWidgetHostHWND::Destroy() {
void RenderWidgetHostHWND::SetTooltipText(const std::wstring& tooltip_text) {
if (tooltip_text != tooltip_text_) {
tooltip_text_ = tooltip_text;
+
+ // Clamp the tooltip length to kMaxTooltipLength so that we don't
+ // accidentally DOS the user with a mega tooltip (since Windows doesn't seem
+ // to do this itself).
+ if (tooltip_text_.length() > kMaxTooltipLength)
+ tooltip_text_ = tooltip_text_.substr(0, kMaxTooltipLength);
+
// Need to check if the tooltip is already showing so that we don't
// immediately show the tooltip with no delay when we move the mouse from
// a region with no tooltip to a region with a tooltip.
diff --git a/chrome/views/tooltip_manager.cc b/chrome/views/tooltip_manager.cc
index fd4b3a3..cdac076 100644
--- a/chrome/views/tooltip_manager.cc
+++ b/chrome/views/tooltip_manager.cc
@@ -27,6 +27,9 @@ static const int kDefaultTimeout = 4000;
// Maximum number of lines we allow in the tooltip.
static const int kMaxLines = 6;
+// Maximum number of characters we allow in a tooltip.
+static const int kMaxTooltipLength = 1024;
+
// Breaks |text| along line boundaries, placing each line of text into lines.
static void SplitTooltipString(const std::wstring& text,
std::vector<std::wstring>* lines) {
@@ -272,6 +275,12 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text,
*max_width = 0;
*line_count = 0;
+ // Clamp the tooltip length to kMaxTooltipLength so that we don't
+ // accidentally DOS the user with a mega tooltip (since Windows doesn't seem
+ // to do this itself).
+ if (text->length() > kMaxTooltipLength)
+ *text = text->substr(0, kMaxTooltipLength);
+
// Determine the available width for the tooltip.
CPoint screen_loc(position_x, position_y);
View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc);