| Index: chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
| diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
| index b3e53ee835a0e986d72134710709c11f767dda2b..dc37d30d9d3acdaf2bf91cb5c6e11440c8847644 100644
|
| --- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
| +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
| @@ -37,7 +37,11 @@
|
| #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
|
| #include "chrome/browser/prefs/incognito_mode_prefs.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_avatar_icon_util.h"
|
| +#include "chrome/browser/profiles/profile_info_cache.h"
|
| #include "chrome/browser/profiles/profile_io_data.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/profiles/profile_window.h"
|
| #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory.h"
|
| #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h"
|
| #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
|
| @@ -225,9 +229,10 @@ const struct UmaEnumCommandIdPair {
|
| {65, IDC_WRITING_DIRECTION_RTL},
|
| {66, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE},
|
| {67, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD},
|
| + {68, IDC_OPEN_LINK_IN_PROFILE_FIRST},
|
| // Add new items here and use |enum_id| from the next line.
|
| // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
|
| - {68, 0}, // Must be the last. Increment |enum_id| when new IDC was added.
|
| + {69, 0}, // Must be the last. Increment |enum_id| when new IDC was added.
|
| };
|
|
|
| // Collapses large ranges of ids before looking for UMA enum.
|
| @@ -250,6 +255,11 @@ int CollapseCommandsForUMA(int id) {
|
| return IDC_SPELLCHECK_SUGGESTION_0;
|
| }
|
|
|
| + if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
|
| + id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
|
| + return IDC_OPEN_LINK_IN_PROFILE_FIRST;
|
| + }
|
| +
|
| return id;
|
| }
|
|
|
| @@ -371,6 +381,7 @@ RenderViewContextMenu::RenderViewContextMenu(
|
| this,
|
| &menu_model_,
|
| base::Bind(MenuItemMatchesParams, params_)),
|
| + profile_link_submenu_model_(this),
|
| protocol_handler_submenu_model_(this),
|
| protocol_handler_registry_(
|
| ProtocolHandlerRegistryFactory::GetForBrowserContext(GetProfile())),
|
| @@ -732,6 +743,59 @@ void RenderViewContextMenu::AppendLinkItems() {
|
| AppendProtocolHandlerSubMenu();
|
| }
|
|
|
| + // g_browser_process->profile_manager() is null during unit tests.
|
| + if (g_browser_process->profile_manager() &&
|
| + GetProfile()->GetProfileType() == Profile::REGULAR_PROFILE) {
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + const ProfileInfoCache& profile_info_cache =
|
| + profile_manager->GetProfileInfoCache();
|
| +
|
| + // Find all regular profiles other than the current one which have at
|
| + // least one open window.
|
| + std::vector<Profile*> target_profiles;
|
| + std::vector<Profile*> all_profiles = profile_manager->GetLoadedProfiles();
|
| + chrome::HostDesktopType desktop_type =
|
| + chrome::GetHostDesktopTypeForNativeView(
|
| + source_web_contents_->GetNativeView());
|
| + for (Profile* profile : all_profiles) {
|
| + if ((profile->GetProfileType() == Profile::REGULAR_PROFILE) &&
|
| + (profile != GetProfile()) &&
|
| + chrome::FindLastActiveWithProfile(profile, desktop_type))
|
| + target_profiles.push_back(profile);
|
| + }
|
| +
|
| + if (target_profiles.size() == 1) {
|
| + Profile* profile = target_profiles[0];
|
| + size_t profile_index =
|
| + profile_info_cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| + menu_model_.AddItem(
|
| + IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
|
| + l10n_util::GetStringFUTF16(
|
| + IDS_CONTENT_CONTEXT_OPENLINKINPROFILE,
|
| + profile_info_cache.GetNameOfProfileAtIndex(profile_index)));
|
| + } else if (!target_profiles.empty()) {
|
| + for (Profile* profile : target_profiles) {
|
| + size_t profile_index =
|
| + profile_info_cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| + profile_link_submenu_model_.AddItem(
|
| + IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
|
| + profile_info_cache.GetNameOfProfileAtIndex(profile_index));
|
| + gfx::Image icon =
|
| + profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index);
|
| + int width = icon.Width();
|
| + int height = icon.Height();
|
| + gfx::CalculateFaviconTargetSize(&width, &height);
|
| + profile_link_submenu_model_.SetIcon(
|
| + profile_link_submenu_model_.GetItemCount() - 1,
|
| + profiles::GetSizedAvatarIcon(icon, true, width, height));
|
| + }
|
| + menu_model_.AddSubMenuWithStringId(
|
| + IDC_CONTENT_CONTEXT_OPENLINKINPROFILE,
|
| + IDS_CONTENT_CONTEXT_OPENLINKINPROFILES,
|
| + &profile_link_submenu_model_);
|
| + }
|
| + }
|
| +
|
| menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD,
|
| IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
|
| menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS,
|
| @@ -1094,6 +1158,11 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
|
| return true;
|
| }
|
|
|
| + if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
|
| + id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
|
| + return params_.link_url.is_valid();
|
| + }
|
| +
|
| IncognitoModePrefs::Availability incognito_avail =
|
| IncognitoModePrefs::GetAvailability(prefs);
|
| switch (id) {
|
| @@ -1160,6 +1229,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
|
|
|
| case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
|
| case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
|
| + case IDC_CONTENT_CONTEXT_OPENLINKINPROFILE:
|
| return params_.link_url.is_valid();
|
|
|
| case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
|
| @@ -1417,6 +1487,44 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
|
| return;
|
| }
|
|
|
| + if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
|
| + id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + const ProfileInfoCache& profile_info_cache =
|
| + profile_manager->GetProfileInfoCache();
|
| +
|
| + base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex(
|
| + id - IDC_OPEN_LINK_IN_PROFILE_FIRST);
|
| + Profile* profile = profile_manager->GetProfileByPath(profile_path);
|
| + DCHECK(profile);
|
| +
|
| + chrome::HostDesktopType desktop_type =
|
| + chrome::GetHostDesktopTypeForNativeView(
|
| + source_web_contents_->GetNativeView());
|
| +
|
| + Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type);
|
| + chrome::NavigateParams nav_params(browser, params_.link_url,
|
| + ui::PAGE_TRANSITION_LINK);
|
| + nav_params.disposition = NEW_FOREGROUND_TAB;
|
| + nav_params.referrer = content::Referrer::SanitizeForRequest(
|
| + params_.link_url,
|
| + content::Referrer(GetDocumentURL(params_).GetAsReferrer(),
|
| + params_.referrer_policy));
|
| + nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
|
| + if (!browser) {
|
| + profiles::FindOrCreateNewWindowForProfile(
|
| + profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
|
| + chrome::startup::IS_NOT_FIRST_RUN, desktop_type,
|
| + false /* always_create */);
|
| + nav_params.browser =
|
| + chrome::FindLastActiveWithProfile(profile, desktop_type);
|
| + DCHECK(nav_params.browser);
|
| + nav_params.disposition = CURRENT_TAB;
|
| + }
|
| + chrome::Navigate(&nav_params);
|
| + return;
|
| + }
|
| +
|
| switch (id) {
|
| case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: {
|
| Browser* browser =
|
|
|