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

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

Issue 941603002: This is followup of 449919 for addressing nit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | components/renderer_context_menu/render_view_context_menu_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 1005
1006 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 1006 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
1007 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 1007 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
1008 return true; 1008 return true;
1009 } 1009 }
1010 1010
1011 IncognitoModePrefs::Availability incognito_avail = 1011 IncognitoModePrefs::Availability incognito_avail =
1012 IncognitoModePrefs::GetAvailability(prefs); 1012 IncognitoModePrefs::GetAvailability(prefs);
1013 switch (id) { 1013 switch (id) {
1014 case IDC_BACK: 1014 case IDC_BACK:
1015 return embedded_web_contents_->GetController().CanGoBack(); 1015 return embedder_web_contents_->GetController().CanGoBack();
1016 1016
1017 case IDC_FORWARD: 1017 case IDC_FORWARD:
1018 return embedded_web_contents_->GetController().CanGoForward(); 1018 return embedder_web_contents_->GetController().CanGoForward();
1019 1019
1020 case IDC_RELOAD: { 1020 case IDC_RELOAD: {
1021 CoreTabHelper* core_tab_helper = 1021 CoreTabHelper* core_tab_helper =
1022 CoreTabHelper::FromWebContents(embedded_web_contents_); 1022 CoreTabHelper::FromWebContents(embedder_web_contents_);
1023 if (!core_tab_helper) 1023 if (!core_tab_helper)
1024 return false; 1024 return false;
1025 1025
1026 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 1026 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
1027 return !core_delegate || 1027 return !core_delegate ||
1028 core_delegate->CanReloadContents(embedded_web_contents_); 1028 core_delegate->CanReloadContents(embedder_web_contents_);
1029 } 1029 }
1030 1030
1031 case IDC_VIEW_SOURCE: 1031 case IDC_VIEW_SOURCE:
1032 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1032 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1033 return embedded_web_contents_->GetController().CanViewSource(); 1033 return embedder_web_contents_->GetController().CanViewSource();
1034 1034
1035 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1035 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1036 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: 1036 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE:
1037 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: 1037 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP:
1038 case IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP: 1038 case IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP:
1039 return IsDevCommandEnabled(id); 1039 return IsDevCommandEnabled(id);
1040 1040
1041 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: 1041 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO:
1042 if (embedded_web_contents_->GetController().GetVisibleEntry() == NULL) 1042 if (embedder_web_contents_->GetController().GetVisibleEntry() == NULL)
1043 return false; 1043 return false;
1044 // Disabled if no browser is associated (e.g. desktop notifications). 1044 // Disabled if no browser is associated (e.g. desktop notifications).
1045 if (chrome::FindBrowserWithWebContents(embedded_web_contents_) == NULL) 1045 if (chrome::FindBrowserWithWebContents(embedder_web_contents_) == NULL)
1046 return false; 1046 return false;
1047 return true; 1047 return true;
1048 1048
1049 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1049 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1050 ChromeTranslateClient* chrome_translate_client = 1050 ChromeTranslateClient* chrome_translate_client =
1051 ChromeTranslateClient::FromWebContents(embedded_web_contents_); 1051 ChromeTranslateClient::FromWebContents(embedder_web_contents_);
1052 if (!chrome_translate_client) 1052 if (!chrome_translate_client)
1053 return false; 1053 return false;
1054 std::string original_lang = 1054 std::string original_lang =
1055 chrome_translate_client->GetLanguageState().original_language(); 1055 chrome_translate_client->GetLanguageState().original_language();
1056 std::string target_lang = g_browser_process->GetApplicationLocale(); 1056 std::string target_lang = g_browser_process->GetApplicationLocale();
1057 target_lang = 1057 target_lang =
1058 translate::TranslateDownloadManager::GetLanguageCode(target_lang); 1058 translate::TranslateDownloadManager::GetLanguageCode(target_lang);
1059 // 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
1060 // 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
1061 // translate a page that might contains text fragments in a different 1061 // translate a page that might contains text fragments in a different
1062 // language. 1062 // language.
1063 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) && 1063 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) &&
1064 !original_lang.empty() && // Did we receive the page language yet? 1064 !original_lang.empty() && // Did we receive the page language yet?
1065 !chrome_translate_client->GetLanguageState().IsPageTranslated() && 1065 !chrome_translate_client->GetLanguageState().IsPageTranslated() &&
1066 !embedded_web_contents_->GetInterstitialPage() && 1066 !embedder_web_contents_->GetInterstitialPage() &&
1067 // 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
1068 // target language for translation. 1068 // target language for translation.
1069 translate::TranslateDownloadManager::IsSupportedLanguage( 1069 translate::TranslateDownloadManager::IsSupportedLanguage(
1070 target_lang) && 1070 target_lang) &&
1071 // Disable on the Instant Extended NTP. 1071 // Disable on the Instant Extended NTP.
1072 !chrome::IsInstantNTP(embedded_web_contents_); 1072 !chrome::IsInstantNTP(embedder_web_contents_);
1073 } 1073 }
1074 1074
1075 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1075 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1076 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1076 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1077 return params_.link_url.is_valid(); 1077 return params_.link_url.is_valid();
1078 1078
1079 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: 1079 case IDC_CONTENT_CONTEXT_COPYLINKLOCATION:
1080 return params_.unfiltered_link_url.is_valid(); 1080 return params_.unfiltered_link_url.is_valid();
1081 1081
1082 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1082 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 } 1157 }
1158 1158
1159 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1159 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1160 // 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
1161 // be saved. So rather than duplicating the MediaCanSave flag, we rely 1161 // be saved. So rather than duplicating the MediaCanSave flag, we rely
1162 // on that here. 1162 // on that here.
1163 return !!(params_.media_flags & WebContextMenuData::MediaCanSave); 1163 return !!(params_.media_flags & WebContextMenuData::MediaCanSave);
1164 1164
1165 case IDC_SAVE_PAGE: { 1165 case IDC_SAVE_PAGE: {
1166 CoreTabHelper* core_tab_helper = 1166 CoreTabHelper* core_tab_helper =
1167 CoreTabHelper::FromWebContents(embedded_web_contents_); 1167 CoreTabHelper::FromWebContents(embedder_web_contents_);
1168 if (!core_tab_helper) 1168 if (!core_tab_helper)
1169 return false; 1169 return false;
1170 1170
1171 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 1171 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
1172 if (core_delegate && 1172 if (core_delegate &&
1173 !core_delegate->CanSaveContents(embedded_web_contents_)) 1173 !core_delegate->CanSaveContents(embedder_web_contents_))
1174 return false; 1174 return false;
1175 1175
1176 PrefService* local_state = g_browser_process->local_state(); 1176 PrefService* local_state = g_browser_process->local_state();
1177 DCHECK(local_state); 1177 DCHECK(local_state);
1178 // Test if file-selection dialogs are forbidden by policy. 1178 // Test if file-selection dialogs are forbidden by policy.
1179 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1179 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
1180 return false; 1180 return false;
1181 1181
1182 // 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
1183 // opposed to any pending URL that hasn't committed yet. 1183 // opposed to any pending URL that hasn't committed yet.
1184 NavigationEntry* entry = 1184 NavigationEntry* entry =
1185 embedded_web_contents_->GetController().GetLastCommittedEntry(); 1185 embedder_web_contents_->GetController().GetLastCommittedEntry();
1186 return content::IsSavableURL(entry ? entry->GetURL() : GURL()); 1186 return content::IsSavableURL(entry ? entry->GetURL() : GURL());
1187 } 1187 }
1188 1188
1189 case IDC_CONTENT_CONTEXT_RELOADFRAME: 1189 case IDC_CONTENT_CONTEXT_RELOADFRAME:
1190 return params_.frame_url.is_valid(); 1190 return params_.frame_url.is_valid();
1191 1191
1192 case IDC_CONTENT_CONTEXT_UNDO: 1192 case IDC_CONTENT_CONTEXT_UNDO:
1193 return !!(params_.edit_flags & WebContextMenuData::CanUndo); 1193 return !!(params_.edit_flags & WebContextMenuData::CanUndo);
1194 1194
1195 case IDC_CONTENT_CONTEXT_REDO: 1195 case IDC_CONTENT_CONTEXT_REDO:
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1461
1462 case IDC_CONTENT_CONTEXT_ROTATECCW: 1462 case IDC_CONTENT_CONTEXT_ROTATECCW:
1463 content::RecordAction( 1463 content::RecordAction(
1464 UserMetricsAction("PluginContextMenu_RotateCounterclockwise")); 1464 UserMetricsAction("PluginContextMenu_RotateCounterclockwise"));
1465 PluginActionAt( 1465 PluginActionAt(
1466 gfx::Point(params_.x, params_.y), 1466 gfx::Point(params_.x, params_.y),
1467 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, true)); 1467 WebPluginAction(WebPluginAction::Rotate90Counterclockwise, true));
1468 break; 1468 break;
1469 1469
1470 case IDC_BACK: 1470 case IDC_BACK:
1471 embedded_web_contents_->GetController().GoBack(); 1471 embedder_web_contents_->GetController().GoBack();
1472 break; 1472 break;
1473 1473
1474 case IDC_FORWARD: 1474 case IDC_FORWARD:
1475 embedded_web_contents_->GetController().GoForward(); 1475 embedder_web_contents_->GetController().GoForward();
1476 break; 1476 break;
1477 1477
1478 case IDC_SAVE_PAGE: 1478 case IDC_SAVE_PAGE:
1479 embedded_web_contents_->OnSavePage(); 1479 embedder_web_contents_->OnSavePage();
1480 break; 1480 break;
1481 1481
1482 case IDC_RELOAD: 1482 case IDC_RELOAD:
1483 embedded_web_contents_->GetController().Reload(true); 1483 embedder_web_contents_->GetController().Reload(true);
1484 break; 1484 break;
1485 1485
1486 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: { 1486 case IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP: {
1487 const Extension* platform_app = GetExtension(); 1487 const Extension* platform_app = GetExtension();
1488 DCHECK(platform_app); 1488 DCHECK(platform_app);
1489 DCHECK(platform_app->is_platform_app()); 1489 DCHECK(platform_app->is_platform_app());
1490 1490
1491 extensions::ExtensionSystem::Get(browser_context_) 1491 extensions::ExtensionSystem::Get(browser_context_)
1492 ->extension_service() 1492 ->extension_service()
1493 ->ReloadExtension(platform_app->id()); 1493 ->ReloadExtension(platform_app->id());
(...skipping 22 matching lines...) Expand all
1516 1516
1517 printing::StartPrint( 1517 printing::StartPrint(
1518 source_web_contents_, 1518 source_web_contents_,
1519 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), 1519 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled),
1520 !params_.selection_text.empty()); 1520 !params_.selection_text.empty());
1521 #endif // ENABLE_PRINTING 1521 #endif // ENABLE_PRINTING
1522 break; 1522 break;
1523 } 1523 }
1524 1524
1525 case IDC_VIEW_SOURCE: 1525 case IDC_VIEW_SOURCE:
1526 embedded_web_contents_->ViewSource(); 1526 embedder_web_contents_->ViewSource();
1527 break; 1527 break;
1528 1528
1529 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1529 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1530 Inspect(params_.x, params_.y); 1530 Inspect(params_.x, params_.y);
1531 break; 1531 break;
1532 1532
1533 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: { 1533 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: {
1534 const Extension* platform_app = GetExtension(); 1534 const Extension* platform_app = GetExtension();
1535 DCHECK(platform_app); 1535 DCHECK(platform_app);
1536 DCHECK(platform_app->is_platform_app()); 1536 DCHECK(platform_app->is_platform_app());
1537 1537
1538 extensions::devtools_util::InspectBackgroundPage(platform_app, 1538 extensions::devtools_util::InspectBackgroundPage(platform_app,
1539 GetProfile()); 1539 GetProfile());
1540 break; 1540 break;
1541 } 1541 }
1542 1542
1543 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: { 1543 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: {
1544 NavigationController* controller = 1544 NavigationController* controller =
1545 &embedded_web_contents_->GetController(); 1545 &embedder_web_contents_->GetController();
1546 // Important to use GetVisibleEntry to match what's showing in the 1546 // Important to use GetVisibleEntry to match what's showing in the
1547 // omnibox. This may return null. 1547 // omnibox. This may return null.
1548 NavigationEntry* nav_entry = controller->GetVisibleEntry(); 1548 NavigationEntry* nav_entry = controller->GetVisibleEntry();
1549 if (!nav_entry) 1549 if (!nav_entry)
1550 return; 1550 return;
1551 Browser* browser = 1551 Browser* browser =
1552 chrome::FindBrowserWithWebContents(embedded_web_contents_); 1552 chrome::FindBrowserWithWebContents(embedder_web_contents_);
1553 chrome::ShowWebsiteSettings(browser, embedded_web_contents_, 1553 chrome::ShowWebsiteSettings(browser, embedder_web_contents_,
1554 nav_entry->GetURL(), nav_entry->GetSSL()); 1554 nav_entry->GetURL(), nav_entry->GetSSL());
1555 break; 1555 break;
1556 } 1556 }
1557 1557
1558 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1558 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1559 // 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
1560 // selected, do nothing in that case. 1560 // selected, do nothing in that case.
1561 ChromeTranslateClient* chrome_translate_client = 1561 ChromeTranslateClient* chrome_translate_client =
1562 ChromeTranslateClient::FromWebContents(embedded_web_contents_); 1562 ChromeTranslateClient::FromWebContents(embedder_web_contents_);
1563 if (!chrome_translate_client || 1563 if (!chrome_translate_client ||
1564 chrome_translate_client->GetLanguageState().IsPageTranslated() || 1564 chrome_translate_client->GetLanguageState().IsPageTranslated() ||
1565 chrome_translate_client->GetLanguageState().translation_pending()) { 1565 chrome_translate_client->GetLanguageState().translation_pending()) {
1566 return; 1566 return;
1567 } 1567 }
1568 std::string original_lang = 1568 std::string original_lang =
1569 chrome_translate_client->GetLanguageState().original_language(); 1569 chrome_translate_client->GetLanguageState().original_language();
1570 std::string target_lang = g_browser_process->GetApplicationLocale(); 1570 std::string target_lang = g_browser_process->GetApplicationLocale();
1571 target_lang = 1571 target_lang =
1572 translate::TranslateDownloadManager::GetLanguageCode(target_lang); 1572 translate::TranslateDownloadManager::GetLanguageCode(target_lang);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 source_web_contents_->GetRenderViewHost()-> 1785 source_web_contents_->GetRenderViewHost()->
1786 ExecuteMediaPlayerActionAtLocation(location, action); 1786 ExecuteMediaPlayerActionAtLocation(location, action);
1787 } 1787 }
1788 1788
1789 void RenderViewContextMenu::PluginActionAt( 1789 void RenderViewContextMenu::PluginActionAt(
1790 const gfx::Point& location, 1790 const gfx::Point& location,
1791 const WebPluginAction& action) { 1791 const WebPluginAction& action) {
1792 source_web_contents_->GetRenderViewHost()-> 1792 source_web_contents_->GetRenderViewHost()->
1793 ExecutePluginActionAtLocation(location, action); 1793 ExecutePluginActionAtLocation(location, action);
1794 } 1794 }
OLDNEW
« no previous file with comments | « no previous file | components/renderer_context_menu/render_view_context_menu_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698