Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 1191453002: Implement "open link as user" context menu entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8af019df57b9f36a23c1a2a2b10f6461053833fb..303f15862b42add883b0066d28b33c3e721e4093 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_SHOW_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,60 @@ 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)) {
Peter Kasting 2015/06/16 08:20:24 Nit: {} not necessary
jochen (gone - plz use gerrit) 2015/06/16 09:01:50 done
+ 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.size() > 1) {
+ for (Profile* profile: target_profiles) {
Peter Kasting 2015/06/16 08:20:24 Nit: space before colon
jochen (gone - plz use gerrit) 2015/06/16 09:01:50 done
+ 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 +1159,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 +1230,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 +1488,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 =

Powered by Google App Engine
This is Rietveld 408576698