| 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 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 26 #include "chrome/browser/apps/app_load_service.h" | 26 #include "chrome/browser/apps/app_load_service.h" |
| 27 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 27 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 31 #include "chrome/browser/devtools/devtools_window.h" | 31 #include "chrome/browser/devtools/devtools_window.h" |
| 32 #include "chrome/browser/download/download_service.h" | 32 #include "chrome/browser/download/download_service.h" |
| 33 #include "chrome/browser/download/download_service_factory.h" | 33 #include "chrome/browser/download/download_service_factory.h" |
| 34 #include "chrome/browser/download/download_stats.h" | 34 #include "chrome/browser/download/download_stats.h" |
| 35 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 36 #include "chrome/browser/media/router/media_router_feature.h" |
| 37 #include "chrome/browser/media/router/media_router_metrics.h" |
| 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 38 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 36 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 39 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 37 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 40 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 38 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 41 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 42 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 40 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 41 #include "chrome/browser/profiles/profile_attributes_entry.h" | 44 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 42 #include "chrome/browser/profiles/profile_attributes_storage.h" | 45 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 43 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 46 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 44 #include "chrome/browser/profiles/profile_io_data.h" | 47 #include "chrome/browser/profiles/profile_io_data.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 #if BUILDFLAG(ENABLE_PRINTING) | 142 #if BUILDFLAG(ENABLE_PRINTING) |
| 140 #include "chrome/browser/printing/print_view_manager_common.h" | 143 #include "chrome/browser/printing/print_view_manager_common.h" |
| 141 #include "components/printing/common/print_messages.h" | 144 #include "components/printing/common/print_messages.h" |
| 142 | 145 |
| 143 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 146 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 144 #include "chrome/browser/printing/print_preview_context_menu_observer.h" | 147 #include "chrome/browser/printing/print_preview_context_menu_observer.h" |
| 145 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 148 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 146 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 149 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 147 #endif // BUILDFLAG(ENABLE_PRINTING) | 150 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 148 | 151 |
| 149 #if defined(ENABLE_MEDIA_ROUTER) | |
| 150 #include "chrome/browser/media/router/media_router_dialog_controller.h" | |
| 151 #include "chrome/browser/media/router/media_router_feature.h" | |
| 152 #include "chrome/browser/media/router/media_router_metrics.h" | |
| 153 #endif | |
| 154 | |
| 155 #if defined(GOOGLE_CHROME_BUILD) | 152 #if defined(GOOGLE_CHROME_BUILD) |
| 156 #include "chrome/grit/theme_resources.h" | 153 #include "chrome/grit/theme_resources.h" |
| 157 #include "ui/base/resource/resource_bundle.h" | 154 #include "ui/base/resource/resource_bundle.h" |
| 158 #endif | 155 #endif |
| 159 | 156 |
| 160 using base::UserMetricsAction; | 157 using base::UserMetricsAction; |
| 161 using blink::WebContextMenuData; | 158 using blink::WebContextMenuData; |
| 162 using blink::WebMediaPlayerAction; | 159 using blink::WebMediaPlayerAction; |
| 163 using blink::WebPluginAction; | 160 using blink::WebPluginAction; |
| 164 using blink::WebString; | 161 using blink::WebString; |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 void RenderViewContextMenu::AppendPrintItem() { | 1282 void RenderViewContextMenu::AppendPrintItem() { |
| 1286 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && | 1283 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && |
| 1287 (params_.media_type == WebContextMenuData::kMediaTypeNone || | 1284 (params_.media_type == WebContextMenuData::kMediaTypeNone || |
| 1288 params_.media_flags & WebContextMenuData::kMediaCanPrint) && | 1285 params_.media_flags & WebContextMenuData::kMediaCanPrint) && |
| 1289 params_.misspelled_word.empty()) { | 1286 params_.misspelled_word.empty()) { |
| 1290 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 1287 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 1291 } | 1288 } |
| 1292 } | 1289 } |
| 1293 | 1290 |
| 1294 void RenderViewContextMenu::AppendMediaRouterItem() { | 1291 void RenderViewContextMenu::AppendMediaRouterItem() { |
| 1295 #if defined(ENABLE_MEDIA_ROUTER) | |
| 1296 if (media_router::MediaRouterEnabled(browser_context_)) { | 1292 if (media_router::MediaRouterEnabled(browser_context_)) { |
| 1297 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, | 1293 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, |
| 1298 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); | 1294 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); |
| 1299 } | 1295 } |
| 1300 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 1301 } | 1296 } |
| 1302 | 1297 |
| 1303 void RenderViewContextMenu::AppendRotationItems() { | 1298 void RenderViewContextMenu::AppendRotationItems() { |
| 1304 if (params_.media_flags & WebContextMenuData::kMediaCanRotate) { | 1299 if (params_.media_flags & WebContextMenuData::kMediaCanRotate) { |
| 1305 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1300 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1306 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, | 1301 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, |
| 1307 IDS_CONTENT_CONTEXT_ROTATECW); | 1302 IDS_CONTENT_CONTEXT_ROTATECW); |
| 1308 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, | 1303 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, |
| 1309 IDS_CONTENT_CONTEXT_ROTATECCW); | 1304 IDS_CONTENT_CONTEXT_ROTATECCW); |
| 1310 } | 1305 } |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 if (params_.media_type != WebContextMenuData::kMediaTypeNone && | 2123 if (params_.media_type != WebContextMenuData::kMediaTypeNone && |
| 2129 !(params_.media_flags & WebContextMenuData::kMediaCanPrint)) { | 2124 !(params_.media_flags & WebContextMenuData::kMediaCanPrint)) { |
| 2130 return false; | 2125 return false; |
| 2131 } | 2126 } |
| 2132 | 2127 |
| 2133 Browser* browser = GetBrowser(); | 2128 Browser* browser = GetBrowser(); |
| 2134 return browser && chrome::CanPrint(browser); | 2129 return browser && chrome::CanPrint(browser); |
| 2135 } | 2130 } |
| 2136 | 2131 |
| 2137 bool RenderViewContextMenu::IsRouteMediaEnabled() const { | 2132 bool RenderViewContextMenu::IsRouteMediaEnabled() const { |
| 2138 #if defined(ENABLE_MEDIA_ROUTER) | |
| 2139 if (!media_router::MediaRouterEnabled(browser_context_)) | 2133 if (!media_router::MediaRouterEnabled(browser_context_)) |
| 2140 return false; | 2134 return false; |
| 2141 | 2135 |
| 2142 Browser* browser = GetBrowser(); | 2136 Browser* browser = GetBrowser(); |
| 2143 if (!browser) | 2137 if (!browser) |
| 2144 return false; | 2138 return false; |
| 2145 | 2139 |
| 2146 // Disable the command if there is an active modal dialog. | 2140 // Disable the command if there is an active modal dialog. |
| 2147 // We don't use |source_web_contents_| here because it could be the | 2141 // We don't use |source_web_contents_| here because it could be the |
| 2148 // WebContents for something that's not the current tab (e.g., WebUI | 2142 // WebContents for something that's not the current tab (e.g., WebUI |
| 2149 // modal dialog). | 2143 // modal dialog). |
| 2150 WebContents* web_contents = | 2144 WebContents* web_contents = |
| 2151 browser->tab_strip_model()->GetActiveWebContents(); | 2145 browser->tab_strip_model()->GetActiveWebContents(); |
| 2152 if (!web_contents) | 2146 if (!web_contents) |
| 2153 return false; | 2147 return false; |
| 2154 | 2148 |
| 2155 const web_modal::WebContentsModalDialogManager* manager = | 2149 const web_modal::WebContentsModalDialogManager* manager = |
| 2156 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 2150 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 2157 return !manager || !manager->IsDialogActive(); | 2151 return !manager || !manager->IsDialogActive(); |
| 2158 #else | |
| 2159 return false; | |
| 2160 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 2161 } | 2152 } |
| 2162 | 2153 |
| 2163 bool RenderViewContextMenu::IsOpenLinkOTREnabled() const { | 2154 bool RenderViewContextMenu::IsOpenLinkOTREnabled() const { |
| 2164 if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid()) | 2155 if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid()) |
| 2165 return false; | 2156 return false; |
| 2166 | 2157 |
| 2167 IncognitoModePrefs::Availability incognito_avail = | 2158 IncognitoModePrefs::Availability incognito_avail = |
| 2168 IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_)); | 2159 IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_)); |
| 2169 return incognito_avail != IncognitoModePrefs::DISABLED; | 2160 return incognito_avail != IncognitoModePrefs::DISABLED; |
| 2170 } | 2161 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 } | 2409 } |
| 2419 | 2410 |
| 2420 printing::StartPrint( | 2411 printing::StartPrint( |
| 2421 source_web_contents_, | 2412 source_web_contents_, |
| 2422 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), | 2413 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), |
| 2423 !params_.selection_text.empty()); | 2414 !params_.selection_text.empty()); |
| 2424 #endif // BUILDFLAG(ENABLE_PRINTING) | 2415 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 2425 } | 2416 } |
| 2426 | 2417 |
| 2427 void RenderViewContextMenu::ExecRouteMedia() { | 2418 void RenderViewContextMenu::ExecRouteMedia() { |
| 2428 #if defined(ENABLE_MEDIA_ROUTER) | |
| 2429 if (!media_router::MediaRouterEnabled(browser_context_)) | 2419 if (!media_router::MediaRouterEnabled(browser_context_)) |
| 2430 return; | 2420 return; |
| 2431 | 2421 |
| 2432 media_router::MediaRouterDialogController* dialog_controller = | 2422 media_router::MediaRouterDialogController* dialog_controller = |
| 2433 media_router::MediaRouterDialogController::GetOrCreateForWebContents( | 2423 media_router::MediaRouterDialogController::GetOrCreateForWebContents( |
| 2434 embedder_web_contents_); | 2424 embedder_web_contents_); |
| 2435 if (!dialog_controller) | 2425 if (!dialog_controller) |
| 2436 return; | 2426 return; |
| 2437 | 2427 |
| 2438 dialog_controller->ShowMediaRouterDialog(); | 2428 dialog_controller->ShowMediaRouterDialog(); |
| 2439 media_router::MediaRouterMetrics::RecordMediaRouterDialogOrigin( | 2429 media_router::MediaRouterMetrics::RecordMediaRouterDialogOrigin( |
| 2440 media_router::MediaRouterDialogOpenOrigin::CONTEXTUAL_MENU); | 2430 media_router::MediaRouterDialogOpenOrigin::CONTEXTUAL_MENU); |
| 2441 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 2442 } | 2431 } |
| 2443 | 2432 |
| 2444 void RenderViewContextMenu::ExecTranslate() { | 2433 void RenderViewContextMenu::ExecTranslate() { |
| 2445 // A translation might have been triggered by the time the menu got | 2434 // A translation might have been triggered by the time the menu got |
| 2446 // selected, do nothing in that case. | 2435 // selected, do nothing in that case. |
| 2447 ChromeTranslateClient* chrome_translate_client = | 2436 ChromeTranslateClient* chrome_translate_client = |
| 2448 ChromeTranslateClient::FromWebContents(embedder_web_contents_); | 2437 ChromeTranslateClient::FromWebContents(embedder_web_contents_); |
| 2449 if (!chrome_translate_client || | 2438 if (!chrome_translate_client || |
| 2450 chrome_translate_client->GetLanguageState().IsPageTranslated() || | 2439 chrome_translate_client->GetLanguageState().IsPageTranslated() || |
| 2451 chrome_translate_client->GetLanguageState().translation_pending()) { | 2440 chrome_translate_client->GetLanguageState().translation_pending()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2501 void RenderViewContextMenu::PluginActionAt( | 2490 void RenderViewContextMenu::PluginActionAt( |
| 2502 const gfx::Point& location, | 2491 const gfx::Point& location, |
| 2503 const WebPluginAction& action) { | 2492 const WebPluginAction& action) { |
| 2504 source_web_contents_->GetRenderViewHost()-> | 2493 source_web_contents_->GetRenderViewHost()-> |
| 2505 ExecutePluginActionAtLocation(location, action); | 2494 ExecutePluginActionAtLocation(location, action); |
| 2506 } | 2495 } |
| 2507 | 2496 |
| 2508 Browser* RenderViewContextMenu::GetBrowser() const { | 2497 Browser* RenderViewContextMenu::GetBrowser() const { |
| 2509 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2498 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
| 2510 } | 2499 } |
| OLD | NEW |