Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 std::vector<size_t> all_target_profiles; | |
| 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 all_target_profiles.push_back(profile_index); | |
| 866 if (chrome::FindLastActiveWithProfile(profile, desktop_type)) | |
| 867 target_profiles.push_back(profile_index); | |
| 868 } | |
| 869 } | |
| 870 | |
| 871 if (target_profiles.size() == 1 || | |
| 872 (target_profiles.size() == 2 && all_target_profiles.size() == 2)) { | |
|
Peter Kasting
2015/10/13 18:59:00
This doesn't seem to match the slides. Unless I'm
jochen (gone - plz use gerrit)
2015/10/13 19:07:30
that's step 2 b i) in the slides
Peter Kasting
2015/10/13 19:16:38
No, it's not 2bi. 2bi is the second bullet I wrot
| |
| 873 for (size_t profile_index : target_profiles) { | |
|
Peter Kasting
2015/10/13 18:59:00
In extreme edge cases, this might add more profile
jochen (gone - plz use gerrit)
2015/10/13 19:50:22
added a bail-out
| |
| 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 } | |
| 883 } else if (!target_profiles.empty()) { | |
| 884 for (size_t profile_index : all_target_profiles) { | |
|
Peter Kasting
2015/10/13 18:59:00
I don't think we should do what this implements.
jochen (gone - plz use gerrit)
2015/10/13 19:07:30
Alex' argument is that this matches what the user
| |
| 885 profile_link_submenu_model_.AddItem( | |
| 886 IDC_OPEN_LINK_IN_PROFILE_FIRST + profile_index, | |
| 887 profile_info_cache.GetNameOfProfileAtIndex(profile_index)); | |
| 888 AddIconToLastMenuItem( | |
| 889 profile_info_cache.GetAvatarIconOfProfileAtIndex(profile_index), | |
| 890 &profile_link_submenu_model_); | |
| 891 } | |
| 892 menu_model_.AddSubMenuWithStringId( | |
| 893 IDC_CONTENT_CONTEXT_OPENLINKINPROFILE, | |
| 894 IDS_CONTENT_CONTEXT_OPENLINKINPROFILES, | |
| 895 &profile_link_submenu_model_); | |
| 896 } | |
| 897 } | |
| 898 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 806 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS, | 899 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVELINKAS, |
| 807 IDS_CONTENT_CONTEXT_SAVELINKAS); | 900 IDS_CONTENT_CONTEXT_SAVELINKAS); |
| 808 } | 901 } |
| 809 | 902 |
| 810 menu_model_.AddItemWithStringId( | 903 menu_model_.AddItemWithStringId( |
| 811 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, | 904 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, |
| 812 params_.link_url.SchemeIs(url::kMailToScheme) ? | 905 params_.link_url.SchemeIs(url::kMailToScheme) ? |
| 813 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : | 906 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : |
| 814 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); | 907 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); |
| 815 } | 908 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1124 | 1217 |
| 1125 // Extension items. | 1218 // Extension items. |
| 1126 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) | 1219 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) |
| 1127 return extension_items_.IsCommandIdEnabled(id); | 1220 return extension_items_.IsCommandIdEnabled(id); |
| 1128 | 1221 |
| 1129 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1222 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1130 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1223 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1131 return true; | 1224 return true; |
| 1132 } | 1225 } |
| 1133 | 1226 |
| 1227 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST && | |
| 1228 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) { | |
| 1229 return params_.link_url.is_valid(); | |
| 1230 } | |
| 1231 | |
| 1134 IncognitoModePrefs::Availability incognito_avail = | 1232 IncognitoModePrefs::Availability incognito_avail = |
| 1135 IncognitoModePrefs::GetAvailability(prefs); | 1233 IncognitoModePrefs::GetAvailability(prefs); |
| 1136 switch (id) { | 1234 switch (id) { |
| 1137 case IDC_BACK: | 1235 case IDC_BACK: |
| 1138 return embedder_web_contents_->GetController().CanGoBack(); | 1236 return embedder_web_contents_->GetController().CanGoBack(); |
| 1139 | 1237 |
| 1140 case IDC_FORWARD: | 1238 case IDC_FORWARD: |
| 1141 return embedder_web_contents_->GetController().CanGoForward(); | 1239 return embedder_web_contents_->GetController().CanGoForward(); |
| 1142 | 1240 |
| 1143 case IDC_RELOAD: { | 1241 case IDC_RELOAD: { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 // There are some application locales which can't be used as a | 1294 // There are some application locales which can't be used as a |
| 1197 // target language for translation. | 1295 // target language for translation. |
| 1198 translate::TranslateDownloadManager::IsSupportedLanguage( | 1296 translate::TranslateDownloadManager::IsSupportedLanguage( |
| 1199 target_lang) && | 1297 target_lang) && |
| 1200 // Disable on the Instant Extended NTP. | 1298 // Disable on the Instant Extended NTP. |
| 1201 !search::IsInstantNTP(embedder_web_contents_); | 1299 !search::IsInstantNTP(embedder_web_contents_); |
| 1202 } | 1300 } |
| 1203 | 1301 |
| 1204 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: | 1302 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: |
| 1205 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: | 1303 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: |
| 1304 case IDC_CONTENT_CONTEXT_OPENLINKINPROFILE: | |
| 1206 return params_.link_url.is_valid(); | 1305 return params_.link_url.is_valid(); |
| 1207 | 1306 |
| 1208 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: | 1307 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: |
| 1209 return params_.unfiltered_link_url.is_valid(); | 1308 return params_.unfiltered_link_url.is_valid(); |
| 1210 | 1309 |
| 1211 case IDC_CONTENT_CONTEXT_SAVELINKAS: { | 1310 case IDC_CONTENT_CONTEXT_SAVELINKAS: { |
| 1212 PrefService* local_state = g_browser_process->local_state(); | 1311 PrefService* local_state = g_browser_process->local_state(); |
| 1213 DCHECK(local_state); | 1312 DCHECK(local_state); |
| 1214 // Test if file-selection dialogs are forbidden by policy. | 1313 // Test if file-selection dialogs are forbidden by policy. |
| 1215 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 1314 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 1569 int handlerIndex = id - IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| 1471 WindowOpenDisposition disposition = | 1570 WindowOpenDisposition disposition = |
| 1472 ForceNewTabDispositionFromEventFlags(event_flags); | 1571 ForceNewTabDispositionFromEventFlags(event_flags); |
| 1473 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url), | 1572 OpenURL(handlers[handlerIndex].TranslateUrl(params_.link_url), |
| 1474 GetDocumentURL(params_), | 1573 GetDocumentURL(params_), |
| 1475 disposition, | 1574 disposition, |
| 1476 ui::PAGE_TRANSITION_LINK); | 1575 ui::PAGE_TRANSITION_LINK); |
| 1477 return; | 1576 return; |
| 1478 } | 1577 } |
| 1479 | 1578 |
| 1579 if (id >= IDC_OPEN_LINK_IN_PROFILE_FIRST && | |
| 1580 id <= IDC_OPEN_LINK_IN_PROFILE_LAST) { | |
| 1581 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 1582 const ProfileInfoCache& profile_info_cache = | |
| 1583 profile_manager->GetProfileInfoCache(); | |
| 1584 | |
| 1585 base::FilePath profile_path = profile_info_cache.GetPathOfProfileAtIndex( | |
| 1586 id - IDC_OPEN_LINK_IN_PROFILE_FIRST); | |
| 1587 chrome::HostDesktopType desktop_type = | |
| 1588 chrome::GetHostDesktopTypeForNativeView( | |
| 1589 source_web_contents_->GetNativeView()); | |
| 1590 | |
| 1591 profiles::SwitchToProfile( | |
| 1592 profile_path, desktop_type, false /* always_create */, | |
|
Peter Kasting
2015/10/13 18:59:00
Nit: Omit the param comment here; it actually misl
jochen (gone - plz use gerrit)
2015/10/13 19:50:22
done
| |
| 1593 base::Bind(OnProfileCreated, desktop_type, params_.link_url, | |
| 1594 CreateReferrer(params_.link_url, params_)), | |
| 1595 ProfileMetrics::CONTEXT_MENU); | |
| 1596 return; | |
| 1597 } | |
| 1598 | |
| 1480 switch (id) { | 1599 switch (id) { |
| 1481 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { | 1600 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: { |
| 1482 Browser* browser = | 1601 Browser* browser = |
| 1483 chrome::FindBrowserWithWebContents(source_web_contents_); | 1602 chrome::FindBrowserWithWebContents(source_web_contents_); |
| 1484 OpenURL(params_.link_url, | 1603 OpenURL(params_.link_url, |
| 1485 GetDocumentURL(params_), | 1604 GetDocumentURL(params_), |
| 1486 !browser || browser->is_app() ? | 1605 !browser || browser->is_app() ? |
| 1487 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, | 1606 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, |
| 1488 ui::PAGE_TRANSITION_LINK); | 1607 ui::PAGE_TRANSITION_LINK); |
| 1489 break; | 1608 break; |
| 1490 } | 1609 } |
| 1491 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: | 1610 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: |
| 1492 OpenURL(params_.link_url, | 1611 OpenURL(params_.link_url, |
| 1493 GetDocumentURL(params_), | 1612 GetDocumentURL(params_), |
| 1494 NEW_WINDOW, | 1613 NEW_WINDOW, |
| 1495 ui::PAGE_TRANSITION_LINK); | 1614 ui::PAGE_TRANSITION_LINK); |
| 1496 break; | 1615 break; |
| 1497 | 1616 |
| 1498 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: | 1617 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: |
| 1499 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, | 1618 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, |
| 1500 ui::PAGE_TRANSITION_LINK); | 1619 ui::PAGE_TRANSITION_LINK); |
| 1501 break; | 1620 break; |
| 1502 | 1621 |
| 1503 case IDC_CONTENT_CONTEXT_SAVELINKAS: { | 1622 case IDC_CONTENT_CONTEXT_SAVELINKAS: { |
| 1504 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); | 1623 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); |
| 1505 const GURL& url = params_.link_url; | 1624 const GURL& url = params_.link_url; |
| 1506 content::Referrer referrer = CreateSaveAsReferrer(url, params_); | 1625 content::Referrer referrer = CreateReferrer(url, params_); |
| 1507 DownloadManager* dlm = | 1626 DownloadManager* dlm = |
| 1508 BrowserContext::GetDownloadManager(browser_context_); | 1627 BrowserContext::GetDownloadManager(browser_context_); |
| 1509 scoped_ptr<DownloadUrlParameters> dl_params( | 1628 scoped_ptr<DownloadUrlParameters> dl_params( |
| 1510 DownloadUrlParameters::FromWebContents(source_web_contents_, url)); | 1629 DownloadUrlParameters::FromWebContents(source_web_contents_, url)); |
| 1511 dl_params->set_referrer(referrer); | 1630 dl_params->set_referrer(referrer); |
| 1512 dl_params->set_referrer_encoding(params_.frame_charset); | 1631 dl_params->set_referrer_encoding(params_.frame_charset); |
| 1513 dl_params->set_suggested_name(params_.suggested_filename); | 1632 dl_params->set_suggested_name(params_.suggested_filename); |
| 1514 dl_params->set_prompt(true); | 1633 dl_params->set_prompt(true); |
| 1515 dlm->DownloadUrl(dl_params.Pass()); | 1634 dlm->DownloadUrl(dl_params.Pass()); |
| 1516 break; | 1635 break; |
| 1517 } | 1636 } |
| 1518 | 1637 |
| 1519 case IDC_CONTENT_CONTEXT_SAVEAVAS: | 1638 case IDC_CONTENT_CONTEXT_SAVEAVAS: |
| 1520 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { | 1639 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { |
| 1521 bool is_large_data_url = params_.has_image_contents && | 1640 bool is_large_data_url = params_.has_image_contents && |
| 1522 params_.src_url.is_empty(); | 1641 params_.src_url.is_empty(); |
| 1523 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || | 1642 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || |
| 1524 (params_.media_type == WebContextMenuData::MediaTypeImage && | 1643 (params_.media_type == WebContextMenuData::MediaTypeImage && |
| 1525 is_large_data_url)) { | 1644 is_large_data_url)) { |
| 1526 source_web_contents_->GetRenderViewHost()->SaveImageAt( | 1645 source_web_contents_->GetRenderViewHost()->SaveImageAt( |
| 1527 params_.x, params_.y); | 1646 params_.x, params_.y); |
| 1528 } else { | 1647 } else { |
| 1529 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); | 1648 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); |
| 1530 const GURL& url = params_.src_url; | 1649 const GURL& url = params_.src_url; |
| 1531 content::Referrer referrer = CreateSaveAsReferrer(url, params_); | 1650 content::Referrer referrer = CreateReferrer(url, params_); |
| 1532 | 1651 |
| 1533 std::string headers; | 1652 std::string headers; |
| 1534 DataReductionProxyChromeSettings* settings = | 1653 DataReductionProxyChromeSettings* settings = |
| 1535 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 1654 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 1536 browser_context_); | 1655 browser_context_); |
| 1537 if (params_.media_type == WebContextMenuData::MediaTypeImage && | 1656 if (params_.media_type == WebContextMenuData::MediaTypeImage && |
| 1538 settings && settings->CanUseDataReductionProxy(params_.src_url)) { | 1657 settings && settings->CanUseDataReductionProxy(params_.src_url)) { |
| 1539 headers = data_reduction_proxy::kDataReductionPassThroughHeader; | 1658 headers = data_reduction_proxy::kDataReductionPassThroughHeader; |
| 1540 } | 1659 } |
| 1541 | 1660 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1977 source_web_contents_->GetRenderViewHost()-> | 2096 source_web_contents_->GetRenderViewHost()-> |
| 1978 ExecuteMediaPlayerActionAtLocation(location, action); | 2097 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1979 } | 2098 } |
| 1980 | 2099 |
| 1981 void RenderViewContextMenu::PluginActionAt( | 2100 void RenderViewContextMenu::PluginActionAt( |
| 1982 const gfx::Point& location, | 2101 const gfx::Point& location, |
| 1983 const WebPluginAction& action) { | 2102 const WebPluginAction& action) { |
| 1984 source_web_contents_->GetRenderViewHost()-> | 2103 source_web_contents_->GetRenderViewHost()-> |
| 1985 ExecutePluginActionAtLocation(location, action); | 2104 ExecutePluginActionAtLocation(location, action); |
| 1986 } | 2105 } |
| OLD | NEW |