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

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 ExtensionPrefs::Get(context)->UpdateExtensionPref(
231 extension_id, kWasInstalledByCustodianPrefName,
232 new base::FundamentalValue(installed_by_custodian));
Marc Treib 2016/06/17 16:34:22 If installed_by_custodian is false, then we should
mamir 2016/06/19 11:43:09 Done.
233 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
234
235 // If the installed_by_custodian flag is reset, do nothing.
Marc Treib 2016/06/17 16:34:22 Hm. Is this correct? Might we need to unload the e
mamir 2016/06/19 11:43:09 The unload would happen in the callback of "MayLoa
Marc Treib 2016/06/20 12:42:28 But UserMayLoad won't get called, right?
mamir 2016/06/20 12:46:46 in which case? ahaaa, you refer to when the flag i
Marc Treib 2016/06/20 15:01:30 Yes. If the flag is set from "true" to "false" her
mamir 2016/06/20 16:08:08 Done.
236 if (!installed_by_custodian)
237 return;
238
239 // If it is already enabled, do nothing;
240 if (registry->enabled_extensions().Contains(extension_id))
241 return;
242
243 // If the extension is not installed, it may need to be reloaded.
244 // Example is a pre-installed extension that was unloaded when a
245 // supervised user flag has been received.
246 const Extension* extension = registry->GetInstalledExtension(extension_id);
247 if (!extension) {
248 ExtensionService* service =
249 ExtensionSystem::Get(context)->extension_service();
250 service->ReloadExtension(extension_id);
251 }
252 }
253
254 bool WasInstalledByCustodian(const std::string& extension_id,
255 content::BrowserContext* context) {
256 bool installed_by_custodian = false;
257 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
258 prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
259 &installed_by_custodian);
260 return installed_by_custodian;
261 }
262
223 bool AllowedScriptingOnAllUrls(const std::string& extension_id, 263 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
224 content::BrowserContext* context) { 264 content::BrowserContext* context) {
225 bool allowed = false; 265 bool allowed = false;
226 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); 266 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
227 if (!prefs->ReadPrefAsBoolean(extension_id, 267 if (!prefs->ReadPrefAsBoolean(extension_id,
228 kExtensionAllowedOnAllUrlsPrefName, 268 kExtensionAllowedOnAllUrlsPrefName,
229 &allowed)) { 269 &allowed)) {
230 // If there is no value present, we make one, defaulting it to the value of 270 // 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 271 // 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. 272 // does not have permission to script on all urls by default.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 411
372 bool CanHostedAppsOpenInWindows() { 412 bool CanHostedAppsOpenInWindows() {
373 #if defined(OS_MACOSX) 413 #if defined(OS_MACOSX)
374 return base::CommandLine::ForCurrentProcess()->HasSwitch( 414 return base::CommandLine::ForCurrentProcess()->HasSwitch(
375 switches::kEnableHostedAppsInWindows); 415 switches::kEnableHostedAppsInWindows);
376 #else 416 #else
377 return true; 417 return true;
378 #endif 418 #endif
379 } 419 }
380 420
381 bool IsExtensionSupervised(const Extension* extension, const Profile* profile) { 421 bool IsExtensionSupervised(const Extension* extension, Profile* profile) {
382 return extension->was_installed_by_custodian() && profile->IsSupervised(); 422 return WasInstalledByCustodian(extension->id(), profile) &&
423 profile->IsSupervised();
383 } 424 }
384 425
385 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) { 426 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) {
386 if (!profile->IsSupervised()) 427 if (!profile->IsSupervised())
387 return false; 428 return false;
388 // Query the trial group name first, to make sure it's properly initialized. 429 // Query the trial group name first, to make sure it's properly initialized.
389 base::FieldTrialList::FindFullName( 430 base::FieldTrialList::FindFullName(
390 kSupervisedUserExtensionPermissionIncreaseFieldTrialName); 431 kSupervisedUserExtensionPermissionIncreaseFieldTrialName);
391 std::string value = variations::GetVariationParamValue( 432 std::string value = variations::GetVariationParamValue(
392 kSupervisedUserExtensionPermissionIncreaseFieldTrialName, 433 kSupervisedUserExtensionPermissionIncreaseFieldTrialName,
393 profile->IsChild() ? "child_account" : "legacy_supervised_user"); 434 profile->IsChild() ? "child_account" : "legacy_supervised_user");
394 return value == "true"; 435 return value == "true";
395 } 436 }
396 437
397 } // namespace util 438 } // namespace util
398 } // namespace extensions 439 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698