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

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

Issue 133273029: Move LanguageState to the translate component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tab_contents/render_view_context_menu.h" 5 #include "chrome/browser/tab_contents/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 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 if (chrome::FindBrowserWithWebContents(source_web_contents_) == NULL) 1222 if (chrome::FindBrowserWithWebContents(source_web_contents_) == NULL)
1223 return false; 1223 return false;
1224 return true; 1224 return true;
1225 1225
1226 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1226 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1227 TranslateTabHelper* translate_tab_helper = 1227 TranslateTabHelper* translate_tab_helper =
1228 TranslateTabHelper::FromWebContents(source_web_contents_); 1228 TranslateTabHelper::FromWebContents(source_web_contents_);
1229 if (!translate_tab_helper) 1229 if (!translate_tab_helper)
1230 return false; 1230 return false;
1231 std::string original_lang = 1231 std::string original_lang =
1232 translate_tab_helper->language_state().original_language(); 1232 translate_tab_helper->GetLanguageState().original_language();
1233 std::string target_lang = g_browser_process->GetApplicationLocale(); 1233 std::string target_lang = g_browser_process->GetApplicationLocale();
1234 target_lang = TranslateManager::GetLanguageCode(target_lang); 1234 target_lang = TranslateManager::GetLanguageCode(target_lang);
1235 // Note that we intentionally enable the menu even if the original and 1235 // Note that we intentionally enable the menu even if the original and
1236 // target languages are identical. This is to give a way to user to 1236 // target languages are identical. This is to give a way to user to
1237 // translate a page that might contains text fragments in a different 1237 // translate a page that might contains text fragments in a different
1238 // language. 1238 // language.
1239 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) && 1239 return ((params_.edit_flags & WebContextMenuData::CanTranslate) != 0) &&
1240 !original_lang.empty() && // Did we receive the page language yet? 1240 !original_lang.empty() && // Did we receive the page language yet?
1241 !translate_tab_helper->language_state().IsPageTranslated() && 1241 !translate_tab_helper->GetLanguageState().IsPageTranslated() &&
1242 !source_web_contents_->GetInterstitialPage() && 1242 !source_web_contents_->GetInterstitialPage() &&
1243 // There are some application locales which can't be used as a 1243 // There are some application locales which can't be used as a
1244 // target language for translation. 1244 // target language for translation.
1245 TranslateManager::IsSupportedLanguage(target_lang) && 1245 TranslateManager::IsSupportedLanguage(target_lang) &&
1246 // Disable on the Instant Extended NTP. 1246 // Disable on the Instant Extended NTP.
1247 !chrome::IsInstantNTP(source_web_contents_); 1247 !chrome::IsInstantNTP(source_web_contents_);
1248 } 1248 }
1249 1249
1250 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1250 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1251 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1251 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 nav_entry->GetURL(), nav_entry->GetSSL()); 1799 nav_entry->GetURL(), nav_entry->GetSSL());
1800 break; 1800 break;
1801 } 1801 }
1802 1802
1803 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1803 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1804 // A translation might have been triggered by the time the menu got 1804 // A translation might have been triggered by the time the menu got
1805 // selected, do nothing in that case. 1805 // selected, do nothing in that case.
1806 TranslateTabHelper* translate_tab_helper = 1806 TranslateTabHelper* translate_tab_helper =
1807 TranslateTabHelper::FromWebContents(source_web_contents_); 1807 TranslateTabHelper::FromWebContents(source_web_contents_);
1808 if (!translate_tab_helper || 1808 if (!translate_tab_helper ||
1809 translate_tab_helper->language_state().IsPageTranslated() || 1809 translate_tab_helper->GetLanguageState().IsPageTranslated() ||
1810 translate_tab_helper->language_state().translation_pending()) { 1810 translate_tab_helper->GetLanguageState().translation_pending()) {
1811 return; 1811 return;
1812 } 1812 }
1813 std::string original_lang = 1813 std::string original_lang =
1814 translate_tab_helper->language_state().original_language(); 1814 translate_tab_helper->GetLanguageState().original_language();
1815 std::string target_lang = g_browser_process->GetApplicationLocale(); 1815 std::string target_lang = g_browser_process->GetApplicationLocale();
1816 target_lang = TranslateManager::GetLanguageCode(target_lang); 1816 target_lang = TranslateManager::GetLanguageCode(target_lang);
1817 // Since the user decided to translate for that language and site, clears 1817 // Since the user decided to translate for that language and site, clears
1818 // any preferences for not translating them. 1818 // any preferences for not translating them.
1819 TranslatePrefs prefs(profile_->GetPrefs()); 1819 TranslatePrefs prefs(profile_->GetPrefs());
1820 prefs.UnblockLanguage(original_lang); 1820 prefs.UnblockLanguage(original_lang);
1821 prefs.RemoveSiteFromBlacklist(params_.page_url.HostNoBrackets()); 1821 prefs.RemoveSiteFromBlacklist(params_.page_url.HostNoBrackets());
1822 TranslateManager::GetInstance()->TranslatePage( 1822 TranslateManager::GetInstance()->TranslatePage(
1823 source_web_contents_, original_lang, target_lang); 1823 source_web_contents_, original_lang, target_lang);
1824 break; 1824 break;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 source_web_contents_->GetRenderViewHost()-> 2098 source_web_contents_->GetRenderViewHost()->
2099 ExecuteMediaPlayerActionAtLocation(location, action); 2099 ExecuteMediaPlayerActionAtLocation(location, action);
2100 } 2100 }
2101 2101
2102 void RenderViewContextMenu::PluginActionAt( 2102 void RenderViewContextMenu::PluginActionAt(
2103 const gfx::Point& location, 2103 const gfx::Point& location,
2104 const WebPluginAction& action) { 2104 const WebPluginAction& action) {
2105 source_web_contents_->GetRenderViewHost()-> 2105 source_web_contents_->GetRenderViewHost()->
2106 ExecutePluginActionAtLocation(location, action); 2106 ExecutePluginActionAtLocation(location, action);
2107 } 2107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698