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

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

Issue 2054773002: Replace the WAS_INSTALLED_BY_CUSTODIAN creation flag with a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Commenting out WAS_INSTALLED_BY_CUSTODIAN flag Created 4 years, 6 months 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/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 // The entry into the ExtensionPrefs for allowing an extension to script on 48 // The entry into the ExtensionPrefs for allowing an extension to script on
49 // all urls without explicit permission. 49 // all urls without explicit permission.
50 const char kExtensionAllowedOnAllUrlsPrefName[] = 50 const char kExtensionAllowedOnAllUrlsPrefName[] =
51 "extension_can_script_all_urls"; 51 "extension_can_script_all_urls";
52 52
53 // The entry into the prefs for when a user has explicitly set the "extension 53 // The entry into the prefs for when a user has explicitly set the "extension
54 // allowed on all urls" pref. 54 // allowed on all urls" pref.
55 const char kHasSetScriptOnAllUrlsPrefName[] = "has_set_script_all_urls"; 55 const char kHasSetScriptOnAllUrlsPrefName[] = "has_set_script_all_urls";
56 56
57 // The entry into the prefs used to flag an extension as installed by custodian.
58 // It is relevant only for supervised users
59 const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian";
60
57 // Returns true if |extension| should always be enabled in incognito mode. 61 // Returns true if |extension| should always be enabled in incognito mode.
58 bool IsWhitelistedForIncognito(const Extension* extension) { 62 bool IsWhitelistedForIncognito(const Extension* extension) {
59 const Feature* feature = FeatureProvider::GetBehaviorFeature( 63 const Feature* feature = FeatureProvider::GetBehaviorFeature(
60 BehaviorFeature::kWhitelistedForIncognito); 64 BehaviorFeature::kWhitelistedForIncognito);
61 return feature && feature->IsAvailableToExtension(extension).is_available(); 65 return feature && feature->IsAvailableToExtension(extension).is_available();
62 } 66 }
63 67
64 // Returns |extension_id|. See note below. 68 // Returns |extension_id|. See note below.
65 std::string ReloadExtensionIfEnabled(const std::string& extension_id, 69 std::string ReloadExtensionIfEnabled(const std::string& extension_id,
66 content::BrowserContext* context) { 70 content::BrowserContext* context) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Reload to update browser state. Only bother if the value changed and the 217 // Reload to update browser state. Only bother if the value changed and the
214 // extension is actually enabled, since there is no UI otherwise. 218 // extension is actually enabled, since there is no UI otherwise.
215 if (allow == AllowFileAccess(extension_id, context)) 219 if (allow == AllowFileAccess(extension_id, context))
216 return; 220 return;
217 221
218 ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow); 222 ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow);
219 223
220 ReloadExtensionIfEnabled(extension_id, context); 224 ReloadExtensionIfEnabled(extension_id, context);
221 } 225 }
222 226
227 void SetWasInstalledByCustodian(const std::string& extension_id,
228 content::BrowserContext* context,
229 bool installed_by_custodian) {
230 ExtensionPrefs::Get(context)->UpdateExtensionPref(
231 extension_id, kWasInstalledByCustodianPrefName,
232 new base::FundamentalValue(installed_by_custodian));
233 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
234
235 // If it is already enabled, nothing to be done.
Marc Treib 2016/06/16 12:35:39 This is assuming that |installed_by_custodian| is
mamir 2016/06/17 08:33:18 Yes. It can never be set to false, but I left the
236 if (registry->enabled_extensions().Contains(extension_id))
237 return;
238
239 // If the extension is not installed, it may need to be reloaded.
Marc Treib 2016/06/16 12:35:39 Why? Is there any situation where registry->GetIns
mamir 2016/06/17 08:33:18 Pre-installed extensions that get unloaded after C
Marc Treib 2016/06/17 08:56:54 And in that case, GetInstalledExtension won't retu
mamir 2016/06/17 16:12:54 Done.
240 const Extension* extension = registry->GetInstalledExtension(extension_id);
241 if (!extension) {
242 ExtensionService* service =
243 ExtensionSystem::Get(context)->extension_service();
244 service->ReloadExtension(extension_id);
245 }
246 }
247
248 bool WasInstalledByCustodian(const std::string& extension_id,
249 content::BrowserContext* context) {
250 bool installed_by_custodian = false;
251 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
252 prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
253 &installed_by_custodian);
254 return installed_by_custodian;
255 }
256
223 bool AllowedScriptingOnAllUrls(const std::string& extension_id, 257 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
224 content::BrowserContext* context) { 258 content::BrowserContext* context) {
225 bool allowed = false; 259 bool allowed = false;
226 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); 260 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
227 if (!prefs->ReadPrefAsBoolean(extension_id, 261 if (!prefs->ReadPrefAsBoolean(extension_id,
228 kExtensionAllowedOnAllUrlsPrefName, 262 kExtensionAllowedOnAllUrlsPrefName,
229 &allowed)) { 263 &allowed)) {
230 // If there is no value present, we make one, defaulting it to the value of 264 // If there is no value present, we make one, defaulting it to the value of
231 // the 'scripts require action' flag. If the flag is on, then the extension 265 // the 'scripts require action' flag. If the flag is on, then the extension
232 // does not have permission to script on all urls by default. 266 // does not have permission to script on all urls by default.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 405
372 bool CanHostedAppsOpenInWindows() { 406 bool CanHostedAppsOpenInWindows() {
373 #if defined(OS_MACOSX) 407 #if defined(OS_MACOSX)
374 return base::CommandLine::ForCurrentProcess()->HasSwitch( 408 return base::CommandLine::ForCurrentProcess()->HasSwitch(
375 switches::kEnableHostedAppsInWindows); 409 switches::kEnableHostedAppsInWindows);
376 #else 410 #else
377 return true; 411 return true;
378 #endif 412 #endif
379 } 413 }
380 414
381 bool IsExtensionSupervised(const Extension* extension, const Profile* profile) { 415 bool IsExtensionSupervised(const Extension* extension, Profile* profile) {
382 return extension->was_installed_by_custodian() && profile->IsSupervised(); 416 return WasInstalledByCustodian(extension->id(), profile) &&
417 profile->IsSupervised();
383 } 418 }
384 419
385 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) { 420 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) {
386 if (!profile->IsSupervised()) 421 if (!profile->IsSupervised())
387 return false; 422 return false;
388 // Query the trial group name first, to make sure it's properly initialized. 423 // Query the trial group name first, to make sure it's properly initialized.
389 base::FieldTrialList::FindFullName( 424 base::FieldTrialList::FindFullName(
390 kSupervisedUserExtensionPermissionIncreaseFieldTrialName); 425 kSupervisedUserExtensionPermissionIncreaseFieldTrialName);
391 std::string value = variations::GetVariationParamValue( 426 std::string value = variations::GetVariationParamValue(
392 kSupervisedUserExtensionPermissionIncreaseFieldTrialName, 427 kSupervisedUserExtensionPermissionIncreaseFieldTrialName,
393 profile->IsChild() ? "child_account" : "legacy_supervised_user"); 428 profile->IsChild() ? "child_account" : "legacy_supervised_user");
394 return value == "true"; 429 return value == "true";
395 } 430 }
396 431
397 } // namespace util 432 } // namespace util
398 } // namespace extensions 433 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698