| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_util.h" | 5 #include "chrome/browser/extensions/extension_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_sync_service.h" | 9 #include "chrome/browser/extensions/extension_sync_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/sync_helper.h" | 12 #include "chrome/common/extensions/sync_helper.h" |
| 14 #include "content/public/browser/site_instance.h" | 13 #include "content/public/browser/site_instance.h" |
| 15 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
| 16 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/manifest.h" | 18 #include "extensions/common/manifest.h" |
| 19 #include "extensions/common/manifest_handlers/incognito_info.h" | 19 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 namespace util { | 22 namespace util { |
| 23 | 23 |
| 24 bool IsIncognitoEnabled(const std::string& extension_id, | 24 bool IsIncognitoEnabled(const std::string& extension_id, |
| 25 content::BrowserContext* context) { | 25 content::BrowserContext* context) { |
| 26 const Extension* extension = ExtensionRegistry::Get(context)-> | 26 const Extension* extension = ExtensionRegistry::Get(context)-> |
| 27 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 27 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 28 if (extension) { | 28 if (extension) { |
| 29 if (!extension->can_be_incognito_enabled()) | 29 if (!extension->can_be_incognito_enabled()) |
| 30 return false; | 30 return false; |
| 31 // If this is an existing component extension we always allow it to | 31 // If this is an existing component extension we always allow it to |
| 32 // work in incognito mode. | 32 // work in incognito mode. |
| 33 if (extension->location() == Manifest::COMPONENT) | 33 if (extension->location() == Manifest::COMPONENT) |
| 34 return true; | 34 return true; |
| 35 if (extension->force_incognito_enabled()) | 35 if (extension->force_incognito_enabled()) |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); | 39 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void SetIsIncognitoEnabled(const std::string& extension_id, | 42 void SetIsIncognitoEnabled(const std::string& extension_id, |
| 43 content::BrowserContext* context, | 43 content::BrowserContext* context, |
| 44 bool enabled) { | 44 bool enabled) { |
| 45 ExtensionService* service = | 45 ExtensionService* service = |
| 46 ExtensionSystem::GetForBrowserContext(context)->extension_service(); | 46 ExtensionSystem::Get(context)->extension_service(); |
| 47 CHECK(service); | 47 CHECK(service); |
| 48 const Extension* extension = service->GetInstalledExtension(extension_id); | 48 const Extension* extension = service->GetInstalledExtension(extension_id); |
| 49 | 49 |
| 50 if (extension) { | 50 if (extension) { |
| 51 if (!extension->can_be_incognito_enabled()) | 51 if (!extension->can_be_incognito_enabled()) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 if (extension->location() == Manifest::COMPONENT) { | 54 if (extension->location() == Manifest::COMPONENT) { |
| 55 // This shouldn't be called for component extensions unless it is called | 55 // This shouldn't be called for component extensions unless it is called |
| 56 // by sync, for syncable component extensions. | 56 // by sync, for syncable component extensions. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 content::BrowserContext* context) { | 114 content::BrowserContext* context) { |
| 115 return CommandLine::ForCurrentProcess()->HasSwitch( | 115 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 switches::kDisableExtensionsFileAccessCheck) || | 116 switches::kDisableExtensionsFileAccessCheck) || |
| 117 ExtensionPrefs::Get(context)->AllowFileAccess(extension_id); | 117 ExtensionPrefs::Get(context)->AllowFileAccess(extension_id); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SetAllowFileAccess(const std::string& extension_id, | 120 void SetAllowFileAccess(const std::string& extension_id, |
| 121 content::BrowserContext* context, | 121 content::BrowserContext* context, |
| 122 bool allow) { | 122 bool allow) { |
| 123 ExtensionService* service = | 123 ExtensionService* service = |
| 124 ExtensionSystem::GetForBrowserContext(context)->extension_service(); | 124 ExtensionSystem::Get(context)->extension_service(); |
| 125 CHECK(service); | 125 CHECK(service); |
| 126 | 126 |
| 127 // Reload to update browser state. Only bother if the value changed and the | 127 // Reload to update browser state. Only bother if the value changed and the |
| 128 // extension is actually enabled, since there is no UI otherwise. | 128 // extension is actually enabled, since there is no UI otherwise. |
| 129 if (allow == AllowFileAccess(extension_id, context)) | 129 if (allow == AllowFileAccess(extension_id, context)) |
| 130 return; | 130 return; |
| 131 | 131 |
| 132 service->extension_prefs()->SetAllowFileAccess(extension_id, allow); | 132 service->extension_prefs()->SetAllowFileAccess(extension_id, allow); |
| 133 | 133 |
| 134 bool extension_is_enabled = service->extensions()->Contains(extension_id); | 134 bool extension_is_enabled = service->extensions()->Contains(extension_id); |
| 135 if (extension_is_enabled) | 135 if (extension_is_enabled) |
| 136 service->ReloadExtension(extension_id); | 136 service->ReloadExtension(extension_id); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool IsAppLaunchable(const std::string& extension_id, | 139 bool IsAppLaunchable(const std::string& extension_id, |
| 140 content::BrowserContext* context) { | 140 content::BrowserContext* context) { |
| 141 return !(ExtensionPrefs::Get(context)->GetDisableReasons(extension_id) & | 141 return !(ExtensionPrefs::Get(context)->GetDisableReasons(extension_id) & |
| 142 Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | 142 Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, | 145 bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, |
| 146 content::BrowserContext* context) { | 146 content::BrowserContext* context) { |
| 147 return ExtensionRegistry::Get(context)->GetExtensionById( | 147 return ExtensionRegistry::Get(context)->GetExtensionById( |
| 148 extension_id, ExtensionRegistry::ENABLED) != NULL; | 148 extension_id, ExtensionRegistry::ENABLED) != NULL; |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool IsExtensionIdle(const std::string& extension_id, | 151 bool IsExtensionIdle(const std::string& extension_id, |
| 152 content::BrowserContext* context) { | 152 content::BrowserContext* context) { |
| 153 ProcessManager* process_manager = | 153 ProcessManager* process_manager = |
| 154 ExtensionSystem::GetForBrowserContext(context)->process_manager(); | 154 ExtensionSystem::Get(context)->process_manager(); |
| 155 DCHECK(process_manager); | 155 DCHECK(process_manager); |
| 156 ExtensionHost* host = | 156 ExtensionHost* host = |
| 157 process_manager->GetBackgroundHostForExtension(extension_id); | 157 process_manager->GetBackgroundHostForExtension(extension_id); |
| 158 if (host) | 158 if (host) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 content::SiteInstance* site_instance = process_manager->GetSiteInstanceForURL( | 161 content::SiteInstance* site_instance = process_manager->GetSiteInstanceForURL( |
| 162 Extension::GetBaseURLFromExtensionId(extension_id)); | 162 Extension::GetBaseURLFromExtensionId(extension_id)); |
| 163 if (site_instance && site_instance->HasProcess()) | 163 if (site_instance && site_instance->HasProcess()) |
| 164 return false; | 164 return false; |
| 165 | 165 |
| 166 return process_manager->GetRenderViewHostsForExtension(extension_id).empty(); | 166 return process_manager->GetRenderViewHostsForExtension(extension_id).empty(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool IsExtensionInstalledPermanently(const std::string& extension_id, | 169 bool IsExtensionInstalledPermanently(const std::string& extension_id, |
| 170 content::BrowserContext* context) { | 170 content::BrowserContext* context) { |
| 171 const Extension* extension = ExtensionRegistry::Get(context)-> | 171 const Extension* extension = ExtensionRegistry::Get(context)-> |
| 172 GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 172 GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
| 173 return extension && !extension->is_ephemeral(); | 173 return extension && !extension->is_ephemeral(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace util | 176 } // namespace util |
| 177 } // namespace extensions | 177 } // namespace extensions |
| OLD | NEW |