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