Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chrome/browser/extensions/extension_util.cc

Issue 789383002: Add the basic infrastructure for the Behavior feature type: BehaviorFeature and (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flag-features
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/behavior_feature.h"
28 #include "extensions/common/features/feature_provider.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| should always be enabled in incognito mode.
45 // always be enabled in incognito windows. 46 bool IsWhitelistedForIncognito(const Extension* extension) {
46 bool IsWhitelistedForIncognito(const std::string& extension_id) { 47 return FeatureProvider::GetBehaviorFeatures()
47 static const char* const kExtensionWhitelist[] = { 48 ->GetFeature(BehaviorFeature::kWhitelistedForIncognito)
48 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 49 ->IsAvailableToExtension(extension)
49 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 50 .is_available();
50 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562
51 };
52
53 return extensions::SimpleFeature::IsIdInList(
54 extension_id,
55 std::set<std::string>(
56 kExtensionWhitelist,
57 kExtensionWhitelist + arraysize(kExtensionWhitelist)));
58 } 51 }
59 52
60 // Returns |extension_id|. See note below. 53 // Returns |extension_id|. See note below.
61 std::string ReloadExtensionIfEnabled(const std::string& extension_id, 54 std::string ReloadExtensionIfEnabled(const std::string& extension_id,
62 content::BrowserContext* context) { 55 content::BrowserContext* context) {
63 ExtensionRegistry* registry = ExtensionRegistry::Get(context); 56 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
64 bool extension_is_enabled = 57 bool extension_is_enabled =
65 registry->enabled_extensions().Contains(extension_id); 58 registry->enabled_extensions().Contains(extension_id);
66 59
67 if (!extension_is_enabled) 60 if (!extension_is_enabled)
(...skipping 15 matching lines...) Expand all
83 content::BrowserContext* context) { 76 content::BrowserContext* context) {
84 const Extension* extension = ExtensionRegistry::Get(context)-> 77 const Extension* extension = ExtensionRegistry::Get(context)->
85 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); 78 GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
86 if (extension) { 79 if (extension) {
87 if (!extension->can_be_incognito_enabled()) 80 if (!extension->can_be_incognito_enabled())
88 return false; 81 return false;
89 // If this is an existing component extension we always allow it to 82 // If this is an existing component extension we always allow it to
90 // work in incognito mode. 83 // work in incognito mode.
91 if (extension->location() == Manifest::COMPONENT) 84 if (extension->location() == Manifest::COMPONENT)
92 return true; 85 return true;
93 if (extension->location() == Manifest::EXTERNAL_COMPONENT && 86 if (IsWhitelistedForIncognito(extension))
94 IsWhitelistedForIncognito(extension_id)) {
95 return true; 87 return true;
96 }
97 } 88 }
98
99 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); 89 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id);
100 } 90 }
101 91
102 void SetIsIncognitoEnabled(const std::string& extension_id, 92 void SetIsIncognitoEnabled(const std::string& extension_id,
103 content::BrowserContext* context, 93 content::BrowserContext* context,
104 bool enabled) { 94 bool enabled) {
105 ExtensionRegistry* registry = ExtensionRegistry::Get(context); 95 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
106 const Extension* extension = 96 const Extension* extension =
107 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); 97 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
108 98
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 IDR_EXTENSION_DEFAULT_ICON); 349 IDR_EXTENSION_DEFAULT_ICON);
360 } 350 }
361 351
362 bool IsStreamlinedHostedAppsEnabled() { 352 bool IsStreamlinedHostedAppsEnabled() {
363 return !CommandLine::ForCurrentProcess()->HasSwitch( 353 return !CommandLine::ForCurrentProcess()->HasSwitch(
364 switches::kDisableNewBookmarkApps); 354 switches::kDisableNewBookmarkApps);
365 } 355 }
366 356
367 } // namespace util 357 } // namespace util
368 } // namespace extensions 358 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/common/extensions/chrome_extensions_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698