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

Unified Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 263453007: Implement "Save image as" for canvas (chromium side). (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_context_menu/render_view_context_menu.cc
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index a7e58d88e4aea7f3e44aea68ce9666ad8081185e..f675e44967300e8bb0d21913f29321ce0f8a8d90 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -630,6 +630,11 @@ void RenderViewContextMenu::InitMenu() {
}
if (content_type_->SupportsGroup(
+ ContextMenuContentType::ITEM_GROUP_MEDIA_CANVAS)) {
+ AppendCanvasItems();
+ }
+
+ if (content_type_->SupportsGroup(
ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) {
AppendPluginItems();
}
@@ -843,6 +848,14 @@ void RenderViewContextMenu::AppendAudioItems() {
IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB);
}
+void RenderViewContextMenu::AppendCanvasItems() {
+ menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS,
+ IDS_CONTENT_CONTEXT_SAVEIMAGEAS);
+
+ // TODO(zino): We should support 'copy image' for canvas.
+ // http://crbug.com/369092
+}
+
void RenderViewContextMenu::AppendVideoItems() {
AppendMediaItems();
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
@@ -1225,6 +1238,9 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
return false;
+ if (params_.media_type == WebContextMenuData::MediaTypeCanvas)
+ return true;
+
return params_.src_url.is_valid() &&
ProfileIOData::IsHandledProtocol(params_.src_url.scheme());
}
@@ -1537,12 +1553,18 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
case IDC_CONTENT_CONTEXT_SAVEAVAS:
case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
- RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
- const GURL& referrer =
- params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
- const GURL& url = params_.src_url;
- source_web_contents_->SaveFrame(url, content::Referrer(
- referrer, params_.referrer_policy));
+ if (params_.media_type == WebContextMenuData::MediaTypeCanvas) {
+ source_web_contents_->GetRenderViewHost()->SaveImageAt(
+ params_.x, params_.y);
+ } else {
+ // TODO(zino): We can use SaveImageAt() like a case of canvas.
+ RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
+ const GURL& referrer =
+ params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
+ const GURL& url = params_.src_url;
+ source_web_contents_->SaveFrame(url, content::Referrer(
+ referrer, params_.referrer_policy));
+ }
break;
}

Powered by Google App Engine
This is Rietveld 408576698