diff options
author | philippe.beauchamp@gmail.com <philippe.beauchamp@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-01 01:55:49 +0000 |
---|---|---|
committer | philippe.beauchamp@gmail.com <philippe.beauchamp@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-01 01:55:49 +0000 |
commit | 747f1c5ae9937394d7383370a60cf43a66a4d6c0 (patch) | |
tree | e637e8d7f9b7d7b92f6e057b5c5a1f0250a95e1a | |
parent | 4b4a94f22b77870f0851661a5f1732c35dadb9e9 (diff) | |
download | chromium_src-747f1c5ae9937394d7383370a60cf43a66a4d6c0.zip chromium_src-747f1c5ae9937394d7383370a60cf43a66a4d6c0.tar.gz chromium_src-747f1c5ae9937394d7383370a60cf43a66a4d6c0.tar.bz2 |
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
-rw-r--r-- | chrome/app/chrome_command_ids.h | 1 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/external_tab_container_win.cc | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 41 | ||||
-rw-r--r-- | chrome/common/automation_messages.cc | 6 | ||||
-rw-r--r-- | chrome/common/automation_messages.h | 5 | ||||
-rw-r--r-- | content/common/view_messages.h | 1 | ||||
-rw-r--r-- | webkit/glue/context_menu.cc | 1 | ||||
-rw-r--r-- | webkit/glue/context_menu.h | 4 |
9 files changed, 66 insertions, 0 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index 3cf660c..76c0774 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -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 diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 47559e3..3b70c0d 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -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"> &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&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 &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"> &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&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 &Methods </message> diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 15a661b..2ade918 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -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(); diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 4a6f871..ed3df60 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -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; diff --git a/chrome/common/automation_messages.cc b/chrome/common/automation_messages.cc index 5f27ac7..87a294b 100644 --- a/chrome/common/automation_messages.cc +++ b/chrome/common/automation_messages.cc @@ -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(")"); } diff --git a/chrome/common/automation_messages.h b/chrome/common/automation_messages.h index f884c54..e714c45 100644 --- a/chrome/common/automation_messages.h +++ b/chrome/common/automation_messages.h @@ -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; }; diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 76e5ce3..7c3ef4a 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -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) diff --git a/webkit/glue/context_menu.cc b/webkit/glue/context_menu.cc index c94ab37..2363a97 100644 --- a/webkit/glue/context_menu.cc +++ b/webkit/glue/context_menu.cc @@ -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), diff --git a/webkit/glue/context_menu.h b/webkit/glue/context_menu.h index e8441e56..3a70bbd 100644 --- a/webkit/glue/context_menu.h +++ b/webkit/glue/context_menu.h @@ -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; |