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

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: Fixing the build 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // Reload to update browser state. Only bother if the value changed and the 219 // Reload to update browser state. Only bother if the value changed and the
216 // extension is actually enabled, since there is no UI otherwise. 220 // extension is actually enabled, since there is no UI otherwise.
217 if (allow == AllowFileAccess(extension_id, context)) 221 if (allow == AllowFileAccess(extension_id, context))
218 return; 222 return;
219 223
220 ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow); 224 ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow);
221 225
222 ReloadExtensionIfEnabled(extension_id, context); 226 ReloadExtensionIfEnabled(extension_id, context);
223 } 227 }
224 228
229 void SetWasInstalledByCustodian(const std::string& extension_id,
230 content::BrowserContext* context,
231 bool installed_by_custodian) {
232 if (installed_by_custodian == WasInstalledByCustodian(extension_id, context))
233 return;
234
235 ExtensionPrefs::Get(context)->UpdateExtensionPref(
236 extension_id, kWasInstalledByCustodianPrefName,
237 installed_by_custodian ? new base::FundamentalValue(true) : nullptr);
238 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
239 const Extension* extension = registry->GetInstalledExtension(extension_id);
240 ExtensionService* service =
241 ExtensionSystem::Get(context)->extension_service();
242
243 // If the installed_by_custodian flag is reset, do nothing.
244 if (!installed_by_custodian) {
245 // If installed_by_custodian changes to false, the extension may need to
246 // be unloaded now.
247 service->ReloadExtension(extension_id);
248 return;
249 }
250
251 // If it is already enabled, do nothing.
252 if (registry->enabled_extensions().Contains(extension_id))
253 return;
254
255 // If the extension is not loaded, it may need to be reloaded.
256 // Example is a pre-installed extension that was unloaded when a
257 // supervised user flag has been received.
258 if (!extension) {
259 service->ReloadExtension(extension_id);
260 }
261 }
262
263 bool WasInstalledByCustodian(const std::string& extension_id,
264 content::BrowserContext* context) {
265 bool installed_by_custodian = false;
266 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
267 prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
268 &installed_by_custodian);
269 return installed_by_custodian;
270 }
271
225 bool AllowedScriptingOnAllUrls(const std::string& extension_id, 272 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
226 content::BrowserContext* context) { 273 content::BrowserContext* context) {
227 bool allowed = false; 274 bool allowed = false;
228 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); 275 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
229 if (!prefs->ReadPrefAsBoolean(extension_id, 276 if (!prefs->ReadPrefAsBoolean(extension_id,
230 kExtensionAllowedOnAllUrlsPrefName, 277 kExtensionAllowedOnAllUrlsPrefName,
231 &allowed)) { 278 &allowed)) {
232 // If there is no value present, we make one, defaulting it to the value of 279 // If there is no value present, we make one, defaulting it to the value of
233 // the 'scripts require action' flag. If the flag is on, then the extension 280 // the 'scripts require action' flag. If the flag is on, then the extension
234 // does not have permission to script on all urls by default. 281 // does not have permission to script on all urls by default.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 420
374 bool CanHostedAppsOpenInWindows() { 421 bool CanHostedAppsOpenInWindows() {
375 #if defined(OS_MACOSX) 422 #if defined(OS_MACOSX)
376 return base::CommandLine::ForCurrentProcess()->HasSwitch( 423 return base::CommandLine::ForCurrentProcess()->HasSwitch(
377 switches::kEnableHostedAppsInWindows); 424 switches::kEnableHostedAppsInWindows);
378 #else 425 #else
379 return true; 426 return true;
380 #endif 427 #endif
381 } 428 }
382 429
383 bool IsExtensionSupervised(const Extension* extension, const Profile* profile) { 430 bool IsExtensionSupervised(const Extension* extension, Profile* profile) {
384 return extension->was_installed_by_custodian() && profile->IsSupervised(); 431 return WasInstalledByCustodian(extension->id(), profile) &&
432 profile->IsSupervised();
385 } 433 }
386 434
387 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) { 435 bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) {
388 if (!profile->IsSupervised()) 436 if (!profile->IsSupervised())
389 return false; 437 return false;
390 // Query the trial group name first, to make sure it's properly initialized. 438 // Query the trial group name first, to make sure it's properly initialized.
391 base::FieldTrialList::FindFullName( 439 base::FieldTrialList::FindFullName(
392 kSupervisedUserExtensionPermissionIncreaseFieldTrialName); 440 kSupervisedUserExtensionPermissionIncreaseFieldTrialName);
393 std::string value = variations::GetVariationParamValue( 441 std::string value = variations::GetVariationParamValue(
394 kSupervisedUserExtensionPermissionIncreaseFieldTrialName, 442 kSupervisedUserExtensionPermissionIncreaseFieldTrialName,
395 profile->IsChild() ? "child_account" : "legacy_supervised_user"); 443 profile->IsChild() ? "child_account" : "legacy_supervised_user");
396 return value == "true"; 444 return value == "true";
397 } 445 }
398 446
399 } // namespace util 447 } // namespace util
400 } // namespace extensions 448 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_util.h ('k') | chrome/browser/extensions/pending_extension_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698