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

Side by Side Diff: chrome/browser/ui/tab_contents/core_tab_helper.cc

Issue 939713003: Enabled the "search web for image" context menu item when "Yandex" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 OnRequestThumbnailForContextNodeACK) 237 OnRequestThumbnailForContextNodeACK)
238 IPC_MESSAGE_UNHANDLED(handled = false) 238 IPC_MESSAGE_UNHANDLED(handled = false)
239 IPC_END_MESSAGE_MAP() 239 IPC_END_MESSAGE_MAP()
240 return handled; 240 return handled;
241 } 241 }
242 242
243 // Handles the image thumbnail for the context node, composes a image search 243 // Handles the image thumbnail for the context node, composes a image search
244 // request based on the received thumbnail and opens the request in a new tab. 244 // request based on the received thumbnail and opens the request in a new tab.
245 void CoreTabHelper::OnRequestThumbnailForContextNodeACK( 245 void CoreTabHelper::OnRequestThumbnailForContextNodeACK(
246 const std::string& thumbnail_data, 246 const std::string& thumbnail_data,
247 const std::string& thumbnail_format,
247 const gfx::Size& original_size) { 248 const gfx::Size& original_size) {
248 if (thumbnail_data.empty()) 249 if (thumbnail_data.empty())
249 return; 250 return;
250 251
251 Profile* profile = 252 Profile* profile =
252 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 253 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
253 254
254 TemplateURLService* template_url_service = 255 TemplateURLService* template_url_service =
255 TemplateURLServiceFactory::GetForProfile(profile); 256 TemplateURLServiceFactory::GetForProfile(profile);
256 if (!template_url_service) 257 if (!template_url_service)
257 return; 258 return;
258 const TemplateURL* const default_provider = 259 const TemplateURL* const default_provider =
259 template_url_service->GetDefaultSearchProvider(); 260 template_url_service->GetDefaultSearchProvider();
260 if (!default_provider) 261 if (!default_provider)
261 return; 262 return;
262 263
263 TemplateURLRef::SearchTermsArgs search_args = 264 TemplateURLRef::SearchTermsArgs search_args =
264 TemplateURLRef::SearchTermsArgs(base::string16()); 265 TemplateURLRef::SearchTermsArgs(base::string16());
265 search_args.image_thumbnail_content = thumbnail_data; 266 search_args.image_thumbnail_content = thumbnail_data;
267 search_args.image_thumbnail_format = thumbnail_format;
266 // TODO(jnd): Add a method in WebContentsViewDelegate to get the image URL 268 // TODO(jnd): Add a method in WebContentsViewDelegate to get the image URL
267 // from the ContextMenuParams which creates current context menu. 269 // from the ContextMenuParams which creates current context menu.
268 search_args.image_url = GURL(); 270 search_args.image_url = GURL();
269 search_args.image_original_size = original_size; 271 search_args.image_original_size = original_size;
270 TemplateURLRef::PostContent post_content; 272 TemplateURLRef::PostContent post_content;
271 GURL result(default_provider->image_url_ref().ReplaceSearchTerms( 273 GURL result(default_provider->image_url_ref().ReplaceSearchTerms(
272 search_args, template_url_service->search_terms_data(), &post_content)); 274 search_args, template_url_service->search_terms_data(), &post_content));
273 if (!result.is_valid()) 275 if (!result.is_valid())
274 return; 276 return;
275 277
276 content::OpenURLParams open_url_params( 278 content::OpenURLParams open_url_params(
277 result, content::Referrer(), NEW_FOREGROUND_TAB, 279 result, content::Referrer(), NEW_FOREGROUND_TAB,
278 ui::PAGE_TRANSITION_LINK, false); 280 ui::PAGE_TRANSITION_LINK, false);
279 const std::string& content_type = post_content.first; 281 const std::string& content_type = post_content.first;
280 std::string* post_data = &post_content.second; 282 std::string* post_data = &post_content.second;
281 if (!post_data->empty()) { 283 if (!post_data->empty()) {
282 DCHECK(!content_type.empty()); 284 DCHECK(!content_type.empty());
283 open_url_params.uses_post = true; 285 open_url_params.uses_post = true;
284 open_url_params.browser_initiated_post_data = 286 open_url_params.browser_initiated_post_data =
285 base::RefCountedString::TakeString(post_data); 287 base::RefCountedString::TakeString(post_data);
286 open_url_params.extra_headers += base::StringPrintf( 288 open_url_params.extra_headers += base::StringPrintf(
287 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, 289 "%s: %s\r\n", net::HttpRequestHeaders::kContentType,
288 content_type.c_str()); 290 content_type.c_str());
289 } 291 }
290 web_contents()->OpenURL(open_url_params); 292 web_contents()->OpenURL(open_url_params);
291 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698