Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestThumbnailForContextNode_ACK, | 195 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestThumbnailForContextNode_ACK, |
| 196 OnRequestThumbnailForContextNodeACK) | 196 OnRequestThumbnailForContextNodeACK) |
| 197 IPC_MESSAGE_UNHANDLED(handled = false) | 197 IPC_MESSAGE_UNHANDLED(handled = false) |
| 198 IPC_END_MESSAGE_MAP() | 198 IPC_END_MESSAGE_MAP() |
| 199 return handled; | 199 return handled; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Handles the image thumbnail for the context node, composes a image search | 202 // Handles the image thumbnail for the context node, composes a image search |
| 203 // request based on the received thumbnail and opens the request in a new tab. | 203 // request based on the received thumbnail and opens the request in a new tab. |
| 204 void CoreTabHelper::OnRequestThumbnailForContextNodeACK( | 204 void CoreTabHelper::OnRequestThumbnailForContextNodeACK( |
| 205 const SkBitmap& bitmap, | 205 const std::string& thumbnail_data, |
| 206 const gfx::Size& original_size) { | 206 const gfx::Size& original_size) { |
| 207 if (bitmap.isNull()) | 207 if (thumbnail_data.empty()) |
| 208 return; | 208 return; |
| 209 | |
| 209 Profile* profile = | 210 Profile* profile = |
| 210 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 211 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 211 | 212 |
| 212 TemplateURLService* template_url_service = | 213 TemplateURLService* template_url_service = |
| 213 TemplateURLServiceFactory::GetForProfile(profile); | 214 TemplateURLServiceFactory::GetForProfile(profile); |
| 214 if (!template_url_service) | 215 if (!template_url_service) |
| 215 return; | 216 return; |
| 216 const TemplateURL* const default_provider = | 217 const TemplateURL* const default_provider = |
| 217 template_url_service->GetDefaultSearchProvider(); | 218 template_url_service->GetDefaultSearchProvider(); |
| 218 if (!default_provider) | 219 if (!default_provider) |
| 219 return; | 220 return; |
| 220 | 221 |
| 221 const int kDefaultQualityForImageSearch = 90; | |
| 222 std::vector<unsigned char> data; | |
| 223 if (!gfx::JPEGCodec::Encode( | |
| 224 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | |
| 225 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | |
| 226 static_cast<int>(bitmap.rowBytes()), kDefaultQualityForImageSearch, | |
| 227 &data)) | |
| 228 return; | |
| 229 | |
| 230 TemplateURLRef::SearchTermsArgs search_args = | 222 TemplateURLRef::SearchTermsArgs search_args = |
| 231 TemplateURLRef::SearchTermsArgs(base::string16()); | 223 TemplateURLRef::SearchTermsArgs(base::string16()); |
| 232 search_args.image_thumbnail_content = std::string(data.begin(), data.end()); | 224 search_args.image_thumbnail_content = thumbnail_data; |
|
sky
2014/12/11 20:26:49
My question is why this is a string and not a SkBi
Peter Kasting
2014/12/11 20:55:33
We're going to pass it to the search engine as tex
sky
2014/12/11 21:09:42
That makes sense. Thanks for the clarification. Th
| |
| 233 // TODO(jnd): Add a method in WebContentsViewDelegate to get the image URL | 225 // TODO(jnd): Add a method in WebContentsViewDelegate to get the image URL |
| 234 // from the ContextMenuParams which creates current context menu. | 226 // from the ContextMenuParams which creates current context menu. |
| 235 search_args.image_url = GURL(); | 227 search_args.image_url = GURL(); |
| 236 search_args.image_original_size = original_size; | 228 search_args.image_original_size = original_size; |
| 237 TemplateURLRef::PostContent post_content; | 229 TemplateURLRef::PostContent post_content; |
| 238 GURL result(default_provider->image_url_ref().ReplaceSearchTerms( | 230 GURL result(default_provider->image_url_ref().ReplaceSearchTerms( |
| 239 search_args, template_url_service->search_terms_data(), &post_content)); | 231 search_args, template_url_service->search_terms_data(), &post_content)); |
| 240 if (!result.is_valid()) | 232 if (!result.is_valid()) |
| 241 return; | 233 return; |
| 242 | 234 |
| 243 content::OpenURLParams open_url_params( | 235 content::OpenURLParams open_url_params( |
| 244 result, content::Referrer(), NEW_FOREGROUND_TAB, | 236 result, content::Referrer(), NEW_FOREGROUND_TAB, |
| 245 ui::PAGE_TRANSITION_LINK, false); | 237 ui::PAGE_TRANSITION_LINK, false); |
| 246 const std::string& content_type = post_content.first; | 238 const std::string& content_type = post_content.first; |
| 247 std::string* post_data = &post_content.second; | 239 std::string* post_data = &post_content.second; |
| 248 if (!post_data->empty()) { | 240 if (!post_data->empty()) { |
| 249 DCHECK(!content_type.empty()); | 241 DCHECK(!content_type.empty()); |
| 250 open_url_params.uses_post = true; | 242 open_url_params.uses_post = true; |
| 251 open_url_params.browser_initiated_post_data = | 243 open_url_params.browser_initiated_post_data = |
| 252 base::RefCountedString::TakeString(post_data); | 244 base::RefCountedString::TakeString(post_data); |
| 253 open_url_params.extra_headers += base::StringPrintf( | 245 open_url_params.extra_headers += base::StringPrintf( |
| 254 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, | 246 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, |
| 255 content_type.c_str()); | 247 content_type.c_str()); |
| 256 } | 248 } |
| 257 web_contents()->OpenURL(open_url_params); | 249 web_contents()->OpenURL(open_url_params); |
| 258 } | 250 } |
| OLD | NEW |