Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/extensions/extension_menu_manager.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_menu_manager.h" 5 #include "chrome/browser/extensions/extension_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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 582
583 // ExtensionService/Extension can be NULL in unit tests :( 583 // ExtensionService/Extension can be NULL in unit tests :(
584 ExtensionService* service = 584 ExtensionService* service =
585 ExtensionSystem::Get(profile_)->extension_service(); 585 ExtensionSystem::Get(profile_)->extension_service();
586 const extensions::Extension* extension = service ? 586 const extensions::Extension* extension = service ?
587 service->extensions()->GetByID(menu_item_id.extension_id) : NULL; 587 service->extensions()->GetByID(menu_item_id.extension_id) : NULL;
588 588
589 if (item->type() == ExtensionMenuItem::RADIO) 589 if (item->type() == ExtensionMenuItem::RADIO)
590 RadioItemSelected(item); 590 RadioItemSelected(item);
591 591
592 ListValue args; 592 ListValue* args = new ListValue();
593 593
594 DictionaryValue* properties = new DictionaryValue(); 594 DictionaryValue* properties = new DictionaryValue();
595 SetIdKeyValue(properties, "menuItemId", item->id()); 595 SetIdKeyValue(properties, "menuItemId", item->id());
596 if (item->parent_id()) 596 if (item->parent_id())
597 SetIdKeyValue(properties, "parentMenuItemId", item->id()); 597 SetIdKeyValue(properties, "parentMenuItemId", item->id());
598 598
599 switch (params.media_type) { 599 switch (params.media_type) {
600 case WebKit::WebContextMenuData::MediaTypeImage: 600 case WebKit::WebContextMenuData::MediaTypeImage:
601 properties->SetString("mediaType", "image"); 601 properties->SetString("mediaType", "image");
602 break; 602 break;
603 case WebKit::WebContextMenuData::MediaTypeVideo: 603 case WebKit::WebContextMenuData::MediaTypeVideo:
604 properties->SetString("mediaType", "video"); 604 properties->SetString("mediaType", "video");
605 break; 605 break;
606 case WebKit::WebContextMenuData::MediaTypeAudio: 606 case WebKit::WebContextMenuData::MediaTypeAudio:
607 properties->SetString("mediaType", "audio"); 607 properties->SetString("mediaType", "audio");
608 break; 608 break;
609 default: {} // Do nothing. 609 default: {} // Do nothing.
610 } 610 }
611 611
612 AddURLProperty(properties, "linkUrl", params.unfiltered_link_url); 612 AddURLProperty(properties, "linkUrl", params.unfiltered_link_url);
613 AddURLProperty(properties, "srcUrl", params.src_url); 613 AddURLProperty(properties, "srcUrl", params.src_url);
614 AddURLProperty(properties, "pageUrl", params.page_url); 614 AddURLProperty(properties, "pageUrl", params.page_url);
615 AddURLProperty(properties, "frameUrl", params.frame_url); 615 AddURLProperty(properties, "frameUrl", params.frame_url);
616 616
617 if (params.selection_text.length() > 0) 617 if (params.selection_text.length() > 0)
618 properties->SetString("selectionText", params.selection_text); 618 properties->SetString("selectionText", params.selection_text);
619 619
620 properties->SetBoolean("editable", params.is_editable); 620 properties->SetBoolean("editable", params.is_editable);
621 621
622 args.Append(properties); 622 args->Append(properties);
623 623
624 // Add the tab info to the argument list. 624 // Add the tab info to the argument list.
625 // Note: web_contents only NULL in unit tests :( 625 // Note: web_contents only NULL in unit tests :(
626 if (web_contents) 626 if (web_contents)
627 args.Append(ExtensionTabUtil::CreateTabValue(web_contents)); 627 args->Append(ExtensionTabUtil::CreateTabValue(web_contents));
628 else 628 else
629 args.Append(new DictionaryValue()); 629 args->Append(new DictionaryValue());
630 630
631 if (item->type() == ExtensionMenuItem::CHECKBOX || 631 if (item->type() == ExtensionMenuItem::CHECKBOX ||
632 item->type() == ExtensionMenuItem::RADIO) { 632 item->type() == ExtensionMenuItem::RADIO) {
633 bool was_checked = item->checked(); 633 bool was_checked = item->checked();
634 properties->SetBoolean("wasChecked", was_checked); 634 properties->SetBoolean("wasChecked", was_checked);
635 635
636 // RADIO items always get set to true when you click on them, but CHECKBOX 636 // RADIO items always get set to true when you click on them, but CHECKBOX
637 // items get their state toggled. 637 // items get their state toggled.
638 bool checked = 638 bool checked =
639 (item->type() == ExtensionMenuItem::RADIO) ? true : !was_checked; 639 (item->type() == ExtensionMenuItem::RADIO) ? true : !was_checked;
640 640
641 item->SetChecked(checked); 641 item->SetChecked(checked);
642 properties->SetBoolean("checked", item->checked()); 642 properties->SetBoolean("checked", item->checked());
643 643
644 if (extension) 644 if (extension)
645 WriteToStorage(extension); 645 WriteToStorage(extension);
646 } 646 }
647 647
648 TabContents* tab_contents = web_contents ? 648 TabContents* tab_contents = web_contents ?
649 TabContents::FromWebContents(web_contents) : NULL; 649 TabContents::FromWebContents(web_contents) : NULL;
650 if (tab_contents && extension) { 650 if (tab_contents && extension) {
651 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> 651 tab_contents->extension_tab_helper()->active_tab_permission_manager()->
652 GrantIfRequested(extension); 652 GrantIfRequested(extension);
653 } 653 }
654 654
655 std::string json_args;
656 base::JSONWriter::Write(&args, &json_args);
657 event_router->DispatchEventToExtension( 655 event_router->DispatchEventToExtension(
658 item->extension_id(), extension_event_names::kOnContextMenus, 656 item->extension_id(), extension_event_names::kOnContextMenus,
659 json_args, profile, GURL(), 657 args, profile, GURL(), ExtensionEventRouter::USER_GESTURE_ENABLED);
660 ExtensionEventRouter::USER_GESTURE_ENABLED);
661 event_router->DispatchEventToExtension( 658 event_router->DispatchEventToExtension(
662 item->extension_id(), extension_event_names::kOnContextMenuClicked, 659 item->extension_id(), extension_event_names::kOnContextMenuClicked,
663 json_args, profile, GURL(), 660 args, profile, GURL(), ExtensionEventRouter::USER_GESTURE_ENABLED);
664 ExtensionEventRouter::USER_GESTURE_ENABLED);
665 } 661 }
666 662
667 void ExtensionMenuManager::SanitizeRadioList( 663 void ExtensionMenuManager::SanitizeRadioList(
668 const ExtensionMenuItem::List& item_list) { 664 const ExtensionMenuItem::List& item_list) {
669 ExtensionMenuItem::List::const_iterator i = item_list.begin(); 665 ExtensionMenuItem::List::const_iterator i = item_list.begin();
670 while (i != item_list.end()) { 666 while (i != item_list.end()) {
671 if ((*i)->type() != ExtensionMenuItem::RADIO) { 667 if ((*i)->type() != ExtensionMenuItem::RADIO) {
672 ++i; 668 ++i;
673 break; 669 break;
674 } 670 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 return true; 820 return true;
825 if (extension_id == other.extension_id) { 821 if (extension_id == other.extension_id) {
826 if (uid < other.uid) 822 if (uid < other.uid)
827 return true; 823 return true;
828 if (uid == other.uid) 824 if (uid == other.uid)
829 return string_uid < other.string_uid; 825 return string_uid < other.string_uid;
830 } 826 }
831 } 827 }
832 return false; 828 return false;
833 } 829 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698