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

Side by Side 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, 7 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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO)) { 623 ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO)) {
624 AppendVideoItems(); 624 AppendVideoItems();
625 } 625 }
626 626
627 if (content_type_->SupportsGroup( 627 if (content_type_->SupportsGroup(
628 ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO)) { 628 ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO)) {
629 AppendAudioItems(); 629 AppendAudioItems();
630 } 630 }
631 631
632 if (content_type_->SupportsGroup( 632 if (content_type_->SupportsGroup(
633 ContextMenuContentType::ITEM_GROUP_MEDIA_CANVAS)) {
634 AppendCanvasItems();
635 }
636
637 if (content_type_->SupportsGroup(
633 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { 638 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) {
634 AppendPluginItems(); 639 AppendPluginItems();
635 } 640 }
636 641
637 // ITEM_GROUP_MEDIA_FILE has no specific items. 642 // ITEM_GROUP_MEDIA_FILE has no specific items.
638 643
639 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_EDITABLE)) 644 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_EDITABLE))
640 AppendEditableItems(); 645 AppendEditableItems();
641 646
642 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) { 647 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 AppendMediaItems(); 841 AppendMediaItems();
837 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 842 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
838 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, 843 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS,
839 IDS_CONTENT_CONTEXT_SAVEAUDIOAS); 844 IDS_CONTENT_CONTEXT_SAVEAUDIOAS);
840 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, 845 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION,
841 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); 846 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION);
842 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, 847 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB,
843 IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB); 848 IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB);
844 } 849 }
845 850
851 void RenderViewContextMenu::AppendCanvasItems() {
852 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS,
853 IDS_CONTENT_CONTEXT_SAVEIMAGEAS);
854
855 // TODO(zino): We should support 'copy image' for canvas.
856 // http://crbug.com/369092
857 }
858
846 void RenderViewContextMenu::AppendVideoItems() { 859 void RenderViewContextMenu::AppendVideoItems() {
847 AppendMediaItems(); 860 AppendMediaItems();
848 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 861 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
849 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, 862 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS,
850 IDS_CONTENT_CONTEXT_SAVEVIDEOAS); 863 IDS_CONTENT_CONTEXT_SAVEVIDEOAS);
851 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, 864 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION,
852 IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); 865 IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION);
853 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, 866 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB,
854 IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); 867 IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB);
855 } 868 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 ProfileIOData::IsHandledProtocol(params_.link_url.scheme()); 1231 ProfileIOData::IsHandledProtocol(params_.link_url.scheme());
1219 } 1232 }
1220 1233
1221 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1234 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1222 PrefService* local_state = g_browser_process->local_state(); 1235 PrefService* local_state = g_browser_process->local_state();
1223 DCHECK(local_state); 1236 DCHECK(local_state);
1224 // Test if file-selection dialogs are forbidden by policy. 1237 // Test if file-selection dialogs are forbidden by policy.
1225 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1238 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
1226 return false; 1239 return false;
1227 1240
1241 if (params_.media_type == WebContextMenuData::MediaTypeCanvas)
1242 return true;
1243
1228 return params_.src_url.is_valid() && 1244 return params_.src_url.is_valid() &&
1229 ProfileIOData::IsHandledProtocol(params_.src_url.scheme()); 1245 ProfileIOData::IsHandledProtocol(params_.src_url.scheme());
1230 } 1246 }
1231 1247
1232 // The images shown in the most visited thumbnails can't be opened or 1248 // The images shown in the most visited thumbnails can't be opened or
1233 // searched for conventionally. 1249 // searched for conventionally.
1234 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1250 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1235 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: 1251 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE:
1236 return params_.src_url.is_valid() && 1252 return params_.src_url.is_valid() &&
1237 (params_.src_url.scheme() != content::kChromeUIScheme); 1253 (params_.src_url.scheme() != content::kChromeUIScheme);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 dl_params->set_referrer( 1546 dl_params->set_referrer(
1531 content::Referrer(referrer, params_.referrer_policy)); 1547 content::Referrer(referrer, params_.referrer_policy));
1532 dl_params->set_referrer_encoding(params_.frame_charset); 1548 dl_params->set_referrer_encoding(params_.frame_charset);
1533 dl_params->set_prompt(true); 1549 dl_params->set_prompt(true);
1534 dlm->DownloadUrl(dl_params.Pass()); 1550 dlm->DownloadUrl(dl_params.Pass());
1535 break; 1551 break;
1536 } 1552 }
1537 1553
1538 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1554 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1539 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1555 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1540 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1556 if (params_.media_type == WebContextMenuData::MediaTypeCanvas) {
1541 const GURL& referrer = 1557 source_web_contents_->GetRenderViewHost()->SaveImageAt(
1542 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; 1558 params_.x, params_.y);
1543 const GURL& url = params_.src_url; 1559 } else {
1544 source_web_contents_->SaveFrame(url, content::Referrer( 1560 // TODO(zino): We can use SaveImageAt() like a case of canvas.
1545 referrer, params_.referrer_policy)); 1561 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1562 const GURL& referrer =
1563 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
1564 const GURL& url = params_.src_url;
1565 source_web_contents_->SaveFrame(url, content::Referrer(
1566 referrer, params_.referrer_policy));
1567 }
1546 break; 1568 break;
1547 } 1569 }
1548 1570
1549 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1571 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1550 WriteURLToClipboard(params_.unfiltered_link_url); 1572 WriteURLToClipboard(params_.unfiltered_link_url);
1551 break; 1573 break;
1552 1574
1553 case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION: 1575 case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION:
1554 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: 1576 case IDC_CONTENT_CONTEXT_COPYAVLOCATION:
1555 WriteURLToClipboard(params_.src_url); 1577 WriteURLToClipboard(params_.src_url);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 source_web_contents_->GetRenderViewHost()-> 2043 source_web_contents_->GetRenderViewHost()->
2022 ExecuteMediaPlayerActionAtLocation(location, action); 2044 ExecuteMediaPlayerActionAtLocation(location, action);
2023 } 2045 }
2024 2046
2025 void RenderViewContextMenu::PluginActionAt( 2047 void RenderViewContextMenu::PluginActionAt(
2026 const gfx::Point& location, 2048 const gfx::Point& location,
2027 const WebPluginAction& action) { 2049 const WebPluginAction& action) {
2028 source_web_contents_->GetRenderViewHost()-> 2050 source_web_contents_->GetRenderViewHost()->
2029 ExecutePluginActionAtLocation(location, action); 2051 ExecutePluginActionAtLocation(location, action);
2030 } 2052 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698