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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0); | 418 canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0); |
419 | 419 |
420 gfx::CalculateFaviconTargetSize(&width, &height); | 420 gfx::CalculateFaviconTargetSize(&width, &height); |
421 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( | 421 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( |
422 gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width, | 422 gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width, |
423 height); | 423 height); |
424 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); | 424 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); |
425 } | 425 } |
426 #endif // !defined(OS_CHROMEOS) | 426 #endif // !defined(OS_CHROMEOS) |
427 | 427 |
428 void OnProfileCreated(chrome::HostDesktopType desktop_type, | 428 void OnProfileCreated(const GURL& link_url, |
429 const GURL& link_url, | |
430 const content::Referrer& referrer, | 429 const content::Referrer& referrer, |
431 Profile* profile, | 430 Profile* profile, |
432 Profile::CreateStatus status) { | 431 Profile::CreateStatus status) { |
433 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 432 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
434 Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type); | 433 Browser* browser = chrome::FindLastActiveWithProfile(profile); |
435 chrome::NavigateParams nav_params(browser, link_url, | 434 chrome::NavigateParams nav_params(browser, link_url, |
436 ui::PAGE_TRANSITION_LINK); | 435 ui::PAGE_TRANSITION_LINK); |
437 nav_params.disposition = NEW_FOREGROUND_TAB; | 436 nav_params.disposition = NEW_FOREGROUND_TAB; |
438 nav_params.referrer = referrer; | 437 nav_params.referrer = referrer; |
439 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 438 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
440 chrome::Navigate(&nav_params); | 439 chrome::Navigate(&nav_params); |
441 } | 440 } |
442 } | 441 } |
443 | 442 |
444 } // namespace | 443 } // namespace |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 // time. | 890 // time. |
892 // TODO(jochen): Consider adding support for ChromeOS with similar | 891 // TODO(jochen): Consider adding support for ChromeOS with similar |
893 // semantics as the profile switcher in the system tray. | 892 // semantics as the profile switcher in the system tray. |
894 #if !defined(OS_CHROMEOS) | 893 #if !defined(OS_CHROMEOS) |
895 // g_browser_process->profile_manager() is null during unit tests. | 894 // g_browser_process->profile_manager() is null during unit tests. |
896 if (g_browser_process->profile_manager() && | 895 if (g_browser_process->profile_manager() && |
897 GetProfile()->GetProfileType() == Profile::REGULAR_PROFILE) { | 896 GetProfile()->GetProfileType() == Profile::REGULAR_PROFILE) { |
898 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 897 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
899 const ProfileInfoCache& profile_info_cache = | 898 const ProfileInfoCache& profile_info_cache = |
900 profile_manager->GetProfileInfoCache(); | 899 profile_manager->GetProfileInfoCache(); |
901 chrome::HostDesktopType desktop_type = | |
902 chrome::GetHostDesktopTypeForNativeView( | |
903 source_web_contents_->GetNativeView()); | |
904 | 900 |
905 // Find all regular profiles other than the current one which have at | 901 // Find all regular profiles other than the current one which have at |
906 // least one open window. | 902 // least one open window. |
907 std::vector<size_t> target_profiles; | 903 std::vector<size_t> target_profiles; |
908 const size_t profile_count = profile_info_cache.GetNumberOfProfiles(); | 904 const size_t profile_count = profile_info_cache.GetNumberOfProfiles(); |
909 for (size_t profile_index = 0; profile_index < profile_count; | 905 for (size_t profile_index = 0; profile_index < profile_count; |
910 ++profile_index) { | 906 ++profile_index) { |
911 base::FilePath profile_path = | 907 base::FilePath profile_path = |
912 profile_info_cache.GetPathOfProfileAtIndex(profile_index); | 908 profile_info_cache.GetPathOfProfileAtIndex(profile_index); |
913 Profile* profile = profile_manager->GetProfileByPath(profile_path); | 909 Profile* profile = profile_manager->GetProfileByPath(profile_path); |
914 if ((profile != GetProfile()) && | 910 if ((profile != GetProfile()) && |
915 !profile_info_cache.IsOmittedProfileAtIndex(profile_index) && | 911 !profile_info_cache.IsOmittedProfileAtIndex(profile_index) && |
916 !profile_info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) { | 912 !profile_info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) { |
917 target_profiles.push_back(profile_index); | 913 target_profiles.push_back(profile_index); |
918 if (chrome::FindLastActiveWithProfile(profile, desktop_type)) | 914 if (chrome::FindLastActiveWithProfile(profile)) |
919 multiple_profiles_open_ = true; | 915 multiple_profiles_open_ = true; |
920 } | 916 } |
921 } | 917 } |
922 | 918 |
923 if (!target_profiles.empty()) { | 919 if (!target_profiles.empty()) { |
924 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.OpenLinkAsUserShown", | 920 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.OpenLinkAsUserShown", |
925 target_profiles.size(), | 921 target_profiles.size(), |
926 kOpenLinkAsUserMaxProfilesReported); | 922 kOpenLinkAsUserMaxProfilesReported); |
927 } | 923 } |
928 | 924 |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 profile_manager->GetProfileInfoCache(); | 1657 profile_manager->GetProfileInfoCache(); |
1662 | 1658 |
1663 base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex( | 1659 base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex( |
1664 id - IDC_OPEN_LINK_IN_PROFILE_FIRST); | 1660 id - IDC_OPEN_LINK_IN_PROFILE_FIRST); |
1665 chrome::HostDesktopType desktop_type = | 1661 chrome::HostDesktopType desktop_type = |
1666 chrome::GetHostDesktopTypeForNativeView( | 1662 chrome::GetHostDesktopTypeForNativeView( |
1667 source_web_contents_->GetNativeView()); | 1663 source_web_contents_->GetNativeView()); |
1668 | 1664 |
1669 Profile* profile = profile_manager->GetProfileByPath(profile_path); | 1665 Profile* profile = profile_manager->GetProfileByPath(profile_path); |
1670 UmaEnumOpenLinkAsUser profile_state; | 1666 UmaEnumOpenLinkAsUser profile_state; |
1671 if (chrome::FindLastActiveWithProfile(profile, desktop_type)) { | 1667 if (chrome::FindLastActiveWithProfile(profile)) { |
1672 profile_state = OPEN_LINK_AS_USER_ACTIVE_PROFILE_ENUM_ID; | 1668 profile_state = OPEN_LINK_AS_USER_ACTIVE_PROFILE_ENUM_ID; |
1673 } else if (multiple_profiles_open_) { | 1669 } else if (multiple_profiles_open_) { |
1674 profile_state = | 1670 profile_state = |
1675 OPEN_LINK_AS_USER_INACTIVE_PROFILE_MULTI_PROFILE_SESSION_ENUM_ID; | 1671 OPEN_LINK_AS_USER_INACTIVE_PROFILE_MULTI_PROFILE_SESSION_ENUM_ID; |
1676 } else { | 1672 } else { |
1677 profile_state = | 1673 profile_state = |
1678 OPEN_LINK_AS_USER_INACTIVE_PROFILE_SINGLE_PROFILE_SESSION_ENUM_ID; | 1674 OPEN_LINK_AS_USER_INACTIVE_PROFILE_SINGLE_PROFILE_SESSION_ENUM_ID; |
1679 } | 1675 } |
1680 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.OpenLinkAsUser", | 1676 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.OpenLinkAsUser", |
1681 profile_state, OPEN_LINK_AS_USER_LAST_ENUM_ID); | 1677 profile_state, OPEN_LINK_AS_USER_LAST_ENUM_ID); |
1682 | 1678 |
1683 profiles::SwitchToProfile( | 1679 profiles::SwitchToProfile( |
1684 profile_path, desktop_type, false, | 1680 profile_path, desktop_type, false, |
1685 base::Bind(OnProfileCreated, desktop_type, params_.link_url, | 1681 base::Bind(OnProfileCreated, params_.link_url, |
1686 CreateReferrer(params_.link_url, params_)), | 1682 CreateReferrer(params_.link_url, params_)), |
1687 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU); | 1683 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU); |
1688 return; | 1684 return; |
1689 } | 1685 } |
1690 | 1686 |
1691 switch (id) { | 1687 switch (id) { |
1692 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { | 1688 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { |
1693 Browser* browser = | 1689 Browser* browser = |
1694 chrome::FindBrowserWithWebContents(source_web_contents_); | 1690 chrome::FindBrowserWithWebContents(source_web_contents_); |
1695 OpenURL(params_.link_url, | 1691 OpenURL(params_.link_url, |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 source_web_contents_->GetRenderViewHost()-> | 2179 source_web_contents_->GetRenderViewHost()-> |
2184 ExecuteMediaPlayerActionAtLocation(location, action); | 2180 ExecuteMediaPlayerActionAtLocation(location, action); |
2185 } | 2181 } |
2186 | 2182 |
2187 void RenderViewContextMenu::PluginActionAt( | 2183 void RenderViewContextMenu::PluginActionAt( |
2188 const gfx::Point& location, | 2184 const gfx::Point& location, |
2189 const WebPluginAction& action) { | 2185 const WebPluginAction& action) { |
2190 source_web_contents_->GetRenderViewHost()-> | 2186 source_web_contents_->GetRenderViewHost()-> |
2191 ExecutePluginActionAtLocation(location, action); | 2187 ExecutePluginActionAtLocation(location, action); |
2192 } | 2188 } |
OLD | NEW |