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

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

Issue 343081: Fix a problem in the implementation of search-vs.-go-in-context-menus. We we... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/tab_contents/render_view_context_menu.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu.cc (revision 30723)
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
@@ -36,25 +36,6 @@
using WebKit::WebContextMenuData;
using WebKit::WebMediaPlayerAction;
-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)
@@ -218,33 +199,37 @@
void RenderViewContextMenu::AppendSearchProvider() {
DCHECK(profile_);
- const TemplateURL* const default_provider =
- profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
- if (!default_provider)
- return;
- string16 selection_text = EscapeAmpersands(WideToUTF16(
- l10n_util::TruncateString(params_.selection_text, 50)));
- if (selection_text.empty())
+ if (params_.selection_text.empty())
return;
bool is_search;
profile_->GetSearchVersusNavigateClassifier()->Classify(
- UTF16ToWide(selection_text), std::wstring(), &is_search,
+ params_.selection_text, std::wstring(), &is_search,
&selection_navigation_url_, &transition_, NULL, NULL);
if (!selection_navigation_url_.is_valid())
return;
+ string16 printable_selection_text(
+ WideToUTF16(l10n_util::TruncateString(params_.selection_text, 50)));
+ // Escape "&" as "&&".
+ for (size_t i = printable_selection_text.find('&'); i != string16::npos;
+ i = printable_selection_text.find('&', i + 2))
+ printable_selection_text.insert(i, 1, '&');
+
if (is_search) {
- string16 label(l10n_util::GetStringFUTF16(
- IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
- WideToUTF16(default_provider->short_name()),
- selection_text));
- AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label);
+ const TemplateURL* const default_provider =
+ profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
+ if (!default_provider)
+ return;
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
+ l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
+ WideToUTF16(default_provider->short_name()),
+ printable_selection_text));
} else {
- string16 label(l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
- selection_text));
- AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL, label);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL,
+ l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
+ printable_selection_text));
}
}
« 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