diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/render_widget_host_hwnd.cc | 10 | ||||
-rw-r--r-- | chrome/views/tooltip_manager.cc | 9 |
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); |