Index: chrome/browser/tab_contents/render_view_context_menu.cc |
=================================================================== |
--- chrome/browser/tab_contents/render_view_context_menu.cc (revision 214769) |
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy) |
@@ -16,6 +16,7 @@ |
#include "base/prefs/pref_service.h" |
#include "base/stl_util.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "chrome/app/chrome_command_ids.h" |
@@ -42,6 +43,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_io_data.h" |
#include "chrome/browser/search/search.h" |
+#include "chrome/browser/search_engines/search_terms_data.h" |
#include "chrome/browser/search_engines/template_url.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
@@ -65,6 +67,7 @@ |
#include "chrome/common/net/url_util.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/print_messages.h" |
+#include "chrome/common/render_messages.h" |
#include "chrome/common/spellcheck_messages.h" |
#include "chrome/common/url_constants.h" |
#include "content/public/browser/child_process_security_policy.h" |
@@ -92,6 +95,8 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/text/text_elider.h" |
#include "ui/gfx/favicon_size.h" |
+#include "ui/gfx/point.h" |
+#include "ui/gfx/size.h" |
using WebKit::WebContextMenuData; |
using WebKit::WebMediaPlayerAction; |
@@ -115,6 +120,10 @@ |
namespace { |
+const int kImageSearchThumbnailMinSize = 300 * 300; |
+const int kImageSearchThumbnailMaxWidth = 600; |
+const int kImageSearchThumbnailMaxHeight = 600; |
Kibeom Kim (inactive)
2013/07/31 21:25:54
Actually, Android Chrome need to access these valu
|
+ |
// Maps UMA enumeration to IDC. IDC could be changed so we can't use |
// just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|. |
// Never change mapping or reuse |enum_id|. Always push back new items. |
@@ -181,8 +190,9 @@ |
{ 54, IDC_SPELLCHECK_MENU }, |
{ 55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE }, |
{ 56, IDC_SPELLCHECK_LANGUAGES_FIRST }, |
+ {57, IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB }, |
Avi (use Gerrit)
2013/07/31 20:11:05
Match style; space after {
Johnny(Jianning) Ding
2013/07/31 21:38:09
Done.
|
// Add new items here and use |enum_id| from the next line. |
- { 57, 0 }, // Must be the last. Increment |enum_id| when new IDC was added. |
+ { 58, 0 }, // Must be the last. Increment |enum_id| when new IDC was added. |
}; |
// Collapses large ranges of ids before looking for UMA enum. |
@@ -843,6 +853,21 @@ |
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, |
IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
AppendPrintItem(); |
+ const TemplateURL* const default_provider = |
+ TemplateURLServiceFactory::GetForProfile(profile_)-> |
+ GetDefaultSearchProvider(); |
+ if (!default_provider) |
+ return; |
+ SearchTermsData search_terms; |
+ if (!default_provider->image_url().empty() && |
+ default_provider->image_url_ref().IsValidUsingTermsData(search_terms)) { |
+ std::string search_provider_name = |
+ UTF16ToUTF8(default_provider->short_name()); |
+ std::string menu_item_name = |
+ base::StringPrintf("Search Image By %s", search_provider_name.c_str()); |
jingbinw
2013/07/31 20:04:45
I would suggest to rename this as
"Search %s for
Avi (use Gerrit)
2013/07/31 20:11:05
Um...
Every one of our UI strings is localized an
Kibeom Kim (inactive)
2013/07/31 20:20:53
note: just like IDS_CONTENT_CONTEXT_SEARCHWEBFOR i
Avi (use Gerrit)
2013/07/31 20:35:53
Yes. Look for examples (in this very file) with l1
Johnny(Jianning) Ding
2013/07/31 21:26:36
The hard-code "Search Image By %s" should be repla
jingbinw
2013/07/31 23:31:29
Can you rewording the message to be "Search %s for
Peter Kasting
2013/07/31 23:38:22
No, it's not correct. You should never see a .cc
Kibeom Kim (inactive)
2013/08/01 00:14:59
here:
menu_model_.AddItem(
IDC_CONTENT_CONTEXT
|
+ menu_model_.AddItem(IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB, |
+ UTF8ToUTF16(menu_item_name)); |
+ } |
} |
void RenderViewContextMenu::AppendAudioItems() { |
@@ -1253,6 +1278,7 @@ |
} |
case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
+ case IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB: |
// The images shown in the most visited thumbnails do not currently open |
// in a new tab as they should. Disabling this context menu option for |
// now, as a quick hack, before we resolve this issue (Issue = 2608). |
@@ -1606,6 +1632,10 @@ |
CopyImageAt(params_.x, params_.y); |
break; |
+ case IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB: |
+ GetImageThumbnailForSearch(params_.x, params_.y); |
+ break; |
+ |
case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
OpenURL( |
@@ -2034,6 +2064,15 @@ |
source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y); |
} |
+void RenderViewContextMenu::GetImageThumbnailForSearch(int x, int y) { |
Kibeom Kim (inactive)
2013/07/31 21:49:49
How x and y are used?
Johnny(Jianning) Ding
2013/07/31 21:53:47
they are gone.
|
+ source_web_contents_->GetRenderViewHost()->Send( |
+ new ChromeViewMsg_RequestThumbnailForContextNode( |
+ source_web_contents_->GetRenderViewHost()->GetRoutingID(), |
+ kImageSearchThumbnailMinSize, |
+ gfx::Size(kImageSearchThumbnailMaxWidth, |
+ kImageSearchThumbnailMaxHeight))); |
+} |
+ |
void RenderViewContextMenu::Inspect(int x, int y) { |
content::RecordAction(UserMetricsAction("DevTools_InspectElement")); |
source_web_contents_->GetRenderViewHostAtPosition( |