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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "content/common/view_messages.h" | 62 #include "content/common/view_messages.h" |
63 #include "grit/generated_resources.h" | 63 #include "grit/generated_resources.h" |
64 #include "net/base/escape.h" | 64 #include "net/base/escape.h" |
65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" | 66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" |
67 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
68 #include "ui/base/text/text_elider.h" | 68 #include "ui/base/text/text_elider.h" |
69 #include "ui/gfx/favicon_size.h" | 69 #include "ui/gfx/favicon_size.h" |
70 #include "webkit/glue/webmenuitem.h" | 70 #include "webkit/glue/webmenuitem.h" |
71 | 71 |
| 72 #ifdef FILE_MANAGER_EXTENSION |
| 73 #include "chrome/browser/extensions/file_manager_util.h" |
| 74 #endif |
| 75 |
72 using WebKit::WebContextMenuData; | 76 using WebKit::WebContextMenuData; |
73 using WebKit::WebMediaPlayerAction; | 77 using WebKit::WebMediaPlayerAction; |
74 using WebKit::WebURL; | 78 using WebKit::WebURL; |
75 using WebKit::WebString; | 79 using WebKit::WebString; |
76 | 80 |
77 namespace { | 81 namespace { |
78 | 82 |
79 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { | 83 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { |
80 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 84 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
81 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST); | 85 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 submenu); | 161 submenu); |
158 break; | 162 break; |
159 } | 163 } |
160 default: | 164 default: |
161 NOTREACHED(); | 165 NOTREACHED(); |
162 break; | 166 break; |
163 } | 167 } |
164 } | 168 } |
165 } | 169 } |
166 | 170 |
| 171 bool ShouldShowTranslateItem(const GURL& page_url) { |
| 172 if (page_url.SchemeIs("chrome")) |
| 173 return false; |
| 174 |
| 175 #ifdef FILE_MANAGER_EXTENSION |
| 176 if (page_url.SchemeIs("chrome-extension") && |
| 177 page_url.DomainIs(kFileBrowserDomain)) |
| 178 return false; |
| 179 #endif |
| 180 |
| 181 return true; |
| 182 } |
| 183 |
167 } // namespace | 184 } // namespace |
168 | 185 |
169 // static | 186 // static |
170 const size_t RenderViewContextMenu::kMaxExtensionItemTitleLength = 75; | 187 const size_t RenderViewContextMenu::kMaxExtensionItemTitleLength = 75; |
171 // static | 188 // static |
172 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; | 189 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; |
173 | 190 |
174 // static | 191 // static |
175 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { | 192 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { |
176 return url.SchemeIs(chrome::kChromeDevToolsScheme) && | 193 return url.SchemeIs(chrome::kChromeDevToolsScheme) && |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 | 691 |
675 void RenderViewContextMenu::AppendPageItems() { | 692 void RenderViewContextMenu::AppendPageItems() { |
676 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); | 693 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); |
677 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); | 694 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); |
678 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 695 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
679 menu_model_.AddSeparator(); | 696 menu_model_.AddSeparator(); |
680 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, | 697 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, |
681 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 698 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
682 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 699 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
683 | 700 |
684 std::string locale = g_browser_process->GetApplicationLocale(); | 701 if (ShouldShowTranslateItem(params_.page_url)) { |
685 locale = TranslateManager::GetLanguageCode(locale); | 702 std::string locale = g_browser_process->GetApplicationLocale(); |
686 string16 language = l10n_util::GetDisplayNameForLocale(locale, locale, true); | 703 locale = TranslateManager::GetLanguageCode(locale); |
687 menu_model_.AddItem( | 704 string16 language = l10n_util::GetDisplayNameForLocale(locale, locale, |
688 IDC_CONTENT_CONTEXT_TRANSLATE, | 705 true); |
689 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); | 706 menu_model_.AddItem( |
| 707 IDC_CONTENT_CONTEXT_TRANSLATE, |
| 708 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); |
| 709 } |
690 | 710 |
691 menu_model_.AddItemWithStringId(IDC_VIEW_SOURCE, | 711 menu_model_.AddItemWithStringId(IDC_VIEW_SOURCE, |
692 IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); | 712 IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); |
693 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, | 713 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, |
694 IDS_CONTENT_CONTEXT_VIEWPAGEINFO); | 714 IDS_CONTENT_CONTEXT_VIEWPAGEINFO); |
695 } | 715 } |
696 | 716 |
697 void RenderViewContextMenu::AppendFrameItems() { | 717 void RenderViewContextMenu::AppendFrameItems() { |
698 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOADFRAME, | 718 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOADFRAME, |
699 IDS_CONTENT_CONTEXT_RELOADFRAME); | 719 IDS_CONTENT_CONTEXT_RELOADFRAME); |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 g_browser_process->clipboard()); | 1854 g_browser_process->clipboard()); |
1835 } | 1855 } |
1836 | 1856 |
1837 void RenderViewContextMenu::MediaPlayerActionAt( | 1857 void RenderViewContextMenu::MediaPlayerActionAt( |
1838 const gfx::Point& location, | 1858 const gfx::Point& location, |
1839 const WebMediaPlayerAction& action) { | 1859 const WebMediaPlayerAction& action) { |
1840 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1860 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
1841 rvh->Send(new ViewMsg_MediaPlayerActionAt( | 1861 rvh->Send(new ViewMsg_MediaPlayerActionAt( |
1842 rvh->routing_id(), location, action)); | 1862 rvh->routing_id(), location, action)); |
1843 } | 1863 } |
OLD | NEW |