Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 7 |
| 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "chrome/browser/profiles/profile_io_data.h" | 35 #include "chrome/browser/profiles/profile_io_data.h" |
| 36 #include "chrome/browser/search_engines/template_url.h" | 36 #include "chrome/browser/search_engines/template_url.h" |
| 37 #include "chrome/browser/search_engines/template_url_service.h" | 37 #include "chrome/browser/search_engines/template_url_service.h" |
| 38 #include "chrome/browser/search_engines/template_url_service_factory.h" | 38 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 39 #include "chrome/browser/spellcheck_host.h" | 39 #include "chrome/browser/spellcheck_host.h" |
| 40 #include "chrome/browser/spellcheck_host_metrics.h" | 40 #include "chrome/browser/spellcheck_host_metrics.h" |
| 41 #include "chrome/browser/spellchecker_platform_engine.h" | 41 #include "chrome/browser/spellchecker_platform_engine.h" |
| 42 #include "chrome/browser/translate/translate_manager.h" | 42 #include "chrome/browser/translate/translate_manager.h" |
| 43 #include "chrome/browser/translate/translate_prefs.h" | 43 #include "chrome/browser/translate/translate_prefs.h" |
| 44 #include "chrome/browser/translate/translate_tab_helper.h" | 44 #include "chrome/browser/translate/translate_tab_helper.h" |
| 45 #include "chrome/browser/ui/browser.h" | |
| 45 #include "chrome/browser/ui/download/download_tab_helper.h" | 46 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 47 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | |
| 46 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 48 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 47 #include "chrome/common/chrome_constants.h" | 49 #include "chrome/common/chrome_constants.h" |
| 48 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/common/print_messages.h" | 52 #include "chrome/common/print_messages.h" |
| 51 #include "chrome/common/spellcheck_messages.h" | 53 #include "chrome/common/spellcheck_messages.h" |
| 52 #include "chrome/common/url_constants.h" | 54 #include "chrome/common/url_constants.h" |
| 53 #include "content/browser/child_process_security_policy.h" | 55 #include "content/browser/child_process_security_policy.h" |
| 54 #include "content/browser/renderer_host/render_view_host.h" | 56 #include "content/browser/renderer_host/render_view_host.h" |
| 55 #include "content/browser/renderer_host/render_widget_host_view.h" | 57 #include "content/browser/renderer_host/render_widget_host_view.h" |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT, | 780 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT, |
| 779 IDS_CONTENT_CONTEXT_CUT); | 781 IDS_CONTENT_CONTEXT_CUT); |
| 780 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, | 782 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, |
| 781 IDS_CONTENT_CONTEXT_COPY); | 783 IDS_CONTENT_CONTEXT_COPY); |
| 782 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE, | 784 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE, |
| 783 IDS_CONTENT_CONTEXT_PASTE); | 785 IDS_CONTENT_CONTEXT_PASTE); |
| 784 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_DELETE, | 786 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_DELETE, |
| 785 IDS_CONTENT_CONTEXT_DELETE); | 787 IDS_CONTENT_CONTEXT_DELETE); |
| 786 menu_model_.AddSeparator(); | 788 menu_model_.AddSeparator(); |
| 787 | 789 |
| 790 if (!params_.keyword_url.is_empty()) { | |
| 791 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, | |
| 792 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); | |
| 793 menu_model_.AddSeparator(); | |
| 794 } | |
| 795 | |
| 788 AppendSpellcheckOptionsSubMenu(); | 796 AppendSpellcheckOptionsSubMenu(); |
| 789 | 797 |
| 790 #if defined(OS_MACOSX) | 798 #if defined(OS_MACOSX) |
| 791 // OS X provides a contextual menu to set writing direction for BiDi | 799 // OS X provides a contextual menu to set writing direction for BiDi |
| 792 // languages. | 800 // languages. |
| 793 // This functionality is exposed as a keyboard shortcut on Windows & Linux. | 801 // This functionality is exposed as a keyboard shortcut on Windows & Linux. |
| 794 AppendBidiSubMenu(); | 802 AppendBidiSubMenu(); |
| 795 #endif // OS_MACOSX | 803 #endif // OS_MACOSX |
| 796 | 804 |
| 797 menu_model_.AddSeparator(); | 805 menu_model_.AddSeparator(); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: | 1178 case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: |
| 1171 // This is OK because the menu is not shown when it isn't | 1179 // This is OK because the menu is not shown when it isn't |
| 1172 // appropriate. | 1180 // appropriate. |
| 1173 return true; | 1181 return true; |
| 1174 #elif defined(OS_POSIX) | 1182 #elif defined(OS_POSIX) |
| 1175 // TODO(suzhe): this should not be enabled for password fields. | 1183 // TODO(suzhe): this should not be enabled for password fields. |
| 1176 case IDC_INPUT_METHODS_MENU: | 1184 case IDC_INPUT_METHODS_MENU: |
| 1177 return true; | 1185 return true; |
| 1178 #endif | 1186 #endif |
| 1179 | 1187 |
| 1188 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: | |
| 1189 return !params_.keyword_url.is_empty(); | |
| 1190 | |
| 1180 case IDC_SPELLCHECK_MENU: | 1191 case IDC_SPELLCHECK_MENU: |
| 1181 return true; | 1192 return true; |
| 1182 | 1193 |
| 1183 case IDC_CONTENT_CONTEXT_OPENLINKWITH: | 1194 case IDC_CONTENT_CONTEXT_OPENLINKWITH: |
| 1184 return true; | 1195 return true; |
| 1185 | 1196 |
| 1186 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: | 1197 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: |
| 1187 return true; | 1198 return true; |
| 1188 | 1199 |
| 1189 default: | 1200 default: |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1615 LookUpInDictionary(); | 1626 LookUpInDictionary(); |
| 1616 break; | 1627 break; |
| 1617 #endif // OS_MACOSX | 1628 #endif // OS_MACOSX |
| 1618 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: { | 1629 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: { |
| 1619 std::string url = std::string(chrome::kChromeUISettingsURL) + | 1630 std::string url = std::string(chrome::kChromeUISettingsURL) + |
| 1620 chrome::kHandlerSettingsSubPage; | 1631 chrome::kHandlerSettingsSubPage; |
| 1621 OpenURL(GURL(url), GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1632 OpenURL(GURL(url), GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 1622 break; | 1633 break; |
| 1623 } | 1634 } |
| 1624 | 1635 |
| 1636 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: { | |
| 1637 // Make sure the model is loaded. | |
| 1638 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | |
|
Peter Kasting
2011/06/29 18:08:23
Nit: Breaking after '=' would be a little more rea
Philippe Beauchamp
2011/06/29 23:47:10
Done.
| |
| 1639 profile_); | |
| 1640 | |
|
Peter Kasting
2011/06/29 18:08:23
Nit: Unnecessary blank line
Philippe Beauchamp
2011/06/29 23:47:10
Done.
| |
| 1641 if (!model) | |
| 1642 return; | |
| 1643 model->Load(); | |
| 1644 | |
| 1645 TemplateURL* template_url = new TemplateURL(); | |
|
Peter Kasting
2011/06/29 18:08:23
Nit: Use a scoped_ptr<> here and then use "release
Philippe Beauchamp
2011/06/29 23:47:10
Done.
| |
| 1646 std::wstring keyword = net::StripWWW(UTF8ToWide(params_.page_url.host())); | |
| 1647 template_url->set_short_name(keyword); | |
| 1648 template_url->set_keyword(keyword); | |
| 1649 template_url->SetURL(params_.keyword_url.spec(), 0, 0); | |
| 1650 template_url->SetFaviconURL(TemplateURL::GenerateFaviconURL( | |
| 1651 params_.page_url.GetOrigin())); | |
| 1652 | |
| 1653 TabContentsWrapper* tab_contents_wrapper = | |
| 1654 TabContentsWrapper::GetCurrentWrapperForContents( | |
| 1655 source_tab_contents_); | |
| 1656 | |
|
Peter Kasting
2011/06/29 18:08:23
Nit: Unnecessary blank line
Philippe Beauchamp
2011/06/29 23:47:10
Done.
| |
| 1657 if (tab_contents_wrapper && | |
| 1658 tab_contents_wrapper->search_engine_tab_helper() && | |
| 1659 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { | |
| 1660 // Takes ownership of |template_url|. | |
| 1661 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> | |
| 1662 ConfirmAddSearchProvider(template_url, profile_); | |
| 1663 } else { | |
| 1664 delete template_url; | |
| 1665 } | |
| 1666 break; | |
| 1667 } | |
| 1668 | |
| 1625 default: | 1669 default: |
| 1626 NOTREACHED(); | 1670 NOTREACHED(); |
| 1627 break; | 1671 break; |
| 1628 } | 1672 } |
| 1629 } | 1673 } |
| 1630 | 1674 |
| 1631 ProtocolHandlerRegistry::ProtocolHandlerList | 1675 ProtocolHandlerRegistry::ProtocolHandlerList |
| 1632 RenderViewContextMenu::GetHandlersForLinkUrl() { | 1676 RenderViewContextMenu::GetHandlersForLinkUrl() { |
| 1633 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1677 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1634 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); | 1678 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1713 g_browser_process->clipboard()); | 1757 g_browser_process->clipboard()); |
| 1714 } | 1758 } |
| 1715 | 1759 |
| 1716 void RenderViewContextMenu::MediaPlayerActionAt( | 1760 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1717 const gfx::Point& location, | 1761 const gfx::Point& location, |
| 1718 const WebMediaPlayerAction& action) { | 1762 const WebMediaPlayerAction& action) { |
| 1719 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1763 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
| 1720 rvh->Send(new ViewMsg_MediaPlayerActionAt( | 1764 rvh->Send(new ViewMsg_MediaPlayerActionAt( |
| 1721 rvh->routing_id(), location, action)); | 1765 rvh->routing_id(), location, action)); |
| 1722 } | 1766 } |
| OLD | NEW |