| 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 <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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (page_url.SchemeIs("chrome-extension") && | 220 if (page_url.SchemeIs("chrome-extension") && |
| 221 page_url.DomainIs(kFileBrowserDomain)) | 221 page_url.DomainIs(kFileBrowserDomain)) |
| 222 return false; | 222 return false; |
| 223 #endif | 223 #endif |
| 224 | 224 |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 } // namespace | 227 } // namespace |
| 228 | 228 |
| 229 // static | 229 // static |
| 230 const size_t RenderViewContextMenu::kMaxExtensionItemTitleLength = 75; | |
| 231 // static | |
| 232 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; | 230 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; |
| 233 | 231 |
| 234 // static | 232 // static |
| 235 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { | 233 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { |
| 236 return url.SchemeIs(chrome::kChromeDevToolsScheme) && | 234 return url.SchemeIs(chrome::kChromeDevToolsScheme) && |
| 237 url.host() == chrome::kChromeUIDevToolsHost; | 235 url.host() == chrome::kChromeUIDevToolsHost; |
| 238 } | 236 } |
| 239 | 237 |
| 240 // static | 238 // static |
| 241 bool RenderViewContextMenu::IsInternalResourcesURL(const GURL& url) { | 239 bool RenderViewContextMenu::IsInternalResourcesURL(const GURL& url) { |
| 242 if (!url.SchemeIs(chrome::kChromeUIScheme)) | 240 if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 243 return false; | 241 return false; |
| 244 return url.host() == chrome::kChromeUISyncResourcesHost; | 242 return url.host() == chrome::kChromeUISyncResourcesHost; |
| 245 } | 243 } |
| 246 | 244 |
| 247 static const int kSpellcheckRadioGroup = 1; | 245 static const int kSpellcheckRadioGroup = 1; |
| 248 | 246 |
| 249 RenderViewContextMenu::RenderViewContextMenu( | 247 RenderViewContextMenu::RenderViewContextMenu( |
| 250 WebContents* web_contents, | 248 WebContents* web_contents, |
| 251 const content::ContextMenuParams& params) | 249 const content::ContextMenuParams& params) |
| 252 : params_(params), | 250 : params_(params), |
| 253 source_web_contents_(web_contents), | 251 source_web_contents_(web_contents), |
| 254 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 252 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 255 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), | 253 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), |
| 254 extension_items_(profile_, this, &menu_model_, |
| 255 base::Bind(MenuItemMatchesParams, params_)), |
| 256 external_(false), | 256 external_(false), |
| 257 ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)), | 257 ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)), |
| 258 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), | 258 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), |
| 259 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), | 259 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), |
| 260 protocol_handler_registry_(profile_->GetProtocolHandlerRegistry()) { | 260 protocol_handler_registry_(profile_->GetProtocolHandlerRegistry()) { |
| 261 } | 261 } |
| 262 | 262 |
| 263 RenderViewContextMenu::~RenderViewContextMenu() { | 263 RenderViewContextMenu::~RenderViewContextMenu() { |
| 264 } | 264 } |
| 265 | 265 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 contexts.Contains(MenuItem::PAGE)) | 332 contexts.Contains(MenuItem::PAGE)) |
| 333 return true; | 333 return true; |
| 334 | 334 |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 | 337 |
| 338 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { | 338 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { |
| 339 return params.frame_url.is_empty() ? params.page_url : params.frame_url; | 339 return params.frame_url.is_empty() ? params.page_url : params.frame_url; |
| 340 } | 340 } |
| 341 | 341 |
| 342 // Given a list of items, returns the ones that match given the contents | |
| 343 // of |params| and the profile. | |
| 344 // static | 342 // static |
| 345 MenuItem::List RenderViewContextMenu::GetRelevantExtensionItems( | 343 bool RenderViewContextMenu::MenuItemMatchesParams( |
| 346 const MenuItem::List& items, | |
| 347 const content::ContextMenuParams& params, | 344 const content::ContextMenuParams& params, |
| 348 Profile* profile, | 345 const extensions::MenuItem* item) { |
| 349 bool can_cross_incognito) { | 346 bool match = ExtensionContextAndPatternMatch(params, item->contexts(), |
| 350 MenuItem::List result; | 347 item->target_url_patterns()); |
| 351 for (MenuItem::List::const_iterator i = items.begin(); | 348 if (!match) |
| 352 i != items.end(); ++i) { | 349 return false; |
| 353 const MenuItem* item = *i; | |
| 354 | 350 |
| 355 if (!ExtensionContextAndPatternMatch(params, item->contexts(), | 351 const GURL& document_url = GetDocumentURL(params); |
| 356 item->target_url_patterns())) | 352 return ExtensionPatternMatch(item->document_url_patterns(), document_url); |
| 357 continue; | |
| 358 | |
| 359 const GURL& document_url = GetDocumentURL(params); | |
| 360 if (!ExtensionPatternMatch(item->document_url_patterns(), document_url)) | |
| 361 continue; | |
| 362 | |
| 363 if (item->id().incognito == profile->IsOffTheRecord() || | |
| 364 can_cross_incognito) | |
| 365 result.push_back(*i); | |
| 366 } | |
| 367 return result; | |
| 368 } | |
| 369 | |
| 370 void RenderViewContextMenu::AppendExtensionItems( | |
| 371 const std::string& extension_id, int* index) { | |
| 372 ExtensionService* service = profile_->GetExtensionService(); | |
| 373 MenuManager* manager = service->menu_manager(); | |
| 374 const Extension* extension = service->GetExtensionById(extension_id, false); | |
| 375 DCHECK_GE(*index, 0); | |
| 376 int max_index = | |
| 377 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | |
| 378 if (!extension || *index >= max_index) | |
| 379 return; | |
| 380 | |
| 381 // Find matching items. | |
| 382 const MenuItem::List* all_items = manager->MenuItems(extension_id); | |
| 383 if (!all_items || all_items->empty()) | |
| 384 return; | |
| 385 bool can_cross_incognito = service->CanCrossIncognito(extension); | |
| 386 MenuItem::List items = | |
| 387 GetRelevantExtensionItems(*all_items, params_, profile_, | |
| 388 can_cross_incognito); | |
| 389 if (items.empty()) | |
| 390 return; | |
| 391 | |
| 392 // If this is the first extension-provided menu item, and there are other | |
| 393 // items in the menu, add a separator. | |
| 394 if (*index == 0 && menu_model_.GetItemCount()) | |
| 395 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 396 | |
| 397 // Extensions (other than platform apps) are only allowed one top-level slot | |
| 398 // (and it can't be a radio or checkbox item because we are going to put the | |
| 399 // extension icon next to it). | |
| 400 // If they have more than that, we automatically push them into a submenu. | |
| 401 if (extension->is_platform_app()) { | |
| 402 RecursivelyAppendExtensionItems(items, can_cross_incognito, &menu_model_, | |
| 403 index); | |
| 404 } else { | |
| 405 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | |
| 406 string16 title; | |
| 407 MenuItem::List submenu_items; | |
| 408 | |
| 409 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { | |
| 410 title = UTF8ToUTF16(extension->name()); | |
| 411 submenu_items = items; | |
| 412 } else { | |
| 413 MenuItem* item = items[0]; | |
| 414 extension_item_map_[menu_id] = item->id(); | |
| 415 title = item->TitleWithReplacement(PrintableSelectionText(), | |
| 416 kMaxExtensionItemTitleLength); | |
| 417 submenu_items = GetRelevantExtensionItems(item->children(), params_, | |
| 418 profile_, can_cross_incognito); | |
| 419 } | |
| 420 | |
| 421 // Now add our item(s) to the menu_model_. | |
| 422 if (submenu_items.empty()) { | |
| 423 menu_model_.AddItem(menu_id, title); | |
| 424 } else { | |
| 425 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | |
| 426 extension_menu_models_.push_back(submenu); | |
| 427 menu_model_.AddSubMenu(menu_id, title, submenu); | |
| 428 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, | |
| 429 submenu, index); | |
| 430 } | |
| 431 SetExtensionIcon(extension_id); | |
| 432 } | |
| 433 } | |
| 434 | |
| 435 void RenderViewContextMenu::RecursivelyAppendExtensionItems( | |
| 436 const MenuItem::List& items, | |
| 437 bool can_cross_incognito, | |
| 438 ui::SimpleMenuModel* menu_model, | |
| 439 int* index) { | |
| 440 string16 selection_text = PrintableSelectionText(); | |
| 441 MenuItem::Type last_type = MenuItem::NORMAL; | |
| 442 int radio_group_id = 1; | |
| 443 | |
| 444 for (MenuItem::List::const_iterator i = items.begin(); | |
| 445 i != items.end(); ++i) { | |
| 446 MenuItem* item = *i; | |
| 447 | |
| 448 // If last item was of type radio but the current one isn't, auto-insert | |
| 449 // a separator. The converse case is handled below. | |
| 450 if (last_type == MenuItem::RADIO && | |
| 451 item->type() != MenuItem::RADIO) { | |
| 452 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 453 last_type = MenuItem::SEPARATOR; | |
| 454 } | |
| 455 | |
| 456 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | |
| 457 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) | |
| 458 return; | |
| 459 extension_item_map_[menu_id] = item->id(); | |
| 460 string16 title = item->TitleWithReplacement(selection_text, | |
| 461 kMaxExtensionItemTitleLength); | |
| 462 if (item->type() == MenuItem::NORMAL) { | |
| 463 MenuItem::List children = | |
| 464 GetRelevantExtensionItems(item->children(), params_, | |
| 465 profile_, can_cross_incognito); | |
| 466 if (children.empty()) { | |
| 467 menu_model->AddItem(menu_id, title); | |
| 468 } else { | |
| 469 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | |
| 470 extension_menu_models_.push_back(submenu); | |
| 471 menu_model->AddSubMenu(menu_id, title, submenu); | |
| 472 RecursivelyAppendExtensionItems(children, can_cross_incognito, | |
| 473 submenu, index); | |
| 474 } | |
| 475 } else if (item->type() == MenuItem::CHECKBOX) { | |
| 476 menu_model->AddCheckItem(menu_id, title); | |
| 477 } else if (item->type() == MenuItem::RADIO) { | |
| 478 if (i != items.begin() && | |
| 479 last_type != MenuItem::RADIO) { | |
| 480 radio_group_id++; | |
| 481 | |
| 482 // Auto-append a separator if needed. | |
| 483 if (last_type != MenuItem::SEPARATOR) | |
| 484 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 485 } | |
| 486 | |
| 487 menu_model->AddRadioItem(menu_id, title, radio_group_id); | |
| 488 } else if (item->type() == MenuItem::SEPARATOR) { | |
| 489 if (i != items.begin() && last_type != MenuItem::SEPARATOR) { | |
| 490 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 491 } | |
| 492 } | |
| 493 last_type = item->type(); | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { | |
| 498 ExtensionService* service = profile_->GetExtensionService(); | |
| 499 MenuManager* menu_manager = service->menu_manager(); | |
| 500 | |
| 501 int index = menu_model_.GetItemCount() - 1; | |
| 502 DCHECK_GE(index, 0); | |
| 503 | |
| 504 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | |
| 505 DCHECK(icon.width() == gfx::kFaviconSize); | |
| 506 DCHECK(icon.height() == gfx::kFaviconSize); | |
| 507 | |
| 508 menu_model_.SetIcon(index, gfx::Image(icon)); | |
| 509 } | 353 } |
| 510 | 354 |
| 511 void RenderViewContextMenu::AppendAllExtensionItems() { | 355 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 512 extension_item_map_.clear(); | 356 extension_items_.Clear(); |
| 513 ExtensionService* service = profile_->GetExtensionService(); | 357 ExtensionService* service = profile_->GetExtensionService(); |
| 514 if (!service) | 358 if (!service) |
| 515 return; // In unit-tests, we may not have an ExtensionService. | 359 return; // In unit-tests, we may not have an ExtensionService. |
| 516 MenuManager* menu_manager = service->menu_manager(); | 360 MenuManager* menu_manager = service->menu_manager(); |
| 517 | 361 |
| 518 // Get a list of extension id's that have context menu items, and sort it by | 362 // Get a list of extension id's that have context menu items, and sort it by |
| 519 // the extension's name. | 363 // the extension's name. |
| 520 std::set<std::string> ids = menu_manager->ExtensionIds(); | 364 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 521 std::vector<std::pair<std::string, std::string> > sorted_ids; | 365 std::vector<std::pair<std::string, std::string> > sorted_ids; |
| 522 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 366 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 523 const Extension* extension = service->GetExtensionById(*i, false); | 367 const Extension* extension = service->GetExtensionById(*i, false); |
| 524 // Platform apps have their context menus created directly in | 368 // Platform apps have their context menus created directly in |
| 525 // AppendPlatformAppItems. | 369 // AppendPlatformAppItems. |
| 526 if (extension && !extension->is_platform_app()) | 370 if (extension && !extension->is_platform_app()) |
| 527 sorted_ids.push_back( | 371 sorted_ids.push_back( |
| 528 std::pair<std::string, std::string>(extension->name(), *i)); | 372 std::pair<std::string, std::string>(extension->name(), *i)); |
| 529 } | 373 } |
| 530 // TODO(asargent) - See if this works properly for i18n names (bug 32363). | 374 // TODO(asargent) - See if this works properly for i18n names (bug 32363). |
| 531 std::sort(sorted_ids.begin(), sorted_ids.end()); | 375 std::sort(sorted_ids.begin(), sorted_ids.end()); |
| 532 | 376 |
| 533 if (sorted_ids.empty()) | 377 if (sorted_ids.empty()) |
| 534 return; | 378 return; |
| 535 | 379 |
| 536 int index = 0; | 380 int index = 0; |
| 537 base::TimeTicks begin = base::TimeTicks::Now(); | 381 base::TimeTicks begin = base::TimeTicks::Now(); |
| 538 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 382 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
| 539 for (i = sorted_ids.begin(); | 383 for (i = sorted_ids.begin(); |
| 540 i != sorted_ids.end(); ++i) { | 384 i != sorted_ids.end(); ++i) { |
| 541 AppendExtensionItems(i->second, &index); | 385 extension_items_.AppendExtensionItems(i->second, PrintableSelectionText(), |
| 386 &index); |
| 542 } | 387 } |
| 543 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 388 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 544 base::TimeTicks::Now() - begin); | 389 base::TimeTicks::Now() - begin); |
| 545 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 390 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 546 } | 391 } |
| 547 | 392 |
| 548 void RenderViewContextMenu::InitMenu() { | 393 void RenderViewContextMenu::InitMenu() { |
| 549 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); | 394 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); |
| 550 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { | 395 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { |
| 551 AppendPlatformAppItems(); | 396 AppendPlatformAppItems(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 507 |
| 663 bool has_selection = !params_.selection_text.empty(); | 508 bool has_selection = !params_.selection_text.empty(); |
| 664 | 509 |
| 665 // Add undo/redo, cut/copy/paste etc for text fields | 510 // Add undo/redo, cut/copy/paste etc for text fields |
| 666 if (params_.is_editable) | 511 if (params_.is_editable) |
| 667 AppendEditableItems(); | 512 AppendEditableItems(); |
| 668 else if (has_selection) | 513 else if (has_selection) |
| 669 AppendCopyItem(); | 514 AppendCopyItem(); |
| 670 | 515 |
| 671 int index = 0; | 516 int index = 0; |
| 672 AppendExtensionItems(platform_app->id(), &index); | 517 extension_items_.AppendExtensionItems(platform_app->id(), |
| 518 PrintableSelectionText(), &index); |
| 673 | 519 |
| 674 // Add dev tools for unpacked extensions. | 520 // Add dev tools for unpacked extensions. |
| 675 if (platform_app->location() == Extension::LOAD) { | 521 if (platform_app->location() == Extension::LOAD) { |
| 676 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 522 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
| 677 AppendDeveloperItems(); | 523 AppendDeveloperItems(); |
| 678 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, | 524 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, |
| 679 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); | 525 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); |
| 680 } | 526 } |
| 681 } | 527 } |
| 682 | 528 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 protocol_handler_submenu_model_.AddItem( | 918 protocol_handler_submenu_model_.AddItem( |
| 1073 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, | 919 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, |
| 1074 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); | 920 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); |
| 1075 | 921 |
| 1076 menu_model_.AddSubMenu( | 922 menu_model_.AddSubMenu( |
| 1077 IDC_CONTENT_CONTEXT_OPENLINKWITH, | 923 IDC_CONTENT_CONTEXT_OPENLINKWITH, |
| 1078 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), | 924 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), |
| 1079 &protocol_handler_submenu_model_); | 925 &protocol_handler_submenu_model_); |
| 1080 } | 926 } |
| 1081 | 927 |
| 1082 MenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { | |
| 1083 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); | |
| 1084 std::map<int, MenuItem::Id>::const_iterator i = | |
| 1085 extension_item_map_.find(id); | |
| 1086 if (i != extension_item_map_.end()) { | |
| 1087 MenuItem* item = manager->GetItemById(i->second); | |
| 1088 if (item) | |
| 1089 return item; | |
| 1090 } | |
| 1091 return NULL; | |
| 1092 } | |
| 1093 | |
| 1094 // Menu delegate functions ----------------------------------------------------- | 928 // Menu delegate functions ----------------------------------------------------- |
| 1095 | 929 |
| 1096 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { | 930 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { |
| 1097 // If this command is is added by one of our observers, we dispatch it to the | 931 // If this command is is added by one of our observers, we dispatch it to the |
| 1098 // observer. | 932 // observer. |
| 1099 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); | 933 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); |
| 1100 RenderViewContextMenuObserver* observer; | 934 RenderViewContextMenuObserver* observer; |
| 1101 while ((observer = it.GetNext()) != NULL) { | 935 while ((observer = it.GetNext()) != NULL) { |
| 1102 if (observer->IsCommandIdSupported(id)) | 936 if (observer->IsCommandIdSupported(id)) |
| 1103 return observer->IsCommandIdEnabled(id); | 937 return observer->IsCommandIdEnabled(id); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1123 | 957 |
| 1124 // Custom items. | 958 // Custom items. |
| 1125 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 959 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1126 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 960 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1127 return IsCustomItemEnabled(params_.custom_items, id); | 961 return IsCustomItemEnabled(params_.custom_items, id); |
| 1128 } | 962 } |
| 1129 | 963 |
| 1130 // Extension items. | 964 // Extension items. |
| 1131 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 965 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1132 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 966 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1133 MenuItem* item = GetExtensionMenuItem(id); | 967 return extension_items_.IsCommandIdEnabled(id); |
| 1134 // If this is the parent menu item, it is always enabled. | |
| 1135 if (!item) | |
| 1136 return true; | |
| 1137 return item->enabled(); | |
| 1138 } | 968 } |
| 1139 | 969 |
| 1140 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 970 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1141 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 971 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1142 return true; | 972 return true; |
| 1143 } | 973 } |
| 1144 | 974 |
| 1145 IncognitoModePrefs::Availability incognito_avail = | 975 IncognitoModePrefs::Availability incognito_avail = |
| 1146 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 976 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 1147 switch (id) { | 977 switch (id) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 | 1266 |
| 1437 // Custom items. | 1267 // Custom items. |
| 1438 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1268 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1439 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1269 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1440 return IsCustomItemChecked(params_.custom_items, id); | 1270 return IsCustomItemChecked(params_.custom_items, id); |
| 1441 } | 1271 } |
| 1442 | 1272 |
| 1443 // Extension items. | 1273 // Extension items. |
| 1444 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1274 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1445 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1275 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1446 MenuItem* item = GetExtensionMenuItem(id); | 1276 return extension_items_.IsCommandIdChecked(id); |
| 1447 if (item) | |
| 1448 return item->checked(); | |
| 1449 else | |
| 1450 return false; | |
| 1451 } | 1277 } |
| 1452 | 1278 |
| 1453 #if defined(OS_MACOSX) | 1279 #if defined(OS_MACOSX) |
| 1454 if (id == IDC_WRITING_DIRECTION_DEFAULT) | 1280 if (id == IDC_WRITING_DIRECTION_DEFAULT) |
| 1455 return params_.writing_direction_default & | 1281 return params_.writing_direction_default & |
| 1456 WebContextMenuData::CheckableMenuItemChecked; | 1282 WebContextMenuData::CheckableMenuItemChecked; |
| 1457 if (id == IDC_WRITING_DIRECTION_RTL) | 1283 if (id == IDC_WRITING_DIRECTION_RTL) |
| 1458 return params_.writing_direction_right_to_left & | 1284 return params_.writing_direction_right_to_left & |
| 1459 WebContextMenuData::CheckableMenuItemChecked; | 1285 WebContextMenuData::CheckableMenuItemChecked; |
| 1460 if (id == IDC_WRITING_DIRECTION_LTR) | 1286 if (id == IDC_WRITING_DIRECTION_LTR) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1321 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1496 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1322 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1497 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1323 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 1498 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); | 1324 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); |
| 1499 return; | 1325 return; |
| 1500 } | 1326 } |
| 1501 | 1327 |
| 1502 // Process extension menu items. | 1328 // Process extension menu items. |
| 1503 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1329 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1504 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1330 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1505 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); | 1331 extension_items_.ExecuteCommand(id, params_); |
| 1506 std::map<int, MenuItem::Id>::const_iterator i = | |
| 1507 extension_item_map_.find(id); | |
| 1508 if (i != extension_item_map_.end()) { | |
| 1509 manager->ExecuteCommand(profile_, source_web_contents_, params_, | |
| 1510 i->second); | |
| 1511 } | |
| 1512 return; | 1332 return; |
| 1513 } | 1333 } |
| 1514 | 1334 |
| 1515 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1335 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1516 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1336 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1517 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1337 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1518 GetHandlersForLinkUrl(); | 1338 GetHandlersForLinkUrl(); |
| 1519 if (handlers.empty()) { | 1339 if (handlers.empty()) { |
| 1520 return; | 1340 return; |
| 1521 } | 1341 } |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2040 source_web_contents_->GetRenderViewHost()-> | 1860 source_web_contents_->GetRenderViewHost()-> |
| 2041 ExecuteMediaPlayerActionAtLocation(location, action); | 1861 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2042 } | 1862 } |
| 2043 | 1863 |
| 2044 void RenderViewContextMenu::PluginActionAt( | 1864 void RenderViewContextMenu::PluginActionAt( |
| 2045 const gfx::Point& location, | 1865 const gfx::Point& location, |
| 2046 const WebPluginAction& action) { | 1866 const WebPluginAction& action) { |
| 2047 source_web_contents_->GetRenderViewHost()-> | 1867 source_web_contents_->GetRenderViewHost()-> |
| 2048 ExecutePluginActionAtLocation(location, action); | 1868 ExecutePluginActionAtLocation(location, action); |
| 2049 } | 1869 } |
| OLD | NEW |