OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 break; | 392 break; |
393 case WebContextMenuData::MediaTypeImage: | 393 case WebContextMenuData::MediaTypeImage: |
394 AppendImageItems(); | 394 AppendImageItems(); |
395 break; | 395 break; |
396 case WebContextMenuData::MediaTypeVideo: | 396 case WebContextMenuData::MediaTypeVideo: |
397 AppendVideoItems(); | 397 AppendVideoItems(); |
398 break; | 398 break; |
399 case WebContextMenuData::MediaTypeAudio: | 399 case WebContextMenuData::MediaTypeAudio: |
400 AppendAudioItems(); | 400 AppendAudioItems(); |
401 break; | 401 break; |
| 402 case WebContextMenuData::MediaTypePlugin: |
| 403 AppendPluginItems(); |
| 404 break; |
402 } | 405 } |
403 | 406 |
404 if (params_.is_editable) | 407 if (params_.is_editable) |
405 AppendEditableItems(); | 408 AppendEditableItems(); |
406 else if (has_selection) | 409 else if (has_selection) |
407 AppendCopyItem(); | 410 AppendCopyItem(); |
408 | 411 |
409 if (has_selection) | 412 if (has_selection) |
410 AppendSearchProvider(); | 413 AppendSearchProvider(); |
411 | 414 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 media_flags & WebContextMenuData::MediaMuted ? | 520 media_flags & WebContextMenuData::MediaMuted ? |
518 IDS_CONTENT_CONTEXT_UNMUTE : | 521 IDS_CONTENT_CONTEXT_UNMUTE : |
519 IDS_CONTENT_CONTEXT_MUTE); | 522 IDS_CONTENT_CONTEXT_MUTE); |
520 | 523 |
521 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_LOOP, | 524 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_LOOP, |
522 IDS_CONTENT_CONTEXT_LOOP); | 525 IDS_CONTENT_CONTEXT_LOOP); |
523 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_CONTROLS, | 526 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_CONTROLS, |
524 IDS_CONTENT_CONTEXT_CONTROLS); | 527 IDS_CONTENT_CONTEXT_CONTROLS); |
525 } | 528 } |
526 | 529 |
| 530 void RenderViewContextMenu::AppendPluginItems() { |
| 531 if (params_.page_url == params_.src_url) { |
| 532 // Full page plugin, so show page menu items. |
| 533 if (params_.link_url.is_empty() && params_.selection_text.empty()) |
| 534 AppendPageItems(); |
| 535 } else { |
| 536 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
| 537 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
| 538 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 539 } |
| 540 } |
| 541 |
527 void RenderViewContextMenu::AppendPageItems() { | 542 void RenderViewContextMenu::AppendPageItems() { |
528 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); | 543 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); |
529 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); | 544 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); |
530 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 545 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
531 menu_model_.AddSeparator(); | 546 menu_model_.AddSeparator(); |
532 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, | 547 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, |
533 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 548 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
534 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 549 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
535 | 550 |
536 std::string locale = g_browser_process->GetApplicationLocale(); | 551 std::string locale = g_browser_process->GetApplicationLocale(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 case IDC_CONTENT_CONTEXT_SELECTALL: | 943 case IDC_CONTENT_CONTEXT_SELECTALL: |
929 return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); | 944 return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); |
930 | 945 |
931 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: | 946 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: |
932 return !profile_->IsOffTheRecord() && params_.link_url.is_valid(); | 947 return !profile_->IsOffTheRecord() && params_.link_url.is_valid(); |
933 | 948 |
934 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: | 949 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: |
935 return !params_.misspelled_word.empty(); | 950 return !params_.misspelled_word.empty(); |
936 | 951 |
937 case IDC_PRINT: | 952 case IDC_PRINT: |
| 953 return params_.media_type == WebContextMenuData::MediaTypeNone || |
| 954 params_.media_flags & WebContextMenuData::MediaCanPrint; |
| 955 |
938 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: | 956 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: |
939 case IDC_CONTENT_CONTEXT_GOTOURL: | 957 case IDC_CONTENT_CONTEXT_GOTOURL: |
940 case IDC_SPELLCHECK_SUGGESTION_0: | 958 case IDC_SPELLCHECK_SUGGESTION_0: |
941 case IDC_SPELLCHECK_SUGGESTION_1: | 959 case IDC_SPELLCHECK_SUGGESTION_1: |
942 case IDC_SPELLCHECK_SUGGESTION_2: | 960 case IDC_SPELLCHECK_SUGGESTION_2: |
943 case IDC_SPELLCHECK_SUGGESTION_3: | 961 case IDC_SPELLCHECK_SUGGESTION_3: |
944 case IDC_SPELLCHECK_SUGGESTION_4: | 962 case IDC_SPELLCHECK_SUGGESTION_4: |
945 case IDC_SPELLPANEL_TOGGLE: | 963 case IDC_SPELLPANEL_TOGGLE: |
946 #if !defined(OS_MACOSX) | 964 #if !defined(OS_MACOSX) |
947 // TODO(jeremy): re-enable - http://crbug.com/34512 . | 965 // TODO(jeremy): re-enable - http://crbug.com/34512 . |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 source_tab_contents_->OnSavePage(); | 1223 source_tab_contents_->OnSavePage(); |
1206 break; | 1224 break; |
1207 | 1225 |
1208 case IDC_RELOAD: | 1226 case IDC_RELOAD: |
1209 // Prevent the modal "Resubmit form post" dialog from appearing in the | 1227 // Prevent the modal "Resubmit form post" dialog from appearing in the |
1210 // context of an external context menu. | 1228 // context of an external context menu. |
1211 source_tab_contents_->controller().Reload(!external_); | 1229 source_tab_contents_->controller().Reload(!external_); |
1212 break; | 1230 break; |
1213 | 1231 |
1214 case IDC_PRINT: | 1232 case IDC_PRINT: |
1215 source_tab_contents_->PrintPreview(); | 1233 if (params_.media_type == WebContextMenuData::MediaTypeNone) { |
| 1234 source_tab_contents_->PrintPreview(); |
| 1235 } else { |
| 1236 source_tab_contents_->render_view_host()->PrintNodeUnderContextMenu(); |
| 1237 } |
1216 break; | 1238 break; |
1217 | 1239 |
1218 case IDC_VIEW_SOURCE: | 1240 case IDC_VIEW_SOURCE: |
1219 source_tab_contents_->ViewSource(); | 1241 source_tab_contents_->ViewSource(); |
1220 break; | 1242 break; |
1221 | 1243 |
1222 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: | 1244 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: |
1223 Inspect(params_.x, params_.y); | 1245 Inspect(params_.x, params_.y); |
1224 break; | 1246 break; |
1225 | 1247 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 LookUpInDictionary(); | 1391 LookUpInDictionary(); |
1370 break; | 1392 break; |
1371 #endif // OS_MACOSX | 1393 #endif // OS_MACOSX |
1372 | 1394 |
1373 default: | 1395 default: |
1374 NOTREACHED(); | 1396 NOTREACHED(); |
1375 break; | 1397 break; |
1376 } | 1398 } |
1377 } | 1399 } |
1378 | 1400 |
| 1401 void RenderViewContextMenu::MenuClosed() { |
| 1402 source_tab_contents_->render_view_host()->ContextMenuClosed(); |
| 1403 } |
| 1404 |
1379 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { | 1405 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
1380 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1406 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
1381 if (command_line.HasSwitch(switches::kAlwaysEnableDevTools)) | 1407 if (command_line.HasSwitch(switches::kAlwaysEnableDevTools)) |
1382 return true; | 1408 return true; |
1383 | 1409 |
1384 NavigationEntry *active_entry = | 1410 NavigationEntry *active_entry = |
1385 source_tab_contents_->controller().GetActiveEntry(); | 1411 source_tab_contents_->controller().GetActiveEntry(); |
1386 if (!active_entry) | 1412 if (!active_entry) |
1387 return false; | 1413 return false; |
1388 | 1414 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1477 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
1452 g_browser_process->clipboard()); | 1478 g_browser_process->clipboard()); |
1453 } | 1479 } |
1454 | 1480 |
1455 void RenderViewContextMenu::MediaPlayerActionAt( | 1481 void RenderViewContextMenu::MediaPlayerActionAt( |
1456 const gfx::Point& location, | 1482 const gfx::Point& location, |
1457 const WebMediaPlayerAction& action) { | 1483 const WebMediaPlayerAction& action) { |
1458 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1484 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
1459 location, action); | 1485 location, action); |
1460 } | 1486 } |
OLD | NEW |