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

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

Powered by Google App Engine
This is Rietveld 408576698