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

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

Issue 10535088: TabContentsWrapper -> TabContents, part 30. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/tab_contents/render_view_context_menu_browsertest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 43 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
44 #include "chrome/browser/tab_contents/retargeting_details.h" 44 #include "chrome/browser/tab_contents/retargeting_details.h"
45 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h" 45 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
46 #include "chrome/browser/tab_contents/spelling_menu_observer.h" 46 #include "chrome/browser/tab_contents/spelling_menu_observer.h"
47 #include "chrome/browser/translate/translate_manager.h" 47 #include "chrome/browser/translate/translate_manager.h"
48 #include "chrome/browser/translate/translate_prefs.h" 48 #include "chrome/browser/translate/translate_prefs.h"
49 #include "chrome/browser/translate/translate_tab_helper.h" 49 #include "chrome/browser/translate/translate_tab_helper.h"
50 #include "chrome/browser/ui/browser.h" 50 #include "chrome/browser/ui/browser.h"
51 #include "chrome/browser/ui/browser_finder.h" 51 #include "chrome/browser/ui/browser_finder.h"
52 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 52 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
53 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 53 #include "chrome/browser/ui/tab_contents/tab_contents.h"
54 #include "chrome/browser/view_type_utils.h" 54 #include "chrome/browser/view_type_utils.h"
55 #include "chrome/common/chrome_constants.h" 55 #include "chrome/common/chrome_constants.h"
56 #include "chrome/common/chrome_notification_types.h" 56 #include "chrome/common/chrome_notification_types.h"
57 #include "chrome/common/chrome_switches.h" 57 #include "chrome/common/chrome_switches.h"
58 #include "chrome/common/extensions/extension.h" 58 #include "chrome/common/extensions/extension.h"
59 #include "chrome/common/net/url_util.h" 59 #include "chrome/common/net/url_util.h"
60 #include "chrome/common/pref_names.h" 60 #include "chrome/common/pref_names.h"
61 #include "chrome/common/print_messages.h" 61 #include "chrome/common/print_messages.h"
62 #include "chrome/common/spellcheck_messages.h" 62 #include "chrome/common/spellcheck_messages.h"
63 #include "chrome/common/url_constants.h" 63 #include "chrome/common/url_constants.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 617
618 if (has_selection) 618 if (has_selection)
619 AppendSearchProvider(); 619 AppendSearchProvider();
620 620
621 if (!IsDevToolsURL(params_.page_url)) 621 if (!IsDevToolsURL(params_.page_url))
622 AppendAllExtensionItems(); 622 AppendAllExtensionItems();
623 623
624 AppendDeveloperItems(); 624 AppendDeveloperItems();
625 625
626 if (!print_preview_menu_observer_.get()) { 626 if (!print_preview_menu_observer_.get()) {
627 TabContentsWrapper* wrapper = 627 TabContents* tab_contents =
628 TabContentsWrapper::GetCurrentWrapperForContents(source_web_contents_); 628 TabContents::FromWebContents(source_web_contents_);
629 print_preview_menu_observer_.reset( 629 print_preview_menu_observer_.reset(
630 new PrintPreviewContextMenuObserver(wrapper)); 630 new PrintPreviewContextMenuObserver(tab_contents));
631 } 631 }
632 observers_.AddObserver(print_preview_menu_observer_.get()); 632 observers_.AddObserver(print_preview_menu_observer_.get());
633 } 633 }
634 634
635 const Extension* RenderViewContextMenu::GetExtension() const { 635 const Extension* RenderViewContextMenu::GetExtension() const {
636 ExtensionSystem* system = ExtensionSystem::Get(profile_); 636 ExtensionSystem* system = ExtensionSystem::Get(profile_);
637 // There is no process manager in some tests. 637 // There is no process manager in some tests.
638 if (!system->process_manager()) 638 if (!system->process_manager())
639 return NULL; 639 return NULL;
640 640
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1133 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1134 return source_web_contents_->GetController().CanViewSource(); 1134 return source_web_contents_->GetController().CanViewSource();
1135 1135
1136 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1136 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1137 return IsDevCommandEnabled(id); 1137 return IsDevCommandEnabled(id);
1138 1138
1139 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: 1139 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO:
1140 return source_web_contents_->GetController().GetActiveEntry() != NULL; 1140 return source_web_contents_->GetController().GetActiveEntry() != NULL;
1141 1141
1142 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1142 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1143 TabContentsWrapper* tab_contents_wrapper = 1143 TabContents* tab_contents =
1144 TabContentsWrapper::GetCurrentWrapperForContents( 1144 TabContents::FromWebContents(source_web_contents_);
1145 source_web_contents_); 1145 if (!tab_contents)
1146 if (!tab_contents_wrapper)
1147 return false; 1146 return false;
1148 TranslateTabHelper* helper = tab_contents_wrapper->translate_tab_helper(); 1147 TranslateTabHelper* helper = tab_contents->translate_tab_helper();
1149 std::string original_lang = 1148 std::string original_lang =
1150 helper->language_state().original_language(); 1149 helper->language_state().original_language();
1151 std::string target_lang = g_browser_process->GetApplicationLocale(); 1150 std::string target_lang = g_browser_process->GetApplicationLocale();
1152 target_lang = TranslateManager::GetLanguageCode(target_lang); 1151 target_lang = TranslateManager::GetLanguageCode(target_lang);
1153 // Note that we intentionally enable the menu even if the original and 1152 // Note that we intentionally enable the menu even if the original and
1154 // target languages are identical. This is to give a way to user to 1153 // target languages are identical. This is to give a way to user to
1155 // translate a page that might contains text fragments in a different 1154 // translate a page that might contains text fragments in a different
1156 // language. 1155 // language.
1157 return !!(params_.edit_flags & WebContextMenuData::CanTranslate) && 1156 return !!(params_.edit_flags & WebContextMenuData::CanTranslate) &&
1158 helper->language_state().page_translatable() && 1157 helper->language_state().page_translatable() &&
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 break; 1660 break;
1662 1661
1663 case IDC_RELOAD: 1662 case IDC_RELOAD:
1664 // Prevent the modal "Resubmit form post" dialog from appearing in the 1663 // Prevent the modal "Resubmit form post" dialog from appearing in the
1665 // context of an external context menu. 1664 // context of an external context menu.
1666 source_web_contents_->GetController().Reload(!external_); 1665 source_web_contents_->GetController().Reload(!external_);
1667 break; 1666 break;
1668 1667
1669 case IDC_PRINT: 1668 case IDC_PRINT:
1670 if (params_.media_type == WebContextMenuData::MediaTypeNone) { 1669 if (params_.media_type == WebContextMenuData::MediaTypeNone) {
1671 TabContentsWrapper* tab_contents_wrapper = 1670 TabContents* tab_contents =
1672 TabContentsWrapper::GetCurrentWrapperForContents( 1671 TabContents::FromWebContents(source_web_contents_);
1673 source_web_contents_); 1672 if (!tab_contents)
1674 if (!tab_contents_wrapper)
1675 break; 1673 break;
1676 if (g_browser_process->local_state()->GetBoolean( 1674 if (g_browser_process->local_state()->GetBoolean(
1677 prefs::kPrintPreviewDisabled)) { 1675 prefs::kPrintPreviewDisabled)) {
1678 tab_contents_wrapper->print_view_manager()->PrintNow(); 1676 tab_contents->print_view_manager()->PrintNow();
1679 } else { 1677 } else {
1680 tab_contents_wrapper->print_view_manager()->PrintPreviewNow(); 1678 tab_contents->print_view_manager()->PrintPreviewNow();
1681 } 1679 }
1682 } else { 1680 } else {
1683 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID())); 1681 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID()));
1684 } 1682 }
1685 break; 1683 break;
1686 1684
1687 case IDC_VIEW_SOURCE: 1685 case IDC_VIEW_SOURCE:
1688 source_web_contents_->ViewSource(); 1686 source_web_contents_->ViewSource();
1689 break; 1687 break;
1690 1688
1691 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1689 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1692 Inspect(params_.x, params_.y); 1690 Inspect(params_.x, params_.y);
1693 break; 1691 break;
1694 1692
1695 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: { 1693 case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: {
1696 NavigationController* controller = &source_web_contents_->GetController(); 1694 NavigationController* controller = &source_web_contents_->GetController();
1697 NavigationEntry* nav_entry = controller->GetActiveEntry(); 1695 NavigationEntry* nav_entry = controller->GetActiveEntry();
1698 Browser* browser = browser::FindBrowserForController(controller, NULL); 1696 Browser* browser = browser::FindBrowserForController(controller, NULL);
1699 browser->ShowPageInfo(source_web_contents_, nav_entry->GetURL(), 1697 browser->ShowPageInfo(source_web_contents_, nav_entry->GetURL(),
1700 nav_entry->GetSSL(), true); 1698 nav_entry->GetSSL(), true);
1701 break; 1699 break;
1702 } 1700 }
1703 1701
1704 case IDC_CONTENT_CONTEXT_TRANSLATE: { 1702 case IDC_CONTENT_CONTEXT_TRANSLATE: {
1705 // A translation might have been triggered by the time the menu got 1703 // A translation might have been triggered by the time the menu got
1706 // selected, do nothing in that case. 1704 // selected, do nothing in that case.
1707 TabContentsWrapper* tab_contents_wrapper = 1705 TabContents* tab_contents =
1708 TabContentsWrapper::GetCurrentWrapperForContents( 1706 TabContents::FromWebContents(source_web_contents_);
1709 source_web_contents_); 1707 if (!tab_contents)
1710 if (!tab_contents_wrapper)
1711 return; 1708 return;
1712 TranslateTabHelper* helper = tab_contents_wrapper->translate_tab_helper(); 1709 TranslateTabHelper* helper = tab_contents->translate_tab_helper();
1713 if (helper->language_state().IsPageTranslated() || 1710 if (helper->language_state().IsPageTranslated() ||
1714 helper->language_state().translation_pending()) { 1711 helper->language_state().translation_pending()) {
1715 return; 1712 return;
1716 } 1713 }
1717 std::string original_lang = helper->language_state().original_language(); 1714 std::string original_lang = helper->language_state().original_language();
1718 std::string target_lang = g_browser_process->GetApplicationLocale(); 1715 std::string target_lang = g_browser_process->GetApplicationLocale();
1719 target_lang = TranslateManager::GetLanguageCode(target_lang); 1716 target_lang = TranslateManager::GetLanguageCode(target_lang);
1720 // Since the user decided to translate for that language and site, clears 1717 // Since the user decided to translate for that language and site, clears
1721 // any preferences for not translating them. 1718 // any preferences for not translating them.
1722 TranslatePrefs prefs(profile_->GetPrefs()); 1719 TranslatePrefs prefs(profile_->GetPrefs());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 } 1820 }
1824 1821
1825 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: { 1822 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: {
1826 // Make sure the model is loaded. 1823 // Make sure the model is loaded.
1827 TemplateURLService* model = 1824 TemplateURLService* model =
1828 TemplateURLServiceFactory::GetForProfile(profile_); 1825 TemplateURLServiceFactory::GetForProfile(profile_);
1829 if (!model) 1826 if (!model)
1830 return; 1827 return;
1831 model->Load(); 1828 model->Load();
1832 1829
1833 TabContentsWrapper* tab_contents_wrapper = 1830 TabContents* tab_contents =
1834 TabContentsWrapper::GetCurrentWrapperForContents( 1831 TabContents::FromWebContents(source_web_contents_);
1835 source_web_contents_); 1832 if (tab_contents &&
1836 if (tab_contents_wrapper && 1833 tab_contents->search_engine_tab_helper() &&
1837 tab_contents_wrapper->search_engine_tab_helper() && 1834 tab_contents->search_engine_tab_helper()->delegate()) {
1838 tab_contents_wrapper->search_engine_tab_helper()->delegate()) {
1839 string16 keyword(TemplateURLService::GenerateKeyword(params_.page_url)); 1835 string16 keyword(TemplateURLService::GenerateKeyword(params_.page_url));
1840 TemplateURLData data; 1836 TemplateURLData data;
1841 data.short_name = keyword; 1837 data.short_name = keyword;
1842 data.SetKeyword(keyword); 1838 data.SetKeyword(keyword);
1843 data.SetURL(params_.keyword_url.spec()); 1839 data.SetURL(params_.keyword_url.spec());
1844 data.favicon_url = 1840 data.favicon_url =
1845 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); 1841 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin());
1846 // Takes ownership of the TemplateURL. 1842 // Takes ownership of the TemplateURL.
1847 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> 1843 tab_contents->search_engine_tab_helper()->delegate()->
1848 ConfirmAddSearchProvider(new TemplateURL(profile_, data), profile_); 1844 ConfirmAddSearchProvider(new TemplateURL(profile_, data), profile_);
1849 } 1845 }
1850 break; 1846 break;
1851 } 1847 }
1852 1848
1853 #if defined(ENABLE_INPUT_SPEECH) 1849 #if defined(ENABLE_INPUT_SPEECH)
1854 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES: { 1850 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES: {
1855 ChromeSpeechRecognitionPreferences::GetForProfile(profile_)-> 1851 ChromeSpeechRecognitionPreferences::GetForProfile(profile_)->
1856 ToggleFilterProfanities(); 1852 ToggleFilterProfanities();
1857 break; 1853 break;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 source_web_contents_->GetRenderViewHost()-> 1981 source_web_contents_->GetRenderViewHost()->
1986 ExecuteMediaPlayerActionAtLocation(location, action); 1982 ExecuteMediaPlayerActionAtLocation(location, action);
1987 } 1983 }
1988 1984
1989 void RenderViewContextMenu::PluginActionAt( 1985 void RenderViewContextMenu::PluginActionAt(
1990 const gfx::Point& location, 1986 const gfx::Point& location,
1991 const WebPluginAction& action) { 1987 const WebPluginAction& action) {
1992 source_web_contents_->GetRenderViewHost()-> 1988 source_web_contents_->GetRenderViewHost()->
1993 ExecutePluginActionAtLocation(location, action); 1989 ExecutePluginActionAtLocation(location, action);
1994 } 1990 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/tab_contents/render_view_context_menu_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698