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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 931073002: Fix for Incomplete context menu shown in PDF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 10 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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 IDS_CONTENT_CONTEXT_UNMUTE : 755 IDS_CONTENT_CONTEXT_UNMUTE :
756 IDS_CONTENT_CONTEXT_MUTE); 756 IDS_CONTENT_CONTEXT_MUTE);
757 757
758 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_LOOP, 758 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_LOOP,
759 IDS_CONTENT_CONTEXT_LOOP); 759 IDS_CONTENT_CONTEXT_LOOP);
760 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_CONTROLS, 760 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_CONTROLS,
761 IDS_CONTENT_CONTEXT_CONTROLS); 761 IDS_CONTENT_CONTEXT_CONTROLS);
762 } 762 }
763 763
764 void RenderViewContextMenu::AppendPluginItems() { 764 void RenderViewContextMenu::AppendPluginItems() {
765 if (params_.page_url == params_.src_url) { 765 if (params_.page_url == params_.src_url ||
766 extensions::GuestViewBase::IsGuest(source_web_contents_)) {
766 // Full page plugin, so show page menu items. 767 // Full page plugin, so show page menu items.
767 if (params_.link_url.is_empty() && params_.selection_text.empty()) 768 if (params_.link_url.is_empty() && params_.selection_text.empty())
768 AppendPageItems(); 769 AppendPageItems();
769 } else { 770 } else {
770 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, 771 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS,
771 IDS_CONTENT_CONTEXT_SAVEPAGEAS); 772 IDS_CONTENT_CONTEXT_SAVEPAGEAS);
772 // The "Print" menu item should always be included for plugins. If 773 // The "Print" menu item should always be included for plugins. If
773 // content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) 774 // content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)
774 // is true the item will be added inside AppendPrintItem(). Otherwise we 775 // is true the item will be added inside AppendPrintItem(). Otherwise we
775 // add "Print" here. 776 // add "Print" here.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 1005
1005 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 1006 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
1006 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 1007 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
1007 return true; 1008 return true;
1008 } 1009 }
1009 1010
1010 IncognitoModePrefs::Availability incognito_avail = 1011 IncognitoModePrefs::Availability incognito_avail =
1011 IncognitoModePrefs::GetAvailability(prefs); 1012 IncognitoModePrefs::GetAvailability(prefs);
1012 switch (id) { 1013 switch (id) {
1013 case IDC_BACK: 1014 case IDC_BACK:
1014 return source_web_contents_->GetController().CanGoBack(); 1015 return embedded_web_contents_->GetController().CanGoBack();
1015 1016
1016 case IDC_FORWARD: 1017 case IDC_FORWARD:
1017 return source_web_contents_->GetController().CanGoForward(); 1018 return embedded_web_contents_->GetController().CanGoForward();
1018 1019
1019 case IDC_RELOAD: { 1020 case IDC_RELOAD: {
1020 CoreTabHelper* core_tab_helper = 1021 CoreTabHelper* core_tab_helper =
1021 CoreTabHelper::FromWebContents(source_web_contents_); 1022 CoreTabHelper::FromWebContents(embedded_web_contents_);
1022 if (!core_tab_helper) 1023 if (!core_tab_helper)
1023 return false; 1024 return false;
1024 1025
1025 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 1026 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
1026 return !core_delegate || 1027 return !core_delegate ||
1027 core_delegate->CanReloadContents(source_web_contents_); 1028 core_delegate->CanReloadContents(embedded_web_contents_);
1028 } 1029 }
1029 1030
1030 case IDC_VIEW_SOURCE: 1031 case IDC_VIEW_SOURCE:
1031 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1032 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1032 return source_web_contents_->GetController().CanViewSource(); 1033 return embedded_web_contents_->GetController().CanViewSource();
1033 1034
1034 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1035 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1035 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: 1036 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE:
1036 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: 1037 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP:
1037 case IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP: 1038 case IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP:
1038 return IsDevCommandEnabled(id); 1039 return IsDevCommandEnabled(id);
1039 1040
1040 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: 1041 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO:
1041 if (source_web_contents_->GetController().GetVisibleEntry() == NULL) 1042 if (embedded_web_contents_->GetController().GetVisibleEntry() == NULL)
1042 return false; 1043 return false;
1043 // Disabled if no browser is associated (e.g. desktop notifications). 1044 // Disabled if no browser is associated (e.g. desktop notifications).
1044 if (chrome::FindBrowserWithWebContents(source_web_contents_) == NULL) 1045 if (chrome::FindBrowserWithWebContents(embedded_web_contents_) == NULL)
1045 return false; 1046 return false;
1046 return true; 1047 return true;
1047 1048
1048 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1049 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1049 ChromeTranslateClient* chrome_translate_client = 1050 ChromeTranslateClient* chrome_translate_client =
1050 ChromeTranslateClient::FromWebContents(source_web_contents_); 1051 ChromeTranslateClient::FromWebContents(embedded_web_contents_);
1051 if (!chrome_translate_client) 1052 if (!chrome_translate_client)
1052 return false; 1053 return false;
1053 std::string original_lang = 1054 std::string original_lang =
1054 chrome_translate_client->GetLanguageState().original_language(); 1055 chrome_translate_client->GetLanguageState().original_language();
1055 std::string target_lang = g_browser_process->GetApplicationLocale(); 1056 std::string target_lang = g_browser_process->GetApplicationLocale();
1056 target_lang = 1057 target_lang =
1057 translate::TranslateDownloadManager::GetLanguageCode(target_lang); 1058 translate::TranslateDownloadManager::GetLanguageCode(target_lang);
1058 // Note that we intentionally enable the menu even if the original and 1059 // Note that we intentionally enable the menu even if the original and
1059 // target languages are identical. This is to give a way to user to 1060 // target languages are identical. This is to give a way to user to
1060 // translate a page that might contains text fragments in a different 1061 // translate a page that might contains text fragments in a different
1061 // language. 1062 // language.
1062 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) && 1063 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) &&
1063 !original_lang.empty() && // Did we receive the page language yet? 1064 !original_lang.empty() && // Did we receive the page language yet?
1064 !chrome_translate_client->GetLanguageState().IsPageTranslated() && 1065 !chrome_translate_client->GetLanguageState().IsPageTranslated() &&
1065 !source_web_contents_->GetInterstitialPage() && 1066 !embedded_web_contents_->GetInterstitialPage() &&
1066 // There are some application locales which can't be used as a 1067 // There are some application locales which can't be used as a
1067 // target language for translation. 1068 // target language for translation.
1068 translate::TranslateDownloadManager::IsSupportedLanguage( 1069 translate::TranslateDownloadManager::IsSupportedLanguage(
1069 target_lang) && 1070 target_lang) &&
1070 // Disable on the Instant Extended NTP. 1071 // Disable on the Instant Extended NTP.
1071 !chrome::IsInstantNTP(source_web_contents_); 1072 !chrome::IsInstantNTP(embedded_web_contents_);
1072 } 1073 }
1073 1074
1074 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1075 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1075 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1076 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1076 return params_.link_url.is_valid(); 1077 return params_.link_url.is_valid();
1077 1078
1078 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1079 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1079 return params_.unfiltered_link_url.is_valid(); 1080 return params_.unfiltered_link_url.is_valid();
1080 1081
1081 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1082 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 } 1157 }
1157 1158
1158 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1159 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1159 // Currently, a media element can be opened in a new tab iff it can 1160 // Currently, a media element can be opened in a new tab iff it can
1160 // be saved. So rather than duplicating the MediaCanSave flag, we rely 1161 // be saved. So rather than duplicating the MediaCanSave flag, we rely
1161 // on that here. 1162 // on that here.
1162 return !!(params_.media_flags & WebContextMenuData::MediaCanSave); 1163 return !!(params_.media_flags & WebContextMenuData::MediaCanSave);
1163 1164
1164 case IDC_SAVE_PAGE: { 1165 case IDC_SAVE_PAGE: {
1165 CoreTabHelper* core_tab_helper = 1166 CoreTabHelper* core_tab_helper =
1166 CoreTabHelper::FromWebContents(source_web_contents_); 1167 CoreTabHelper::FromWebContents(embedded_web_contents_);
1167 if (!core_tab_helper) 1168 if (!core_tab_helper)
1168 return false; 1169 return false;
1169 1170
1170 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 1171 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
1171 if (core_delegate && 1172 if (core_delegate &&
1172 !core_delegate->CanSaveContents(source_web_contents_)) 1173 !core_delegate->CanSaveContents(embedded_web_contents_))
1173 return false; 1174 return false;
1174 1175
1175 PrefService* local_state = g_browser_process->local_state(); 1176 PrefService* local_state = g_browser_process->local_state();
1176 DCHECK(local_state); 1177 DCHECK(local_state);
1177 // Test if file-selection dialogs are forbidden by policy. 1178 // Test if file-selection dialogs are forbidden by policy.
1178 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1179 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
1179 return false; 1180 return false;
1180 1181
1181 // We save the last committed entry (which the user is looking at), as 1182 // We save the last committed entry (which the user is looking at), as
1182 // opposed to any pending URL that hasn't committed yet. 1183 // opposed to any pending URL that hasn't committed yet.
1183 NavigationEntry* entry = 1184 NavigationEntry* entry =
1184 source_web_contents_->GetController().GetLastCommittedEntry(); 1185 embedded_web_contents_->GetController().GetLastCommittedEntry();
1185 return content::IsSavableURL(entry ? entry->GetURL() : GURL()); 1186 return content::IsSavableURL(entry ? entry->GetURL() : GURL());
1186 } 1187 }
1187 1188
1188 case IDC_CONTENT_CONTEXT_RELOADFRAME: 1189 case IDC_CONTENT_CONTEXT_RELOADFRAME:
1189 return params_.frame_url.is_valid(); 1190 return params_.frame_url.is_valid();
1190 1191
1191 case IDC_CONTENT_CONTEXT_UNDO: 1192 case IDC_CONTENT_CONTEXT_UNDO:
1192 return !!(params_.edit_flags & WebContextMenuData::CanUndo); 1193 return !!(params_.edit_flags & WebContextMenuData::CanUndo);
1193 1194
1194 case IDC_CONTENT_CONTEXT_REDO: 1195 case IDC_CONTENT_CONTEXT_REDO:
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 1461
1461 case IDC_CONTENT_CONTEXT_ROTATECCW: 1462 case IDC_CONTENT_CONTEXT_ROTATECCW:
1462 content::RecordAction( 1463 content::RecordAction(
1463 UserMetricsAction("PluginContextMenu_RotateCounterclockwise")); 1464 UserMetricsAction("PluginContextMenu_RotateCounterclockwise"));
1464 PluginActionAt( 1465 PluginActionAt(
1465 gfx::Point(params_.x, params_.y), 1466 gfx::Point(params_.x, params_.y),
1466 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, true)); 1467 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, true));
1467 break; 1468 break;
1468 1469
1469 case IDC_BACK: 1470 case IDC_BACK:
1470 source_web_contents_->GetController().GoBack(); 1471 embedded_web_contents_->GetController().GoBack();
1471 break; 1472 break;
1472 1473
1473 case IDC_FORWARD: 1474 case IDC_FORWARD:
1474 source_web_contents_->GetController().GoForward(); 1475 embedded_web_contents_->GetController().GoForward();
1475 break; 1476 break;
1476 1477
1477 case IDC_SAVE_PAGE: 1478 case IDC_SAVE_PAGE:
1478 source_web_contents_->OnSavePage(); 1479 embedded_web_contents_->OnSavePage();
1479 break; 1480 break;
1480 1481
1481 case IDC_RELOAD: 1482 case IDC_RELOAD:
1482 source_web_contents_->GetController().Reload(true); 1483 embedded_web_contents_->GetController().Reload(true);
1483 break; 1484 break;
1484 1485
1485 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: { 1486 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: {
1486 const Extension* platform_app = GetExtension(); 1487 const Extension* platform_app = GetExtension();
1487 DCHECK(platform_app); 1488 DCHECK(platform_app);
1488 DCHECK(platform_app->is_platform_app()); 1489 DCHECK(platform_app->is_platform_app());
1489 1490
1490 extensions::ExtensionSystem::Get(browser_context_) 1491 extensions::ExtensionSystem::Get(browser_context_)
1491 ->extension_service() 1492 ->extension_service()
1492 ->ReloadExtension(platform_app->id()); 1493 ->ReloadExtension(platform_app->id());
(...skipping 22 matching lines...) Expand all
1515 1516
1516 printing::StartPrint( 1517 printing::StartPrint(
1517 source_web_contents_, 1518 source_web_contents_,
1518 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), 1519 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled),
1519 !params_.selection_text.empty()); 1520 !params_.selection_text.empty());
1520 #endif // ENABLE_PRINTING 1521 #endif // ENABLE_PRINTING
1521 break; 1522 break;
1522 } 1523 }
1523 1524
1524 case IDC_VIEW_SOURCE: 1525 case IDC_VIEW_SOURCE:
1525 source_web_contents_->ViewSource(); 1526 embedded_web_contents_->ViewSource();
1526 break; 1527 break;
1527 1528
1528 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1529 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1529 Inspect(params_.x, params_.y); 1530 Inspect(params_.x, params_.y);
1530 break; 1531 break;
1531 1532
1532 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: { 1533 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: {
1533 const Extension* platform_app = GetExtension(); 1534 const Extension* platform_app = GetExtension();
1534 DCHECK(platform_app); 1535 DCHECK(platform_app);
1535 DCHECK(platform_app->is_platform_app()); 1536 DCHECK(platform_app->is_platform_app());
1536 1537
1537 extensions::devtools_util::InspectBackgroundPage(platform_app, 1538 extensions::devtools_util::InspectBackgroundPage(platform_app,
1538 GetProfile()); 1539 GetProfile());
1539 break; 1540 break;
1540 } 1541 }
1541 1542
1542 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: { 1543 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: {
1543 NavigationController* controller = &source_web_contents_->GetController(); 1544 NavigationController* controller =
1545 &embedded_web_contents_->GetController();
1544 // Important to use GetVisibleEntry to match what's showing in the 1546 // Important to use GetVisibleEntry to match what's showing in the
1545 // omnibox. This may return null. 1547 // omnibox. This may return null.
1546 NavigationEntry* nav_entry = controller->GetVisibleEntry(); 1548 NavigationEntry* nav_entry = controller->GetVisibleEntry();
1547 if (!nav_entry) 1549 if (!nav_entry)
1548 return; 1550 return;
1549 Browser* browser = 1551 Browser* browser =
1550 chrome::FindBrowserWithWebContents(source_web_contents_); 1552 chrome::FindBrowserWithWebContents(embedded_web_contents_);
1551 chrome::ShowWebsiteSettings(browser, source_web_contents_, 1553 chrome::ShowWebsiteSettings(browser, embedded_web_contents_,
1552 nav_entry->GetURL(), nav_entry->GetSSL()); 1554 nav_entry->GetURL(), nav_entry->GetSSL());
1553 break; 1555 break;
1554 } 1556 }
1555 1557
1556 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1558 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1557 // A translation might have been triggered by the time the menu got 1559 // A translation might have been triggered by the time the menu got
1558 // selected, do nothing in that case. 1560 // selected, do nothing in that case.
1559 ChromeTranslateClient* chrome_translate_client = 1561 ChromeTranslateClient* chrome_translate_client =
1560 ChromeTranslateClient::FromWebContents(source_web_contents_); 1562 ChromeTranslateClient::FromWebContents(embedded_web_contents_);
1561 if (!chrome_translate_client || 1563 if (!chrome_translate_client ||
1562 chrome_translate_client->GetLanguageState().IsPageTranslated() || 1564 chrome_translate_client->GetLanguageState().IsPageTranslated() ||
1563 chrome_translate_client->GetLanguageState().translation_pending()) { 1565 chrome_translate_client->GetLanguageState().translation_pending()) {
1564 return; 1566 return;
1565 } 1567 }
1566 std::string original_lang = 1568 std::string original_lang =
1567 chrome_translate_client->GetLanguageState().original_language(); 1569 chrome_translate_client->GetLanguageState().original_language();
1568 std::string target_lang = g_browser_process->GetApplicationLocale(); 1570 std::string target_lang = g_browser_process->GetApplicationLocale();
1569 target_lang = 1571 target_lang =
1570 translate::TranslateDownloadManager::GetLanguageCode(target_lang); 1572 translate::TranslateDownloadManager::GetLanguageCode(target_lang);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 source_web_contents_->GetRenderViewHost()-> 1785 source_web_contents_->GetRenderViewHost()->
1784 ExecuteMediaPlayerActionAtLocation(location, action); 1786 ExecuteMediaPlayerActionAtLocation(location, action);
1785 } 1787 }
1786 1788
1787 void RenderViewContextMenu::PluginActionAt( 1789 void RenderViewContextMenu::PluginActionAt(
1788 const gfx::Point& location, 1790 const gfx::Point& location,
1789 const WebPluginAction& action) { 1791 const WebPluginAction& action) {
1790 source_web_contents_->GetRenderViewHost()-> 1792 source_web_contents_->GetRenderViewHost()->
1791 ExecutePluginActionAtLocation(location, action); 1793 ExecutePluginActionAtLocation(location, action);
1792 } 1794 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698