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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 518693002: Fix a crash when saving a <canvas> or <img> image which is large. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer_context_menu/render_view_context_menu.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 ProfileIOData::IsHandledProtocol(params_.link_url.scheme()); 1079 ProfileIOData::IsHandledProtocol(params_.link_url.scheme());
1080 } 1080 }
1081 1081
1082 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1082 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1083 PrefService* local_state = g_browser_process->local_state(); 1083 PrefService* local_state = g_browser_process->local_state();
1084 DCHECK(local_state); 1084 DCHECK(local_state);
1085 // Test if file-selection dialogs are forbidden by policy. 1085 // Test if file-selection dialogs are forbidden by policy.
1086 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1086 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
1087 return false; 1087 return false;
1088 1088
1089 if (params_.media_type == WebContextMenuData::MediaTypeCanvas) 1089 // If |params_.src_url| is empty, it might be a large data url.
Avi (use Gerrit) 2014/09/03 15:21:05 The word "might" here makes me uncomfortable. Two
Ken Russell (switch to Gerrit) 2014/09/04 00:23:26 Agree with Avi's comments; if the changes I sugges
zino 2014/09/05 03:47:47 Done. It is better to use has_image_contents inste
1090 return true; 1090 // In that case, we should enable the context menu and use
1091 1091 // RenderViewHost::SaveImageAt() method to save a image.
1092 return params_.src_url.is_valid() && 1092 return params_.src_url.is_empty() ||
1093 ProfileIOData::IsHandledProtocol(params_.src_url.scheme()); 1093 (params_.src_url.is_valid() &&
1094 ProfileIOData::IsHandledProtocol(params_.src_url.scheme()));
1094 } 1095 }
1095 1096
1096 // The images shown in the most visited thumbnails can't be opened or 1097 // The images shown in the most visited thumbnails can't be opened or
1097 // searched for conventionally. 1098 // searched for conventionally.
1098 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1099 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1099 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: 1100 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE:
1100 return params_.src_url.is_valid() && 1101 return params_.src_url.is_valid() &&
1101 (params_.src_url.scheme() != content::kChromeUIScheme); 1102 (params_.src_url.scheme() != content::kChromeUIScheme);
1102 1103
1103 case IDC_CONTENT_CONTEXT_COPYIMAGE: 1104 case IDC_CONTENT_CONTEXT_COPYIMAGE:
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 dl_params->set_referrer(referrer); 1339 dl_params->set_referrer(referrer);
1339 dl_params->set_referrer_encoding(params_.frame_charset); 1340 dl_params->set_referrer_encoding(params_.frame_charset);
1340 dl_params->set_suggested_name(params_.suggested_filename); 1341 dl_params->set_suggested_name(params_.suggested_filename);
1341 dl_params->set_prompt(true); 1342 dl_params->set_prompt(true);
1342 dlm->DownloadUrl(dl_params.Pass()); 1343 dlm->DownloadUrl(dl_params.Pass());
1343 break; 1344 break;
1344 } 1345 }
1345 1346
1346 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1347 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1347 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1348 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1348 if (params_.media_type == WebContextMenuData::MediaTypeCanvas) { 1349 if (params_.media_type == WebContextMenuData::MediaTypeCanvas ||
1350 (params_.media_type == WebContextMenuData::MediaTypeImage &&
1351 params_.src_url.is_empty())) {
1349 source_web_contents_->GetRenderViewHost()->SaveImageAt( 1352 source_web_contents_->GetRenderViewHost()->SaveImageAt(
1350 params_.x, params_.y); 1353 params_.x, params_.y);
1351 } else { 1354 } else {
1352 // TODO(zino): We can use SaveImageAt() like a case of canvas.
1353 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1355 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1354 const GURL& url = params_.src_url; 1356 const GURL& url = params_.src_url;
1355 content::Referrer referrer = CreateSaveAsReferrer(url, params_); 1357 content::Referrer referrer = CreateSaveAsReferrer(url, params_);
1356 source_web_contents_->SaveFrame(url, referrer); 1358 source_web_contents_->SaveFrame(url, referrer);
1357 } 1359 }
1358 break; 1360 break;
1359 } 1361 }
1360 1362
1361 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1363 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1362 WriteURLToClipboard(params_.unfiltered_link_url); 1364 WriteURLToClipboard(params_.unfiltered_link_url);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 source_web_contents_->GetRenderViewHost()-> 1773 source_web_contents_->GetRenderViewHost()->
1772 ExecuteMediaPlayerActionAtLocation(location, action); 1774 ExecuteMediaPlayerActionAtLocation(location, action);
1773 } 1775 }
1774 1776
1775 void RenderViewContextMenu::PluginActionAt( 1777 void RenderViewContextMenu::PluginActionAt(
1776 const gfx::Point& location, 1778 const gfx::Point& location,
1777 const WebPluginAction& action) { 1779 const WebPluginAction& action) {
1778 source_web_contents_->GetRenderViewHost()-> 1780 source_web_contents_->GetRenderViewHost()->
1779 ExecutePluginActionAtLocation(location, action); 1781 ExecutePluginActionAtLocation(location, action);
1780 } 1782 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698