summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorjnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-04 06:31:41 +0000
committerjnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-04 06:31:41 +0000
commitb2272e5852cdafbd66a99b2e9743a4eeb312b3f4 (patch)
tree6edeecdd158236e92fbac98d26daa8e8a634c615 /chrome/browser/tab_contents
parentad00d2438af70ab6430c4ee3b72b4a66f73131fc (diff)
downloadchromium_src-b2272e5852cdafbd66a99b2e9743a4eeb312b3f4.zip
chromium_src-b2272e5852cdafbd66a99b2e9743a4eeb312b3f4.tar.gz
chromium_src-b2272e5852cdafbd66a99b2e9743a4eeb312b3f4.tar.bz2
The UI part of search-by-image search.
When users click the 'search-by-image', the work flow is (1) Chrome sends ChromeViewMsg_RequestThumbnailForContextNode to render (2) Render gets the image, down-scale (if necessary) and send it back with ChromeViewHostMsg_RequestThumbnailForContextNode_ACK) (3) Chrome generates image search URL for current search provider, sends the search request and opens a new tab to show the result. BUG=89945 TEST= it depends on https://codereview.chromium.org/21378002/ to pass compilation. Review URL: https://chromiumcodereview.appspot.com/21323003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215528 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc39
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h3
2 files changed, 41 insertions, 1 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index ade80c3..a788771 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -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 @@ using extensions::MenuManager;
namespace {
+const int kImageSearchThumbnailMinSize = 300 * 300;
+const int kImageSearchThumbnailMaxWidth = 600;
+const int kImageSearchThumbnailMaxHeight = 600;
+
// 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 @@ const struct UmaEnumCommandIdPair {
{ 54, IDC_SPELLCHECK_MENU },
{ 55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE },
{ 56, IDC_SPELLCHECK_LANGUAGES_FIRST },
+ { 57, IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB },
// 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,19 @@ void RenderViewContextMenu::AppendImageItems() {
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)) {
+ menu_model_.AddItem(
+ IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB,
+ l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFORIMAGE,
+ default_provider->short_name()));
+ }
}
void RenderViewContextMenu::AppendAudioItems() {
@@ -1253,6 +1276,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
}
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 +1630,10 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
CopyImageAt(params_.x, params_.y);
break;
+ case IDC_CONTENT_CONTEXT_SEARCHIMAGENEWTAB:
+ GetImageThumbnailForSearch();
+ break;
+
case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
OpenURL(
@@ -2034,6 +2062,15 @@ void RenderViewContextMenu::CopyImageAt(int x, int y) {
source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y);
}
+void RenderViewContextMenu::GetImageThumbnailForSearch() {
+ 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(
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index 6f2d0b4..db0bb7e 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -237,6 +237,9 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
// Copy to the clipboard an image located at a point in the RenderView
void CopyImageAt(int x, int y);
+ // Get an image located at a point in the RenderView for search.
+ void GetImageThumbnailForSearch();
+
// Launch the inspector targeting a point in the RenderView
void Inspect(int x, int y);