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

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

Issue 9045007: Allow plugins to participate in Chrome context menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 12 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
OLDNEW
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 #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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "content/browser/tab_contents/navigation_entry.h" 68 #include "content/browser/tab_contents/navigation_entry.h"
69 #include "content/browser/tab_contents/tab_contents.h" 69 #include "content/browser/tab_contents/tab_contents.h"
70 #include "content/public/browser/notification_service.h" 70 #include "content/public/browser/notification_service.h"
71 #include "content/public/browser/user_metrics.h" 71 #include "content/public/browser/user_metrics.h"
72 #include "content/public/common/content_restriction.h" 72 #include "content/public/common/content_restriction.h"
73 #include "grit/generated_resources.h" 73 #include "grit/generated_resources.h"
74 #include "net/base/escape.h" 74 #include "net/base/escape.h"
75 #include "net/base/net_util.h" 75 #include "net/base/net_util.h"
76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction. h" 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction. h"
78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
78 #include "ui/base/l10n/l10n_util.h" 79 #include "ui/base/l10n/l10n_util.h"
79 #include "ui/base/text/text_elider.h" 80 #include "ui/base/text/text_elider.h"
80 #include "ui/gfx/favicon_size.h" 81 #include "ui/gfx/favicon_size.h"
81 #include "webkit/glue/webmenuitem.h" 82 #include "webkit/glue/webmenuitem.h"
82 83
83 #ifdef FILE_MANAGER_EXTENSION 84 #ifdef FILE_MANAGER_EXTENSION
84 #include "chrome/browser/extensions/file_manager_util.h" 85 #include "chrome/browser/extensions/file_manager_util.h"
85 #endif 86 #endif
86 87
87 using content::UserMetricsAction; 88 using content::UserMetricsAction;
88 using WebKit::WebContextMenuData; 89 using WebKit::WebContextMenuData;
89 using WebKit::WebMediaPlayerAction; 90 using WebKit::WebMediaPlayerAction;
91 using WebKit::WebPluginAction;
90 using WebKit::WebURL; 92 using WebKit::WebURL;
91 using WebKit::WebString; 93 using WebKit::WebString;
92 94
93 namespace { 95 namespace {
94 96
95 // Usually a new tab is expected where this function is used, 97 // Usually a new tab is expected where this function is used,
96 // however users should be able to open a tab in background 98 // however users should be able to open a tab in background
97 // or in a new window. 99 // or in a new window.
98 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( 100 WindowOpenDisposition ForceNewTabDispositionFromEventFlags(
99 int event_flags) { 101 int event_flags) {
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 void RenderViewContextMenu::AppendPluginItems() { 778 void RenderViewContextMenu::AppendPluginItems() {
777 if (params_.page_url == params_.src_url) { 779 if (params_.page_url == params_.src_url) {
778 // Full page plugin, so show page menu items. 780 // Full page plugin, so show page menu items.
779 if (params_.link_url.is_empty() && params_.selection_text.empty()) 781 if (params_.link_url.is_empty() && params_.selection_text.empty())
780 AppendPageItems(); 782 AppendPageItems();
781 } else { 783 } else {
782 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, 784 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS,
783 IDS_CONTENT_CONTEXT_SAVEPAGEAS); 785 IDS_CONTENT_CONTEXT_SAVEPAGEAS);
784 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); 786 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT);
785 } 787 }
788
789 if (params_.plugin_flags & WebContextMenuData::PluginCanFitPage) {
790 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_FITPAGEWIDTH,
791 IDS_CONTENT_CONTEXT_FITPAGEWIDTH);
792 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_FITPAGEHEIGHT,
793 IDS_CONTENT_CONTEXT_FITPAGEHEIGHT);
794 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_FITPAGE,
795 IDS_CONTENT_CONTEXT_FITPAGE);
796 }
797 if (params_.plugin_flags & WebContextMenuData::PluginCanRotatePage) {
798 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATEPAGECW,
799 IDS_CONTENT_CONTEXT_ROTATEPAGECW);
800 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATEPAGECCW,
801 IDS_CONTENT_CONTEXT_ROTATEPAGECCW);
802 }
786 } 803 }
787 804
788 void RenderViewContextMenu::AppendPageItems() { 805 void RenderViewContextMenu::AppendPageItems() {
789 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); 806 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK);
790 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); 807 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD);
791 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); 808 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD);
792 menu_model_.AddSeparator(); 809 menu_model_.AddSeparator();
793 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, 810 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE,
794 IDS_CONTENT_CONTEXT_SAVEPAGEAS); 811 IDS_CONTENT_CONTEXT_SAVEPAGEAS);
795 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); 812 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 return true; 1278 return true;
1262 #elif defined(OS_POSIX) 1279 #elif defined(OS_POSIX)
1263 // TODO(suzhe): this should not be enabled for password fields. 1280 // TODO(suzhe): this should not be enabled for password fields.
1264 case IDC_INPUT_METHODS_MENU: 1281 case IDC_INPUT_METHODS_MENU:
1265 return true; 1282 return true;
1266 #endif 1283 #endif
1267 1284
1268 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: 1285 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE:
1269 return !params_.keyword_url.is_empty(); 1286 return !params_.keyword_url.is_empty();
1270 1287
1288 case IDC_CONTENT_CONTEXT_FITPAGEWIDTH:
1289 case IDC_CONTENT_CONTEXT_FITPAGEHEIGHT:
1290 case IDC_CONTENT_CONTEXT_FITPAGE:
1291 return
1292 (params_.plugin_flags & WebContextMenuData::PluginCanFitPage) != 0;
1293
1294 case IDC_CONTENT_CONTEXT_ROTATEPAGECW:
1295 case IDC_CONTENT_CONTEXT_ROTATEPAGECCW:
1296 return
1297 (params_.plugin_flags & WebContextMenuData::PluginCanRotatePage) != 0;
1298
1271 case IDC_SPELLCHECK_MENU: 1299 case IDC_SPELLCHECK_MENU:
1272 return true; 1300 return true;
1273 1301
1274 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES: 1302 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES:
1275 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: 1303 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT:
1276 case IDC_SPEECH_INPUT_MENU: 1304 case IDC_SPEECH_INPUT_MENU:
1277 return true; 1305 return true;
1278 1306
1279 case IDC_CONTENT_CONTEXT_OPENLINKWITH: 1307 case IDC_CONTENT_CONTEXT_OPENLINKWITH:
1280 return true; 1308 return true;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 1538
1511 case IDC_CONTENT_CONTEXT_CONTROLS: 1539 case IDC_CONTENT_CONTEXT_CONTROLS:
1512 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls")); 1540 content::RecordAction(UserMetricsAction("MediaContextMenu_Controls"));
1513 MediaPlayerActionAt( 1541 MediaPlayerActionAt(
1514 gfx::Point(params_.x, params_.y), 1542 gfx::Point(params_.x, params_.y),
1515 WebMediaPlayerAction( 1543 WebMediaPlayerAction(
1516 WebMediaPlayerAction::Controls, 1544 WebMediaPlayerAction::Controls,
1517 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS))); 1545 !IsCommandIdChecked(IDC_CONTENT_CONTEXT_CONTROLS)));
1518 break; 1546 break;
1519 1547
1548 case IDC_CONTENT_CONTEXT_FITPAGEWIDTH:
1549 content::RecordAction(
1550 UserMetricsAction("PluginContextMenu_FitPageWidth"));
1551 PluginAction(WebPluginAction(WebPluginAction::FitPageWidth));
1552 break;
1553
1554 case IDC_CONTENT_CONTEXT_FITPAGEHEIGHT:
1555 content::RecordAction(
1556 UserMetricsAction("PluginContextMenu_FitPageHeight"));
1557 PluginAction(WebPluginAction(WebPluginAction::FitPageHeight));
1558 break;
1559
1560 case IDC_CONTENT_CONTEXT_FITPAGE:
1561 content::RecordAction(
1562 UserMetricsAction("PluginContextMenu_FitPage"));
1563 PluginAction(WebPluginAction(WebPluginAction::FitPage));
1564 break;
1565
1566 case IDC_CONTENT_CONTEXT_ROTATEPAGECW:
1567 content::RecordAction(
1568 UserMetricsAction("PluginContextMenu_RotatePageCW"));
1569 PluginAction(WebPluginAction(WebPluginAction::RotatePageCW));
1570 break;
1571
1572 case IDC_CONTENT_CONTEXT_ROTATEPAGECCW:
1573 content::RecordAction(
1574 UserMetricsAction("PluginContextMenu_RotatePageCCW"));
1575 PluginAction(WebPluginAction(WebPluginAction::RotatePageCCW));
1576 break;
1577
1520 case IDC_BACK: 1578 case IDC_BACK:
1521 source_tab_contents_->controller().GoBack(); 1579 source_tab_contents_->controller().GoBack();
1522 break; 1580 break;
1523 1581
1524 case IDC_FORWARD: 1582 case IDC_FORWARD:
1525 source_tab_contents_->controller().GoForward(); 1583 source_tab_contents_->controller().GoForward();
1526 break; 1584 break;
1527 1585
1528 case IDC_SAVE_PAGE: 1586 case IDC_SAVE_PAGE:
1529 source_tab_contents_->OnSavePage(); 1587 source_tab_contents_->OnSavePage();
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1917 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1860 g_browser_process->clipboard()); 1918 g_browser_process->clipboard());
1861 } 1919 }
1862 1920
1863 void RenderViewContextMenu::MediaPlayerActionAt( 1921 void RenderViewContextMenu::MediaPlayerActionAt(
1864 const gfx::Point& location, 1922 const gfx::Point& location,
1865 const WebMediaPlayerAction& action) { 1923 const WebMediaPlayerAction& action) {
1866 source_tab_contents_->render_view_host()-> 1924 source_tab_contents_->render_view_host()->
1867 ExecuteMediaPlayerActionAtLocation(location, action); 1925 ExecuteMediaPlayerActionAtLocation(location, action);
1868 } 1926 }
1927
1928 void RenderViewContextMenu::PluginAction(const WebPluginAction& action) {
1929 source_tab_contents_->render_view_host()->ExecutePluginAction(action);
1930 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698