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

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: reload if installed_by_custodian becomes false. 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
Marc Treib 2016/06/20 16:42:38 nit: period after comment
mamir 2016/06/20 16:55:44 Done.
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 installed_by_custodian ? new base::FundamentalValue(true) : nullptr);
233 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
234 const Extension* extension = registry->GetInstalledExtension(extension_id);
235
236 // If the installed_by_custodian flag is reset, do nothing.
237 if (!installed_by_custodian) {
238 // If installed_by_custodian changes to false, the extension may need to
239 // be unloaded now.
240 service->ReloadExtension(extension_id);
Marc Treib 2016/06/20 16:42:38 You'll get here every time any sync data for an ex
mamir 2016/06/20 16:55:44 Done.
241 return;
242 }
243
244 // If it is already enabled, do nothing;
Marc Treib 2016/06/20 16:42:38 nit: period after comment
mamir 2016/06/20 16:55:44 Done.
245 if (registry->enabled_extensions().Contains(extension_id))
246 return;
247
248 // If the extension is not installed, it may need to be reloaded.
249 // Example is a pre-installed extension that was unloaded when a
250 // supervised user flag has been received.
251 if (!extension) {
252 ExtensionService* service =
253 ExtensionSystem::Get(context)->extension_service();
254 service->ReloadExtension(extension_id);
255 }
256 }
257
258 bool WasInstalledByCustodian(const std::string& extension_id,
259 content::BrowserContext* context) {
260 bool installed_by_custodian = false;
261 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
262 prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
263 &installed_by_custodian);
264 return installed_by_custodian;
265 }
266
223 bool AllowedScriptingOnAllUrls(const std::string& extension_id, 267 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
224 content::BrowserContext* context) { 268 content::BrowserContext* context) {
225 bool allowed = false; 269 bool allowed = false;
226 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); 270 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
227 if (!prefs->ReadPrefAsBoolean(extension_id, 271 if (!prefs->ReadPrefAsBoolean(extension_id,
228 kExtensionAllowedOnAllUrlsPrefName, 272 kExtensionAllowedOnAllUrlsPrefName,
229 &allowed)) { 273 &allowed)) {
230 // If there is no value present, we make one, defaulting it to the value of 274 // 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 275 // 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. 276 // does not have permission to script on all urls by default.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 415
372 bool CanHostedAppsOpenInWindows() { 416 bool CanHostedAppsOpenInWindows() {
373 #if defined(OS_MACOSX) 417 #if defined(OS_MACOSX)
374 return base::CommandLine::ForCurrentProcess()->HasSwitch( 418 return base::CommandLine::ForCurrentProcess()->HasSwitch(
375 switches::kEnableHostedAppsInWindows); 419 switches::kEnableHostedAppsInWindows);
376 #else 420 #else
377 return true; 421 return true;
378 #endif 422 #endif
379 } 423 }
380 424
381 bool IsExtensionSupervised(const Extension* extension, const Profile* profile) { 425 bool IsExtensionSupervised(const Extension* extension, Profile* profile) {
382 return extension->was_installed_by_custodian() && profile->IsSupervised(); 426 return WasInstalledByCustodian(extension->id(), profile) &&
427 profile->IsSupervised();
383 } 428 }
384 429
385 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) { 430 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) {
386 if (!profile->IsSupervised()) 431 if (!profile->IsSupervised())
387 return false; 432 return false;
388 // Query the trial group name first, to make sure it's properly initialized. 433 // Query the trial group name first, to make sure it's properly initialized.
389 base::FieldTrialList::FindFullName( 434 base::FieldTrialList::FindFullName(
390 kSupervisedUserExtensionPermissionIncreaseFieldTrialName); 435 kSupervisedUserExtensionPermissionIncreaseFieldTrialName);
391 std::string value = variations::GetVariationParamValue( 436 std::string value = variations::GetVariationParamValue(
392 kSupervisedUserExtensionPermissionIncreaseFieldTrialName, 437 kSupervisedUserExtensionPermissionIncreaseFieldTrialName,
393 profile->IsChild() ? "child_account" : "legacy_supervised_user"); 438 profile->IsChild() ? "child_account" : "legacy_supervised_user");
394 return value == "true"; 439 return value == "true";
395 } 440 }
396 441
397 } // namespace util 442 } // namespace util
398 } // namespace extensions 443 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698