| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 9 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 #include "content/public/browser/notification_service.h" | 72 #include "content/public/browser/notification_service.h" |
| 73 #include "content/public/browser/ssl_status.h" | 73 #include "content/public/browser/ssl_status.h" |
| 74 #include "content/public/browser/user_metrics.h" | 74 #include "content/public/browser/user_metrics.h" |
| 75 #include "content/public/browser/web_contents.h" | 75 #include "content/public/browser/web_contents.h" |
| 76 #include "content/public/common/content_restriction.h" | 76 #include "content/public/common/content_restriction.h" |
| 77 #include "grit/generated_resources.h" | 77 #include "grit/generated_resources.h" |
| 78 #include "net/base/escape.h" | 78 #include "net/base/escape.h" |
| 79 #include "net/base/net_util.h" | 79 #include "net/base/net_util.h" |
| 80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" | 81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" |
| 82 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h" |
| 82 #include "ui/base/l10n/l10n_util.h" | 83 #include "ui/base/l10n/l10n_util.h" |
| 83 #include "ui/base/text/text_elider.h" | 84 #include "ui/base/text/text_elider.h" |
| 84 #include "ui/gfx/favicon_size.h" | 85 #include "ui/gfx/favicon_size.h" |
| 85 #include "webkit/glue/webmenuitem.h" | 86 #include "webkit/glue/webmenuitem.h" |
| 86 | 87 |
| 87 #ifdef FILE_MANAGER_EXTENSION | 88 #ifdef FILE_MANAGER_EXTENSION |
| 88 #include "chrome/browser/extensions/file_manager_util.h" | 89 #include "chrome/browser/extensions/file_manager_util.h" |
| 89 #endif | 90 #endif |
| 90 | 91 |
| 91 using content::DownloadManager; | 92 using content::DownloadManager; |
| 92 using content::NavigationEntry; | 93 using content::NavigationEntry; |
| 93 using content::OpenURLParams; | 94 using content::OpenURLParams; |
| 94 using content::SSLStatus; | 95 using content::SSLStatus; |
| 95 using content::UserMetricsAction; | 96 using content::UserMetricsAction; |
| 96 using content::WebContents; | 97 using content::WebContents; |
| 97 using WebKit::WebContextMenuData; | 98 using WebKit::WebContextMenuData; |
| 98 using WebKit::WebMediaPlayerAction; | 99 using WebKit::WebMediaPlayerAction; |
| 100 using WebKit::WebPluginAction; |
| 99 using WebKit::WebURL; | 101 using WebKit::WebURL; |
| 100 using WebKit::WebString; | 102 using WebKit::WebString; |
| 101 | 103 |
| 102 namespace { | 104 namespace { |
| 103 | 105 |
| 104 // Usually a new tab is expected where this function is used, | 106 // Usually a new tab is expected where this function is used, |
| 105 // however users should be able to open a tab in background | 107 // however users should be able to open a tab in background |
| 106 // or in a new window. | 108 // or in a new window. |
| 107 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( | 109 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( |
| 108 int event_flags) { | 110 int event_flags) { |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 void RenderViewContextMenu::AppendPluginItems() { | 808 void RenderViewContextMenu::AppendPluginItems() { |
| 807 if (params_.page_url == params_.src_url) { | 809 if (params_.page_url == params_.src_url) { |
| 808 // Full page plugin, so show page menu items. | 810 // Full page plugin, so show page menu items. |
| 809 if (params_.link_url.is_empty() && params_.selection_text.empty()) | 811 if (params_.link_url.is_empty() && params_.selection_text.empty()) |
| 810 AppendPageItems(); | 812 AppendPageItems(); |
| 811 } else { | 813 } else { |
| 812 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 814 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
| 813 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 815 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
| 814 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 816 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 815 } | 817 } |
| 818 |
| 819 if (params_.media_flags & WebContextMenuData::MediaCanRotate) { |
| 820 menu_model_.AddSeparator(); |
| 821 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, |
| 822 IDS_CONTENT_CONTEXT_ROTATECW); |
| 823 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, |
| 824 IDS_CONTENT_CONTEXT_ROTATECCW); |
| 825 } |
| 816 } | 826 } |
| 817 | 827 |
| 818 void RenderViewContextMenu::AppendPageItems() { | 828 void RenderViewContextMenu::AppendPageItems() { |
| 819 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); | 829 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); |
| 820 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); | 830 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); |
| 821 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 831 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
| 822 menu_model_.AddSeparator(); | 832 menu_model_.AddSeparator(); |
| 823 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, | 833 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, |
| 824 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 834 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
| 825 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 835 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 (params_.media_flags & | 1190 (params_.media_flags & |
| 1181 WebContextMenuData::MediaInError) == 0; | 1191 WebContextMenuData::MediaInError) == 0; |
| 1182 | 1192 |
| 1183 // Media controls can be toggled only for video player. If we toggle | 1193 // Media controls can be toggled only for video player. If we toggle |
| 1184 // controls for audio then the player disappears, and there is no way to | 1194 // controls for audio then the player disappears, and there is no way to |
| 1185 // return it back. | 1195 // return it back. |
| 1186 case IDC_CONTENT_CONTEXT_CONTROLS: | 1196 case IDC_CONTENT_CONTEXT_CONTROLS: |
| 1187 return (params_.media_flags & | 1197 return (params_.media_flags & |
| 1188 WebContextMenuData::MediaHasVideo) != 0; | 1198 WebContextMenuData::MediaHasVideo) != 0; |
| 1189 | 1199 |
| 1200 case IDC_CONTENT_CONTEXT_ROTATECW: |
| 1201 case IDC_CONTENT_CONTEXT_ROTATECCW: |
| 1202 return |
| 1203 (params_.media_flags & WebContextMenuData::MediaCanRotate) != 0; |
| 1204 |
| 1190 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: | 1205 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: |
| 1191 case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION: | 1206 case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION: |
| 1192 return params_.src_url.is_valid(); | 1207 return params_.src_url.is_valid(); |
| 1193 | 1208 |
| 1194 case IDC_CONTENT_CONTEXT_SAVEAVAS: { | 1209 case IDC_CONTENT_CONTEXT_SAVEAVAS: { |
| 1195 PrefService* local_state = g_browser_process->local_state(); | 1210 PrefService* local_state = g_browser_process->local_state(); |
| 1196 DCHECK(local_state); | 1211 DCHECK(local_state); |
| 1197 // Test if file-selection dialogs are forbidden by policy. | 1212 // Test if file-selection dialogs are forbidden by policy. |
| 1198 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 1213 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| 1199 return false; | 1214 return false; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 | 1555 |
| 1541 case IDC_CONTENT_CONTEXT_CONTROLS: | 1556 case IDC_CONTENT_CONTEXT_CONTROLS: |
| 1542 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); | 1557 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); |
| 1543 MediaPlayerActionAt( | 1558 MediaPlayerActionAt( |
| 1544 gfx::Point(params_.x, params_.y), | 1559 gfx::Point(params_.x, params_.y), |
| 1545 WebMediaPlayerAction( | 1560 WebMediaPlayerAction( |
| 1546 WebMediaPlayerAction::Controls, | 1561 WebMediaPlayerAction::Controls, |
| 1547 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); | 1562 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); |
| 1548 break; | 1563 break; |
| 1549 | 1564 |
| 1565 case IDC_CONTENT_CONTEXT_ROTATECW: |
| 1566 content::RecordAction( |
| 1567 UserMetricsAction("PluginContextMenu_RotateClockwise")); |
| 1568 PluginActionAt( |
| 1569 gfx::Point(params_.x, params_.y), |
| 1570 WebPluginAction( |
| 1571 WebPluginAction::Rotate90Clockwise, |
| 1572 true)); |
| 1573 break; |
| 1574 |
| 1575 case IDC_CONTENT_CONTEXT_ROTATECCW: |
| 1576 content::RecordAction( |
| 1577 UserMetricsAction("PluginContextMenu_RotateCounterclockwise")); |
| 1578 PluginActionAt( |
| 1579 gfx::Point(params_.x, params_.y), |
| 1580 WebPluginAction( |
| 1581 WebPluginAction::Rotate90Counterclockwise, |
| 1582 true)); |
| 1583 break; |
| 1584 |
| 1550 case IDC_BACK: | 1585 case IDC_BACK: |
| 1551 source_web_contents_->GetController().GoBack(); | 1586 source_web_contents_->GetController().GoBack(); |
| 1552 break; | 1587 break; |
| 1553 | 1588 |
| 1554 case IDC_FORWARD: | 1589 case IDC_FORWARD: |
| 1555 source_web_contents_->GetController().GoForward(); | 1590 source_web_contents_->GetController().GoForward(); |
| 1556 break; | 1591 break; |
| 1557 | 1592 |
| 1558 case IDC_SAVE_PAGE: | 1593 case IDC_SAVE_PAGE: |
| 1559 source_web_contents_->OnSavePage(); | 1594 source_web_contents_->OnSavePage(); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1925 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1891 g_browser_process->clipboard()); | 1926 g_browser_process->clipboard()); |
| 1892 } | 1927 } |
| 1893 | 1928 |
| 1894 void RenderViewContextMenu::MediaPlayerActionAt( | 1929 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1895 const gfx::Point& location, | 1930 const gfx::Point& location, |
| 1896 const WebMediaPlayerAction& action) { | 1931 const WebMediaPlayerAction& action) { |
| 1897 source_web_contents_->GetRenderViewHost()-> | 1932 source_web_contents_->GetRenderViewHost()-> |
| 1898 ExecuteMediaPlayerActionAtLocation(location, action); | 1933 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1899 } | 1934 } |
| 1935 |
| 1936 void RenderViewContextMenu::PluginActionAt( |
| 1937 const gfx::Point& location, |
| 1938 const WebPluginAction& action) { |
| 1939 source_web_contents_->GetRenderViewHost()-> |
| 1940 ExecutePluginActionAtLocation(location, action); |
| 1941 } |
| 1942 |
| OLD | NEW |