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

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

Issue 326026: Add "Go to..." to the context menu when the selected text in a page is a url... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: UTF16ToWide Created 11 years, 2 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 | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | 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 30667)
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
@@ -18,6 +18,7 @@
#include "chrome/browser/net/browser_url_util.h"
#include "chrome/browser/page_info_window.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/spellchecker.h"
#include "chrome/browser/spellchecker_platform_engine.h"
@@ -73,7 +74,6 @@
}
void RenderViewContextMenu::InitMenu() {
-
bool has_link = !params_.link_url.is_empty();
bool has_selection = !params_.selection_text.empty();
@@ -220,16 +220,31 @@
DCHECK(profile_);
const TemplateURL* const default_provider =
profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
- if (default_provider != NULL) {
- string16 selection_text = EscapeAmpersands(WideToUTF16(
- l10n_util::TruncateString(params_.selection_text, 50)));
- if (!selection_text.empty()) {
- string16 label(l10n_util::GetStringFUTF16(
- IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
- WideToUTF16(default_provider->short_name()),
- selection_text));
- AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label);
- }
+ if (!default_provider)
+ return;
+
+ string16 selection_text = EscapeAmpersands(WideToUTF16(
+ l10n_util::TruncateString(params_.selection_text, 50)));
+ if (selection_text.empty())
+ return;
+
+ bool is_search;
+ profile_->GetSearchVersusNavigateClassifier()->Classify(
+ UTF16ToWide(selection_text), std::wstring(), &is_search,
+ &selection_navigation_url_, &transition_, NULL, NULL);
+ if (!selection_navigation_url_.is_valid())
+ return;
+
+ 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);
+ } else {
+ string16 label(l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
+ selection_text));
+ AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL, label);
}
}
@@ -445,6 +460,7 @@
case IDS_CONTENT_CONTEXT_COPYIMAGE:
case IDS_CONTENT_CONTEXT_PRINT:
case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
+ case IDS_CONTENT_CONTEXT_GOTOURL:
case IDC_SPELLCHECK_SUGGESTION_0:
case IDC_SPELLCHECK_SUGGESTION_1:
case IDC_SPELLCHECK_SUGGESTION_2:
@@ -701,16 +717,9 @@
source_tab_contents_->render_view_host()->SelectAll();
break;
- case IDS_CONTENT_CONTEXT_SEARCHWEBFOR: {
- const TemplateURL* const default_provider =
- profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
- DCHECK(default_provider); // The context menu should not contain this
- // item when there is no provider.
- const TemplateURLRef* const search_url = default_provider->url();
- DCHECK(search_url->SupportsReplacement());
- OpenURL(GURL(WideToUTF8(search_url->ReplaceSearchTerms(*default_provider,
- params_.selection_text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring()))), NEW_FOREGROUND_TAB, PageTransition::GENERATED);
+ case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
+ case IDS_CONTENT_CONTEXT_GOTOURL: {
+ OpenURL(selection_navigation_url_, NEW_FOREGROUND_TAB, transition_);
break;
}
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698