| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #include "content/browser/child_process_security_policy.h" | 60 #include "content/browser/child_process_security_policy.h" |
| 61 #include "content/browser/download/download_manager.h" | 61 #include "content/browser/download/download_manager.h" |
| 62 #include "content/browser/download/download_stats.h" | 62 #include "content/browser/download/download_stats.h" |
| 63 #include "content/browser/download/save_package.h" | 63 #include "content/browser/download/save_package.h" |
| 64 #include "content/browser/renderer_host/render_view_host.h" | 64 #include "content/browser/renderer_host/render_view_host.h" |
| 65 #include "content/browser/renderer_host/render_widget_host_view.h" | 65 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 66 #include "content/browser/speech/speech_input_preferences.h" | 66 #include "content/browser/speech/speech_input_preferences.h" |
| 67 #include "content/browser/tab_contents/navigation_details.h" | 67 #include "content/browser/tab_contents/navigation_details.h" |
| 68 #include "content/browser/tab_contents/navigation_entry.h" | 68 #include "content/browser/tab_contents/navigation_entry.h" |
| 69 #include "content/browser/tab_contents/tab_contents.h" | 69 #include "content/browser/tab_contents/tab_contents.h" |
| 70 #include "content/browser/user_metrics.h" | |
| 71 #include "content/public/browser/notification_service.h" | 70 #include "content/public/browser/notification_service.h" |
| 71 #include "content/public/browser/user_metrics.h" |
| 72 #include "content/public/common/content_restriction.h" | 72 #include "content/public/common/content_restriction.h" |
| 73 #include "grit/generated_resources.h" | 73 #include "grit/generated_resources.h" |
| 74 #include "net/base/escape.h" | 74 #include "net/base/escape.h" |
| 75 #include "net/base/net_util.h" | 75 #include "net/base/net_util.h" |
| 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" | 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" |
| 78 #include "ui/base/l10n/l10n_util.h" | 78 #include "ui/base/l10n/l10n_util.h" |
| 79 #include "ui/base/text/text_elider.h" | 79 #include "ui/base/text/text_elider.h" |
| 80 #include "ui/gfx/favicon_size.h" | 80 #include "ui/gfx/favicon_size.h" |
| 81 #include "webkit/glue/webmenuitem.h" | 81 #include "webkit/glue/webmenuitem.h" |
| 82 | 82 |
| 83 #ifdef FILE_MANAGER_EXTENSION | 83 #ifdef FILE_MANAGER_EXTENSION |
| 84 #include "chrome/browser/extensions/file_manager_util.h" | 84 #include "chrome/browser/extensions/file_manager_util.h" |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 using content::UserMetricsAction; |
| 87 using WebKit::WebContextMenuData; | 88 using WebKit::WebContextMenuData; |
| 88 using WebKit::WebMediaPlayerAction; | 89 using WebKit::WebMediaPlayerAction; |
| 89 using WebKit::WebURL; | 90 using WebKit::WebURL; |
| 90 using WebKit::WebString; | 91 using WebKit::WebString; |
| 91 | 92 |
| 92 namespace { | 93 namespace { |
| 93 | 94 |
| 94 // Usually a new tab is expected where this function is used, | 95 // Usually a new tab is expected where this function is used, |
| 95 // however users should be able to open a tab in background | 96 // however users should be able to open a tab in background |
| 96 // or in a new window. | 97 // or in a new window. |
| (...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 return; | 1386 return; |
| 1386 } | 1387 } |
| 1387 | 1388 |
| 1388 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1389 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1389 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1390 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1390 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1391 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1391 GetHandlersForLinkUrl(); | 1392 GetHandlersForLinkUrl(); |
| 1392 if (handlers.empty()) { | 1393 if (handlers.empty()) { |
| 1393 return; | 1394 return; |
| 1394 } | 1395 } |
| 1395 UserMetrics::RecordAction( | 1396 content::RecordAction( |
| 1396 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Open")); | 1397 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Open")); |
| 1397 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 1398 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| 1398 WindowOpenDisposition disposition = | 1399 WindowOpenDisposition disposition = |
| 1399 ForceNewTabDispositionFromEventFlags(event_flags); | 1400 ForceNewTabDispositionFromEventFlags(event_flags); |
| 1400 OpenURL( | 1401 OpenURL( |
| 1401 handlers[handlerIndex].TranslateUrl(params_.link_url), | 1402 handlers[handlerIndex].TranslateUrl(params_.link_url), |
| 1402 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | 1403 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, |
| 1403 params_.frame_id, | 1404 params_.frame_id, |
| 1404 disposition, | 1405 disposition, |
| 1405 content::PAGE_TRANSITION_LINK); | 1406 content::PAGE_TRANSITION_LINK); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 OpenURL( | 1470 OpenURL( |
| 1470 params_.src_url, | 1471 params_.src_url, |
| 1471 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | 1472 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, |
| 1472 params_.frame_id, | 1473 params_.frame_id, |
| 1473 NEW_BACKGROUND_TAB, content::PAGE_TRANSITION_LINK); | 1474 NEW_BACKGROUND_TAB, content::PAGE_TRANSITION_LINK); |
| 1474 break; | 1475 break; |
| 1475 | 1476 |
| 1476 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { | 1477 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { |
| 1477 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); | 1478 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); |
| 1478 if (play) { | 1479 if (play) { |
| 1479 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play")); | 1480 content::RecordAction(UserMetricsAction("MediaContextMenu_Play")); |
| 1480 } else { | 1481 } else { |
| 1481 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause")); | 1482 content::RecordAction(UserMetricsAction("MediaContextMenu_Pause")); |
| 1482 } | 1483 } |
| 1483 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 1484 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
| 1484 WebMediaPlayerAction( | 1485 WebMediaPlayerAction( |
| 1485 WebMediaPlayerAction::Play, play)); | 1486 WebMediaPlayerAction::Play, play)); |
| 1486 break; | 1487 break; |
| 1487 } | 1488 } |
| 1488 | 1489 |
| 1489 case IDC_CONTENT_CONTEXT_MUTE: { | 1490 case IDC_CONTENT_CONTEXT_MUTE: { |
| 1490 bool mute = !(params_.media_flags & WebContextMenuData::MediaMuted); | 1491 bool mute = !(params_.media_flags & WebContextMenuData::MediaMuted); |
| 1491 if (mute) { | 1492 if (mute) { |
| 1492 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Mute")); | 1493 content::RecordAction(UserMetricsAction("MediaContextMenu_Mute")); |
| 1493 } else { | 1494 } else { |
| 1494 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Unmute")); | 1495 content::RecordAction(UserMetricsAction("MediaContextMenu_Unmute")); |
| 1495 } | 1496 } |
| 1496 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 1497 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
| 1497 WebMediaPlayerAction( | 1498 WebMediaPlayerAction( |
| 1498 WebMediaPlayerAction::Mute, mute)); | 1499 WebMediaPlayerAction::Mute, mute)); |
| 1499 break; | 1500 break; |
| 1500 } | 1501 } |
| 1501 | 1502 |
| 1502 case IDC_CONTENT_CONTEXT_LOOP: | 1503 case IDC_CONTENT_CONTEXT_LOOP: |
| 1503 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Loop")); | 1504 content::RecordAction(UserMetricsAction("MediaContextMenu_Loop")); |
| 1504 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 1505 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
| 1505 WebMediaPlayerAction( | 1506 WebMediaPlayerAction( |
| 1506 WebMediaPlayerAction::Loop, | 1507 WebMediaPlayerAction::Loop, |
| 1507 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_LOOP))); | 1508 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_LOOP))); |
| 1508 break; | 1509 break; |
| 1509 | 1510 |
| 1510 case IDC_CONTENT_CONTEXT_CONTROLS: | 1511 case IDC_CONTENT_CONTEXT_CONTROLS: |
| 1511 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); | 1512 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); |
| 1512 MediaPlayerActionAt( | 1513 MediaPlayerActionAt( |
| 1513 gfx::Point(params_.x, params_.y), | 1514 gfx::Point(params_.x, params_.y), |
| 1514 WebMediaPlayerAction( | 1515 WebMediaPlayerAction( |
| 1515 WebMediaPlayerAction::Controls, | 1516 WebMediaPlayerAction::Controls, |
| 1516 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); | 1517 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); |
| 1517 break; | 1518 break; |
| 1518 | 1519 |
| 1519 case IDC_BACK: | 1520 case IDC_BACK: |
| 1520 source_tab_contents_->controller().GoBack(); | 1521 source_tab_contents_->controller().GoBack(); |
| 1521 break; | 1522 break; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 dir = WebKit::WebTextDirectionRightToLeft; | 1689 dir = WebKit::WebTextDirectionRightToLeft; |
| 1689 rvh->UpdateTextDirection(dir); | 1690 rvh->UpdateTextDirection(dir); |
| 1690 rvh->NotifyTextDirection(); | 1691 rvh->NotifyTextDirection(); |
| 1691 break; | 1692 break; |
| 1692 } | 1693 } |
| 1693 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: | 1694 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: |
| 1694 LookUpInDictionary(); | 1695 LookUpInDictionary(); |
| 1695 break; | 1696 break; |
| 1696 #endif // OS_MACOSX | 1697 #endif // OS_MACOSX |
| 1697 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: { | 1698 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: { |
| 1698 UserMetrics::RecordAction( | 1699 content::RecordAction( |
| 1699 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Settings")); | 1700 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Settings")); |
| 1700 WindowOpenDisposition disposition = | 1701 WindowOpenDisposition disposition = |
| 1701 ForceNewTabDispositionFromEventFlags(event_flags); | 1702 ForceNewTabDispositionFromEventFlags(event_flags); |
| 1702 std::string url = std::string(chrome::kChromeUISettingsURL) + | 1703 std::string url = std::string(chrome::kChromeUISettingsURL) + |
| 1703 chrome::kHandlerSettingsSubPage; | 1704 chrome::kHandlerSettingsSubPage; |
| 1704 OpenURL(GURL(url), GURL(), 0, disposition, content::PAGE_TRANSITION_LINK); | 1705 OpenURL(GURL(url), GURL(), 0, disposition, content::PAGE_TRANSITION_LINK); |
| 1705 break; | 1706 break; |
| 1706 } | 1707 } |
| 1707 | 1708 |
| 1708 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: { | 1709 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 source_tab_contents_->browser_context()), | 1841 source_tab_contents_->browser_context()), |
| 1841 content::Details<content::RetargetingDetails>(&details)); | 1842 content::Details<content::RetargetingDetails>(&details)); |
| 1842 } | 1843 } |
| 1843 } | 1844 } |
| 1844 | 1845 |
| 1845 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1846 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
| 1846 source_tab_contents_->render_view_host()->CopyImageAt(x, y); | 1847 source_tab_contents_->render_view_host()->CopyImageAt(x, y); |
| 1847 } | 1848 } |
| 1848 | 1849 |
| 1849 void RenderViewContextMenu::Inspect(int x, int y) { | 1850 void RenderViewContextMenu::Inspect(int x, int y) { |
| 1850 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement")); | 1851 content::RecordAction(UserMetricsAction("DevTools_InspectElement")); |
| 1851 DevToolsWindow::InspectElement( | 1852 DevToolsWindow::InspectElement( |
| 1852 source_tab_contents_->render_view_host(), x, y); | 1853 source_tab_contents_->render_view_host(), x, y); |
| 1853 } | 1854 } |
| 1854 | 1855 |
| 1855 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 1856 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
| 1856 chrome_browser_net::WriteURLToClipboard( | 1857 chrome_browser_net::WriteURLToClipboard( |
| 1857 url, | 1858 url, |
| 1858 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1859 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1859 g_browser_process->clipboard()); | 1860 g_browser_process->clipboard()); |
| 1860 } | 1861 } |
| 1861 | 1862 |
| 1862 void RenderViewContextMenu::MediaPlayerActionAt( | 1863 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1863 const gfx::Point& location, | 1864 const gfx::Point& location, |
| 1864 const WebMediaPlayerAction& action) { | 1865 const WebMediaPlayerAction& action) { |
| 1865 source_tab_contents_->render_view_host()-> | 1866 source_tab_contents_->render_view_host()-> |
| 1866 ExecuteMediaPlayerActionAtLocation(location, action); | 1867 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1867 } | 1868 } |
| OLD | NEW |