0

Add the feature "Add as seach engine..." when right clicking on a form text field.

Note: POST forms are not supported with this patch 

BUG=6872
TEST=none


Review URL: http://codereview.chromium.org/335023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91253 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
philippe.beauchamp@gmail.com
2011-07-01 01:55:49 +00:00
parent 4b4a94f22b
commit 747f1c5ae9
9 changed files with 66 additions and 0 deletions

@ -268,6 +268,7 @@
// Search items.
#define IDC_CONTENT_CONTEXT_GOTOURL 50170
#define IDC_CONTENT_CONTEXT_SEARCHWEBFOR 50171
#define IDC_CONTENT_CONTEXT_ADDSEARCHENGINE 50172
// Context menu items in the bookmark bar
#define IDC_BOOKMARK_BAR_OPEN_ALL 51000

@ -543,6 +543,9 @@ are declared in build/common.gypi.
<message name="IDS_CONTENT_CONTEXT_GOTOURL" desc="The name of the Go to 'url' command in the content area context menu">
&amp;Go to <ph name="URL">$1<ex>http://www.google.com/</ex></ph>
</message>
<message name="IDS_CONTENT_CONTEXT_ADDSEARCHENGINE" desc="The name of the Add as Search Engine command in the content area context menu">
Add as search en&amp;gine...
</message>
<message name="IDS_CONTENT_CONTEXT_INPUT_METHODS_MENU" desc="The name of the input method submenu in the content area context menu">
Input &amp;methods
</message>
@ -734,6 +737,9 @@ are declared in build/common.gypi.
<message name="IDS_CONTENT_CONTEXT_GOTOURL" desc="In Title Case: The name of the Go to url for 'string' command in the content area context menu">
&amp;Go to <ph name="URL">$1<ex>http://www.google.com/</ex></ph>
</message>
<message name="IDS_CONTENT_CONTEXT_ADDSEARCHENGINE" desc="In Title Case: The name of the Add as Search Engine command in the content area context menu">
Add As Search En&amp;gine...
</message>
<message name="IDS_CONTENT_CONTEXT_INPUT_METHODS_MENU" desc="In Title Case: The name of the input method submenu in the content area context menu">
Input &amp;Methods
</message>

@ -614,6 +614,7 @@ bool ExternalTabContainer::HandleContextMenu(const ContextMenuParams& params) {
params.unfiltered_link_url,
params.src_url,
params.page_url,
params.keyword_url,
params.frame_url);
bool rtl = base::i18n::IsRTL();

@ -40,7 +40,9 @@
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/browser/translate/translate_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/download/download_tab_helper.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@ -785,6 +787,12 @@ void RenderViewContextMenu::AppendEditableItems() {
IDS_CONTENT_CONTEXT_DELETE);
menu_model_.AddSeparator();
if (!params_.keyword_url.is_empty()) {
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE,
IDS_CONTENT_CONTEXT_ADDSEARCHENGINE);
menu_model_.AddSeparator();
}
AppendSpellcheckOptionsSubMenu();
#if defined(OS_MACOSX)
@ -1177,6 +1185,9 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
return true;
#endif
case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE:
return !params_.keyword_url.is_empty();
case IDC_SPELLCHECK_MENU:
return true;
@ -1622,6 +1633,36 @@ void RenderViewContextMenu::ExecuteCommand(int id) {
break;
}
case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: {
// Make sure the model is loaded.
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(profile_);
if (!model)
return;
model->Load();
scoped_ptr<TemplateURL> template_url(new TemplateURL);
string16 keyword =
net::StripWWW(UTF8ToUTF16((params_.page_url.host())));
template_url->set_short_name(keyword);
template_url->set_keyword(keyword);
template_url->SetURL(params_.keyword_url.spec(), 0, 0);
template_url->SetFaviconURL(TemplateURL::GenerateFaviconURL(
params_.page_url.GetOrigin()));
TabContentsWrapper* tab_contents_wrapper =
TabContentsWrapper::GetCurrentWrapperForContents(
source_tab_contents_);
if (tab_contents_wrapper &&
tab_contents_wrapper->search_engine_tab_helper() &&
tab_contents_wrapper->search_engine_tab_helper()->delegate()) {
// Takes ownership of |template_url|.
tab_contents_wrapper->search_engine_tab_helper()->delegate()->
ConfirmAddSearchProvider(template_url.release(), profile_);
}
break;
}
default:
NOTREACHED();
break;

@ -134,6 +134,7 @@ MiniContextMenuParams::MiniContextMenuParams(int in_screen_x,
const GURL& in_unfiltered_link_url,
const GURL& in_src_url,
const GURL& in_page_url,
const GURL& in_keyword_url,
const GURL& in_frame_url)
: screen_x(in_screen_x),
screen_y(in_screen_y),
@ -141,6 +142,7 @@ MiniContextMenuParams::MiniContextMenuParams(int in_screen_x,
unfiltered_link_url(in_unfiltered_link_url),
src_url(in_src_url),
page_url(in_page_url),
keyword_url(in_keyword_url),
frame_url(in_frame_url) {
}
@ -601,6 +603,7 @@ void ParamTraits<MiniContextMenuParams>::Write(Message* m,
WriteParam(m, p.unfiltered_link_url);
WriteParam(m, p.src_url);
WriteParam(m, p.page_url);
WriteParam(m, p.keyword_url);
WriteParam(m, p.frame_url);
}
@ -614,6 +617,7 @@ bool ParamTraits<MiniContextMenuParams>::Read(const Message* m,
ReadParam(m, iter, &p->unfiltered_link_url) &&
ReadParam(m, iter, &p->src_url) &&
ReadParam(m, iter, &p->page_url) &&
ReadParam(m, iter, &p->keyword_url) &&
ReadParam(m, iter, &p->frame_url);
}
@ -633,6 +637,8 @@ void ParamTraits<MiniContextMenuParams>::Log(const param_type& p,
l->append(", ");
LogParam(p.page_url, l);
l->append(", ");
LogParam(p.keyword_url, l);
l->append(", ");
LogParam(p.frame_url, l);
l->append(")");
}

@ -118,6 +118,7 @@ struct MiniContextMenuParams {
const GURL& unfiltered_link_url,
const GURL& src_url,
const GURL& page_url,
const GURL& keyword_url,
const GURL& frame_url);
~MiniContextMenuParams();
@ -144,6 +145,10 @@ struct MiniContextMenuParams {
// on.
GURL page_url;
// This is the absolute keyword search URL including the %s search tag when
// the "Add as search engine..." option is clicked (left empty if not used).
GURL keyword_url;
// This is the URL of the subframe that the context menu was invoked on.
GURL frame_url;
};

@ -179,6 +179,7 @@ IPC_STRUCT_TRAITS_BEGIN(ContextMenuParams)
IPC_STRUCT_TRAITS_MEMBER(src_url)
IPC_STRUCT_TRAITS_MEMBER(is_image_blocked)
IPC_STRUCT_TRAITS_MEMBER(page_url)
IPC_STRUCT_TRAITS_MEMBER(keyword_url)
IPC_STRUCT_TRAITS_MEMBER(frame_url)
IPC_STRUCT_TRAITS_MEMBER(frame_content_state)
IPC_STRUCT_TRAITS_MEMBER(media_flags)

@ -37,6 +37,7 @@ ContextMenuParams::ContextMenuParams(const WebKit::WebContextMenuData& data)
src_url(data.srcURL),
is_image_blocked(data.isImageBlocked),
page_url(data.pageURL),
keyword_url(data.keywordURL),
frame_url(data.frameURL),
media_flags(data.mediaFlags),
selection_text(data.selectedText),

@ -66,6 +66,10 @@ struct ContextMenuParams {
// on.
GURL page_url;
// This is the absolute keyword search URL including the %s search tag when
// the "Add as search engine..." option is clicked (left empty if not used).
GURL keyword_url;
// This is the URL of the subframe that the context menu was invoked on.
GURL frame_url;