OLD | NEW |
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 "chrome/browser/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 case WebContextMenuData::MediaTypeFile: | 480 case WebContextMenuData::MediaTypeFile: |
481 break; | 481 break; |
482 #endif | 482 #endif |
483 } | 483 } |
484 | 484 |
485 if (params_.is_editable) | 485 if (params_.is_editable) |
486 AppendEditableItems(); | 486 AppendEditableItems(); |
487 else if (has_selection) | 487 else if (has_selection) |
488 AppendCopyItem(); | 488 AppendCopyItem(); |
489 | 489 |
490 if (has_selection) | 490 if (has_selection) { |
| 491 AppendPrintItem(); |
491 AppendSearchProvider(); | 492 AppendSearchProvider(); |
| 493 } |
492 | 494 |
493 if (!IsDevToolsURL(params_.page_url)) | 495 if (!IsDevToolsURL(params_.page_url)) |
494 AppendAllExtensionItems(); | 496 AppendAllExtensionItems(); |
495 | 497 |
496 AppendDeveloperItems(); | 498 AppendDeveloperItems(); |
497 | 499 |
498 if (!print_preview_menu_observer_.get()) { | 500 if (!print_preview_menu_observer_.get()) { |
499 print_preview_menu_observer_.reset( | 501 print_preview_menu_observer_.reset( |
500 new PrintPreviewContextMenuObserver(source_web_contents_)); | 502 new PrintPreviewContextMenuObserver(source_web_contents_)); |
501 } | 503 } |
(...skipping 23 matching lines...) Expand all Loading... |
525 bool has_selection = !params_.selection_text.empty(); | 527 bool has_selection = !params_.selection_text.empty(); |
526 | 528 |
527 // Add undo/redo, cut/copy/paste etc for text fields. | 529 // Add undo/redo, cut/copy/paste etc for text fields. |
528 if (params_.is_editable) | 530 if (params_.is_editable) |
529 AppendEditableItems(); | 531 AppendEditableItems(); |
530 else if (has_selection) | 532 else if (has_selection) |
531 AppendCopyItem(); | 533 AppendCopyItem(); |
532 | 534 |
533 int index = 0; | 535 int index = 0; |
534 extension_items_.AppendExtensionItems(platform_app->id(), | 536 extension_items_.AppendExtensionItems(platform_app->id(), |
535 PrintableSelectionText(), &index); | 537 PrintableSelectionText(), &index); |
536 | 538 |
537 // Add dev tools for unpacked extensions. | 539 // Add dev tools for unpacked extensions. |
538 if (platform_app->location() == extensions::Manifest::LOAD || | 540 if (platform_app->location() == extensions::Manifest::LOAD || |
539 CommandLine::ForCurrentProcess()->HasSwitch( | 541 CommandLine::ForCurrentProcess()->HasSwitch( |
540 switches::kDebugPackedApps)) { | 542 switches::kDebugPackedApps)) { |
541 // Add a separator if there are any items already in the menu. | 543 // Add a separator if there are any items already in the menu. |
542 if (menu_model_.GetItemCount() && | 544 if (menu_model_.GetItemCount() && |
543 menu_model_.GetTypeAt(menu_model_.GetItemCount() - 1) != | 545 menu_model_.GetTypeAt(menu_model_.GetItemCount() - 1) != |
544 ui::MenuModel::TYPE_SEPARATOR) | 546 ui::MenuModel::TYPE_SEPARATOR) |
545 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 547 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMEINFO, | 800 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMEINFO, |
799 IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); | 801 IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); |
800 } | 802 } |
801 } | 803 } |
802 | 804 |
803 void RenderViewContextMenu::AppendCopyItem() { | 805 void RenderViewContextMenu::AppendCopyItem() { |
804 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, | 806 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, |
805 IDS_CONTENT_CONTEXT_COPY); | 807 IDS_CONTENT_CONTEXT_COPY); |
806 } | 808 } |
807 | 809 |
| 810 void RenderViewContextMenu::AppendPrintItem() { |
| 811 if (profile_->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && |
| 812 (params_.media_type == WebContextMenuData::MediaTypeNone || |
| 813 params_.media_flags & WebContextMenuData::MediaCanPrint)) { |
| 814 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 815 } |
| 816 } |
| 817 |
808 void RenderViewContextMenu::AppendSearchProvider() { | 818 void RenderViewContextMenu::AppendSearchProvider() { |
809 DCHECK(profile_); | 819 DCHECK(profile_); |
810 | 820 |
811 TrimWhitespace(params_.selection_text, TRIM_ALL, ¶ms_.selection_text); | 821 TrimWhitespace(params_.selection_text, TRIM_ALL, ¶ms_.selection_text); |
812 if (params_.selection_text.empty()) | 822 if (params_.selection_text.empty()) |
813 return; | 823 return; |
814 | 824 |
815 ReplaceChars(params_.selection_text, AutocompleteMatch::kInvalidChars, | 825 ReplaceChars(params_.selection_text, AutocompleteMatch::kInvalidChars, |
816 ASCIIToUTF16(" "), ¶ms_.selection_text); | 826 ASCIIToUTF16(" "), ¶ms_.selection_text); |
817 | 827 |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 | 1566 |
1557 case IDC_PRINT: | 1567 case IDC_PRINT: |
1558 if (params_.media_type == WebContextMenuData::MediaTypeNone) { | 1568 if (params_.media_type == WebContextMenuData::MediaTypeNone) { |
1559 printing::PrintViewManager* print_view_manager = | 1569 printing::PrintViewManager* print_view_manager = |
1560 printing::PrintViewManager::FromWebContents(source_web_contents_); | 1570 printing::PrintViewManager::FromWebContents(source_web_contents_); |
1561 if (!print_view_manager) | 1571 if (!print_view_manager) |
1562 break; | 1572 break; |
1563 if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { | 1573 if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { |
1564 print_view_manager->PrintNow(); | 1574 print_view_manager->PrintNow(); |
1565 } else { | 1575 } else { |
1566 print_view_manager->PrintPreviewNow(); | 1576 print_view_manager->PrintPreviewNow(!params_.selection_text.empty()); |
1567 } | 1577 } |
1568 } else { | 1578 } else { |
1569 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID())); | 1579 rvh->Send(new PrintMsg_PrintNodeUnderContextMenu(rvh->GetRoutingID())); |
1570 } | 1580 } |
1571 break; | 1581 break; |
1572 | 1582 |
1573 case IDC_VIEW_SOURCE: | 1583 case IDC_VIEW_SOURCE: |
1574 source_web_contents_->ViewSource(); | 1584 source_web_contents_->ViewSource(); |
1575 break; | 1585 break; |
1576 | 1586 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 source_web_contents_->GetRenderViewHost()-> | 1876 source_web_contents_->GetRenderViewHost()-> |
1867 ExecuteMediaPlayerActionAtLocation(location, action); | 1877 ExecuteMediaPlayerActionAtLocation(location, action); |
1868 } | 1878 } |
1869 | 1879 |
1870 void RenderViewContextMenu::PluginActionAt( | 1880 void RenderViewContextMenu::PluginActionAt( |
1871 const gfx::Point& location, | 1881 const gfx::Point& location, |
1872 const WebPluginAction& action) { | 1882 const WebPluginAction& action) { |
1873 source_web_contents_->GetRenderViewHost()-> | 1883 source_web_contents_->GetRenderViewHost()-> |
1874 ExecutePluginActionAtLocation(location, action); | 1884 ExecutePluginActionAtLocation(location, action); |
1875 } | 1885 } |
OLD | NEW |