Chromium Code Reviews| 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/extension_action_manager.h" | 5 #include "chrome/browser/extensions/extension_action_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | |
| 7 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r_factory.h" | 8 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r_factory.h" |
| 8 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 12 #include "extensions/browser/extension_icon_image.h" | |
| 11 #include "extensions/browser/extension_registry.h" | 13 #include "extensions/browser/extension_registry.h" |
| 12 #include "extensions/browser/extension_system.h" | 14 #include "extensions/browser/extension_system.h" |
| 13 #include "extensions/browser/extensions_browser_client.h" | 15 #include "extensions/browser/extensions_browser_client.h" |
| 14 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 17 #include "ui/gfx/image/image_skia.h" | |
| 15 | 18 |
| 16 namespace extensions { | 19 namespace extensions { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 // BrowserContextKeyedServiceFactory for ExtensionActionManager. | 23 // BrowserContextKeyedServiceFactory for ExtensionActionManager. |
| 21 class ExtensionActionManagerFactory : public BrowserContextKeyedServiceFactory { | 24 class ExtensionActionManagerFactory : public BrowserContextKeyedServiceFactory { |
| 22 public: | 25 public: |
| 23 // BrowserContextKeyedServiceFactory implementation: | 26 // BrowserContextKeyedServiceFactory implementation: |
| 24 static ExtensionActionManager* GetForBrowserContext( | 27 static ExtensionActionManager* GetForBrowserContext( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 return nullptr; | 103 return nullptr; |
| 101 | 104 |
| 102 // Only create action info for enabled extensions. | 105 // Only create action info for enabled extensions. |
| 103 // This avoids bugs where actions are recreated just after being removed | 106 // This avoids bugs where actions are recreated just after being removed |
| 104 // in response to OnExtensionUnloaded(). | 107 // in response to OnExtensionUnloaded(). |
| 105 if (!ExtensionRegistry::Get(profile) | 108 if (!ExtensionRegistry::Get(profile) |
| 106 ->enabled_extensions().Contains(extension.id())) { | 109 ->enabled_extensions().Contains(extension.id())) { |
| 107 return nullptr; | 110 return nullptr; |
| 108 } | 111 } |
| 109 | 112 |
| 110 std::unique_ptr<ExtensionAction> action( | 113 auto action = |
| 111 new ExtensionAction(extension, action_type, *action_info)); | 114 base::MakeUnique<ExtensionAction>(extension, action_type, *action_info); |
| 115 | |
| 116 if (action->default_icon()) { | |
| 117 action->SetDefaultIconImage(base::MakeUnique<IconImage>( | |
| 118 profile, &extension, *action->default_icon(), | |
| 119 ExtensionAction::ActionIconSize(), | |
| 120 ExtensionAction::DefaultIcon().AsImageSkia(), nullptr)); | |
|
asargent_no_longer_on_chrome
2016/11/18 00:55:27
The naming here is pretty confusing and I really h
Devlin
2016/11/18 01:56:47
Rename DefaultIcon() to FallbackIcon() - I agree t
asargent_no_longer_on_chrome
2016/11/18 18:29:33
Yeah, agreed. I guess to complete the thought, I w
| |
| 121 } | |
| 122 | |
| 112 ExtensionAction* raw_action = action.get(); | 123 ExtensionAction* raw_action = action.get(); |
| 113 (*map)[extension.id()] = std::move(action); | 124 (*map)[extension.id()] = std::move(action); |
| 114 return raw_action; | 125 return raw_action; |
| 115 } | 126 } |
| 116 | 127 |
| 117 } // namespace | 128 } // namespace |
| 118 | 129 |
| 119 ExtensionAction* ExtensionActionManager::GetPageAction( | 130 ExtensionAction* ExtensionActionManager::GetPageAction( |
| 120 const Extension& extension) const { | 131 const Extension& extension) const { |
| 121 return GetOrCreateOrNull(&page_actions_, extension, | 132 return GetOrCreateOrNull(&page_actions_, extension, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 profile_); | 173 profile_); |
| 163 } | 174 } |
| 164 | 175 |
| 165 ExtensionAction* ExtensionActionManager::GetExtensionAction( | 176 ExtensionAction* ExtensionActionManager::GetExtensionAction( |
| 166 const Extension& extension) const { | 177 const Extension& extension) const { |
| 167 ExtensionAction* action = GetBrowserAction(extension); | 178 ExtensionAction* action = GetBrowserAction(extension); |
| 168 return action ? action : GetPageAction(extension); | 179 return action ? action : GetPageAction(extension); |
| 169 } | 180 } |
| 170 | 181 |
| 171 } // namespace extensions | 182 } // namespace extensions |
| OLD | NEW |