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

Unified Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 203078: Escape ampersands in web view text selection for right click context menu so ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 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 | chrome/common/gtk_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/render_view_context_menu.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu.cc (revision 26282)
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
@@ -31,6 +31,25 @@
#include "net/base/net_util.h"
#include "webkit/glue/media_player_action.h"
+namespace {
+
+string16 EscapeAmpersands(const string16& text) {
+ string16 ret;
+ ret.reserve(text.length() * 2);
+ for (string16::const_iterator i = text.begin();
+ i != text.end(); ++i) {
+ // The escape for an ampersand is two ampersands.
+ if ('&' == *i)
+ ret.push_back(*i);
+
+ ret.push_back(*i);
+ }
+
+ return ret;
+}
+
+} // namespace
+
RenderViewContextMenu::RenderViewContextMenu(
TabContents* tab_contents,
const ContextMenuParams& params)
@@ -189,13 +208,13 @@
const TemplateURL* const default_provider =
profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
if (default_provider != NULL) {
- std::wstring selection_text =
- l10n_util::TruncateString(params_.selection_text, 50);
+ string16 selection_text = EscapeAmpersands(WideToUTF16(
+ l10n_util::TruncateString(params_.selection_text, 50)));
if (!selection_text.empty()) {
- string16 label(WideToUTF16(
- l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
- default_provider->short_name(),
- selection_text)));
+ string16 label(l10n_util::GetStringFUTF16(
+ IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
+ WideToUTF16(default_provider->short_name()),
+ selection_text));
AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label);
}
}
« no previous file with comments | « no previous file | chrome/common/gtk_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698