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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
19 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 19 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
20 #include "chrome/browser/autocomplete/autocomplete_match.h" | 20 #include "chrome/browser/autocomplete/autocomplete_match.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/debugger/devtools_manager.h" | 22 #include "chrome/browser/debugger/devtools_manager.h" |
23 #include "chrome/browser/debugger/devtools_window.h" | 23 #include "chrome/browser/debugger/devtools_window.h" |
24 #include "chrome/browser/download/download_manager.h" | 24 #include "chrome/browser/download/download_manager.h" |
25 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
26 #include "chrome/browser/download/save_package.h" | 26 #include "chrome/browser/download/save_package.h" |
| 27 #include "chrome/browser/event_disposition.h" |
27 #include "chrome/browser/extensions/extension_event_router.h" | 28 #include "chrome/browser/extensions/extension_event_router.h" |
28 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
29 #include "chrome/browser/net/browser_url_util.h" | 30 #include "chrome/browser/net/browser_url_util.h" |
30 #include "chrome/browser/page_info_window.h" | 31 #include "chrome/browser/page_info_window.h" |
31 #include "chrome/browser/platform_util.h" | 32 #include "chrome/browser/platform_util.h" |
32 #include "chrome/browser/prefs/pref_member.h" | 33 #include "chrome/browser/prefs/pref_member.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/profiles/profile_io_data.h" | 36 #include "chrome/browser/profiles/profile_io_data.h" |
36 #include "chrome/browser/search_engines/template_url.h" | 37 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 20 matching lines...) Expand all Loading... |
57 #include "content/browser/user_metrics.h" | 58 #include "content/browser/user_metrics.h" |
58 #include "content/common/content_restriction.h" | 59 #include "content/common/content_restriction.h" |
59 #include "content/common/view_messages.h" | 60 #include "content/common/view_messages.h" |
60 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
61 #include "net/base/escape.h" | 62 #include "net/base/escape.h" |
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" | 64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.
h" |
64 #include "ui/base/l10n/l10n_util.h" | 65 #include "ui/base/l10n/l10n_util.h" |
65 #include "ui/gfx/favicon_size.h" | 66 #include "ui/gfx/favicon_size.h" |
66 #include "webkit/glue/webmenuitem.h" | 67 #include "webkit/glue/webmenuitem.h" |
| 68 #include "webkit/glue/window_open_disposition.h" |
67 | 69 |
68 using WebKit::WebContextMenuData; | 70 using WebKit::WebContextMenuData; |
69 using WebKit::WebMediaPlayerAction; | 71 using WebKit::WebMediaPlayerAction; |
70 using WebKit::WebURL; | 72 using WebKit::WebURL; |
71 using WebKit::WebString; | 73 using WebKit::WebString; |
72 | 74 |
73 namespace { | 75 namespace { |
74 | 76 |
75 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { | 77 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { |
76 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 78 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 // language. | 1195 // language. |
1194 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || | 1196 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || |
1195 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) | 1197 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) |
1196 return false; | 1198 return false; |
1197 | 1199 |
1198 std::vector<std::string> languages; | 1200 std::vector<std::string> languages; |
1199 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == | 1201 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == |
1200 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); | 1202 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); |
1201 } | 1203 } |
1202 | 1204 |
| 1205 void RenderViewContextMenu::ExecuteCommandWithFlags(int id, int flags) { |
| 1206 switch (id) { |
| 1207 case IDC_BACK: |
| 1208 GoBack(flags); |
| 1209 return; |
| 1210 case IDC_FORWARD: |
| 1211 GoForward(flags); |
| 1212 return; |
| 1213 } |
| 1214 |
| 1215 // If not processed, call ExecuteCommand instead. |
| 1216 ExecuteCommand(id); |
| 1217 } |
| 1218 |
1203 void RenderViewContextMenu::ExecuteCommand(int id) { | 1219 void RenderViewContextMenu::ExecuteCommand(int id) { |
1204 // Check to see if one of the spell check language ids have been clicked. | 1220 // Check to see if one of the spell check language ids have been clicked. |
1205 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && | 1221 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && |
1206 id < IDC_SPELLCHECK_LANGUAGES_LAST) { | 1222 id < IDC_SPELLCHECK_LANGUAGES_LAST) { |
1207 const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST; | 1223 const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST; |
1208 std::vector<std::string> languages; | 1224 std::vector<std::string> languages; |
1209 SpellCheckHost::GetSpellCheckLanguages(profile_, &languages); | 1225 SpellCheckHost::GetSpellCheckLanguages(profile_, &languages); |
1210 if (language_number < languages.size()) { | 1226 if (language_number < languages.size()) { |
1211 StringPrefMember dictionary_language; | 1227 StringPrefMember dictionary_language; |
1212 dictionary_language.Init(prefs::kSpellCheckDictionary, | 1228 dictionary_language.Init(prefs::kSpellCheckDictionary, |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 | 1630 |
1615 // Controller functions -------------------------------------------------------- | 1631 // Controller functions -------------------------------------------------------- |
1616 | 1632 |
1617 void RenderViewContextMenu::OpenURL( | 1633 void RenderViewContextMenu::OpenURL( |
1618 const GURL& url, const GURL& referrer, | 1634 const GURL& url, const GURL& referrer, |
1619 WindowOpenDisposition disposition, | 1635 WindowOpenDisposition disposition, |
1620 PageTransition::Type transition) { | 1636 PageTransition::Type transition) { |
1621 source_tab_contents_->OpenURL(url, referrer, disposition, transition); | 1637 source_tab_contents_->OpenURL(url, referrer, disposition, transition); |
1622 } | 1638 } |
1623 | 1639 |
| 1640 void RenderViewContextMenu::GoBack(int event_flags) { |
| 1641 WindowOpenDisposition disposition = |
| 1642 browser::DispositionFromEventFlags(event_flags); |
| 1643 if (source_tab_contents_->delegate()) |
| 1644 source_tab_contents_->delegate()->GoBack(disposition); |
| 1645 } |
| 1646 |
| 1647 void RenderViewContextMenu::GoForward(int event_flags) { |
| 1648 WindowOpenDisposition disposition = |
| 1649 browser::DispositionFromEventFlags(event_flags); |
| 1650 if (source_tab_contents_->delegate()) |
| 1651 source_tab_contents_->delegate()->GoForward(disposition); |
| 1652 } |
| 1653 |
1624 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1654 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
1625 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1655 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
1626 rvh->Send(new ViewMsg_CopyImageAt(rvh->routing_id(), x, y)); | 1656 rvh->Send(new ViewMsg_CopyImageAt(rvh->routing_id(), x, y)); |
1627 } | 1657 } |
1628 | 1658 |
1629 void RenderViewContextMenu::Inspect(int x, int y) { | 1659 void RenderViewContextMenu::Inspect(int x, int y) { |
1630 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement")); | 1660 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement")); |
1631 DevToolsManager::GetInstance()->InspectElement( | 1661 DevToolsManager::GetInstance()->InspectElement( |
1632 source_tab_contents_->render_view_host(), x, y); | 1662 source_tab_contents_->render_view_host(), x, y); |
1633 } | 1663 } |
1634 | 1664 |
1635 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 1665 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
1636 chrome_browser_net::WriteURLToClipboard( | 1666 chrome_browser_net::WriteURLToClipboard( |
1637 url, | 1667 url, |
1638 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1668 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
1639 g_browser_process->clipboard()); | 1669 g_browser_process->clipboard()); |
1640 } | 1670 } |
1641 | 1671 |
1642 void RenderViewContextMenu::MediaPlayerActionAt( | 1672 void RenderViewContextMenu::MediaPlayerActionAt( |
1643 const gfx::Point& location, | 1673 const gfx::Point& location, |
1644 const WebMediaPlayerAction& action) { | 1674 const WebMediaPlayerAction& action) { |
1645 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1675 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
1646 rvh->Send(new ViewMsg_MediaPlayerActionAt( | 1676 rvh->Send(new ViewMsg_MediaPlayerActionAt( |
1647 rvh->routing_id(), location, action)); | 1677 rvh->routing_id(), location, action)); |
1648 } | 1678 } |
OLD | NEW |