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