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

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, 2 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 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 {59, -1, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, 239 {59, -1, IDC_SPELLCHECK_ADD_TO_DICTIONARY},
235 {60, -1, IDC_SPELLPANEL_TOGGLE}, 240 {60, -1, IDC_SPELLPANEL_TOGGLE},
236 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, 241 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB},
237 {62, -1, IDC_WRITING_DIRECTION_MENU}, 242 {62, -1, IDC_WRITING_DIRECTION_MENU},
238 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, 243 {63, -1, IDC_WRITING_DIRECTION_DEFAULT},
239 {64, -1, IDC_WRITING_DIRECTION_LTR}, 244 {64, -1, IDC_WRITING_DIRECTION_LTR},
240 {65, -1, IDC_WRITING_DIRECTION_RTL}, 245 {65, -1, IDC_WRITING_DIRECTION_RTL},
241 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, 246 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE},
242 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, 247 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD},
243 {68, -1, IDC_ROUTE_MEDIA}, 248 {68, -1, IDC_ROUTE_MEDIA},
249 {69, -1, IDC_OPEN_LINK_IN_PROFILE_FIRST},
244 // Add new items here and use |enum_id| from the next line. 250 // Add new items here and use |enum_id| from the next line.
245 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. 251 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
246 {69, -1, 0}, // Must be the last. Increment |enum_id| when new IDC 252 {70, -1, 0}, // Must be the last. Increment |enum_id| when new IDC
247 // was added. 253 // was added.
248 }; 254 };
249 255
250 // Collapses large ranges of ids before looking for UMA enum. 256 // Collapses large ranges of ids before looking for UMA enum.
251 int CollapseCommandsForUMA(int id) { 257 int CollapseCommandsForUMA(int id) {
252 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); 258 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id));
253 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); 259 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id));
254 260
255 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 261 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
256 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 262 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
257 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; 263 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
258 } 264 }
259 265
260 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 266 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
261 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { 267 id <= IDC_SPELLCHECK_LANGUAGES_LAST) {
262 return IDC_SPELLCHECK_LANGUAGES_FIRST; 268 return IDC_SPELLCHECK_LANGUAGES_FIRST;
263 } 269 }
264 270
265 if (id >= IDC_SPELLCHECK_SUGGESTION_0 && 271 if (id >= IDC_SPELLCHECK_SUGGESTION_0 &&
266 id <= IDC_SPELLCHECK_SUGGESTION_LAST) { 272 id <= IDC_SPELLCHECK_SUGGESTION_LAST) {
267 return IDC_SPELLCHECK_SUGGESTION_0; 273 return IDC_SPELLCHECK_SUGGESTION_0;
268 } 274 }
269 275
276 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
277 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
278 return IDC_OPEN_LINK_IN_PROFILE_FIRST;
279 }
280
270 return id; 281 return id;
271 } 282 }
272 283
273 // Returns UMA enum value for command specified by |id| or -1 if not found. 284 // Returns UMA enum value for command specified by |id| or -1 if not found.
274 // |use_specific_context_enum| set to true returns the context_specific_enum_id. 285 // |use_specific_context_enum| set to true returns the context_specific_enum_id.
275 int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType enum_lookup_type) { 286 int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType enum_lookup_type) {
276 if (RenderViewContextMenu::IsContentCustomCommandId(id)) 287 if (RenderViewContextMenu::IsContentCustomCommandId(id))
277 return 0; 288 return 0;
278 289
279 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) 290 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // No patterns means no restriction, so that implicitly matches. 326 // No patterns means no restriction, so that implicitly matches.
316 if (patterns.is_empty()) 327 if (patterns.is_empty())
317 return true; 328 return true;
318 return patterns.MatchesURL(url); 329 return patterns.MatchesURL(url);
319 } 330 }
320 331
321 const GURL& GetDocumentURL(const content::ContextMenuParams& params) { 332 const GURL& GetDocumentURL(const content::ContextMenuParams& params) {
322 return params.frame_url.is_empty() ? params.page_url : params.frame_url; 333 return params.frame_url.is_empty() ? params.page_url : params.frame_url;
323 } 334 }
324 335
325 content::Referrer CreateSaveAsReferrer( 336 content::Referrer CreateReferrer(const GURL& url,
326 const GURL& url, 337 const content::ContextMenuParams& params) {
327 const content::ContextMenuParams& params) {
328 const GURL& referring_url = GetDocumentURL(params); 338 const GURL& referring_url = GetDocumentURL(params);
329 return content::Referrer::SanitizeForRequest( 339 return content::Referrer::SanitizeForRequest(
330 url, 340 url,
331 content::Referrer(referring_url.GetAsReferrer(), params.referrer_policy)); 341 content::Referrer(referring_url.GetAsReferrer(), params.referrer_policy));
332 } 342 }
333 343
334 content::WebContents* GetWebContentsToUse(content::WebContents* web_contents) { 344 content::WebContents* GetWebContentsToUse(content::WebContents* web_contents) {
335 #if defined(ENABLE_EXTENSIONS) 345 #if defined(ENABLE_EXTENSIONS)
336 // If we're viewing in a MimeHandlerViewGuest, use its embedder WebContents. 346 // If we're viewing in a MimeHandlerViewGuest, use its embedder WebContents.
337 if (extensions::MimeHandlerViewGuest::FromWebContents(web_contents)) { 347 if (extensions::MimeHandlerViewGuest::FromWebContents(web_contents)) {
(...skipping 18 matching lines...) Expand all
356 : url_formatter::FormatUrl( 366 : url_formatter::FormatUrl(
357 url, languages, url_formatter::kFormatUrlOmitNothing, 367 url, languages, url_formatter::kFormatUrlOmitNothing,
358 net::UnescapeRule::NONE, nullptr, nullptr, nullptr); 368 net::UnescapeRule::NONE, nullptr, nullptr, nullptr);
359 369
360 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); 370 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
361 scw.WriteURL(text); 371 scw.WriteURL(text);
362 } 372 }
363 373
364 bool g_custom_id_ranges_initialized = false; 374 bool g_custom_id_ranges_initialized = false;
365 375
376 void AddIconToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) {
377 int width = icon.Width();
378 int height = icon.Height();
379 gfx::CalculateFaviconTargetSize(&width, &height);
380 menu->SetIcon(menu->GetItemCount() - 1,
381 profiles::GetSizedAvatarIcon(icon, true, width, height));
382 }
383
384 void OnProfileCreated(chrome::HostDesktopType desktop_type,
385 const GURL& link_url,
386 const content::Referrer& referrer,
387 Profile* profile,
388 Profile::CreateStatus status) {
389 if (status == Profile::CREATE_STATUS_INITIALIZED) {
390 Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type);
391 chrome::NavigateParams nav_params(browser, link_url,
392 ui::PAGE_TRANSITION_LINK);
393 nav_params.disposition = NEW_FOREGROUND_TAB;
394 nav_params.referrer = referrer;
395 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
396 chrome::Navigate(&nav_params);
397 }
398 }
399
366 } // namespace 400 } // namespace
367 401
368 // static 402 // static
369 gfx::Vector2d RenderViewContextMenu::GetOffset( 403 gfx::Vector2d RenderViewContextMenu::GetOffset(
370 RenderFrameHost* render_frame_host) { 404 RenderFrameHost* render_frame_host) {
371 gfx::Vector2d offset; 405 gfx::Vector2d offset;
372 #if defined(ENABLE_EXTENSIONS) 406 #if defined(ENABLE_EXTENSIONS)
373 WebContents* web_contents = 407 WebContents* web_contents =
374 WebContents::FromRenderFrameHost(render_frame_host); 408 WebContents::FromRenderFrameHost(render_frame_host);
375 WebContents* top_level_web_contents = 409 WebContents* top_level_web_contents =
(...skipping 21 matching lines...) Expand all
397 } 431 }
398 432
399 RenderViewContextMenu::RenderViewContextMenu( 433 RenderViewContextMenu::RenderViewContextMenu(
400 content::RenderFrameHost* render_frame_host, 434 content::RenderFrameHost* render_frame_host,
401 const content::ContextMenuParams& params) 435 const content::ContextMenuParams& params)
402 : RenderViewContextMenuBase(render_frame_host, params), 436 : RenderViewContextMenuBase(render_frame_host, params),
403 extension_items_(browser_context_, 437 extension_items_(browser_context_,
404 this, 438 this,
405 &menu_model_, 439 &menu_model_,
406 base::Bind(MenuItemMatchesParams, params_)), 440 base::Bind(MenuItemMatchesParams, params_)),
441 profile_link_submenu_model_(this),
407 protocol_handler_submenu_model_(this), 442 protocol_handler_submenu_model_(this),
408 protocol_handler_registry_( 443 protocol_handler_registry_(
409 ProtocolHandlerRegistryFactory::GetForBrowserContext(GetProfile())), 444 ProtocolHandlerRegistryFactory::GetForBrowserContext(GetProfile())),
410 embedder_web_contents_(GetWebContentsToUse(source_web_contents_)) { 445 embedder_web_contents_(GetWebContentsToUse(source_web_contents_)) {
411 if (!g_custom_id_ranges_initialized) { 446 if (!g_custom_id_ranges_initialized) {
412 g_custom_id_ranges_initialized = true; 447 g_custom_id_ranges_initialized = true;
413 SetContentCustomCommandIdRange(IDC_CONTENT_CONTEXT_CUSTOM_FIRST, 448 SetContentCustomCommandIdRange(IDC_CONTENT_CONTEXT_CUSTOM_FIRST,
414 IDC_CONTENT_CONTEXT_CUSTOM_LAST); 449 IDC_CONTENT_CONTEXT_CUSTOM_LAST);
415 } 450 }
416 set_content_type(ContextMenuContentTypeFactory::Create( 451 set_content_type(ContextMenuContentTypeFactory::Create(
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 831 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB,
797 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); 832 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB);
798 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW, 833 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW,
799 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); 834 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW);
800 if (params_.link_url.is_valid()) { 835 if (params_.link_url.is_valid()) {
801 AppendProtocolHandlerSubMenu(); 836 AppendProtocolHandlerSubMenu();
802 } 837 }
803 838
804 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD, 839 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD,
805 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); 840 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
841
842 // g_browser_process->profile_manager() is null during unit tests.
843 if (g_browser_process->profile_manager() &&
844 GetProfile()->GetProfileType() == Profile::REGULAR_PROFILE) {
845 ProfileManager* profile_manager = g_browser_process->profile_manager();
846 const ProfileInfoCache& profile_info_cache =
847 profile_manager->GetProfileInfoCache();
848
849 // Find all regular profiles other than the current one which have at
850 // least one open window.
851 std::vector<size_t> target_profiles;
852 bool more_than_one_profile_open = false;
853 chrome::HostDesktopType desktop_type =
854 chrome::GetHostDesktopTypeForNativeView(
855 source_web_contents_->GetNativeView());
856
857 const size_t profile_count = profile_info_cache.GetNumberOfProfiles();
858 for (size_t profile_index = 0; profile_index < profile_count;
859 ++profile_index) {
860 base::FilePath profile_path =
861 profile_info_cache.GetPathOfProfileAtIndex(profile_index);
862 Profile* profile = profile_manager->GetProfileByPath(profile_path);
863 if ((profile != GetProfile()) &&
864 !profile_info_cache.IsOmittedProfileAtIndex(profile_index)) {
865 target_profiles.push_back(profile_index);
866 if (chrome::FindLastActiveWithProfile(profile, desktop_type))
867 more_than_one_profile_open = true;
868 }
869 }
870
871 if (more_than_one_profile_open) {
872 if (target_profiles.size() == 1) {
873 size_t profile_index = target_profiles.at(0);
Peter Kasting 2015/10/13 20:23:53 Nit: target_profiles[0] YOu can inline this into
jochen (gone - plz use gerrit) 2015/10/20 14:07:23 done
874 menu_model_.AddItem(
875 IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
876 l10n_util::GetStringFUTF16(
877 IDS_CONTENT_CONTEXT_OPENLINKINPROFILE,
878 profile_info_cache.GetNameOfProfileAtIndex(profile_index)));
879 AddIconToLastMenuItem(
880 profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index),
881 &menu_model_);
882 } else if (!target_profiles.empty()) {
Peter Kasting 2015/10/13 20:23:53 This condition can never fail. The best thing to
jochen (gone - plz use gerrit) 2015/10/20 14:07:23 I replaced it with } else { - even if target_profi
883 for (size_t profile_index : target_profiles) {
884 // In extreme cases, we might have more profiles than available
885 // command ids. In that case, just stop creating new entries - the
886 // menu is probably useless at this point already.
887 if (IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index >
888 IDC_OPEN_LINK_IN_PROFILE_LAST)
889 break;
890 profile_link_submenu_model_.AddItem(
891 IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index,
892 profile_info_cache.GetNameOfProfileAtIndex(profile_index));
893 AddIconToLastMenuItem(
894 profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index),
895 &profile_link_submenu_model_);
896 }
897 menu_model_.AddSubMenuWithStringId(
898 IDC_CONTENT_CONTEXT_OPENLINKINPROFILE,
899 IDS_CONTENT_CONTEXT_OPENLINKINPROFILES,
900 &profile_link_submenu_model_);
901 }
902 }
903 }
904 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
806 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS, 905 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS,
807 IDS_CONTENT_CONTEXT_SAVELINKAS); 906 IDS_CONTENT_CONTEXT_SAVELINKAS);
808 } 907 }
809 908
810 menu_model_.AddItemWithStringId( 909 menu_model_.AddItemWithStringId(
811 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, 910 IDC_CONTENT_CONTEXT_COPYLINKLOCATION,
812 params_.link_url.SchemeIs(url::kMailToScheme) ? 911 params_.link_url.SchemeIs(url::kMailToScheme) ?
813 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : 912 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS :
814 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); 913 IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
815 } 914 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1223
1125 // Extension items. 1224 // Extension items.
1126 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) 1225 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id))
1127 return extension_items_.IsCommandIdEnabled(id); 1226 return extension_items_.IsCommandIdEnabled(id);
1128 1227
1129 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 1228 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
1130 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 1229 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
1131 return true; 1230 return true;
1132 } 1231 }
1133 1232
1233 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
1234 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
1235 return params_.link_url.is_valid();
1236 }
1237
1134 IncognitoModePrefs::Availability incognito_avail = 1238 IncognitoModePrefs::Availability incognito_avail =
1135 IncognitoModePrefs::GetAvailability(prefs); 1239 IncognitoModePrefs::GetAvailability(prefs);
1136 switch (id) { 1240 switch (id) {
1137 case IDC_BACK: 1241 case IDC_BACK:
1138 return embedder_web_contents_->GetController().CanGoBack(); 1242 return embedder_web_contents_->GetController().CanGoBack();
1139 1243
1140 case IDC_FORWARD: 1244 case IDC_FORWARD:
1141 return embedder_web_contents_->GetController().CanGoForward(); 1245 return embedder_web_contents_->GetController().CanGoForward();
1142 1246
1143 case IDC_RELOAD: { 1247 case IDC_RELOAD: {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 // There are some application locales which can't be used as a 1300 // There are some application locales which can't be used as a
1197 // target language for translation. 1301 // target language for translation.
1198 translate::TranslateDownloadManager::IsSupportedLanguage( 1302 translate::TranslateDownloadManager::IsSupportedLanguage(
1199 target_lang) && 1303 target_lang) &&
1200 // Disable on the Instant Extended NTP. 1304 // Disable on the Instant Extended NTP.
1201 !search::IsInstantNTP(embedder_web_contents_); 1305 !search::IsInstantNTP(embedder_web_contents_);
1202 } 1306 }
1203 1307
1204 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1308 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1205 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1309 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1310 case IDC_CONTENT_CONTEXT_OPENLINKINPROFILE:
1206 return params_.link_url.is_valid(); 1311 return params_.link_url.is_valid();
1207 1312
1208 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1313 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1209 return params_.unfiltered_link_url.is_valid(); 1314 return params_.unfiltered_link_url.is_valid();
1210 1315
1211 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1316 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1212 PrefService* local_state = g_browser_process->local_state(); 1317 PrefService* local_state = g_browser_process->local_state();
1213 DCHECK(local_state); 1318 DCHECK(local_state);
1214 // Test if file-selection dialogs are forbidden by policy. 1319 // Test if file-selection dialogs are forbidden by policy.
1215 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1320 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; 1575 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
1471 WindowOpenDisposition disposition = 1576 WindowOpenDisposition disposition =
1472 ForceNewTabDispositionFromEventFlags(event_flags); 1577 ForceNewTabDispositionFromEventFlags(event_flags);
1473 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url), 1578 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url),
1474 GetDocumentURL(params_), 1579 GetDocumentURL(params_),
1475 disposition, 1580 disposition,
1476 ui::PAGE_TRANSITION_LINK); 1581 ui::PAGE_TRANSITION_LINK);
1477 return; 1582 return;
1478 } 1583 }
1479 1584
1585 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST &&
1586 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) {
1587 ProfileManager* profile_manager = g_browser_process->profile_manager();
1588 const ProfileInfoCache& profile_info_cache =
1589 profile_manager->GetProfileInfoCache();
1590
1591 base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex(
1592 id - IDC_OPEN_LINK_IN_PROFILE_FIRST);
1593 chrome::HostDesktopType desktop_type =
1594 chrome::GetHostDesktopTypeForNativeView(
1595 source_web_contents_->GetNativeView());
1596
1597 profiles::SwitchToProfile(
1598 profile_path, desktop_type, false,
1599 base::Bind(OnProfileCreated, desktop_type, params_.link_url,
1600 CreateReferrer(params_.link_url, params_)),
1601 ProfileMetrics::SWITCH_PROFILE_CONTEXT_MENU);
1602 return;
1603 }
1604
1480 switch (id) { 1605 switch (id) {
1481 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { 1606 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: {
1482 Browser* browser = 1607 Browser* browser =
1483 chrome::FindBrowserWithWebContents(source_web_contents_); 1608 chrome::FindBrowserWithWebContents(source_web_contents_);
1484 OpenURL(params_.link_url, 1609 OpenURL(params_.link_url,
1485 GetDocumentURL(params_), 1610 GetDocumentURL(params_),
1486 !browser || browser->is_app() ? 1611 !browser || browser->is_app() ?
1487 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, 1612 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB,
1488 ui::PAGE_TRANSITION_LINK); 1613 ui::PAGE_TRANSITION_LINK);
1489 break; 1614 break;
1490 } 1615 }
1491 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1616 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1492 OpenURL(params_.link_url, 1617 OpenURL(params_.link_url,
1493 GetDocumentURL(params_), 1618 GetDocumentURL(params_),
1494 NEW_WINDOW, 1619 NEW_WINDOW,
1495 ui::PAGE_TRANSITION_LINK); 1620 ui::PAGE_TRANSITION_LINK);
1496 break; 1621 break;
1497 1622
1498 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: 1623 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
1499 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, 1624 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD,
1500 ui::PAGE_TRANSITION_LINK); 1625 ui::PAGE_TRANSITION_LINK);
1501 break; 1626 break;
1502 1627
1503 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1628 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1504 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1629 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1505 const GURL& url = params_.link_url; 1630 const GURL& url = params_.link_url;
1506 content::Referrer referrer = CreateSaveAsReferrer(url, params_); 1631 content::Referrer referrer = CreateReferrer(url, params_);
1507 DownloadManager* dlm = 1632 DownloadManager* dlm =
1508 BrowserContext::GetDownloadManager(browser_context_); 1633 BrowserContext::GetDownloadManager(browser_context_);
1509 scoped_ptr<DownloadUrlParameters> dl_params( 1634 scoped_ptr<DownloadUrlParameters> dl_params(
1510 DownloadUrlParameters::FromWebContents(source_web_contents_, url)); 1635 DownloadUrlParameters::FromWebContents(source_web_contents_, url));
1511 dl_params->set_referrer(referrer); 1636 dl_params->set_referrer(referrer);
1512 dl_params->set_referrer_encoding(params_.frame_charset); 1637 dl_params->set_referrer_encoding(params_.frame_charset);
1513 dl_params->set_suggested_name(params_.suggested_filename); 1638 dl_params->set_suggested_name(params_.suggested_filename);
1514 dl_params->set_prompt(true); 1639 dl_params->set_prompt(true);
1515 dlm->DownloadUrl(dl_params.Pass()); 1640 dlm->DownloadUrl(dl_params.Pass());
1516 break; 1641 break;
1517 } 1642 }
1518 1643
1519 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1644 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1520 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1645 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1521 bool is_large_data_url = params_.has_image_contents && 1646 bool is_large_data_url = params_.has_image_contents &&
1522 params_.src_url.is_empty(); 1647 params_.src_url.is_empty();
1523 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || 1648 if (params_.media_type == WebContextMenuData::MediaTypeCanvas ||
1524 (params_.media_type == WebContextMenuData::MediaTypeImage && 1649 (params_.media_type == WebContextMenuData::MediaTypeImage &&
1525 is_large_data_url)) { 1650 is_large_data_url)) {
1526 source_web_contents_->GetRenderViewHost()->SaveImageAt( 1651 source_web_contents_->GetRenderViewHost()->SaveImageAt(
1527 params_.x, params_.y); 1652 params_.x, params_.y);
1528 } else { 1653 } else {
1529 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1654 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
1530 const GURL& url = params_.src_url; 1655 const GURL& url = params_.src_url;
1531 content::Referrer referrer = CreateSaveAsReferrer(url, params_); 1656 content::Referrer referrer = CreateReferrer(url, params_);
1532 1657
1533 std::string headers; 1658 std::string headers;
1534 DataReductionProxyChromeSettings* settings = 1659 DataReductionProxyChromeSettings* settings =
1535 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 1660 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
1536 browser_context_); 1661 browser_context_);
1537 if (params_.media_type == WebContextMenuData::MediaTypeImage && 1662 if (params_.media_type == WebContextMenuData::MediaTypeImage &&
1538 settings && settings->CanUseDataReductionProxy(params_.src_url)) { 1663 settings && settings->CanUseDataReductionProxy(params_.src_url)) {
1539 headers = data_reduction_proxy::kDataReductionPassThroughHeader; 1664 headers = data_reduction_proxy::kDataReductionPassThroughHeader;
1540 } 1665 }
1541 1666
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 source_web_contents_->GetRenderViewHost()-> 2102 source_web_contents_->GetRenderViewHost()->
1978 ExecuteMediaPlayerActionAtLocation(location, action); 2103 ExecuteMediaPlayerActionAtLocation(location, action);
1979 } 2104 }
1980 2105
1981 void RenderViewContextMenu::PluginActionAt( 2106 void RenderViewContextMenu::PluginActionAt(
1982 const gfx::Point& location, 2107 const gfx::Point& location,
1983 const WebPluginAction& action) { 2108 const WebPluginAction& action) {
1984 source_web_contents_->GetRenderViewHost()-> 2109 source_web_contents_->GetRenderViewHost()->
1985 ExecutePluginActionAtLocation(location, action); 2110 ExecutePluginActionAtLocation(location, action);
1986 } 2111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698