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

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 Devlin 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 const Extension* extension =
231 ExtensionRegistry::Get(context)->GetInstalledExtension(extension_id);
232 // Extension can be null if it exists in the sync data but not yet installed.
233 if (extension &&
234 installed_by_custodian == extension->was_installed_by_custodian())
235 return;
236 ExtensionPrefs::Get(context)->UpdateExtensionPref(
237 extension_id, kWasInstalledByCustodianPrefName,
238 new base::FundamentalValue(installed_by_custodian));
239
Devlin 2016/06/15 00:30:36 maybe also: if (!extension) return;
mamir 2016/06/15 09:54:41 Done.
mamir 2016/06/15 15:09:59 Not really. If we return here, the extension won't
240 ExtensionService* service =
241 ExtensionSystem::Get(context)->extension_service();
242 // Since the was_installed_by_custodian is stored as a creation flag in the
243 // Extension immutable object, a reload is required.
244 service->ReloadExtension(extension_id);
245 }
246
247 bool WasInstalledByCustodian(const std::string& extension_id,
248 content::BrowserContext* context) {
249 bool installed_by_custodian = false;
250 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
251 prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
252 &installed_by_custodian);
253 return installed_by_custodian;
254 }
255
223 bool AllowedScriptingOnAllUrls(const std::string& extension_id, 256 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
224 content::BrowserContext* context) { 257 content::BrowserContext* context) {
225 bool allowed = false; 258 bool allowed = false;
226 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); 259 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
227 if (!prefs->ReadPrefAsBoolean(extension_id, 260 if (!prefs->ReadPrefAsBoolean(extension_id,
228 kExtensionAllowedOnAllUrlsPrefName, 261 kExtensionAllowedOnAllUrlsPrefName,
229 &allowed)) { 262 &allowed)) {
230 // If there is no value present, we make one, defaulting it to the value of 263 // 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 264 // 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. 265 // does not have permission to script on all urls by default.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 base::FieldTrialList::FindFullName( 422 base::FieldTrialList::FindFullName(
390 kSupervisedUserExtensionPermissionIncreaseFieldTrialName); 423 kSupervisedUserExtensionPermissionIncreaseFieldTrialName);
391 std::string value = variations::GetVariationParamValue( 424 std::string value = variations::GetVariationParamValue(
392 kSupervisedUserExtensionPermissionIncreaseFieldTrialName, 425 kSupervisedUserExtensionPermissionIncreaseFieldTrialName,
393 profile->IsChild() ? "child_account" : "legacy_supervised_user"); 426 profile->IsChild() ? "child_account" : "legacy_supervised_user");
394 return value == "true"; 427 return value == "true";
395 } 428 }
396 429
397 } // namespace util 430 } // namespace util
398 } // namespace extensions 431 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698