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