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/extensions/menu_manager.h" | 5 #include "chrome/browser/extensions/menu_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 577 |
578 // ExtensionService/Extension can be NULL in unit tests :( | 578 // ExtensionService/Extension can be NULL in unit tests :( |
579 ExtensionService* service = | 579 ExtensionService* service = |
580 ExtensionSystem::Get(profile_)->extension_service(); | 580 ExtensionSystem::Get(profile_)->extension_service(); |
581 const Extension* extension = service ? | 581 const Extension* extension = service ? |
582 service->extensions()->GetByID(menu_item_id.extension_id) : NULL; | 582 service->extensions()->GetByID(menu_item_id.extension_id) : NULL; |
583 | 583 |
584 if (item->type() == MenuItem::RADIO) | 584 if (item->type() == MenuItem::RADIO) |
585 RadioItemSelected(item); | 585 RadioItemSelected(item); |
586 | 586 |
587 ListValue args; | 587 scoped_ptr<ListValue> args(new ListValue()); |
588 | 588 |
589 DictionaryValue* properties = new DictionaryValue(); | 589 DictionaryValue* properties = new DictionaryValue(); |
590 SetIdKeyValue(properties, "menuItemId", item->id()); | 590 SetIdKeyValue(properties, "menuItemId", item->id()); |
591 if (item->parent_id()) | 591 if (item->parent_id()) |
592 SetIdKeyValue(properties, "parentMenuItemId", item->id()); | 592 SetIdKeyValue(properties, "parentMenuItemId", item->id()); |
593 | 593 |
594 switch (params.media_type) { | 594 switch (params.media_type) { |
595 case WebKit::WebContextMenuData::MediaTypeImage: | 595 case WebKit::WebContextMenuData::MediaTypeImage: |
596 properties->SetString("mediaType", "image"); | 596 properties->SetString("mediaType", "image"); |
597 break; | 597 break; |
598 case WebKit::WebContextMenuData::MediaTypeVideo: | 598 case WebKit::WebContextMenuData::MediaTypeVideo: |
599 properties->SetString("mediaType", "video"); | 599 properties->SetString("mediaType", "video"); |
600 break; | 600 break; |
601 case WebKit::WebContextMenuData::MediaTypeAudio: | 601 case WebKit::WebContextMenuData::MediaTypeAudio: |
602 properties->SetString("mediaType", "audio"); | 602 properties->SetString("mediaType", "audio"); |
603 break; | 603 break; |
604 default: {} // Do nothing. | 604 default: {} // Do nothing. |
605 } | 605 } |
606 | 606 |
607 AddURLProperty(properties, "linkUrl", params.unfiltered_link_url); | 607 AddURLProperty(properties, "linkUrl", params.unfiltered_link_url); |
608 AddURLProperty(properties, "srcUrl", params.src_url); | 608 AddURLProperty(properties, "srcUrl", params.src_url); |
609 AddURLProperty(properties, "pageUrl", params.page_url); | 609 AddURLProperty(properties, "pageUrl", params.page_url); |
610 AddURLProperty(properties, "frameUrl", params.frame_url); | 610 AddURLProperty(properties, "frameUrl", params.frame_url); |
611 | 611 |
612 if (params.selection_text.length() > 0) | 612 if (params.selection_text.length() > 0) |
613 properties->SetString("selectionText", params.selection_text); | 613 properties->SetString("selectionText", params.selection_text); |
614 | 614 |
615 properties->SetBoolean("editable", params.is_editable); | 615 properties->SetBoolean("editable", params.is_editable); |
616 | 616 |
617 args.Append(properties); | 617 args->Append(properties); |
618 | 618 |
619 // Add the tab info to the argument list. | 619 // Add the tab info to the argument list. |
620 // Note: web_contents only NULL in unit tests :( | 620 // Note: web_contents only NULL in unit tests :( |
621 if (web_contents) | 621 if (web_contents) |
622 args.Append(ExtensionTabUtil::CreateTabValue(web_contents)); | 622 args->Append(ExtensionTabUtil::CreateTabValue(web_contents)); |
623 else | 623 else |
624 args.Append(new DictionaryValue()); | 624 args->Append(new DictionaryValue()); |
625 | 625 |
626 if (item->type() == MenuItem::CHECKBOX || | 626 if (item->type() == MenuItem::CHECKBOX || |
627 item->type() == MenuItem::RADIO) { | 627 item->type() == MenuItem::RADIO) { |
628 bool was_checked = item->checked(); | 628 bool was_checked = item->checked(); |
629 properties->SetBoolean("wasChecked", was_checked); | 629 properties->SetBoolean("wasChecked", was_checked); |
630 | 630 |
631 // RADIO items always get set to true when you click on them, but CHECKBOX | 631 // RADIO items always get set to true when you click on them, but CHECKBOX |
632 // items get their state toggled. | 632 // items get their state toggled. |
633 bool checked = | 633 bool checked = |
634 (item->type() == MenuItem::RADIO) ? true : !was_checked; | 634 (item->type() == MenuItem::RADIO) ? true : !was_checked; |
635 | 635 |
636 item->SetChecked(checked); | 636 item->SetChecked(checked); |
637 properties->SetBoolean("checked", item->checked()); | 637 properties->SetBoolean("checked", item->checked()); |
638 | 638 |
639 if (extension) | 639 if (extension) |
640 WriteToStorage(extension); | 640 WriteToStorage(extension); |
641 } | 641 } |
642 | 642 |
643 TabContents* tab_contents = web_contents ? | 643 TabContents* tab_contents = web_contents ? |
644 TabContents::FromWebContents(web_contents) : NULL; | 644 TabContents::FromWebContents(web_contents) : NULL; |
645 if (tab_contents && extension) { | 645 if (tab_contents && extension) { |
646 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> | 646 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> |
647 GrantIfRequested(extension); | 647 GrantIfRequested(extension); |
648 } | 648 } |
649 | 649 |
650 std::string json_args; | |
651 base::JSONWriter::Write(&args, &json_args); | |
652 event_router->DispatchEventToExtension( | 650 event_router->DispatchEventToExtension( |
653 item->extension_id(), event_names::kOnContextMenus, | 651 item->extension_id(), event_names::kOnContextMenus, |
654 json_args, profile, GURL(), | 652 scoped_ptr<ListValue>(args->DeepCopy()), profile, GURL(), |
655 EventRouter::USER_GESTURE_ENABLED); | 653 EventRouter::USER_GESTURE_ENABLED); |
656 event_router->DispatchEventToExtension( | 654 event_router->DispatchEventToExtension( |
657 item->extension_id(), event_names::kOnContextMenuClicked, | 655 item->extension_id(), event_names::kOnContextMenuClicked, |
658 json_args, profile, GURL(), | 656 args.Pass(), profile, GURL(), |
659 EventRouter::USER_GESTURE_ENABLED); | 657 EventRouter::USER_GESTURE_ENABLED); |
660 } | 658 } |
661 | 659 |
662 void MenuManager::SanitizeRadioList(const MenuItem::List& item_list) { | 660 void MenuManager::SanitizeRadioList(const MenuItem::List& item_list) { |
663 MenuItem::List::const_iterator i = item_list.begin(); | 661 MenuItem::List::const_iterator i = item_list.begin(); |
664 while (i != item_list.end()) { | 662 while (i != item_list.end()) { |
665 if ((*i)->type() != MenuItem::RADIO) { | 663 if ((*i)->type() != MenuItem::RADIO) { |
666 ++i; | 664 ++i; |
667 break; | 665 break; |
668 } | 666 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 if (uid < other.uid) | 815 if (uid < other.uid) |
818 return true; | 816 return true; |
819 if (uid == other.uid) | 817 if (uid == other.uid) |
820 return string_uid < other.string_uid; | 818 return string_uid < other.string_uid; |
821 } | 819 } |
822 } | 820 } |
823 return false; | 821 return false; |
824 } | 822 } |
825 | 823 |
826 } // namespace extensions | 824 } // namespace extensions |
OLD | NEW |