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

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

Issue 10535155: Hook the activeTab permission up to the omnibox, page action, and context menu APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 8 years, 6 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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/extensions/extension_event_names.h" 15 #include "chrome/browser/extensions/extension_event_names.h"
16 #include "chrome/browser/extensions/extension_event_router.h" 16 #include "chrome/browser/extensions/extension_event_router.h"
17 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_system.h" 18 #include "chrome/browser/extensions/extension_system.h"
19 #include "chrome/browser/extensions/extension_tab_helper.h"
19 #include "chrome/browser/extensions/extension_tab_util.h" 20 #include "chrome/browser/extensions/extension_tab_util.h"
20 #include "chrome/browser/extensions/state_store.h" 21 #include "chrome/browser/extensions/state_store.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h"
22 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
24 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/context_menu_params.h" 29 #include "content/public/common/context_menu_params.h"
27 #include "ui/base/text/text_elider.h" 30 #include "ui/base/text/text_elider.h"
28 #include "ui/gfx/favicon_size.h" 31 #include "ui/gfx/favicon_size.h"
29 32
30 using content::WebContents; 33 using content::WebContents;
31 34
32 namespace { 35 namespace {
33 36
34 // Keys for serialization to and from Value to store in the preferences. 37 // Keys for serialization to and from Value to store in the preferences.
35 const char kContextMenusKey[] = "context_menus"; 38 const char kContextMenusKey[] = "context_menus";
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 static void AddURLProperty(DictionaryValue* dictionary, 564 static void AddURLProperty(DictionaryValue* dictionary,
562 const std::string& key, const GURL& url) { 565 const std::string& key, const GURL& url) {
563 if (!url.is_empty()) 566 if (!url.is_empty())
564 dictionary->SetString(key, url.possibly_invalid_spec()); 567 dictionary->SetString(key, url.possibly_invalid_spec());
565 } 568 }
566 569
567 void ExtensionMenuManager::ExecuteCommand( 570 void ExtensionMenuManager::ExecuteCommand(
568 Profile* profile, 571 Profile* profile,
569 WebContents* web_contents, 572 WebContents* web_contents,
570 const content::ContextMenuParams& params, 573 const content::ContextMenuParams& params,
571 const ExtensionMenuItem::Id& menuItemId) { 574 const ExtensionMenuItem::Id& menu_item_id) {
572 ExtensionEventRouter* event_router = profile->GetExtensionEventRouter(); 575 ExtensionEventRouter* event_router = profile->GetExtensionEventRouter();
573 if (!event_router) 576 if (!event_router)
574 return; 577 return;
575 578
576 ExtensionMenuItem* item = GetItemById(menuItemId); 579 ExtensionMenuItem* item = GetItemById(menu_item_id);
577 if (!item) 580 if (!item)
578 return; 581 return;
579 582
583 // ExtensionService/Extension can be NULL in unit tests :(
584 ExtensionService* service =
585 ExtensionSystem::Get(profile_)->extension_service();
586 const extensions::Extension* extension = service ?
587 service->extensions()->GetByID(menu_item_id.extension_id) : NULL;
588
580 if (item->type() == ExtensionMenuItem::RADIO) 589 if (item->type() == ExtensionMenuItem::RADIO)
581 RadioItemSelected(item); 590 RadioItemSelected(item);
582 591
583 ListValue args; 592 ListValue args;
584 593
585 DictionaryValue* properties = new DictionaryValue(); 594 DictionaryValue* properties = new DictionaryValue();
586 SetIdKeyValue(properties, "menuItemId", item->id()); 595 SetIdKeyValue(properties, "menuItemId", item->id());
587 if (item->parent_id()) 596 if (item->parent_id())
588 SetIdKeyValue(properties, "parentMenuItemId", item->id()); 597 SetIdKeyValue(properties, "parentMenuItemId", item->id());
589 598
(...skipping 16 matching lines...) Expand all
606 AddURLProperty(properties, "frameUrl", params.frame_url); 615 AddURLProperty(properties, "frameUrl", params.frame_url);
607 616
608 if (params.selection_text.length() > 0) 617 if (params.selection_text.length() > 0)
609 properties->SetString("selectionText", params.selection_text); 618 properties->SetString("selectionText", params.selection_text);
610 619
611 properties->SetBoolean("editable", params.is_editable); 620 properties->SetBoolean("editable", params.is_editable);
612 621
613 args.Append(properties); 622 args.Append(properties);
614 623
615 // Add the tab info to the argument list. 624 // Add the tab info to the argument list.
616 if (web_contents) { 625 // Note: web_contents only NULL in unit tests :(
626 if (web_contents)
617 args.Append(ExtensionTabUtil::CreateTabValue(web_contents)); 627 args.Append(ExtensionTabUtil::CreateTabValue(web_contents));
618 } else { 628 else
619 args.Append(new DictionaryValue()); 629 args.Append(new DictionaryValue());
620 }
621 630
622 if (item->type() == ExtensionMenuItem::CHECKBOX || 631 if (item->type() == ExtensionMenuItem::CHECKBOX ||
623 item->type() == ExtensionMenuItem::RADIO) { 632 item->type() == ExtensionMenuItem::RADIO) {
624 bool was_checked = item->checked(); 633 bool was_checked = item->checked();
625 properties->SetBoolean("wasChecked", was_checked); 634 properties->SetBoolean("wasChecked", was_checked);
626 635
627 // 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
628 // items get their state toggled. 637 // items get their state toggled.
629 bool checked = 638 bool checked =
630 (item->type() == ExtensionMenuItem::RADIO) ? true : !was_checked; 639 (item->type() == ExtensionMenuItem::RADIO) ? true : !was_checked;
631 640
632 item->SetChecked(checked); 641 item->SetChecked(checked);
633 properties->SetBoolean("checked", item->checked()); 642 properties->SetBoolean("checked", item->checked());
634 643
635 const extensions::Extension* extension = ExtensionSystem::Get(profile_)-> 644 if (extension)
636 extension_service()->GetExtensionById(menuItemId.extension_id, false); 645 WriteToStorage(extension);
637 WriteToStorage(extension); 646 }
647
648 TabContents* tab_contents = web_contents ?
649 TabContents::FromWebContents(web_contents) : NULL;
650 if (tab_contents && extension) {
651 tab_contents->extension_tab_helper()->active_tab_permission_manager()->
652 GrantIfRequested(extension);
638 } 653 }
639 654
640 std::string json_args; 655 std::string json_args;
641 base::JSONWriter::Write(&args, &json_args); 656 base::JSONWriter::Write(&args, &json_args);
642 event_router->DispatchEventToExtension( 657 event_router->DispatchEventToExtension(
643 item->extension_id(), extension_event_names::kOnContextMenus, 658 item->extension_id(), extension_event_names::kOnContextMenus,
644 json_args, profile, GURL(), 659 json_args, profile, GURL(),
645 ExtensionEventRouter::USER_GESTURE_ENABLED); 660 ExtensionEventRouter::USER_GESTURE_ENABLED);
646 event_router->DispatchEventToExtension( 661 event_router->DispatchEventToExtension(
647 item->extension_id(), extension_event_names::kOnContextMenuClicked, 662 item->extension_id(), extension_event_names::kOnContextMenuClicked,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 return true; 824 return true;
810 if (extension_id == other.extension_id) { 825 if (extension_id == other.extension_id) {
811 if (uid < other.uid) 826 if (uid < other.uid)
812 return true; 827 return true;
813 if (uid == other.uid) 828 if (uid == other.uid)
814 return string_uid < other.string_uid; 829 return string_uid < other.string_uid;
815 } 830 }
816 } 831 }
817 return false; 832 return false;
818 } 833 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager.h ('k') | chrome/browser/extensions/page_action_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698