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/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
14 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
15 #include "chrome/browser/extensions/extension_service.h" | |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "content/public/browser/invalidate_type.h" | 17 #include "content/public/browser/invalidate_type.h" |
19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
20 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_registry.h" |
21 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
22 | 21 |
23 namespace extensions { | 22 namespace extensions { |
24 | 23 |
25 namespace keys = declarative_content_constants; | 24 namespace keys = declarative_content_constants; |
26 | 25 |
27 namespace { | 26 namespace { |
28 // Error messages. | 27 // Error messages. |
29 const char kInvalidInstanceTypeError[] = | 28 const char kInvalidInstanceTypeError[] = |
30 "An action has an invalid instanceType: %s"; | 29 "An action has an invalid instanceType: %s"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 GetPageAction(apply_info->profile, extension_id)) { | 75 GetPageAction(apply_info->profile, extension_id)) { |
77 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); | 76 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); |
78 apply_info->tab->NotifyNavigationStateChanged( | 77 apply_info->tab->NotifyNavigationStateChanged( |
79 content::INVALIDATE_TYPE_PAGE_ACTIONS); | 78 content::INVALIDATE_TYPE_PAGE_ACTIONS); |
80 } | 79 } |
81 } | 80 } |
82 | 81 |
83 private: | 82 private: |
84 static ExtensionAction* GetPageAction(Profile* profile, | 83 static ExtensionAction* GetPageAction(Profile* profile, |
85 const std::string& extension_id) { | 84 const std::string& extension_id) { |
86 ExtensionService* service = | 85 const Extension* extension = |
87 ExtensionSystem::Get(profile)->extension_service(); | 86 ExtensionRegistry::Get(profile) |
88 const Extension* extension = service->GetInstalledExtension(extension_id); | 87 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
89 if (!extension) | 88 if (!extension) |
90 return NULL; | 89 return NULL; |
91 return ExtensionActionManager::Get(profile)->GetPageAction(*extension); | 90 return ExtensionActionManager::Get(profile)->GetPageAction(*extension); |
92 } | 91 } |
93 virtual ~ShowPageAction() {} | 92 virtual ~ShowPageAction() {} |
94 | 93 |
95 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); | 94 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); |
96 }; | 95 }; |
97 | 96 |
98 struct ContentActionFactory { | 97 struct ContentActionFactory { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 factory_method_iter = factory.factory_methods.find(instance_type); | 150 factory_method_iter = factory.factory_methods.find(instance_type); |
152 if (factory_method_iter != factory.factory_methods.end()) | 151 if (factory_method_iter != factory.factory_methods.end()) |
153 return (*factory_method_iter->second)( | 152 return (*factory_method_iter->second)( |
154 extension, action_dict, error, bad_message); | 153 extension, action_dict, error, bad_message); |
155 | 154 |
156 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); | 155 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); |
157 return scoped_refptr<ContentAction>(); | 156 return scoped_refptr<ContentAction>(); |
158 } | 157 } |
159 | 158 |
160 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |