| 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 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/app/chrome_command_ids.h" | 24 #include "chrome/app/chrome_command_ids.h" |
| 25 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 26 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 26 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| 29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 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_stats.h" | 33 #include "chrome/browser/download/download_stats.h" |
| 34 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 35 #include "chrome/browser/media/router/media_router_feature.h" |
| 36 #include "chrome/browser/media/router/media_router_metrics.h" |
| 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 37 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 38 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 36 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 39 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 37 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 40 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 38 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 41 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 39 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
| 40 #include "chrome/browser/profiles/profile_attributes_entry.h" | 43 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 41 #include "chrome/browser/profiles/profile_attributes_storage.h" | 44 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 42 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 45 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 43 #include "chrome/browser/profiles/profile_io_data.h" | 46 #include "chrome/browser/profiles/profile_io_data.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 #if BUILDFLAG(ENABLE_PRINTING) | 145 #if BUILDFLAG(ENABLE_PRINTING) |
| 143 #include "chrome/browser/printing/print_view_manager_common.h" | 146 #include "chrome/browser/printing/print_view_manager_common.h" |
| 144 #include "components/printing/common/print_messages.h" | 147 #include "components/printing/common/print_messages.h" |
| 145 | 148 |
| 146 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 149 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 147 #include "chrome/browser/printing/print_preview_context_menu_observer.h" | 150 #include "chrome/browser/printing/print_preview_context_menu_observer.h" |
| 148 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 151 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 149 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 152 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 150 #endif // BUILDFLAG(ENABLE_PRINTING) | 153 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 151 | 154 |
| 152 #if defined(ENABLE_MEDIA_ROUTER) | |
| 153 #include "chrome/browser/media/router/media_router_dialog_controller.h" | |
| 154 #include "chrome/browser/media/router/media_router_feature.h" | |
| 155 #include "chrome/browser/media/router/media_router_metrics.h" | |
| 156 #endif | |
| 157 | |
| 158 #if defined(GOOGLE_CHROME_BUILD) | 155 #if defined(GOOGLE_CHROME_BUILD) |
| 159 #include "chrome/grit/theme_resources.h" | 156 #include "chrome/grit/theme_resources.h" |
| 160 #include "ui/base/resource/resource_bundle.h" | 157 #include "ui/base/resource/resource_bundle.h" |
| 161 #endif | 158 #endif |
| 162 | 159 |
| 163 using base::UserMetricsAction; | 160 using base::UserMetricsAction; |
| 164 using blink::WebContextMenuData; | 161 using blink::WebContextMenuData; |
| 165 using blink::WebMediaPlayerAction; | 162 using blink::WebMediaPlayerAction; |
| 166 using blink::WebPluginAction; | 163 using blink::WebPluginAction; |
| 167 using blink::WebString; | 164 using blink::WebString; |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 void RenderViewContextMenu::AppendPrintItem() { | 1294 void RenderViewContextMenu::AppendPrintItem() { |
| 1298 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && | 1295 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && |
| 1299 (params_.media_type == WebContextMenuData::MediaTypeNone || | 1296 (params_.media_type == WebContextMenuData::MediaTypeNone || |
| 1300 params_.media_flags & WebContextMenuData::MediaCanPrint) && | 1297 params_.media_flags & WebContextMenuData::MediaCanPrint) && |
| 1301 params_.misspelled_word.empty()) { | 1298 params_.misspelled_word.empty()) { |
| 1302 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 1299 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 1303 } | 1300 } |
| 1304 } | 1301 } |
| 1305 | 1302 |
| 1306 void RenderViewContextMenu::AppendMediaRouterItem() { | 1303 void RenderViewContextMenu::AppendMediaRouterItem() { |
| 1307 #if defined(ENABLE_MEDIA_ROUTER) | |
| 1308 if (media_router::MediaRouterEnabled(browser_context_)) { | 1304 if (media_router::MediaRouterEnabled(browser_context_)) { |
| 1309 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, | 1305 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, |
| 1310 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); | 1306 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); |
| 1311 } | 1307 } |
| 1312 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 1313 } | 1308 } |
| 1314 | 1309 |
| 1315 void RenderViewContextMenu::AppendRotationItems() { | 1310 void RenderViewContextMenu::AppendRotationItems() { |
| 1316 if (params_.media_flags & WebContextMenuData::MediaCanRotate) { | 1311 if (params_.media_flags & WebContextMenuData::MediaCanRotate) { |
| 1317 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1312 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1318 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, | 1313 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, |
| 1319 IDS_CONTENT_CONTEXT_ROTATECW); | 1314 IDS_CONTENT_CONTEXT_ROTATECW); |
| 1320 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, | 1315 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, |
| 1321 IDS_CONTENT_CONTEXT_ROTATECCW); | 1316 IDS_CONTENT_CONTEXT_ROTATECCW); |
| 1322 } | 1317 } |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 if (params_.media_type != WebContextMenuData::MediaTypeNone && | 2139 if (params_.media_type != WebContextMenuData::MediaTypeNone && |
| 2145 !(params_.media_flags & WebContextMenuData::MediaCanPrint)) { | 2140 !(params_.media_flags & WebContextMenuData::MediaCanPrint)) { |
| 2146 return false; | 2141 return false; |
| 2147 } | 2142 } |
| 2148 | 2143 |
| 2149 Browser* browser = GetBrowser(); | 2144 Browser* browser = GetBrowser(); |
| 2150 return browser && chrome::CanPrint(browser); | 2145 return browser && chrome::CanPrint(browser); |
| 2151 } | 2146 } |
| 2152 | 2147 |
| 2153 bool RenderViewContextMenu::IsRouteMediaEnabled() const { | 2148 bool RenderViewContextMenu::IsRouteMediaEnabled() const { |
| 2154 #if defined(ENABLE_MEDIA_ROUTER) | |
| 2155 if (!media_router::MediaRouterEnabled(browser_context_)) | 2149 if (!media_router::MediaRouterEnabled(browser_context_)) |
| 2156 return false; | 2150 return false; |
| 2157 | 2151 |
| 2158 Browser* browser = GetBrowser(); | 2152 Browser* browser = GetBrowser(); |
| 2159 if (!browser) | 2153 if (!browser) |
| 2160 return false; | 2154 return false; |
| 2161 | 2155 |
| 2162 // Disable the command if there is an active modal dialog. | 2156 // Disable the command if there is an active modal dialog. |
| 2163 // We don't use |source_web_contents_| here because it could be the | 2157 // We don't use |source_web_contents_| here because it could be the |
| 2164 // WebContents for something that's not the current tab (e.g., WebUI | 2158 // WebContents for something that's not the current tab (e.g., WebUI |
| 2165 // modal dialog). | 2159 // modal dialog). |
| 2166 WebContents* web_contents = | 2160 WebContents* web_contents = |
| 2167 browser->tab_strip_model()->GetActiveWebContents(); | 2161 browser->tab_strip_model()->GetActiveWebContents(); |
| 2168 if (!web_contents) | 2162 if (!web_contents) |
| 2169 return false; | 2163 return false; |
| 2170 | 2164 |
| 2171 const web_modal::WebContentsModalDialogManager* manager = | 2165 const web_modal::WebContentsModalDialogManager* manager = |
| 2172 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 2166 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 2173 return !manager || !manager->IsDialogActive(); | 2167 return !manager || !manager->IsDialogActive(); |
| 2174 #else | |
| 2175 return false; | |
| 2176 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 2177 } | 2168 } |
| 2178 | 2169 |
| 2179 bool RenderViewContextMenu::IsOpenLinkOTREnabled() const { | 2170 bool RenderViewContextMenu::IsOpenLinkOTREnabled() const { |
| 2180 if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid()) | 2171 if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid()) |
| 2181 return false; | 2172 return false; |
| 2182 | 2173 |
| 2183 IncognitoModePrefs::Availability incognito_avail = | 2174 IncognitoModePrefs::Availability incognito_avail = |
| 2184 IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_)); | 2175 IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_)); |
| 2185 return incognito_avail != IncognitoModePrefs::DISABLED; | 2176 return incognito_avail != IncognitoModePrefs::DISABLED; |
| 2186 } | 2177 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2436 } | 2427 } |
| 2437 | 2428 |
| 2438 printing::StartPrint( | 2429 printing::StartPrint( |
| 2439 source_web_contents_, | 2430 source_web_contents_, |
| 2440 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), | 2431 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), |
| 2441 !params_.selection_text.empty()); | 2432 !params_.selection_text.empty()); |
| 2442 #endif // BUILDFLAG(ENABLE_PRINTING) | 2433 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 2443 } | 2434 } |
| 2444 | 2435 |
| 2445 void RenderViewContextMenu::ExecRouteMedia() { | 2436 void RenderViewContextMenu::ExecRouteMedia() { |
| 2446 #if defined(ENABLE_MEDIA_ROUTER) | |
| 2447 if (!media_router::MediaRouterEnabled(browser_context_)) | 2437 if (!media_router::MediaRouterEnabled(browser_context_)) |
| 2448 return; | 2438 return; |
| 2449 | 2439 |
| 2450 media_router::MediaRouterDialogController* dialog_controller = | 2440 media_router::MediaRouterDialogController* dialog_controller = |
| 2451 media_router::MediaRouterDialogController::GetOrCreateForWebContents( | 2441 media_router::MediaRouterDialogController::GetOrCreateForWebContents( |
| 2452 embedder_web_contents_); | 2442 embedder_web_contents_); |
| 2453 if (!dialog_controller) | 2443 if (!dialog_controller) |
| 2454 return; | 2444 return; |
| 2455 | 2445 |
| 2456 dialog_controller->ShowMediaRouterDialog(); | 2446 dialog_controller->ShowMediaRouterDialog(); |
| 2457 media_router::MediaRouterMetrics::RecordMediaRouterDialogOrigin( | 2447 media_router::MediaRouterMetrics::RecordMediaRouterDialogOrigin( |
| 2458 media_router::MediaRouterDialogOpenOrigin::CONTEXTUAL_MENU); | 2448 media_router::MediaRouterDialogOpenOrigin::CONTEXTUAL_MENU); |
| 2459 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 2460 } | 2449 } |
| 2461 | 2450 |
| 2462 void RenderViewContextMenu::ExecTranslate() { | 2451 void RenderViewContextMenu::ExecTranslate() { |
| 2463 // A translation might have been triggered by the time the menu got | 2452 // A translation might have been triggered by the time the menu got |
| 2464 // selected, do nothing in that case. | 2453 // selected, do nothing in that case. |
| 2465 ChromeTranslateClient* chrome_translate_client = | 2454 ChromeTranslateClient* chrome_translate_client = |
| 2466 ChromeTranslateClient::FromWebContents(embedder_web_contents_); | 2455 ChromeTranslateClient::FromWebContents(embedder_web_contents_); |
| 2467 if (!chrome_translate_client || | 2456 if (!chrome_translate_client || |
| 2468 chrome_translate_client->GetLanguageState().IsPageTranslated() || | 2457 chrome_translate_client->GetLanguageState().IsPageTranslated() || |
| 2469 chrome_translate_client->GetLanguageState().translation_pending()) { | 2458 chrome_translate_client->GetLanguageState().translation_pending()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2519 void RenderViewContextMenu::PluginActionAt( | 2508 void RenderViewContextMenu::PluginActionAt( |
| 2520 const gfx::Point& location, | 2509 const gfx::Point& location, |
| 2521 const WebPluginAction& action) { | 2510 const WebPluginAction& action) { |
| 2522 source_web_contents_->GetRenderViewHost()-> | 2511 source_web_contents_->GetRenderViewHost()-> |
| 2523 ExecutePluginActionAtLocation(location, action); | 2512 ExecutePluginActionAtLocation(location, action); |
| 2524 } | 2513 } |
| 2525 | 2514 |
| 2526 Browser* RenderViewContextMenu::GetBrowser() const { | 2515 Browser* RenderViewContextMenu::GetBrowser() const { |
| 2527 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2516 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
| 2528 } | 2517 } |
| OLD | NEW |