| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/devtools/devtools_window.h" | 30 #include "chrome/browser/devtools/devtools_window.h" |
| 31 #include "chrome/browser/download/download_service.h" | 31 #include "chrome/browser/download/download_service.h" |
| 32 #include "chrome/browser/download/download_service_factory.h" | 32 #include "chrome/browser/download/download_service_factory.h" |
| 33 #include "chrome/browser/download/download_util.h" | 33 #include "chrome/browser/download/download_util.h" |
| 34 #include "chrome/browser/extensions/extension_host.h" | 34 #include "chrome/browser/extensions/extension_host.h" |
| 35 #include "chrome/browser/extensions/extension_service.h" | 35 #include "chrome/browser/extensions/extension_service.h" |
| 36 #include "chrome/browser/extensions/extension_system.h" | 36 #include "chrome/browser/extensions/extension_system.h" |
| 37 #include "chrome/browser/google/google_util.h" | 37 #include "chrome/browser/google/google_util.h" |
| 38 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 38 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 40 #include "chrome/browser/printing/print_preview_context_menu_observer.h" | |
| 41 #include "chrome/browser/printing/print_preview_dialog_controller.h" | |
| 42 #include "chrome/browser/printing/print_view_manager.h" | |
| 43 #include "chrome/browser/profiles/profile.h" | 40 #include "chrome/browser/profiles/profile.h" |
| 44 #include "chrome/browser/profiles/profile_io_data.h" | 41 #include "chrome/browser/profiles/profile_io_data.h" |
| 45 #include "chrome/browser/search/search.h" | 42 #include "chrome/browser/search/search.h" |
| 46 #include "chrome/browser/search_engines/search_terms_data.h" | 43 #include "chrome/browser/search_engines/search_terms_data.h" |
| 47 #include "chrome/browser/search_engines/template_url.h" | 44 #include "chrome/browser/search_engines/template_url.h" |
| 48 #include "chrome/browser/search_engines/template_url_service.h" | 45 #include "chrome/browser/search_engines/template_url_service.h" |
| 49 #include "chrome/browser/search_engines/template_url_service_factory.h" | 46 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 50 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 47 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 51 #include "chrome/browser/spellchecker/spellcheck_service.h" | 48 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 52 #include "chrome/browser/tab_contents/retargeting_details.h" | 49 #include "chrome/browser/tab_contents/retargeting_details.h" |
| 53 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h" | 50 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h" |
| 54 #include "chrome/browser/tab_contents/spelling_menu_observer.h" | 51 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
| 55 #include "chrome/browser/translate/translate_manager.h" | 52 #include "chrome/browser/translate/translate_manager.h" |
| 56 #include "chrome/browser/translate/translate_prefs.h" | 53 #include "chrome/browser/translate/translate_prefs.h" |
| 57 #include "chrome/browser/translate/translate_tab_helper.h" | 54 #include "chrome/browser/translate/translate_tab_helper.h" |
| 58 #include "chrome/browser/ui/browser.h" | 55 #include "chrome/browser/ui/browser.h" |
| 59 #include "chrome/browser/ui/browser_commands.h" | 56 #include "chrome/browser/ui/browser_commands.h" |
| 60 #include "chrome/browser/ui/browser_finder.h" | 57 #include "chrome/browser/ui/browser_finder.h" |
| 61 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 58 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 62 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 59 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 63 #include "chrome/common/chrome_constants.h" | 60 #include "chrome/common/chrome_constants.h" |
| 64 #include "chrome/common/chrome_switches.h" | 61 #include "chrome/common/chrome_switches.h" |
| 65 #include "chrome/common/content_restriction.h" | 62 #include "chrome/common/content_restriction.h" |
| 66 #include "chrome/common/extensions/extension.h" | 63 #include "chrome/common/extensions/extension.h" |
| 67 #include "chrome/common/net/url_util.h" | 64 #include "chrome/common/net/url_util.h" |
| 68 #include "chrome/common/pref_names.h" | 65 #include "chrome/common/pref_names.h" |
| 69 #include "chrome/common/print_messages.h" | |
| 70 #include "chrome/common/render_messages.h" | 66 #include "chrome/common/render_messages.h" |
| 71 #include "chrome/common/spellcheck_messages.h" | 67 #include "chrome/common/spellcheck_messages.h" |
| 72 #include "chrome/common/url_constants.h" | 68 #include "chrome/common/url_constants.h" |
| 73 #include "content/public/browser/child_process_security_policy.h" | 69 #include "content/public/browser/child_process_security_policy.h" |
| 74 #include "content/public/browser/download_manager.h" | 70 #include "content/public/browser/download_manager.h" |
| 75 #include "content/public/browser/download_save_info.h" | 71 #include "content/public/browser/download_save_info.h" |
| 76 #include "content/public/browser/download_url_parameters.h" | 72 #include "content/public/browser/download_url_parameters.h" |
| 77 #include "content/public/browser/navigation_details.h" | 73 #include "content/public/browser/navigation_details.h" |
| 78 #include "content/public/browser/navigation_entry.h" | 74 #include "content/public/browser/navigation_entry.h" |
| 79 #include "content/public/browser/notification_service.h" | 75 #include "content/public/browser/notification_service.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 87 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 92 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" | 88 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 93 #include "third_party/WebKit/public/web/WebPluginAction.h" | 89 #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 94 #include "ui/base/clipboard/clipboard.h" | 90 #include "ui/base/clipboard/clipboard.h" |
| 95 #include "ui/base/l10n/l10n_util.h" | 91 #include "ui/base/l10n/l10n_util.h" |
| 96 #include "ui/base/text/text_elider.h" | 92 #include "ui/base/text/text_elider.h" |
| 97 #include "ui/gfx/favicon_size.h" | 93 #include "ui/gfx/favicon_size.h" |
| 98 #include "ui/gfx/point.h" | 94 #include "ui/gfx/point.h" |
| 99 #include "ui/gfx/size.h" | 95 #include "ui/gfx/size.h" |
| 100 | 96 |
| 97 #if defined(ENABLE_PRINTING) |
| 98 #include "chrome/common/print_messages.h" |
| 99 |
| 100 #if defined(ENABLE_FULL_PRINTING) |
| 101 #include "chrome/browser/printing/print_preview_context_menu_observer.h" |
| 102 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 103 #include "chrome/browser/printing/print_view_manager.h" |
| 104 #else |
| 105 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 106 #endif // defined(ENABLE_FULL_PRINTING) |
| 107 #endif // defined(ENABLE_PRINTING) |
| 108 |
| 101 using WebKit::WebContextMenuData; | 109 using WebKit::WebContextMenuData; |
| 102 using WebKit::WebMediaPlayerAction; | 110 using WebKit::WebMediaPlayerAction; |
| 103 using WebKit::WebPluginAction; | 111 using WebKit::WebPluginAction; |
| 104 using WebKit::WebString; | 112 using WebKit::WebString; |
| 105 using WebKit::WebURL; | 113 using WebKit::WebURL; |
| 106 using content::BrowserContext; | 114 using content::BrowserContext; |
| 107 using content::ChildProcessSecurityPolicy; | 115 using content::ChildProcessSecurityPolicy; |
| 108 using content::DownloadManager; | 116 using content::DownloadManager; |
| 109 using content::DownloadUrlParameters; | 117 using content::DownloadUrlParameters; |
| 110 using content::NavigationController; | 118 using content::NavigationController; |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 if (!IsDevToolsURL(params_.page_url)) | 650 if (!IsDevToolsURL(params_.page_url)) |
| 643 AppendPrintItem(); | 651 AppendPrintItem(); |
| 644 } | 652 } |
| 645 | 653 |
| 646 if (!IsDevToolsURL(params_.page_url)) | 654 if (!IsDevToolsURL(params_.page_url)) |
| 647 AppendAllExtensionItems(); | 655 AppendAllExtensionItems(); |
| 648 | 656 |
| 649 AppendDeveloperItems(); | 657 AppendDeveloperItems(); |
| 650 | 658 |
| 651 if (!is_guest_) { | 659 if (!is_guest_) { |
| 660 #if defined(ENABLE_FULL_PRINTING) |
| 652 if (!print_preview_menu_observer_.get()) { | 661 if (!print_preview_menu_observer_.get()) { |
| 653 print_preview_menu_observer_.reset( | 662 print_preview_menu_observer_.reset( |
| 654 new PrintPreviewContextMenuObserver(source_web_contents_)); | 663 new PrintPreviewContextMenuObserver(source_web_contents_)); |
| 655 } | 664 } |
| 656 | 665 |
| 657 observers_.AddObserver(print_preview_menu_observer_.get()); | 666 observers_.AddObserver(print_preview_menu_observer_.get()); |
| 667 #endif |
| 658 } | 668 } |
| 659 } | 669 } |
| 660 | 670 |
| 661 const Extension* RenderViewContextMenu::GetExtension() const { | 671 const Extension* RenderViewContextMenu::GetExtension() const { |
| 662 extensions::ExtensionSystem* system = | 672 extensions::ExtensionSystem* system = |
| 663 extensions::ExtensionSystem::Get(profile_); | 673 extensions::ExtensionSystem::Get(profile_); |
| 664 // There is no process manager in some tests. | 674 // There is no process manager in some tests. |
| 665 if (!system->process_manager()) | 675 if (!system->process_manager()) |
| 666 return NULL; | 676 return NULL; |
| 667 | 677 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 while ((observer = it.GetNext()) != NULL) { | 1151 while ((observer = it.GetNext()) != NULL) { |
| 1142 if (observer->IsCommandIdSupported(id)) | 1152 if (observer->IsCommandIdSupported(id)) |
| 1143 return observer->IsCommandIdEnabled(id); | 1153 return observer->IsCommandIdEnabled(id); |
| 1144 } | 1154 } |
| 1145 | 1155 |
| 1146 CoreTabHelper* core_tab_helper = | 1156 CoreTabHelper* core_tab_helper = |
| 1147 CoreTabHelper::FromWebContents(source_web_contents_); | 1157 CoreTabHelper::FromWebContents(source_web_contents_); |
| 1148 int content_restrictions = 0; | 1158 int content_restrictions = 0; |
| 1149 if (core_tab_helper) | 1159 if (core_tab_helper) |
| 1150 content_restrictions = core_tab_helper->content_restrictions(); | 1160 content_restrictions = core_tab_helper->content_restrictions(); |
| 1151 if (id == IDC_PRINT && | 1161 if (id == IDC_PRINT && (content_restrictions & CONTENT_RESTRICTION_PRINT)) |
| 1152 (content_restrictions & CONTENT_RESTRICTION_PRINT)) { | |
| 1153 return false; | 1162 return false; |
| 1154 } | |
| 1155 | 1163 |
| 1156 if (id == IDC_SAVE_PAGE && | 1164 if (id == IDC_SAVE_PAGE && |
| 1157 (content_restrictions & CONTENT_RESTRICTION_SAVE)) { | 1165 (content_restrictions & CONTENT_RESTRICTION_SAVE)) { |
| 1158 return false; | 1166 return false; |
| 1159 } | 1167 } |
| 1160 | 1168 |
| 1161 // Allow Spell Check language items on sub menu for text area context menu. | 1169 // Allow Spell Check language items on sub menu for text area context menu. |
| 1162 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && | 1170 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && |
| 1163 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { | 1171 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { |
| 1164 return profile_->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); | 1172 return profile_->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 return params_.src_url.is_valid(); | 1321 return params_.src_url.is_valid(); |
| 1314 | 1322 |
| 1315 case IDC_CONTENT_CONTEXT_SAVEAVAS: { | 1323 case IDC_CONTENT_CONTEXT_SAVEAVAS: { |
| 1316 PrefService* local_state = g_browser_process->local_state(); | 1324 PrefService* local_state = g_browser_process->local_state(); |
| 1317 DCHECK(local_state); | 1325 DCHECK(local_state); |
| 1318 // Test if file-selection dialogs are forbidden by policy. | 1326 // Test if file-selection dialogs are forbidden by policy. |
| 1319 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 1327 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| 1320 return false; | 1328 return false; |
| 1321 | 1329 |
| 1322 const GURL& url = params_.src_url; | 1330 const GURL& url = params_.src_url; |
| 1323 return (params_.media_flags & WebContextMenuData::MediaCanSave) && | 1331 bool can_save = |
| 1324 url.is_valid() && ProfileIOData::IsHandledProtocol(url.scheme()) && | 1332 (params_.media_flags & WebContextMenuData::MediaCanSave) && |
| 1333 url.is_valid() && ProfileIOData::IsHandledProtocol(url.scheme()); |
| 1334 #if defined(ENABLE_FULL_PRINTING) |
| 1325 // Do not save the preview PDF on the print preview page. | 1335 // Do not save the preview PDF on the print preview page. |
| 1336 can_save = can_save && |
| 1326 !(printing::PrintPreviewDialogController::IsPrintPreviewURL(url)); | 1337 !(printing::PrintPreviewDialogController::IsPrintPreviewURL(url)); |
| 1338 #endif |
| 1339 return can_save; |
| 1327 } | 1340 } |
| 1328 | 1341 |
| 1329 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: | 1342 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
| 1330 return true; | 1343 return true; |
| 1331 | 1344 |
| 1332 case IDC_SAVE_PAGE: { | 1345 case IDC_SAVE_PAGE: { |
| 1333 CoreTabHelper* core_tab_helper = | 1346 CoreTabHelper* core_tab_helper = |
| 1334 CoreTabHelper::FromWebContents(source_web_contents_); | 1347 CoreTabHelper::FromWebContents(source_web_contents_); |
| 1335 if (!core_tab_helper) | 1348 if (!core_tab_helper) |
| 1336 return false; | 1349 return false; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 const Extension* platform_app = GetExtension(); | 1744 const Extension* platform_app = GetExtension(); |
| 1732 DCHECK(platform_app); | 1745 DCHECK(platform_app); |
| 1733 DCHECK(platform_app->is_platform_app()); | 1746 DCHECK(platform_app->is_platform_app()); |
| 1734 | 1747 |
| 1735 apps::AppLoadService::Get(profile_)->RestartApplication( | 1748 apps::AppLoadService::Get(profile_)->RestartApplication( |
| 1736 platform_app->id()); | 1749 platform_app->id()); |
| 1737 break; | 1750 break; |
| 1738 } | 1751 } |
| 1739 | 1752 |
| 1740 case IDC_PRINT: | 1753 case IDC_PRINT: |
| 1754 #if defined(ENABLE_PRINTING) |
| 1741 if (params_.media_type == WebContextMenuData::MediaTypeNone) { | 1755 if (params_.media_type == WebContextMenuData::MediaTypeNone) { |
| 1756 #if defined(ENABLE_FULL_PRINTING) |
| 1742 printing::PrintViewManager* print_view_manager = | 1757 printing::PrintViewManager* print_view_manager = |
| 1743 printing::PrintViewManager::FromWebContents(source_web_contents_); | 1758 printing::PrintViewManager::FromWebContents(source_web_contents_); |
| 1759 |
| 1744 if (!print_view_manager) | 1760 if (!print_view_manager) |
| 1745 break; | 1761 break; |
| 1746 if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { | 1762 if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { |
| 1747 print_view_manager->PrintNow(); | 1763 print_view_manager->PrintNow(); |
| 1748 } else { | 1764 } else { |
| 1749 print_view_manager->PrintPreviewNow(!params_.selection_text.empty()); | 1765 print_view_manager->PrintPreviewNow(!params_.selection_text.empty()); |
| 1750 } | 1766 } |
| 1767 #else |
| 1768 printing::PrintViewManagerBasic* print_view_manager = |
| 1769 printing::PrintViewManagerBasic::FromWebContents( |
| 1770 source_web_contents_); |
| 1771 if (!print_view_manager) |
| 1772 break; |
| 1773 print_view_manager->PrintNow(); |
| 1774 #endif // defined(ENABLE_FULL_PRINTING) |
| 1751 } else { | 1775 } else { |
| 1752 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID())); | 1776 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID())); |
| 1753 } | 1777 } |
| 1778 #endif // defined(ENABLE_PRINTING) |
| 1754 break; | 1779 break; |
| 1755 | 1780 |
| 1756 case IDC_VIEW_SOURCE: | 1781 case IDC_VIEW_SOURCE: |
| 1757 source_web_contents_->ViewSource(); | 1782 source_web_contents_->ViewSource(); |
| 1758 break; | 1783 break; |
| 1759 | 1784 |
| 1760 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: | 1785 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: |
| 1761 Inspect(params_.x, params_.y); | 1786 Inspect(params_.x, params_.y); |
| 1762 break; | 1787 break; |
| 1763 | 1788 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 source_web_contents_->GetRenderViewHost()-> | 2103 source_web_contents_->GetRenderViewHost()-> |
| 2079 ExecuteMediaPlayerActionAtLocation(location, action); | 2104 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2080 } | 2105 } |
| 2081 | 2106 |
| 2082 void RenderViewContextMenu::PluginActionAt( | 2107 void RenderViewContextMenu::PluginActionAt( |
| 2083 const gfx::Point& location, | 2108 const gfx::Point& location, |
| 2084 const WebPluginAction& action) { | 2109 const WebPluginAction& action) { |
| 2085 source_web_contents_->GetRenderViewHost()-> | 2110 source_web_contents_->GetRenderViewHost()-> |
| 2086 ExecutePluginActionAtLocation(location, action); | 2111 ExecutePluginActionAtLocation(location, action); |
| 2087 } | 2112 } |
| OLD | NEW |