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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/extensions/extension_service.h" | |
17 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
18 #include "chrome/browser/extensions/menu_manager_factory.h" | 17 #include "chrome/browser/extensions/menu_manager_factory.h" |
19 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/extensions/api/chrome_web_view_internal.h" | 20 #include "chrome/common/extensions/api/chrome_web_view_internal.h" |
22 #include "chrome/common/extensions/api/context_menus.h" | 21 #include "chrome/common/extensions/api/context_menus.h" |
23 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/context_menu_params.h" | 26 #include "content/public/common/context_menu_params.h" |
28 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
29 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_system.h" | |
31 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 29 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
32 #include "extensions/browser/state_store.h" | 30 #include "extensions/browser/state_store.h" |
33 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
34 #include "extensions/common/manifest_handlers/background_info.h" | 32 #include "extensions/common/manifest_handlers/background_info.h" |
35 #include "ui/gfx/favicon_size.h" | 33 #include "ui/gfx/favicon_size.h" |
36 #include "ui/gfx/text_elider.h" | 34 #include "ui/gfx/text_elider.h" |
37 | 35 |
38 using content::WebContents; | 36 using content::WebContents; |
39 using extensions::ExtensionSystem; | |
40 | 37 |
41 namespace extensions { | 38 namespace extensions { |
42 | 39 |
43 namespace context_menus = api::context_menus; | 40 namespace context_menus = api::context_menus; |
44 namespace chrome_web_view = api::chrome_web_view_internal; | 41 namespace chrome_web_view = api::chrome_web_view_internal; |
45 | 42 |
46 namespace { | 43 namespace { |
47 | 44 |
48 // Keys for serialization to and from Value to store in the preferences. | 45 // Keys for serialization to and from Value to store in the preferences. |
49 const char kContextMenusKey[] = "context_menus"; | 46 const char kContextMenusKey[] = "context_menus"; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 const content::ContextMenuParams& params, | 606 const content::ContextMenuParams& params, |
610 const MenuItem::Id& menu_item_id) { | 607 const MenuItem::Id& menu_item_id) { |
611 EventRouter* event_router = EventRouter::Get(context); | 608 EventRouter* event_router = EventRouter::Get(context); |
612 if (!event_router) | 609 if (!event_router) |
613 return; | 610 return; |
614 | 611 |
615 MenuItem* item = GetItemById(menu_item_id); | 612 MenuItem* item = GetItemById(menu_item_id); |
616 if (!item) | 613 if (!item) |
617 return; | 614 return; |
618 | 615 |
619 // ExtensionService/Extension can be NULL in unit tests :( | 616 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); |
620 ExtensionService* service = | |
621 ExtensionSystem::Get(browser_context_)->extension_service(); | |
622 const Extension* extension = | 617 const Extension* extension = |
623 service ? service->extensions()->GetByID(item->extension_id()) : NULL; | 618 registry->enabled_extensions().GetByID(item->extension_id()); |
624 | 619 |
625 if (item->type() == MenuItem::RADIO) | 620 if (item->type() == MenuItem::RADIO) |
626 RadioItemSelected(item); | 621 RadioItemSelected(item); |
627 | 622 |
628 scoped_ptr<base::ListValue> args(new base::ListValue()); | 623 scoped_ptr<base::ListValue> args(new base::ListValue()); |
629 | 624 |
630 base::DictionaryValue* properties = new base::DictionaryValue(); | 625 base::DictionaryValue* properties = new base::DictionaryValue(); |
631 SetIdKeyValue(properties, "menuItemId", item->id()); | 626 SetIdKeyValue(properties, "menuItemId", item->id()); |
632 if (item->parent_id()) | 627 if (item->parent_id()) |
633 SetIdKeyValue(properties, "parentMenuItemId", *item->parent_id()); | 628 SetIdKeyValue(properties, "parentMenuItemId", *item->parent_id()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 } | 792 } |
798 | 793 |
799 if (store_) { | 794 if (store_) { |
800 store_->SetExtensionValue(extension->id(), kContextMenusKey, | 795 store_->SetExtensionValue(extension->id(), kContextMenusKey, |
801 MenuItemsToValue(all_items)); | 796 MenuItemsToValue(all_items)); |
802 } | 797 } |
803 } | 798 } |
804 | 799 |
805 void MenuManager::ReadFromStorage(const std::string& extension_id, | 800 void MenuManager::ReadFromStorage(const std::string& extension_id, |
806 scoped_ptr<base::Value> value) { | 801 scoped_ptr<base::Value> value) { |
807 const Extension* extension = ExtensionSystem::Get(browser_context_) | 802 const Extension* extension = ExtensionRegistry::Get(browser_context_) |
808 ->extension_service() | 803 ->enabled_extensions() |
809 ->extensions() | 804 .GetByID(extension_id); |
810 ->GetByID(extension_id); | |
811 if (!extension) | 805 if (!extension) |
812 return; | 806 return; |
813 | 807 |
814 MenuItem::List items = MenuItemsFromValue(extension_id, value.get()); | 808 MenuItem::List items = MenuItemsFromValue(extension_id, value.get()); |
815 for (size_t i = 0; i < items.size(); ++i) { | 809 for (size_t i = 0; i < items.size(); ++i) { |
816 bool added = false; | 810 bool added = false; |
817 | 811 |
818 if (items[i]->parent_id()) { | 812 if (items[i]->parent_id()) { |
819 // Parent IDs are stored in the parent_id field for convenience, but | 813 // Parent IDs are stored in the parent_id field for convenience, but |
820 // they have not yet been validated. Separate them out here. | 814 // they have not yet been validated. Separate them out here. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (uid < other.uid) | 940 if (uid < other.uid) |
947 return true; | 941 return true; |
948 if (uid == other.uid) | 942 if (uid == other.uid) |
949 return string_uid < other.string_uid; | 943 return string_uid < other.string_uid; |
950 } | 944 } |
951 } | 945 } |
952 return false; | 946 return false; |
953 } | 947 } |
954 | 948 |
955 } // namespace extensions | 949 } // namespace extensions |
OLD | NEW |