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> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "apps/app_load_service.h" | 13 #include "apps/app_load_service.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/metrics/user_metrics.h" |
19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "chrome/app/chrome_command_ids.h" | 25 #include "chrome/app/chrome_command_ids.h" |
25 #include "chrome/browser/app_mode/app_mode_utils.h" | 26 #include "chrome/browser/app_mode/app_mode_utils.h" |
26 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 27 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #include "content/public/browser/guest_mode.h" | 95 #include "content/public/browser/guest_mode.h" |
95 #include "content/public/browser/navigation_details.h" | 96 #include "content/public/browser/navigation_details.h" |
96 #include "content/public/browser/navigation_entry.h" | 97 #include "content/public/browser/navigation_entry.h" |
97 #include "content/public/browser/notification_service.h" | 98 #include "content/public/browser/notification_service.h" |
98 #include "content/public/browser/render_frame_host.h" | 99 #include "content/public/browser/render_frame_host.h" |
99 #include "content/public/browser/render_process_host.h" | 100 #include "content/public/browser/render_process_host.h" |
100 #include "content/public/browser/render_view_host.h" | 101 #include "content/public/browser/render_view_host.h" |
101 #include "content/public/browser/render_widget_host_view.h" | 102 #include "content/public/browser/render_widget_host_view.h" |
102 #include "content/public/browser/ssl_status.h" | 103 #include "content/public/browser/ssl_status.h" |
103 #include "content/public/browser/storage_partition.h" | 104 #include "content/public/browser/storage_partition.h" |
104 #include "content/public/browser/user_metrics.h" | |
105 #include "content/public/browser/web_contents.h" | 105 #include "content/public/browser/web_contents.h" |
106 #include "content/public/common/menu_item.h" | 106 #include "content/public/common/menu_item.h" |
107 #include "content/public/common/url_utils.h" | 107 #include "content/public/common/url_utils.h" |
108 #include "extensions/features/features.h" | 108 #include "extensions/features/features.h" |
109 #include "net/base/escape.h" | 109 #include "net/base/escape.h" |
110 #include "ppapi/features/features.h" | 110 #include "ppapi/features/features.h" |
111 #include "printing/features/features.h" | 111 #include "printing/features/features.h" |
112 #include "services/service_manager/public/cpp/interface_provider.h" | 112 #include "services/service_manager/public/cpp/interface_provider.h" |
113 #include "third_party/WebKit/public/public_features.h" | 113 #include "third_party/WebKit/public/public_features.h" |
114 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 114 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 ui::PAGE_TRANSITION_LINK, "", true); | 2179 ui::PAGE_TRANSITION_LINK, "", true); |
2180 } | 2180 } |
2181 | 2181 |
2182 void RenderViewContextMenu::ExecProtocolHandler(int event_flags, | 2182 void RenderViewContextMenu::ExecProtocolHandler(int event_flags, |
2183 int handler_index) { | 2183 int handler_index) { |
2184 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 2184 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
2185 GetHandlersForLinkUrl(); | 2185 GetHandlersForLinkUrl(); |
2186 if (handlers.empty()) | 2186 if (handlers.empty()) |
2187 return; | 2187 return; |
2188 | 2188 |
2189 content::RecordAction( | 2189 base::RecordAction( |
2190 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Open")); | 2190 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Open")); |
2191 WindowOpenDisposition disposition = | 2191 WindowOpenDisposition disposition = |
2192 ForceNewTabDispositionFromEventFlags(event_flags); | 2192 ForceNewTabDispositionFromEventFlags(event_flags); |
2193 OpenURL(handlers[handler_index].TranslateUrl(params_.link_url), | 2193 OpenURL(handlers[handler_index].TranslateUrl(params_.link_url), |
2194 GetDocumentURL(params_), | 2194 GetDocumentURL(params_), |
2195 disposition, | 2195 disposition, |
2196 ui::PAGE_TRANSITION_LINK); | 2196 ui::PAGE_TRANSITION_LINK); |
2197 } | 2197 } |
2198 | 2198 |
2199 void RenderViewContextMenu::ExecOpenLinkInProfile(int profile_index) { | 2199 void RenderViewContextMenu::ExecOpenLinkInProfile(int profile_index) { |
(...skipping 18 matching lines...) Expand all Loading... |
2218 profile_state, OPEN_LINK_AS_USER_LAST_ENUM_ID); | 2218 profile_state, OPEN_LINK_AS_USER_LAST_ENUM_ID); |
2219 | 2219 |
2220 profiles::SwitchToProfile( | 2220 profiles::SwitchToProfile( |
2221 profile_path, false, | 2221 profile_path, false, |
2222 base::Bind(OnProfileCreated, params_.link_url, | 2222 base::Bind(OnProfileCreated, params_.link_url, |
2223 CreateReferrer(params_.link_url, params_)), | 2223 CreateReferrer(params_.link_url, params_)), |
2224 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU); | 2224 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU); |
2225 } | 2225 } |
2226 | 2226 |
2227 void RenderViewContextMenu::ExecInspectElement() { | 2227 void RenderViewContextMenu::ExecInspectElement() { |
2228 content::RecordAction(UserMetricsAction("DevTools_InspectElement")); | 2228 base::RecordAction(UserMetricsAction("DevTools_InspectElement")); |
2229 RenderFrameHost* render_frame_host = GetRenderFrameHost(); | 2229 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
2230 if (!render_frame_host) | 2230 if (!render_frame_host) |
2231 return; | 2231 return; |
2232 DevToolsWindow::InspectElement(render_frame_host, params_.x, params_.y); | 2232 DevToolsWindow::InspectElement(render_frame_host, params_.x, params_.y); |
2233 } | 2233 } |
2234 | 2234 |
2235 void RenderViewContextMenu::ExecInspectBackgroundPage() { | 2235 void RenderViewContextMenu::ExecInspectBackgroundPage() { |
2236 const Extension* platform_app = GetExtension(); | 2236 const Extension* platform_app = GetExtension(); |
2237 DCHECK(platform_app); | 2237 DCHECK(platform_app); |
2238 DCHECK(platform_app->is_platform_app()); | 2238 DCHECK(platform_app->is_platform_app()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 if (!render_frame_host) | 2332 if (!render_frame_host) |
2333 return; | 2333 return; |
2334 chrome::mojom::ImageContextMenuRendererPtr renderer; | 2334 chrome::mojom::ImageContextMenuRendererPtr renderer; |
2335 render_frame_host->GetRemoteInterfaces()->GetInterface(&renderer); | 2335 render_frame_host->GetRemoteInterfaces()->GetInterface(&renderer); |
2336 renderer->RequestReloadImageForContextNode(); | 2336 renderer->RequestReloadImageForContextNode(); |
2337 } | 2337 } |
2338 | 2338 |
2339 void RenderViewContextMenu::ExecPlayPause() { | 2339 void RenderViewContextMenu::ExecPlayPause() { |
2340 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); | 2340 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); |
2341 if (play) | 2341 if (play) |
2342 content::RecordAction(UserMetricsAction("MediaContextMenu_Play")); | 2342 base::RecordAction(UserMetricsAction("MediaContextMenu_Play")); |
2343 else | 2343 else |
2344 content::RecordAction(UserMetricsAction("MediaContextMenu_Pause")); | 2344 base::RecordAction(UserMetricsAction("MediaContextMenu_Pause")); |
2345 | 2345 |
2346 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 2346 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
2347 WebMediaPlayerAction( | 2347 WebMediaPlayerAction( |
2348 WebMediaPlayerAction::Play, play)); | 2348 WebMediaPlayerAction::Play, play)); |
2349 } | 2349 } |
2350 | 2350 |
2351 void RenderViewContextMenu::ExecMute() { | 2351 void RenderViewContextMenu::ExecMute() { |
2352 bool mute = !(params_.media_flags & WebContextMenuData::MediaMuted); | 2352 bool mute = !(params_.media_flags & WebContextMenuData::MediaMuted); |
2353 if (mute) | 2353 if (mute) |
2354 content::RecordAction(UserMetricsAction("MediaContextMenu_Mute")); | 2354 base::RecordAction(UserMetricsAction("MediaContextMenu_Mute")); |
2355 else | 2355 else |
2356 content::RecordAction(UserMetricsAction("MediaContextMenu_Unmute")); | 2356 base::RecordAction(UserMetricsAction("MediaContextMenu_Unmute")); |
2357 | 2357 |
2358 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 2358 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
2359 WebMediaPlayerAction( | 2359 WebMediaPlayerAction( |
2360 WebMediaPlayerAction::Mute, mute)); | 2360 WebMediaPlayerAction::Mute, mute)); |
2361 } | 2361 } |
2362 | 2362 |
2363 void RenderViewContextMenu::ExecLoop() { | 2363 void RenderViewContextMenu::ExecLoop() { |
2364 content::RecordAction(UserMetricsAction("MediaContextMenu_Loop")); | 2364 base::RecordAction(UserMetricsAction("MediaContextMenu_Loop")); |
2365 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 2365 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
2366 WebMediaPlayerAction( | 2366 WebMediaPlayerAction( |
2367 WebMediaPlayerAction::Loop, | 2367 WebMediaPlayerAction::Loop, |
2368 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_LOOP))); | 2368 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_LOOP))); |
2369 } | 2369 } |
2370 | 2370 |
2371 void RenderViewContextMenu::ExecControls() { | 2371 void RenderViewContextMenu::ExecControls() { |
2372 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); | 2372 base::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); |
2373 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), | 2373 MediaPlayerActionAt(gfx::Point(params_.x, params_.y), |
2374 WebMediaPlayerAction( | 2374 WebMediaPlayerAction( |
2375 WebMediaPlayerAction::Controls, | 2375 WebMediaPlayerAction::Controls, |
2376 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); | 2376 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); |
2377 } | 2377 } |
2378 | 2378 |
2379 void RenderViewContextMenu::ExecRotateCW() { | 2379 void RenderViewContextMenu::ExecRotateCW() { |
2380 content::RecordAction(UserMetricsAction("PluginContextMenu_RotateClockwise")); | 2380 base::RecordAction(UserMetricsAction("PluginContextMenu_RotateClockwise")); |
2381 PluginActionAt(gfx::Point(params_.x, params_.y), | 2381 PluginActionAt(gfx::Point(params_.x, params_.y), |
2382 WebPluginAction(WebPluginAction::Rotate90Clockwise, true)); | 2382 WebPluginAction(WebPluginAction::Rotate90Clockwise, true)); |
2383 } | 2383 } |
2384 | 2384 |
2385 void RenderViewContextMenu::ExecRotateCCW() { | 2385 void RenderViewContextMenu::ExecRotateCCW() { |
2386 content::RecordAction( | 2386 base::RecordAction( |
2387 UserMetricsAction("PluginContextMenu_RotateCounterclockwise")); | 2387 UserMetricsAction("PluginContextMenu_RotateCounterclockwise")); |
2388 PluginActionAt(gfx::Point(params_.x, params_.y), | 2388 PluginActionAt(gfx::Point(params_.x, params_.y), |
2389 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, | 2389 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, |
2390 true)); | 2390 true)); |
2391 } | 2391 } |
2392 | 2392 |
2393 void RenderViewContextMenu::ExecReloadPackagedApp() { | 2393 void RenderViewContextMenu::ExecReloadPackagedApp() { |
2394 const Extension* platform_app = GetExtension(); | 2394 const Extension* platform_app = GetExtension(); |
2395 DCHECK(platform_app); | 2395 DCHECK(platform_app); |
2396 DCHECK(platform_app->is_platform_app()); | 2396 DCHECK(platform_app->is_platform_app()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 } | 2475 } |
2476 | 2476 |
2477 void RenderViewContextMenu::ExecLanguageSettings(int event_flags) { | 2477 void RenderViewContextMenu::ExecLanguageSettings(int event_flags) { |
2478 WindowOpenDisposition disposition = | 2478 WindowOpenDisposition disposition = |
2479 ForceNewTabDispositionFromEventFlags(event_flags); | 2479 ForceNewTabDispositionFromEventFlags(event_flags); |
2480 GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage); | 2480 GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage); |
2481 OpenURL(url, GURL(), disposition, ui::PAGE_TRANSITION_LINK); | 2481 OpenURL(url, GURL(), disposition, ui::PAGE_TRANSITION_LINK); |
2482 } | 2482 } |
2483 | 2483 |
2484 void RenderViewContextMenu::ExecProtocolHandlerSettings(int event_flags) { | 2484 void RenderViewContextMenu::ExecProtocolHandlerSettings(int event_flags) { |
2485 content::RecordAction( | 2485 base::RecordAction( |
2486 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Settings")); | 2486 UserMetricsAction("RegisterProtocolHandler.ContextMenu_Settings")); |
2487 WindowOpenDisposition disposition = | 2487 WindowOpenDisposition disposition = |
2488 ForceNewTabDispositionFromEventFlags(event_flags); | 2488 ForceNewTabDispositionFromEventFlags(event_flags); |
2489 GURL url = chrome::GetSettingsUrl(chrome::kHandlerSettingsSubPage); | 2489 GURL url = chrome::GetSettingsUrl(chrome::kHandlerSettingsSubPage); |
2490 OpenURL(url, GURL(), disposition, ui::PAGE_TRANSITION_LINK); | 2490 OpenURL(url, GURL(), disposition, ui::PAGE_TRANSITION_LINK); |
2491 } | 2491 } |
2492 | 2492 |
2493 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 2493 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
2494 ::WriteURLToClipboard(url); | 2494 ::WriteURLToClipboard(url); |
2495 } | 2495 } |
2496 | 2496 |
2497 void RenderViewContextMenu::MediaPlayerActionAt( | 2497 void RenderViewContextMenu::MediaPlayerActionAt( |
2498 const gfx::Point& location, | 2498 const gfx::Point& location, |
2499 const WebMediaPlayerAction& action) { | 2499 const WebMediaPlayerAction& action) { |
2500 source_web_contents_->GetRenderViewHost()-> | 2500 source_web_contents_->GetRenderViewHost()-> |
2501 ExecuteMediaPlayerActionAtLocation(location, action); | 2501 ExecuteMediaPlayerActionAtLocation(location, action); |
2502 } | 2502 } |
2503 | 2503 |
2504 void RenderViewContextMenu::PluginActionAt( | 2504 void RenderViewContextMenu::PluginActionAt( |
2505 const gfx::Point& location, | 2505 const gfx::Point& location, |
2506 const WebPluginAction& action) { | 2506 const WebPluginAction& action) { |
2507 source_web_contents_->GetRenderViewHost()-> | 2507 source_web_contents_->GetRenderViewHost()-> |
2508 ExecutePluginActionAtLocation(location, action); | 2508 ExecutePluginActionAtLocation(location, action); |
2509 } | 2509 } |
2510 | 2510 |
2511 Browser* RenderViewContextMenu::GetBrowser() const { | 2511 Browser* RenderViewContextMenu::GetBrowser() const { |
2512 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2512 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
2513 } | 2513 } |
OLD | NEW |