| 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(protocol_handler_submenu_model_(this)), | 258 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), |
| 259 protocol_handler_registry_(profile_->GetProtocolHandlerRegistry()) { | 259 protocol_handler_registry_(profile_->GetProtocolHandlerRegistry()) { |
| 260 } | 260 } |
| 261 | 261 |
| 262 RenderViewContextMenu::~RenderViewContextMenu() { | 262 RenderViewContextMenu::~RenderViewContextMenu() { |
| 263 } | 263 } |
| 264 | 264 |
| 265 // Menu construction functions ------------------------------------------------- | 265 // Menu construction functions ------------------------------------------------- |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 contexts.Contains(MenuItem::PAGE)) | 331 contexts.Contains(MenuItem::PAGE)) |
| 332 return true; | 332 return true; |
| 333 | 333 |
| 334 return false; | 334 return false; |
| 335 } | 335 } |
| 336 | 336 |
| 337 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { | 337 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { |
| 338 return params.frame_url.is_empty() ? params.page_url : params.frame_url; | 338 return params.frame_url.is_empty() ? params.page_url : params.frame_url; |
| 339 } | 339 } |
| 340 | 340 |
| 341 // Given a list of items, returns the ones that match given the contents | |
| 342 // of |params| and the profile. | |
| 343 // static | 341 // static |
| 344 MenuItem::List RenderViewContextMenu::GetRelevantExtensionItems( | 342 bool RenderViewContextMenu::MenuItemMatchesParams( |
| 345 const MenuItem::List& items, | |
| 346 const content::ContextMenuParams& params, | 343 const content::ContextMenuParams& params, |
| 347 Profile* profile, | 344 const extensions::MenuItem* item) { |
| 348 bool can_cross_incognito) { | 345 bool match = ExtensionContextAndPatternMatch(params, item->contexts(), |
| 349 MenuItem::List result; | 346 item->target_url_patterns()); |
| 350 for (MenuItem::List::const_iterator i = items.begin(); | 347 if (!match) |
| 351 i != items.end(); ++i) { | 348 return false; |
| 352 const MenuItem* item = *i; | |
| 353 | 349 |
| 354 if (!ExtensionContextAndPatternMatch(params, item->contexts(), | 350 const GURL& document_url = GetDocumentURL(params); |
| 355 item->target_url_patterns())) | 351 return ExtensionPatternMatch(item->document_url_patterns(), document_url); |
| 356 continue; | |
| 357 | |
| 358 const GURL& document_url = GetDocumentURL(params); | |
| 359 if (!ExtensionPatternMatch(item->document_url_patterns(), document_url)) | |
| 360 continue; | |
| 361 | |
| 362 if (item->id().incognito == profile->IsOffTheRecord() || | |
| 363 can_cross_incognito) | |
| 364 result.push_back(*i); | |
| 365 } | |
| 366 return result; | |
| 367 } | |
| 368 | |
| 369 void RenderViewContextMenu::AppendExtensionItems( | |
| 370 const std::string& extension_id, int* index) { | |
| 371 ExtensionService* service = profile_->GetExtensionService(); | |
| 372 MenuManager* manager = service->menu_manager(); | |
| 373 const Extension* extension = service->GetExtensionById(extension_id, false); | |
| 374 DCHECK_GE(*index, 0); | |
| 375 int max_index = | |
| 376 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | |
| 377 if (!extension || *index >= max_index) | |
| 378 return; | |
| 379 | |
| 380 // Find matching items. | |
| 381 const MenuItem::List* all_items = manager->MenuItems(extension_id); | |
| 382 if (!all_items || all_items->empty()) | |
| 383 return; | |
| 384 bool can_cross_incognito = service->CanCrossIncognito(extension); | |
| 385 MenuItem::List items = | |
| 386 GetRelevantExtensionItems(*all_items, params_, profile_, | |
| 387 can_cross_incognito); | |
| 388 if (items.empty()) | |
| 389 return; | |
| 390 | |
| 391 // If this is the first extension-provided menu item, and there are other | |
| 392 // items in the menu, add a separator. | |
| 393 if (*index == 0 && menu_model_.GetItemCount()) | |
| 394 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 395 | |
| 396 // Extensions (other than platform apps) are only allowed one top-level slot | |
| 397 // (and it can't be a radio or checkbox item because we are going to put the | |
| 398 // extension icon next to it). | |
| 399 // If they have more than that, we automatically push them into a submenu. | |
| 400 if (extension->is_platform_app()) { | |
| 401 RecursivelyAppendExtensionItems(items, can_cross_incognito, &menu_model_, | |
| 402 index); | |
| 403 } else { | |
| 404 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | |
| 405 string16 title; | |
| 406 MenuItem::List submenu_items; | |
| 407 | |
| 408 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { | |
| 409 title = UTF8ToUTF16(extension->name()); | |
| 410 submenu_items = items; | |
| 411 } else { | |
| 412 MenuItem* item = items[0]; | |
| 413 extension_item_map_[menu_id] = item->id(); | |
| 414 title = item->TitleWithReplacement(PrintableSelectionText(), | |
| 415 kMaxExtensionItemTitleLength); | |
| 416 submenu_items = GetRelevantExtensionItems(item->children(), params_, | |
| 417 profile_, can_cross_incognito); | |
| 418 } | |
| 419 | |
| 420 // Now add our item(s) to the menu_model_. | |
| 421 if (submenu_items.empty()) { | |
| 422 menu_model_.AddItem(menu_id, title); | |
| 423 } else { | |
| 424 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | |
| 425 extension_menu_models_.push_back(submenu); | |
| 426 menu_model_.AddSubMenu(menu_id, title, submenu); | |
| 427 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, | |
| 428 submenu, index); | |
| 429 } | |
| 430 SetExtensionIcon(extension_id); | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 void RenderViewContextMenu::RecursivelyAppendExtensionItems( | |
| 435 const MenuItem::List& items, | |
| 436 bool can_cross_incognito, | |
| 437 ui::SimpleMenuModel* menu_model, | |
| 438 int* index) { | |
| 439 string16 selection_text = PrintableSelectionText(); | |
| 440 MenuItem::Type last_type = MenuItem::NORMAL; | |
| 441 int radio_group_id = 1; | |
| 442 | |
| 443 for (MenuItem::List::const_iterator i = items.begin(); | |
| 444 i != items.end(); ++i) { | |
| 445 MenuItem* item = *i; | |
| 446 | |
| 447 // If last item was of type radio but the current one isn't, auto-insert | |
| 448 // a separator. The converse case is handled below. | |
| 449 if (last_type == MenuItem::RADIO && | |
| 450 item->type() != MenuItem::RADIO) { | |
| 451 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 452 last_type = MenuItem::SEPARATOR; | |
| 453 } | |
| 454 | |
| 455 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | |
| 456 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) | |
| 457 return; | |
| 458 extension_item_map_[menu_id] = item->id(); | |
| 459 string16 title = item->TitleWithReplacement(selection_text, | |
| 460 kMaxExtensionItemTitleLength); | |
| 461 if (item->type() == MenuItem::NORMAL) { | |
| 462 MenuItem::List children = | |
| 463 GetRelevantExtensionItems(item->children(), params_, | |
| 464 profile_, can_cross_incognito); | |
| 465 if (children.empty()) { | |
| 466 menu_model->AddItem(menu_id, title); | |
| 467 } else { | |
| 468 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | |
| 469 extension_menu_models_.push_back(submenu); | |
| 470 menu_model->AddSubMenu(menu_id, title, submenu); | |
| 471 RecursivelyAppendExtensionItems(children, can_cross_incognito, | |
| 472 submenu, index); | |
| 473 } | |
| 474 } else if (item->type() == MenuItem::CHECKBOX) { | |
| 475 menu_model->AddCheckItem(menu_id, title); | |
| 476 } else if (item->type() == MenuItem::RADIO) { | |
| 477 if (i != items.begin() && | |
| 478 last_type != MenuItem::RADIO) { | |
| 479 radio_group_id++; | |
| 480 | |
| 481 // Auto-append a separator if needed. | |
| 482 if (last_type != MenuItem::SEPARATOR) | |
| 483 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 484 } | |
| 485 | |
| 486 menu_model->AddRadioItem(menu_id, title, radio_group_id); | |
| 487 } else if (item->type() == MenuItem::SEPARATOR) { | |
| 488 if (i != items.begin() && last_type != MenuItem::SEPARATOR) { | |
| 489 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 490 } | |
| 491 } | |
| 492 last_type = item->type(); | |
| 493 } | |
| 494 } | |
| 495 | |
| 496 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { | |
| 497 ExtensionService* service = profile_->GetExtensionService(); | |
| 498 MenuManager* menu_manager = service->menu_manager(); | |
| 499 | |
| 500 int index = menu_model_.GetItemCount() - 1; | |
| 501 DCHECK_GE(index, 0); | |
| 502 | |
| 503 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | |
| 504 DCHECK(icon.width() == gfx::kFaviconSize); | |
| 505 DCHECK(icon.height() == gfx::kFaviconSize); | |
| 506 | |
| 507 menu_model_.SetIcon(index, gfx::Image(icon)); | |
| 508 } | 352 } |
| 509 | 353 |
| 510 void RenderViewContextMenu::AppendAllExtensionItems() { | 354 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 511 extension_item_map_.clear(); | 355 extension_items_.Clear(); |
| 512 ExtensionService* service = profile_->GetExtensionService(); | 356 ExtensionService* service = profile_->GetExtensionService(); |
| 513 if (!service) | 357 if (!service) |
| 514 return; // In unit-tests, we may not have an ExtensionService. | 358 return; // In unit-tests, we may not have an ExtensionService. |
| 515 MenuManager* menu_manager = service->menu_manager(); | 359 MenuManager* menu_manager = service->menu_manager(); |
| 516 | 360 |
| 517 // Get a list of extension id's that have context menu items, and sort it by | 361 // Get a list of extension id's that have context menu items, and sort it by |
| 518 // the extension's name. | 362 // the extension's name. |
| 519 std::set<std::string> ids = menu_manager->ExtensionIds(); | 363 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 520 std::vector<std::pair<std::string, std::string> > sorted_ids; | 364 std::vector<std::pair<std::string, std::string> > sorted_ids; |
| 521 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 365 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 522 const Extension* extension = service->GetExtensionById(*i, false); | 366 const Extension* extension = service->GetExtensionById(*i, false); |
| 523 // Platform apps have their context menus created directly in | 367 // Platform apps have their context menus created directly in |
| 524 // AppendPlatformAppItems. | 368 // AppendPlatformAppItems. |
| 525 if (extension && !extension->is_platform_app()) | 369 if (extension && !extension->is_platform_app()) |
| 526 sorted_ids.push_back( | 370 sorted_ids.push_back( |
| 527 std::pair<std::string, std::string>(extension->name(), *i)); | 371 std::pair<std::string, std::string>(extension->name(), *i)); |
| 528 } | 372 } |
| 529 // TODO(asargent) - See if this works properly for i18n names (bug 32363). | 373 // TODO(asargent) - See if this works properly for i18n names (bug 32363). |
| 530 std::sort(sorted_ids.begin(), sorted_ids.end()); | 374 std::sort(sorted_ids.begin(), sorted_ids.end()); |
| 531 | 375 |
| 532 if (sorted_ids.empty()) | 376 if (sorted_ids.empty()) |
| 533 return; | 377 return; |
| 534 | 378 |
| 535 int index = 0; | 379 int index = 0; |
| 536 base::TimeTicks begin = base::TimeTicks::Now(); | 380 base::TimeTicks begin = base::TimeTicks::Now(); |
| 537 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 381 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
| 538 for (i = sorted_ids.begin(); | 382 for (i = sorted_ids.begin(); |
| 539 i != sorted_ids.end(); ++i) { | 383 i != sorted_ids.end(); ++i) { |
| 540 AppendExtensionItems(i->second, &index); | 384 extension_items_.AppendExtensionItems(i->second, PrintableSelectionText(), |
| 385 &index); |
| 541 } | 386 } |
| 542 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 387 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 543 base::TimeTicks::Now() - begin); | 388 base::TimeTicks::Now() - begin); |
| 544 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 389 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 545 } | 390 } |
| 546 | 391 |
| 547 void RenderViewContextMenu::InitMenu() { | 392 void RenderViewContextMenu::InitMenu() { |
| 548 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); | 393 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); |
| 549 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { | 394 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { |
| 550 AppendPlatformAppItems(); | 395 AppendPlatformAppItems(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 506 |
| 662 bool has_selection = !params_.selection_text.empty(); | 507 bool has_selection = !params_.selection_text.empty(); |
| 663 | 508 |
| 664 // Add undo/redo, cut/copy/paste etc for text fields | 509 // Add undo/redo, cut/copy/paste etc for text fields |
| 665 if (params_.is_editable) | 510 if (params_.is_editable) |
| 666 AppendEditableItems(); | 511 AppendEditableItems(); |
| 667 else if (has_selection) | 512 else if (has_selection) |
| 668 AppendCopyItem(); | 513 AppendCopyItem(); |
| 669 | 514 |
| 670 int index = 0; | 515 int index = 0; |
| 671 AppendExtensionItems(platform_app->id(), &index); | 516 extension_items_.AppendExtensionItems(platform_app->id(), |
| 517 PrintableSelectionText(), &index); |
| 672 | 518 |
| 673 // Add dev tools for unpacked extensions. | 519 // Add dev tools for unpacked extensions. |
| 674 if (platform_app->location() == Extension::LOAD) { | 520 if (platform_app->location() == Extension::LOAD) { |
| 675 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 521 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
| 676 AppendDeveloperItems(); | 522 AppendDeveloperItems(); |
| 677 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, | 523 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, |
| 678 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); | 524 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); |
| 679 } | 525 } |
| 680 } | 526 } |
| 681 | 527 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 898 |
| 1053 menu_model_.AddSubMenu( | 899 menu_model_.AddSubMenu( |
| 1054 IDC_CONTENT_CONTEXT_OPENLINKWITH, | 900 IDC_CONTENT_CONTEXT_OPENLINKWITH, |
| 1055 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), | 901 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), |
| 1056 &protocol_handler_submenu_model_); | 902 &protocol_handler_submenu_model_); |
| 1057 } | 903 } |
| 1058 | 904 |
| 1059 void RenderViewContextMenu::AppendPlatformEditableItems() { | 905 void RenderViewContextMenu::AppendPlatformEditableItems() { |
| 1060 } | 906 } |
| 1061 | 907 |
| 1062 MenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { | |
| 1063 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); | |
| 1064 std::map<int, MenuItem::Id>::const_iterator i = | |
| 1065 extension_item_map_.find(id); | |
| 1066 if (i != extension_item_map_.end()) { | |
| 1067 MenuItem* item = manager->GetItemById(i->second); | |
| 1068 if (item) | |
| 1069 return item; | |
| 1070 } | |
| 1071 return NULL; | |
| 1072 } | |
| 1073 | |
| 1074 // Menu delegate functions ----------------------------------------------------- | 908 // Menu delegate functions ----------------------------------------------------- |
| 1075 | 909 |
| 1076 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { | 910 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { |
| 1077 // If this command is is added by one of our observers, we dispatch it to the | 911 // If this command is is added by one of our observers, we dispatch it to the |
| 1078 // observer. | 912 // observer. |
| 1079 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); | 913 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); |
| 1080 RenderViewContextMenuObserver* observer; | 914 RenderViewContextMenuObserver* observer; |
| 1081 while ((observer = it.GetNext()) != NULL) { | 915 while ((observer = it.GetNext()) != NULL) { |
| 1082 if (observer->IsCommandIdSupported(id)) | 916 if (observer->IsCommandIdSupported(id)) |
| 1083 return observer->IsCommandIdEnabled(id); | 917 return observer->IsCommandIdEnabled(id); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1103 | 937 |
| 1104 // Custom items. | 938 // Custom items. |
| 1105 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 939 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1106 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 940 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1107 return IsCustomItemEnabled(params_.custom_items, id); | 941 return IsCustomItemEnabled(params_.custom_items, id); |
| 1108 } | 942 } |
| 1109 | 943 |
| 1110 // Extension items. | 944 // Extension items. |
| 1111 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 945 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1112 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 946 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1113 MenuItem* item = GetExtensionMenuItem(id); | 947 return extension_items_.IsCommandIdEnabled(id); |
| 1114 // If this is the parent menu item, it is always enabled. | |
| 1115 if (!item) | |
| 1116 return true; | |
| 1117 return item->enabled(); | |
| 1118 } | 948 } |
| 1119 | 949 |
| 1120 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 950 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1121 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 951 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1122 return true; | 952 return true; |
| 1123 } | 953 } |
| 1124 | 954 |
| 1125 IncognitoModePrefs::Availability incognito_avail = | 955 IncognitoModePrefs::Availability incognito_avail = |
| 1126 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 956 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 1127 switch (id) { | 957 switch (id) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 | 1234 |
| 1405 // Custom items. | 1235 // Custom items. |
| 1406 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1236 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1407 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1237 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1408 return IsCustomItemChecked(params_.custom_items, id); | 1238 return IsCustomItemChecked(params_.custom_items, id); |
| 1409 } | 1239 } |
| 1410 | 1240 |
| 1411 // Extension items. | 1241 // Extension items. |
| 1412 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1242 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1413 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1243 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1414 MenuItem* item = GetExtensionMenuItem(id); | 1244 return extension_items_.IsCommandIdChecked(id); |
| 1415 if (item) | |
| 1416 return item->checked(); | |
| 1417 else | |
| 1418 return false; | |
| 1419 } | 1245 } |
| 1420 | 1246 |
| 1421 #if defined(ENABLE_INPUT_SPEECH) | 1247 #if defined(ENABLE_INPUT_SPEECH) |
| 1422 // Check box for menu item 'Block offensive words'. | 1248 // Check box for menu item 'Block offensive words'. |
| 1423 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES) { | 1249 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES) { |
| 1424 return ChromeSpeechRecognitionPreferences::GetForProfile(profile_)-> | 1250 return ChromeSpeechRecognitionPreferences::GetForProfile(profile_)-> |
| 1425 FilterProfanities(); | 1251 FilterProfanities(); |
| 1426 } | 1252 } |
| 1427 #endif | 1253 #endif |
| 1428 | 1254 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1449 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1275 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1450 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1276 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1451 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1277 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 1452 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); | 1278 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); |
| 1453 return; | 1279 return; |
| 1454 } | 1280 } |
| 1455 | 1281 |
| 1456 // Process extension menu items. | 1282 // Process extension menu items. |
| 1457 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1283 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1458 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1284 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1459 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); | 1285 extension_items_.ExecuteCommand(id, params_); |
| 1460 std::map<int, MenuItem::Id>::const_iterator i = | |
| 1461 extension_item_map_.find(id); | |
| 1462 if (i != extension_item_map_.end()) { | |
| 1463 manager->ExecuteCommand(profile_, source_web_contents_, params_, | |
| 1464 i->second); | |
| 1465 } | |
| 1466 return; | 1286 return; |
| 1467 } | 1287 } |
| 1468 | 1288 |
| 1469 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1289 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1470 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1290 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1471 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1291 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1472 GetHandlersForLinkUrl(); | 1292 GetHandlersForLinkUrl(); |
| 1473 if (handlers.empty()) { | 1293 if (handlers.empty()) { |
| 1474 return; | 1294 return; |
| 1475 } | 1295 } |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 source_web_contents_->GetRenderViewHost()-> | 1798 source_web_contents_->GetRenderViewHost()-> |
| 1979 ExecuteMediaPlayerActionAtLocation(location, action); | 1799 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1980 } | 1800 } |
| 1981 | 1801 |
| 1982 void RenderViewContextMenu::PluginActionAt( | 1802 void RenderViewContextMenu::PluginActionAt( |
| 1983 const gfx::Point& location, | 1803 const gfx::Point& location, |
| 1984 const WebPluginAction& action) { | 1804 const WebPluginAction& action) { |
| 1985 source_web_contents_->GetRenderViewHost()-> | 1805 source_web_contents_->GetRenderViewHost()-> |
| 1986 ExecutePluginActionAtLocation(location, action); | 1806 ExecutePluginActionAtLocation(location, action); |
| 1987 } | 1807 } |
| OLD | NEW |