| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/sync_helper.h" | 22 #include "chrome/common/extensions/sync_helper.h" |
| 23 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
| 24 #include "content/public/browser/site_instance.h" | 24 #include "content/public/browser/site_instance.h" |
| 25 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 26 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/extension_util.h" | 28 #include "extensions/browser/extension_util.h" |
| 29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_icon_set.h" | 30 #include "extensions/common/extension_icon_set.h" |
| 31 #include "extensions/common/features/behavior_feature.h" | |
| 32 #include "extensions/common/features/feature.h" | |
| 33 #include "extensions/common/features/feature_provider.h" | |
| 34 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
| 35 #include "extensions/common/manifest_handlers/app_isolation_info.h" | 32 #include "extensions/common/manifest_handlers/app_isolation_info.h" |
| 36 #include "extensions/common/manifest_handlers/incognito_info.h" | 33 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 37 #include "extensions/common/permissions/permissions_data.h" | 34 #include "extensions/common/permissions/permissions_data.h" |
| 38 #include "extensions/grit/extensions_browser_resources.h" | 35 #include "extensions/grit/extensions_browser_resources.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 40 | 37 |
| 41 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 42 #include "chrome/browser/chromeos/file_manager/app_id.h" | 39 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 43 #endif | 40 #endif |
| 44 | 41 |
| 45 namespace extensions { | 42 namespace extensions { |
| 46 namespace util { | 43 namespace util { |
| 47 | 44 |
| 48 namespace { | 45 namespace { |
| 49 // The entry into the prefs used to flag an extension as installed by custodian. | 46 // The entry into the prefs used to flag an extension as installed by custodian. |
| 50 // It is relevant only for supervised users. | 47 // It is relevant only for supervised users. |
| 51 const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian"; | 48 const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian"; |
| 52 | 49 |
| 53 // Returns true if |extension| should always be enabled in incognito mode. | |
| 54 bool IsWhitelistedForIncognito(const Extension* extension) { | |
| 55 const Feature* feature = FeatureProvider::GetBehaviorFeature( | |
| 56 behavior_feature::kWhitelistedForIncognito); | |
| 57 return feature && feature->IsAvailableToExtension(extension).is_available(); | |
| 58 } | |
| 59 | |
| 60 // Returns |extension_id|. See note below. | 50 // Returns |extension_id|. See note below. |
| 61 std::string ReloadExtensionIfEnabled(const std::string& extension_id, | 51 std::string ReloadExtensionIfEnabled(const std::string& extension_id, |
| 62 content::BrowserContext* context) { | 52 content::BrowserContext* context) { |
| 63 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 53 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 64 bool extension_is_enabled = | 54 bool extension_is_enabled = |
| 65 registry->enabled_extensions().Contains(extension_id); | 55 registry->enabled_extensions().Contains(extension_id); |
| 66 | 56 |
| 67 if (!extension_is_enabled) | 57 if (!extension_is_enabled) |
| 68 return extension_id; | 58 return extension_id; |
| 69 | 59 |
| 70 // When we reload the extension the ID may be invalidated if we've passed it | 60 // When we reload the extension the ID may be invalidated if we've passed it |
| 71 // by const ref everywhere. Make a copy to be safe. http://crbug.com/103762 | 61 // by const ref everywhere. Make a copy to be safe. http://crbug.com/103762 |
| 72 std::string id = extension_id; | 62 std::string id = extension_id; |
| 73 ExtensionService* service = | 63 ExtensionService* service = |
| 74 ExtensionSystem::Get(context)->extension_service(); | 64 ExtensionSystem::Get(context)->extension_service(); |
| 75 CHECK(service); | 65 CHECK(service); |
| 76 service->ReloadExtension(id); | 66 service->ReloadExtension(id); |
| 77 return id; | 67 return id; |
| 78 } | 68 } |
| 79 | 69 |
| 80 } // namespace | 70 } // namespace |
| 81 | 71 |
| 82 bool IsIncognitoEnabled(const std::string& extension_id, | |
| 83 content::BrowserContext* context) { | |
| 84 const Extension* extension = ExtensionRegistry::Get(context)-> | |
| 85 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | |
| 86 if (extension) { | |
| 87 if (!util::CanBeIncognitoEnabled(extension)) | |
| 88 return false; | |
| 89 // If this is an existing component extension we always allow it to | |
| 90 // work in incognito mode. | |
| 91 if (extension->location() == Manifest::COMPONENT || | |
| 92 extension->location() == Manifest::EXTERNAL_COMPONENT) { | |
| 93 return true; | |
| 94 } | |
| 95 if (IsWhitelistedForIncognito(extension)) | |
| 96 return true; | |
| 97 } | |
| 98 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); | |
| 99 } | |
| 100 | |
| 101 void SetIsIncognitoEnabled(const std::string& extension_id, | 72 void SetIsIncognitoEnabled(const std::string& extension_id, |
| 102 content::BrowserContext* context, | 73 content::BrowserContext* context, |
| 103 bool enabled) { | 74 bool enabled) { |
| 104 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 75 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 105 const Extension* extension = | 76 const Extension* extension = |
| 106 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 77 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
| 107 | 78 |
| 108 if (extension) { | 79 if (extension) { |
| 109 if (!util::CanBeIncognitoEnabled(extension)) | 80 if (!util::CanBeIncognitoEnabled(extension)) |
| 110 return; | 81 return; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 #endif | 318 #endif |
| 348 } | 319 } |
| 349 | 320 |
| 350 bool IsExtensionSupervised(const Extension* extension, Profile* profile) { | 321 bool IsExtensionSupervised(const Extension* extension, Profile* profile) { |
| 351 return WasInstalledByCustodian(extension->id(), profile) && | 322 return WasInstalledByCustodian(extension->id(), profile) && |
| 352 profile->IsSupervised(); | 323 profile->IsSupervised(); |
| 353 } | 324 } |
| 354 | 325 |
| 355 } // namespace util | 326 } // namespace util |
| 356 } // namespace extensions | 327 } // namespace extensions |
| OLD | NEW |