Chromium Code Reviews| 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 "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_sync_service.h" | 11 #include "chrome/browser/extensions/extension_sync_service.h" |
| 12 #include "chrome/browser/extensions/permissions_updater.h" | 12 #include "chrome/browser/extensions/permissions_updater.h" |
| 13 #include "chrome/browser/extensions/shared_module_service.h" | 13 #include "chrome/browser/extensions/shared_module_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 15 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
| 18 #include "chrome/common/extensions/sync_helper.h" | 18 #include "chrome/common/extensions/sync_helper.h" |
| 19 #include "content/public/browser/site_instance.h" | 19 #include "content/public/browser/site_instance.h" |
| 20 #include "extensions/browser/extension_prefs.h" | 20 #include "extensions/browser/extension_prefs.h" |
| 21 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 23 #include "extensions/browser/extension_util.h" | 23 #include "extensions/browser/extension_util.h" |
| 24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_icon_set.h" | 25 #include "extensions/common/extension_icon_set.h" |
| 26 #include "extensions/common/feature_switch.h" | 26 #include "extensions/common/feature_switch.h" |
| 27 #include "extensions/common/features/simple_feature.h" | 27 #include "extensions/common/features/feature_provider.h" |
| 28 #include "extensions/common/features/switch_feature.h" | |
| 28 #include "extensions/common/manifest.h" | 29 #include "extensions/common/manifest.h" |
| 29 #include "extensions/common/manifest_handlers/incognito_info.h" | 30 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 30 #include "extensions/common/permissions/permissions_data.h" | 31 #include "extensions/common/permissions/permissions_data.h" |
| 31 #include "extensions/grit/extensions_browser_resources.h" | 32 #include "extensions/grit/extensions_browser_resources.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 33 | 34 |
| 34 namespace extensions { | 35 namespace extensions { |
| 35 namespace util { | 36 namespace util { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // The entry into the ExtensionPrefs for allowing an extension to script on | 40 // The entry into the ExtensionPrefs for allowing an extension to script on |
| 40 // all urls without explicit permission. | 41 // all urls without explicit permission. |
| 41 const char kExtensionAllowedOnAllUrlsPrefName[] = | 42 const char kExtensionAllowedOnAllUrlsPrefName[] = |
| 42 "extension_can_script_all_urls"; | 43 "extension_can_script_all_urls"; |
| 43 | 44 |
| 44 // Returns true if |extension_id| for an external component extension should | 45 // Returns true if |extension_id| should always be enabled in incognito |
| 45 // always be enabled in incognito windows. | 46 // windows. |
| 46 bool IsWhitelistedForIncognito(const std::string& extension_id) { | 47 bool IsWhitelistedForIncognito(const Extension* extension) { |
| 47 static const char* const kExtensionWhitelist[] = { | 48 return FeatureProvider::GetSwitchFeatures() |
|
not at google - send to devlin
2014/12/11 17:51:00
Btw, wdyt about renaming all of these to "GetSwitc
| |
| 48 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 | 49 ->GetFeature(SwitchFeature::kWhitelistedForIncognito) |
| 49 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 | 50 ->IsAvailableToExtension(extension) |
| 50 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562 | 51 .is_available(); |
| 51 }; | |
| 52 | |
| 53 return extensions::SimpleFeature::IsIdInList( | |
| 54 extension_id, | |
| 55 std::set<std::string>( | |
| 56 kExtensionWhitelist, | |
| 57 kExtensionWhitelist + arraysize(kExtensionWhitelist))); | |
| 58 } | 52 } |
| 59 | 53 |
| 60 // Returns |extension_id|. See note below. | 54 // Returns |extension_id|. See note below. |
| 61 std::string ReloadExtensionIfEnabled(const std::string& extension_id, | 55 std::string ReloadExtensionIfEnabled(const std::string& extension_id, |
| 62 content::BrowserContext* context) { | 56 content::BrowserContext* context) { |
| 63 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 57 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 64 bool extension_is_enabled = | 58 bool extension_is_enabled = |
| 65 registry->enabled_extensions().Contains(extension_id); | 59 registry->enabled_extensions().Contains(extension_id); |
| 66 | 60 |
| 67 if (!extension_is_enabled) | 61 if (!extension_is_enabled) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 83 content::BrowserContext* context) { | 77 content::BrowserContext* context) { |
| 84 const Extension* extension = ExtensionRegistry::Get(context)-> | 78 const Extension* extension = ExtensionRegistry::Get(context)-> |
| 85 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 79 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 86 if (extension) { | 80 if (extension) { |
| 87 if (!extension->can_be_incognito_enabled()) | 81 if (!extension->can_be_incognito_enabled()) |
| 88 return false; | 82 return false; |
| 89 // If this is an existing component extension we always allow it to | 83 // If this is an existing component extension we always allow it to |
| 90 // work in incognito mode. | 84 // work in incognito mode. |
| 91 if (extension->location() == Manifest::COMPONENT) | 85 if (extension->location() == Manifest::COMPONENT) |
| 92 return true; | 86 return true; |
| 93 if (extension->location() == Manifest::EXTERNAL_COMPONENT && | 87 if (IsWhitelistedForIncognito(extension)) |
| 94 IsWhitelistedForIncognito(extension_id)) { | |
| 95 return true; | 88 return true; |
| 96 } | |
| 97 } | 89 } |
| 98 | |
| 99 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); | 90 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); |
| 100 } | 91 } |
| 101 | 92 |
| 102 void SetIsIncognitoEnabled(const std::string& extension_id, | 93 void SetIsIncognitoEnabled(const std::string& extension_id, |
| 103 content::BrowserContext* context, | 94 content::BrowserContext* context, |
| 104 bool enabled) { | 95 bool enabled) { |
| 105 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 96 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 106 const Extension* extension = | 97 const Extension* extension = |
| 107 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 98 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
| 108 | 99 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 IDR_EXTENSION_DEFAULT_ICON); | 350 IDR_EXTENSION_DEFAULT_ICON); |
| 360 } | 351 } |
| 361 | 352 |
| 362 bool IsStreamlinedHostedAppsEnabled() { | 353 bool IsStreamlinedHostedAppsEnabled() { |
| 363 return CommandLine::ForCurrentProcess()->HasSwitch( | 354 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 364 switches::kEnableStreamlinedHostedApps); | 355 switches::kEnableStreamlinedHostedApps); |
| 365 } | 356 } |
| 366 | 357 |
| 367 } // namespace util | 358 } // namespace util |
| 368 } // namespace extensions | 359 } // namespace extensions |
| OLD | NEW |