| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 #include "content/public/browser/render_process_host.h" | 98 #include "content/public/browser/render_process_host.h" |
| 99 #include "content/public/browser/render_view_host.h" | 99 #include "content/public/browser/render_view_host.h" |
| 100 #include "content/public/browser/render_widget_host_view.h" | 100 #include "content/public/browser/render_widget_host_view.h" |
| 101 #include "content/public/browser/ssl_status.h" | 101 #include "content/public/browser/ssl_status.h" |
| 102 #include "content/public/browser/storage_partition.h" | 102 #include "content/public/browser/storage_partition.h" |
| 103 #include "content/public/browser/user_metrics.h" | 103 #include "content/public/browser/user_metrics.h" |
| 104 #include "content/public/browser/web_contents.h" | 104 #include "content/public/browser/web_contents.h" |
| 105 #include "content/public/common/menu_item.h" | 105 #include "content/public/common/menu_item.h" |
| 106 #include "content/public/common/url_utils.h" | 106 #include "content/public/common/url_utils.h" |
| 107 #include "net/base/escape.h" | 107 #include "net/base/escape.h" |
| 108 #include "printing/features/features.h" |
| 108 #include "third_party/WebKit/public/public_features.h" | 109 #include "third_party/WebKit/public/public_features.h" |
| 109 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 110 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 110 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" | 111 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 111 #include "third_party/WebKit/public/web/WebPluginAction.h" | 112 #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 112 #include "ui/base/clipboard/clipboard.h" | 113 #include "ui/base/clipboard/clipboard.h" |
| 113 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 114 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 114 #include "ui/base/l10n/l10n_util.h" | 115 #include "ui/base/l10n/l10n_util.h" |
| 115 #include "ui/gfx/canvas.h" | 116 #include "ui/gfx/canvas.h" |
| 116 #include "ui/gfx/favicon_size.h" | 117 #include "ui/gfx/favicon_size.h" |
| 117 #include "ui/gfx/geometry/point.h" | 118 #include "ui/gfx/geometry/point.h" |
| 118 #include "ui/gfx/geometry/size.h" | 119 #include "ui/gfx/geometry/size.h" |
| 119 #include "ui/gfx/path.h" | 120 #include "ui/gfx/path.h" |
| 120 #include "ui/gfx/text_elider.h" | 121 #include "ui/gfx/text_elider.h" |
| 121 | 122 |
| 122 #if !defined(USE_BROWSER_SPELLCHECKER) | 123 #if !defined(USE_BROWSER_SPELLCHECKER) |
| 123 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer
.h" | 124 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer
.h" |
| 124 #endif | 125 #endif |
| 125 | 126 |
| 126 #if defined(ENABLE_EXTENSIONS) | 127 #if defined(ENABLE_EXTENSIONS) |
| 127 #include "chrome/browser/extensions/devtools_util.h" | 128 #include "chrome/browser/extensions/devtools_util.h" |
| 128 #include "chrome/browser/extensions/extension_service.h" | 129 #include "chrome/browser/extensions/extension_service.h" |
| 129 #include "extensions/browser/extension_host.h" | 130 #include "extensions/browser/extension_host.h" |
| 130 #include "extensions/browser/extension_system.h" | 131 #include "extensions/browser/extension_system.h" |
| 131 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 132 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 132 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 133 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 133 #include "extensions/browser/view_type_utils.h" | 134 #include "extensions/browser/view_type_utils.h" |
| 134 #include "extensions/common/extension.h" | 135 #include "extensions/common/extension.h" |
| 135 #endif | 136 #endif |
| 136 | 137 |
| 137 #if defined(ENABLE_PRINTING) | 138 #if BUILDFLAG(ENABLE_PRINTING) |
| 138 #include "chrome/browser/printing/print_view_manager_common.h" | 139 #include "chrome/browser/printing/print_view_manager_common.h" |
| 139 #include "components/printing/common/print_messages.h" | 140 #include "components/printing/common/print_messages.h" |
| 140 | 141 |
| 141 #if defined(ENABLE_PRINT_PREVIEW) | 142 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 142 #include "chrome/browser/printing/print_preview_context_menu_observer.h" | 143 #include "chrome/browser/printing/print_preview_context_menu_observer.h" |
| 143 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 144 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 144 #endif // defined(ENABLE_PRINT_PREVIEW) | 145 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 145 #endif // defined(ENABLE_PRINTING) | 146 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 146 | 147 |
| 147 #if defined(ENABLE_MEDIA_ROUTER) | 148 #if defined(ENABLE_MEDIA_ROUTER) |
| 148 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 149 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 149 #include "chrome/browser/media/router/media_router_feature.h" | 150 #include "chrome/browser/media/router/media_router_feature.h" |
| 150 #include "chrome/browser/media/router/media_router_metrics.h" | 151 #include "chrome/browser/media/router/media_router_metrics.h" |
| 151 #endif | 152 #endif |
| 152 | 153 |
| 153 #if defined(GOOGLE_CHROME_BUILD) | 154 #if defined(GOOGLE_CHROME_BUILD) |
| 154 #include "chrome/grit/theme_resources.h" | 155 #include "chrome/grit/theme_resources.h" |
| 155 #include "ui/base/resource/resource_bundle.h" | 156 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 } | 909 } |
| 909 | 910 |
| 910 #if defined(ENABLE_PLUGINS) | 911 #if defined(ENABLE_PLUGINS) |
| 911 void RenderViewContextMenu::HandleAuthorizeAllPlugins() { | 912 void RenderViewContextMenu::HandleAuthorizeAllPlugins() { |
| 912 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 913 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
| 913 source_web_contents_, false, std::string()); | 914 source_web_contents_, false, std::string()); |
| 914 } | 915 } |
| 915 #endif | 916 #endif |
| 916 | 917 |
| 917 void RenderViewContextMenu::AppendPrintPreviewItems() { | 918 void RenderViewContextMenu::AppendPrintPreviewItems() { |
| 918 #if defined(ENABLE_PRINT_PREVIEW) | 919 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 919 if (!print_preview_menu_observer_.get()) { | 920 if (!print_preview_menu_observer_.get()) { |
| 920 print_preview_menu_observer_.reset( | 921 print_preview_menu_observer_.reset( |
| 921 new PrintPreviewContextMenuObserver(source_web_contents_)); | 922 new PrintPreviewContextMenuObserver(source_web_contents_)); |
| 922 } | 923 } |
| 923 | 924 |
| 924 observers_.AddObserver(print_preview_menu_observer_.get()); | 925 observers_.AddObserver(print_preview_menu_observer_.get()); |
| 925 #endif | 926 #endif |
| 926 } | 927 } |
| 927 | 928 |
| 928 const Extension* RenderViewContextMenu::GetExtension() const { | 929 const Extension* RenderViewContextMenu::GetExtension() const { |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 PrefService* local_state = g_browser_process->local_state(); | 2074 PrefService* local_state = g_browser_process->local_state(); |
| 2074 DCHECK(local_state); | 2075 DCHECK(local_state); |
| 2075 // Test if file-selection dialogs are forbidden by policy. | 2076 // Test if file-selection dialogs are forbidden by policy. |
| 2076 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 2077 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| 2077 return false; | 2078 return false; |
| 2078 | 2079 |
| 2079 const GURL& url = params_.src_url; | 2080 const GURL& url = params_.src_url; |
| 2080 bool can_save = | 2081 bool can_save = |
| 2081 (params_.media_flags & WebContextMenuData::MediaCanSave) && | 2082 (params_.media_flags & WebContextMenuData::MediaCanSave) && |
| 2082 url.is_valid() && ProfileIOData::IsHandledProtocol(url.scheme()); | 2083 url.is_valid() && ProfileIOData::IsHandledProtocol(url.scheme()); |
| 2083 #if defined(ENABLE_PRINT_PREVIEW) | 2084 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 2084 // Do not save the preview PDF on the print preview page. | 2085 // Do not save the preview PDF on the print preview page. |
| 2085 can_save = can_save && | 2086 can_save = can_save && |
| 2086 !(printing::PrintPreviewDialogController::IsPrintPreviewURL(url)); | 2087 !(printing::PrintPreviewDialogController::IsPrintPreviewURL(url)); |
| 2087 #endif | 2088 #endif |
| 2088 return can_save; | 2089 return can_save; |
| 2089 } | 2090 } |
| 2090 | 2091 |
| 2091 bool RenderViewContextMenu::IsSavePageEnabled() const { | 2092 bool RenderViewContextMenu::IsSavePageEnabled() const { |
| 2092 CoreTabHelper* core_tab_helper = | 2093 CoreTabHelper* core_tab_helper = |
| 2093 CoreTabHelper::FromWebContents(embedder_web_contents_); | 2094 CoreTabHelper::FromWebContents(embedder_web_contents_); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 void RenderViewContextMenu::ExecRestartPackagedApp() { | 2397 void RenderViewContextMenu::ExecRestartPackagedApp() { |
| 2397 const Extension* platform_app = GetExtension(); | 2398 const Extension* platform_app = GetExtension(); |
| 2398 DCHECK(platform_app); | 2399 DCHECK(platform_app); |
| 2399 DCHECK(platform_app->is_platform_app()); | 2400 DCHECK(platform_app->is_platform_app()); |
| 2400 | 2401 |
| 2401 apps::AppLoadService::Get(GetProfile()) | 2402 apps::AppLoadService::Get(GetProfile()) |
| 2402 ->RestartApplication(platform_app->id()); | 2403 ->RestartApplication(platform_app->id()); |
| 2403 } | 2404 } |
| 2404 | 2405 |
| 2405 void RenderViewContextMenu::ExecPrint() { | 2406 void RenderViewContextMenu::ExecPrint() { |
| 2406 #if defined(ENABLE_PRINTING) | 2407 #if BUILDFLAG(ENABLE_PRINTING) |
| 2407 if (params_.media_type != WebContextMenuData::MediaTypeNone) { | 2408 if (params_.media_type != WebContextMenuData::MediaTypeNone) { |
| 2408 RenderFrameHost* render_frame_host = GetRenderFrameHost(); | 2409 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 2409 if (render_frame_host) { | 2410 if (render_frame_host) { |
| 2410 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu( | 2411 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu( |
| 2411 render_frame_host->GetRoutingID())); | 2412 render_frame_host->GetRoutingID())); |
| 2412 } | 2413 } |
| 2413 return; | 2414 return; |
| 2414 } | 2415 } |
| 2415 | 2416 |
| 2416 printing::StartPrint( | 2417 printing::StartPrint( |
| 2417 source_web_contents_, | 2418 source_web_contents_, |
| 2418 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), | 2419 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), |
| 2419 !params_.selection_text.empty()); | 2420 !params_.selection_text.empty()); |
| 2420 #endif // defined(ENABLE_PRINTING) | 2421 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 2421 } | 2422 } |
| 2422 | 2423 |
| 2423 void RenderViewContextMenu::ExecRouteMedia() { | 2424 void RenderViewContextMenu::ExecRouteMedia() { |
| 2424 #if defined(ENABLE_MEDIA_ROUTER) | 2425 #if defined(ENABLE_MEDIA_ROUTER) |
| 2425 if (!media_router::MediaRouterEnabled(browser_context_)) | 2426 if (!media_router::MediaRouterEnabled(browser_context_)) |
| 2426 return; | 2427 return; |
| 2427 | 2428 |
| 2428 media_router::MediaRouterDialogController* dialog_controller = | 2429 media_router::MediaRouterDialogController* dialog_controller = |
| 2429 media_router::MediaRouterDialogController::GetOrCreateForWebContents( | 2430 media_router::MediaRouterDialogController::GetOrCreateForWebContents( |
| 2430 embedder_web_contents_); | 2431 embedder_web_contents_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 void RenderViewContextMenu::PluginActionAt( | 2498 void RenderViewContextMenu::PluginActionAt( |
| 2498 const gfx::Point& location, | 2499 const gfx::Point& location, |
| 2499 const WebPluginAction& action) { | 2500 const WebPluginAction& action) { |
| 2500 source_web_contents_->GetRenderViewHost()-> | 2501 source_web_contents_->GetRenderViewHost()-> |
| 2501 ExecutePluginActionAtLocation(location, action); | 2502 ExecutePluginActionAtLocation(location, action); |
| 2502 } | 2503 } |
| 2503 | 2504 |
| 2504 Browser* RenderViewContextMenu::GetBrowser() const { | 2505 Browser* RenderViewContextMenu::GetBrowser() const { |
| 2505 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2506 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
| 2506 } | 2507 } |
| OLD | NEW |