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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/download/download_stats.h" 30 #include "chrome/browser/download/download_stats.h"
31 #include "chrome/browser/extensions/devtools_util.h" 31 #include "chrome/browser/extensions/devtools_util.h"
32 #include "chrome/browser/extensions/extension_service.h" 32 #include "chrome/browser/extensions/extension_service.h"
33 #include "chrome/browser/media/router/media_router_dialog_controller.h" 33 #include "chrome/browser/media/router/media_router_dialog_controller.h"
34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
36 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 36 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
37 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 37 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
38 #include "chrome/browser/prefs/incognito_mode_prefs.h" 38 #include "chrome/browser/prefs/incognito_mode_prefs.h"
39 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
41 #include "chrome/browser/profiles/profile_info_cache.h"
40 #include "chrome/browser/profiles/profile_io_data.h" 42 #include "chrome/browser/profiles/profile_io_data.h"
43 #include "chrome/browser/profiles/profile_manager.h"
44 #include "chrome/browser/profiles/profile_window.h"
41 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h" 45 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h"
42 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" 46 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
43 #include "chrome/browser/search/search.h" 47 #include "chrome/browser/search/search.h"
44 #include "chrome/browser/search_engines/template_url_service_factory.h" 48 #include "chrome/browser/search_engines/template_url_service_factory.h"
45 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 49 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
46 #include "chrome/browser/spellchecker/spellcheck_service.h" 50 #include "chrome/browser/spellchecker/spellcheck_service.h"
47 #include "chrome/browser/ssl/security_state_model.h" 51 #include "chrome/browser/ssl/security_state_model.h"
48 #include "chrome/browser/tab_contents/retargeting_details.h" 52 #include "chrome/browser/tab_contents/retargeting_details.h"
49 #include "chrome/browser/translate/chrome_translate_client.h" 53 #include "chrome/browser/translate/chrome_translate_client.h"
50 #include "chrome/browser/translate/translate_service.h" 54 #include "chrome/browser/translate/translate_service.h"
51 #include "chrome/browser/ui/browser.h" 55 #include "chrome/browser/ui/browser.h"
52 #include "chrome/browser/ui/browser_commands.h" 56 #include "chrome/browser/ui/browser_commands.h"
53 #include "chrome/browser/ui/browser_finder.h" 57 #include "chrome/browser/ui/browser_finder.h"
58 #include "chrome/browser/ui/browser_navigator_params.h"
54 #include "chrome/browser/ui/chrome_pages.h" 59 #include "chrome/browser/ui/chrome_pages.h"
55 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 60 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" 61 #include "chrome/browser/ui/tabs/tab_strip_model.h"
57 #include "chrome/common/chrome_constants.h" 62 #include "chrome/common/chrome_constants.h"
58 #include "chrome/common/chrome_switches.h" 63 #include "chrome/common/chrome_switches.h"
59 #include "chrome/common/content_restriction.h" 64 #include "chrome/common/content_restriction.h"
60 #include "chrome/common/pref_names.h" 65 #include "chrome/common/pref_names.h"
61 #include "chrome/common/render_messages.h" 66 #include "chrome/common/render_messages.h"
62 #include "chrome/common/spellcheck_common.h" 67 #include "chrome/common/spellcheck_common.h"
63 #include "chrome/common/url_constants.h" 68 #include "chrome/common/url_constants.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #if defined(ENABLE_PRINTING) 121 #if defined(ENABLE_PRINTING)
117 #include "chrome/browser/printing/print_view_manager_common.h" 122 #include "chrome/browser/printing/print_view_manager_common.h"
118 #include "components/printing/common/print_messages.h" 123 #include "components/printing/common/print_messages.h"
119 124
120 #if defined(ENABLE_PRINT_PREVIEW) 125 #if defined(ENABLE_PRINT_PREVIEW)
121 #include "chrome/browser/printing/print_preview_context_menu_observer.h" 126 #include "chrome/browser/printing/print_preview_context_menu_observer.h"
122 #include "chrome/browser/printing/print_preview_dialog_controller.h" 127 #include "chrome/browser/printing/print_preview_dialog_controller.h"
123 #endif // defined(ENABLE_PRINT_PREVIEW) 128 #endif // defined(ENABLE_PRINT_PREVIEW)
124 #endif // defined(ENABLE_PRINTING) 129 #endif // defined(ENABLE_PRINTING)
125 130
131 #if defined(OS_CHROMEOS)
132 #include "chrome/browser/chromeos/profiles/profile_helper.h"
133 #endif
134
126 using base::UserMetricsAction; 135 using base::UserMetricsAction;
127 using blink::WebContextMenuData; 136 using blink::WebContextMenuData;
128 using blink::WebMediaPlayerAction; 137 using blink::WebMediaPlayerAction;
129 using blink::WebPluginAction; 138 using blink::WebPluginAction;
130 using blink::WebString; 139 using blink::WebString;
131 using blink::WebURL; 140 using blink::WebURL;
132 using content::BrowserContext; 141 using content::BrowserContext;
133 using content::ChildProcessSecurityPolicy; 142 using content::ChildProcessSecurityPolicy;
134 using content::DownloadManager; 143 using content::DownloadManager;
135 using content::DownloadUrlParameters; 144 using content::DownloadUrlParameters;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 {60, -1, IDC_SPELLPANEL_TOGGLE}, 244 {60, -1, IDC_SPELLPANEL_TOGGLE},
236 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, 245 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB},
237 {62, -1, IDC_WRITING_DIRECTION_MENU}, 246 {62, -1, IDC_WRITING_DIRECTION_MENU},
238 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, 247 {63, -1, IDC_WRITING_DIRECTION_DEFAULT},
239 {64, -1, IDC_WRITING_DIRECTION_LTR}, 248 {64, -1, IDC_WRITING_DIRECTION_LTR},
240 {65, -1, IDC_WRITING_DIRECTION_RTL}, 249 {65, -1, IDC_WRITING_DIRECTION_RTL},
241 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, 250 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE},
242 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, 251 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD},
243 {68, -1, IDC_ROUTE_MEDIA}, 252 {68, -1, IDC_ROUTE_MEDIA},
244 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT}, 253 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT},
254 {70, -1, IDC_CONTENT_CONTEXT_OPENLINKINPROFILE},
255 {71, -1, IDC_OPEN_LINK_IN_PROFILE_FIRST},
245 // Add new items here and use |enum_id| from the next line. 256 // Add new items here and use |enum_id| from the next line.
246 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. 257 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
247 {70, -1, 0}, // Must be the last. Increment |enum_id| when new IDC 258 {72, -1, 0}, // Must be the last. Increment |enum_id| when new IDC
248 // was added. 259 // was added.
249 }; 260 };
250 261
251 // Collapses large ranges of ids before looking for UMA enum. 262 // Collapses large ranges of ids before looking for UMA enum.
252 int CollapseCommandsForUMA(int id) { 263 int CollapseCommandsForUMA(int id) {
253 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); 264 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id));
254 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); 265 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id));
255 266
256 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 267 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
257 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 268 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
258 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; 269 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
259 } 270 }
260 271
261 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 272 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
262 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { 273 id <= IDC_SPELLCHECK_LANGUAGES_LAST) {
263 return IDC_SPELLCHECK_LANGUAGES_FIRST; 274 return IDC_SPELLCHECK_LANGUAGES_FIRST;
264 } 275 }
265 276
266 if (id >= IDC_SPELLCHECK_SUGGESTION_0 && 277 if (id >= IDC_SPELLCHECK_SUGGESTION_0 &&
267 id <= IDC_SPELLCHECK_SUGGESTION_LAST) { 278 id <= IDC_SPELLCHECK_SUGGESTION_LAST) {
268 return IDC_SPELLCHECK_SUGGESTION_0; 279 return IDC_SPELLCHECK_SUGGESTION_0;
269 } 280 }
270 281
282 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
283 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
284 return IDC_OPEN_LINK_IN_PROFILE_FIRST;
285 }
286
271 return id; 287 return id;
272 } 288 }
273 289
274 // Returns UMA enum value for command specified by |id| or -1 if not found. 290 // Returns UMA enum value for command specified by |id| or -1 if not found.
275 // |use_specific_context_enum| set to true returns the context_specific_enum_id. 291 // |use_specific_context_enum| set to true returns the context_specific_enum_id.
276 int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType enum_lookup_type) { 292 int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType enum_lookup_type) {
277 if (RenderViewContextMenu::IsContentCustomCommandId(id)) 293 if (RenderViewContextMenu::IsContentCustomCommandId(id))
278 return 0; 294 return 0;
279 295
280 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) 296 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // No patterns means no restriction, so that implicitly matches. 332 // No patterns means no restriction, so that implicitly matches.
317 if (patterns.is_empty()) 333 if (patterns.is_empty())
318 return true; 334 return true;
319 return patterns.MatchesURL(url); 335 return patterns.MatchesURL(url);
320 } 336 }
321 337
322 const GURL& GetDocumentURL(const content::ContextMenuParams& params) { 338 const GURL& GetDocumentURL(const content::ContextMenuParams& params) {
323 return params.frame_url.is_empty() ? params.page_url : params.frame_url; 339 return params.frame_url.is_empty() ? params.page_url : params.frame_url;
324 } 340 }
325 341
326 content::Referrer CreateSaveAsReferrer( 342 content::Referrer CreateReferrer(const GURL& url,
327 const GURL& url, 343 const content::ContextMenuParams& params) {
328 const content::ContextMenuParams& params) {
329 const GURL& referring_url = GetDocumentURL(params); 344 const GURL& referring_url = GetDocumentURL(params);
330 return content::Referrer::SanitizeForRequest( 345 return content::Referrer::SanitizeForRequest(
331 url, 346 url,
332 content::Referrer(referring_url.GetAsReferrer(), params.referrer_policy)); 347 content::Referrer(referring_url.GetAsReferrer(), params.referrer_policy));
333 } 348 }
334 349
335 content::WebContents* GetWebContentsToUse(content::WebContents* web_contents) { 350 content::WebContents* GetWebContentsToUse(content::WebContents* web_contents) {
336 #if defined(ENABLE_EXTENSIONS) 351 #if defined(ENABLE_EXTENSIONS)
337 // If we're viewing in a MimeHandlerViewGuest, use its embedder WebContents. 352 // If we're viewing in a MimeHandlerViewGuest, use its embedder WebContents.
338 if (extensions::MimeHandlerViewGuest::FromWebContents(web_contents)) { 353 if (extensions::MimeHandlerViewGuest::FromWebContents(web_contents)) {
(...skipping 23 matching lines...) Expand all
362 scw.WriteURL(text); 377 scw.WriteURL(text);
363 } 378 }
364 379
365 void WriteTextToClipboard(const base::string16& text) { 380 void WriteTextToClipboard(const base::string16& text) {
366 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); 381 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
367 scw.WriteText(text); 382 scw.WriteText(text);
368 } 383 }
369 384
370 bool g_custom_id_ranges_initialized = false; 385 bool g_custom_id_ranges_initialized = false;
371 386
387 void AddIconToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) {
388 int width = icon.Width();
389 int height = icon.Height();
390 gfx::CalculateFaviconTargetSize(&width, &height);
391 menu->SetIcon(menu->GetItemCount() - 1,
392 profiles::GetSizedAvatarIcon(icon, true, width, height));
393 }
394
395 void OnProfileCreated(chrome::HostDesktopType desktop_type,
396 const GURL& link_url,
397 const content::Referrer& referrer,
398 Profile* profile,
399 Profile::CreateStatus status) {
400 if (status == Profile::CREATE_STATUS_INITIALIZED) {
401 Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type);
402 chrome::NavigateParams nav_params(browser, link_url,
403 ui::PAGE_TRANSITION_LINK);
404 nav_params.disposition = NEW_FOREGROUND_TAB;
405 nav_params.referrer = referrer;
406 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
407 chrome::Navigate(&nav_params);
408 }
409 }
410
372 } // namespace 411 } // namespace
373 412
374 // static 413 // static
375 gfx::Vector2d RenderViewContextMenu::GetOffset( 414 gfx::Vector2d RenderViewContextMenu::GetOffset(
376 RenderFrameHost* render_frame_host) { 415 RenderFrameHost* render_frame_host) {
377 gfx::Vector2d offset; 416 gfx::Vector2d offset;
378 #if defined(ENABLE_EXTENSIONS) 417 #if defined(ENABLE_EXTENSIONS)
379 WebContents* web_contents = 418 WebContents* web_contents =
380 WebContents::FromRenderFrameHost(render_frame_host); 419 WebContents::FromRenderFrameHost(render_frame_host);
381 WebContents* top_level_web_contents = 420 WebContents* top_level_web_contents =
(...skipping 21 matching lines...) Expand all
403 } 442 }
404 443
405 RenderViewContextMenu::RenderViewContextMenu( 444 RenderViewContextMenu::RenderViewContextMenu(
406 content::RenderFrameHost* render_frame_host, 445 content::RenderFrameHost* render_frame_host,
407 const content::ContextMenuParams& params) 446 const content::ContextMenuParams& params)
408 : RenderViewContextMenuBase(render_frame_host, params), 447 : RenderViewContextMenuBase(render_frame_host, params),
409 extension_items_(browser_context_, 448 extension_items_(browser_context_,
410 this, 449 this,
411 &menu_model_, 450 &menu_model_,
412 base::Bind(MenuItemMatchesParams, params_)), 451 base::Bind(MenuItemMatchesParams, params_)),
452 profile_link_submenu_model_(this),
413 protocol_handler_submenu_model_(this), 453 protocol_handler_submenu_model_(this),
414 protocol_handler_registry_( 454 protocol_handler_registry_(
415 ProtocolHandlerRegistryFactory::GetForBrowserContext(GetProfile())), 455 ProtocolHandlerRegistryFactory::GetForBrowserContext(GetProfile())),
416 embedder_web_contents_(GetWebContentsToUse(source_web_contents_)) { 456 embedder_web_contents_(GetWebContentsToUse(source_web_contents_)) {
417 if (!g_custom_id_ranges_initialized) { 457 if (!g_custom_id_ranges_initialized) {
418 g_custom_id_ranges_initialized = true; 458 g_custom_id_ranges_initialized = true;
419 SetContentCustomCommandIdRange(IDC_CONTENT_CONTEXT_CUSTOM_FIRST, 459 SetContentCustomCommandIdRange(IDC_CONTENT_CONTEXT_CUSTOM_FIRST,
420 IDC_CONTENT_CONTEXT_CUSTOM_LAST); 460 IDC_CONTENT_CONTEXT_CUSTOM_LAST);
421 } 461 }
422 set_content_type(ContextMenuContentTypeFactory::Create( 462 set_content_type(ContextMenuContentTypeFactory::Create(
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 845 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB,
806 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); 846 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB);
807 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW, 847 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW,
808 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); 848 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW);
809 if (params_.link_url.is_valid()) { 849 if (params_.link_url.is_valid()) {
810 AppendProtocolHandlerSubMenu(); 850 AppendProtocolHandlerSubMenu();
811 } 851 }
812 852
813 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD, 853 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD,
814 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); 854 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
855
856 // g_browser_process->profile_manager() is null during unit tests.
857 if (g_browser_process->profile_manager() &&
858 GetProfile()->GetProfileType() == Profile::REGULAR_PROFILE) {
859 ProfileManager* profile_manager = g_browser_process->profile_manager();
860 const ProfileInfoCache& profile_info_cache =
861 profile_manager->GetProfileInfoCache();
862
863 // Find all regular profiles other than the current one which have at
864 // least one open window.
865 std::vector<size_t> target_profiles;
866 const size_t profile_count = profile_info_cache.GetNumberOfProfiles();
867 for (size_t profile_index = 0; profile_index < profile_count;
868 ++profile_index) {
869 base::FilePath profile_path =
870 profile_info_cache.GetPathOfProfileAtIndex(profile_index);
871 #if defined(OS_CHROMEOS)
872 if (profile_path == chromeos::ProfileHelper::GetSigninProfileDir())
873 continue;
874 #endif
875 Profile* profile = profile_manager->GetProfileByPath(profile_path);
876 if ((profile != GetProfile()) &&
877 !profile_info_cache.IsOmittedProfileAtIndex(profile_index)) {
878 target_profiles.push_back(profile_index);
879 }
880 }
881
882 if (target_profiles.size() == 1) {
883 size_t profile_index = target_profiles[0];
884 menu_model_.AddItem(
885 IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
886 l10n_util::GetStringFUTF16(
887 IDS_CONTENT_CONTEXT_OPENLINKINPROFILE,
888 profile_info_cache.GetNameOfProfileAtIndex(profile_index)));
889 AddIconToLastMenuItem(
890 profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index),
891 &menu_model_);
892 } else if (target_profiles.size() > 1) {
893 for (size_t profile_index : target_profiles) {
894 // In extreme cases, we might have more profiles than available
895 // command ids. In that case, just stop creating new entries - the
896 // menu is probably useless at this point already.
897 if (IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index >
898 IDC_OPEN_LINK_IN_PROFILE_LAST)
899 break;
900 profile_link_submenu_model_.AddItem(
901 IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
902 profile_info_cache.GetNameOfProfileAtIndex(profile_index));
903 AddIconToLastMenuItem(
904 profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index),
905 &profile_link_submenu_model_);
906 }
907 menu_model_.AddSubMenuWithStringId(
908 IDC_CONTENT_CONTEXT_OPENLINKINPROFILE,
909 IDS_CONTENT_CONTEXT_OPENLINKINPROFILES,
910 &profile_link_submenu_model_);
911 }
912 }
913 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
815 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS, 914 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS,
816 IDS_CONTENT_CONTEXT_SAVELINKAS); 915 IDS_CONTENT_CONTEXT_SAVELINKAS);
817 } 916 }
818 917
819 menu_model_.AddItemWithStringId( 918 menu_model_.AddItemWithStringId(
820 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, 919 IDC_CONTENT_CONTEXT_COPYLINKLOCATION,
821 params_.link_url.SchemeIs(url::kMailToScheme) ? 920 params_.link_url.SchemeIs(url::kMailToScheme) ?
822 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : 921 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS :
823 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); 922 IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
824 923
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1239
1141 // Extension items. 1240 // Extension items.
1142 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) 1241 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id))
1143 return extension_items_.IsCommandIdEnabled(id); 1242 return extension_items_.IsCommandIdEnabled(id);
1144 1243
1145 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 1244 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
1146 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 1245 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
1147 return true; 1246 return true;
1148 } 1247 }
1149 1248
1249 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
1250 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
1251 return params_.link_url.is_valid();
1252 }
1253
1150 IncognitoModePrefs::Availability incognito_avail = 1254 IncognitoModePrefs::Availability incognito_avail =
1151 IncognitoModePrefs::GetAvailability(prefs); 1255 IncognitoModePrefs::GetAvailability(prefs);
1152 switch (id) { 1256 switch (id) {
1153 case IDC_BACK: 1257 case IDC_BACK:
1154 return embedder_web_contents_->GetController().CanGoBack(); 1258 return embedder_web_contents_->GetController().CanGoBack();
1155 1259
1156 case IDC_FORWARD: 1260 case IDC_FORWARD:
1157 return embedder_web_contents_->GetController().CanGoForward(); 1261 return embedder_web_contents_->GetController().CanGoForward();
1158 1262
1159 case IDC_RELOAD: { 1263 case IDC_RELOAD: {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 // There are some application locales which can't be used as a 1320 // There are some application locales which can't be used as a
1217 // target language for translation. 1321 // target language for translation.
1218 translate::TranslateDownloadManager::IsSupportedLanguage( 1322 translate::TranslateDownloadManager::IsSupportedLanguage(
1219 target_lang) && 1323 target_lang) &&
1220 // Disable on the Instant Extended NTP. 1324 // Disable on the Instant Extended NTP.
1221 !search::IsInstantNTP(embedder_web_contents_); 1325 !search::IsInstantNTP(embedder_web_contents_);
1222 } 1326 }
1223 1327
1224 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1328 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1225 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1329 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1330 case IDC_CONTENT_CONTEXT_OPENLINKINPROFILE:
1226 return params_.link_url.is_valid(); 1331 return params_.link_url.is_valid();
1227 1332
1228 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1333 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1229 return params_.unfiltered_link_url.is_valid(); 1334 return params_.unfiltered_link_url.is_valid();
1230 1335
1231 case IDC_CONTENT_CONTEXT_COPYLINKTEXT: 1336 case IDC_CONTENT_CONTEXT_COPYLINKTEXT:
1232 return true; 1337 return true;
1233 1338
1234 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1339 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1235 PrefService* local_state = g_browser_process->local_state(); 1340 PrefService* local_state = g_browser_process->local_state();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; 1592 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
1488 WindowOpenDisposition disposition = 1593 WindowOpenDisposition disposition =
1489 ForceNewTabDispositionFromEventFlags(event_flags); 1594 ForceNewTabDispositionFromEventFlags(event_flags);
1490 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url), 1595 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url),
1491 GetDocumentURL(params_), 1596 GetDocumentURL(params_),
1492 disposition, 1597 disposition,
1493 ui::PAGE_TRANSITION_LINK); 1598 ui::PAGE_TRANSITION_LINK);
1494 return; 1599 return;
1495 } 1600 }
1496 1601
1602 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
1603 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
1604 ProfileManager* profile_manager = g_browser_process->profile_manager();
1605 const ProfileInfoCache& profile_info_cache =
1606 profile_manager->GetProfileInfoCache();
1607
1608 base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex(
1609 id - IDC_OPEN_LINK_IN_PROFILE_FIRST);
1610 chrome::HostDesktopType desktop_type =
1611 chrome::GetHostDesktopTypeForNativeView(
1612 source_web_contents_->GetNativeView());
1613
1614 profiles::SwitchToProfile(
1615 profile_path, desktop_type, false,
1616 base::Bind(OnProfileCreated, desktop_type, params_.link_url,
1617 CreateReferrer(params_.link_url, params_)),
1618 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU);
1619 return;
1620 }
1621
1497 switch (id) { 1622 switch (id) {
1498 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { 1623 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: {
1499 Browser* browser = 1624 Browser* browser =
1500 chrome::FindBrowserWithWebContents(source_web_contents_); 1625 chrome::FindBrowserWithWebContents(source_web_contents_);
1501 OpenURL(params_.link_url, 1626 OpenURL(params_.link_url,
1502 GetDocumentURL(params_), 1627 GetDocumentURL(params_),
1503 !browser || browser->is_app() ? 1628 !browser || browser->is_app() ?
1504 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, 1629 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB,
1505 ui::PAGE_TRANSITION_LINK); 1630 ui::PAGE_TRANSITION_LINK);
1506 break; 1631 break;
1507 } 1632 }
1508 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1633 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1509 OpenURL(params_.link_url, 1634 OpenURL(params_.link_url,
1510 GetDocumentURL(params_), 1635 GetDocumentURL(params_),
1511 NEW_WINDOW, 1636 NEW_WINDOW,
1512 ui::PAGE_TRANSITION_LINK); 1637 ui::PAGE_TRANSITION_LINK);
1513 break; 1638 break;
1514 1639
1515 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: 1640 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
1516 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, 1641 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD,
1517 ui::PAGE_TRANSITION_LINK); 1642 ui::PAGE_TRANSITION_LINK);
1518 break; 1643 break;
1519 1644
1520 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1645 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1521 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1646 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1522 const GURL& url = params_.link_url; 1647 const GURL& url = params_.link_url;
1523 content::Referrer referrer = CreateSaveAsReferrer(url, params_); 1648 content::Referrer referrer = CreateReferrer(url, params_);
1524 DownloadManager* dlm = 1649 DownloadManager* dlm =
1525 BrowserContext::GetDownloadManager(browser_context_); 1650 BrowserContext::GetDownloadManager(browser_context_);
1526 scoped_ptr<DownloadUrlParameters> dl_params( 1651 scoped_ptr<DownloadUrlParameters> dl_params(
1527 DownloadUrlParameters::FromWebContents(source_web_contents_, url)); 1652 DownloadUrlParameters::FromWebContents(source_web_contents_, url));
1528 dl_params->set_referrer(referrer); 1653 dl_params->set_referrer(referrer);
1529 dl_params->set_referrer_encoding(params_.frame_charset); 1654 dl_params->set_referrer_encoding(params_.frame_charset);
1530 dl_params->set_suggested_name(params_.suggested_filename); 1655 dl_params->set_suggested_name(params_.suggested_filename);
1531 dl_params->set_prompt(true); 1656 dl_params->set_prompt(true);
1532 dlm->DownloadUrl(dl_params.Pass()); 1657 dlm->DownloadUrl(dl_params.Pass());
1533 break; 1658 break;
1534 } 1659 }
1535 1660
1536 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1661 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1537 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1662 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1538 bool is_large_data_url = params_.has_image_contents && 1663 bool is_large_data_url = params_.has_image_contents &&
1539 params_.src_url.is_empty(); 1664 params_.src_url.is_empty();
1540 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || 1665 if (params_.media_type == WebContextMenuData::MediaTypeCanvas ||
1541 (params_.media_type == WebContextMenuData::MediaTypeImage && 1666 (params_.media_type == WebContextMenuData::MediaTypeImage &&
1542 is_large_data_url)) { 1667 is_large_data_url)) {
1543 source_web_contents_->GetRenderViewHost()->SaveImageAt( 1668 source_web_contents_->GetRenderViewHost()->SaveImageAt(
1544 params_.x, params_.y); 1669 params_.x, params_.y);
1545 } else { 1670 } else {
1546 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1671 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1547 const GURL& url = params_.src_url; 1672 const GURL& url = params_.src_url;
1548 content::Referrer referrer = CreateSaveAsReferrer(url, params_); 1673 content::Referrer referrer = CreateReferrer(url, params_);
1549 1674
1550 std::string headers; 1675 std::string headers;
1551 DataReductionProxyChromeSettings* settings = 1676 DataReductionProxyChromeSettings* settings =
1552 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 1677 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
1553 browser_context_); 1678 browser_context_);
1554 if (params_.media_type == WebContextMenuData::MediaTypeImage && 1679 if (params_.media_type == WebContextMenuData::MediaTypeImage &&
1555 settings && settings->CanUseDataReductionProxy(params_.src_url)) { 1680 settings && settings->CanUseDataReductionProxy(params_.src_url)) {
1556 headers = data_reduction_proxy::kDataReductionPassThroughHeader; 1681 headers = data_reduction_proxy::kDataReductionPassThroughHeader;
1557 } 1682 }
1558 1683
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 source_web_contents_->GetRenderViewHost()-> 2122 source_web_contents_->GetRenderViewHost()->
1998 ExecuteMediaPlayerActionAtLocation(location, action); 2123 ExecuteMediaPlayerActionAtLocation(location, action);
1999 } 2124 }
2000 2125
2001 void RenderViewContextMenu::PluginActionAt( 2126 void RenderViewContextMenu::PluginActionAt(
2002 const gfx::Point& location, 2127 const gfx::Point& location,
2003 const WebPluginAction& action) { 2128 const WebPluginAction& action) {
2004 source_web_contents_->GetRenderViewHost()-> 2129 source_web_contents_->GetRenderViewHost()->
2005 ExecutePluginActionAtLocation(location, action); 2130 ExecutePluginActionAtLocation(location, action);
2006 } 2131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698