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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 2529083002: Make extensions developer mode adhere to policy (Closed)
Patch Set: Get rid of busy loop in test Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const char kFileSelectionCanceled[] = 96 const char kFileSelectionCanceled[] =
97 "File selection was canceled."; 97 "File selection was canceled.";
98 const char kNoSuchRendererError[] = "No such renderer."; 98 const char kNoSuchRendererError[] = "No such renderer.";
99 const char kInvalidPathError[] = "Invalid path."; 99 const char kInvalidPathError[] = "Invalid path.";
100 const char kManifestKeyIsRequiredError[] = 100 const char kManifestKeyIsRequiredError[] =
101 "The 'manifestKey' argument is required for manifest files."; 101 "The 'manifestKey' argument is required for manifest files.";
102 const char kCouldNotFindWebContentsError[] = 102 const char kCouldNotFindWebContentsError[] =
103 "Could not find a valid web contents."; 103 "Could not find a valid web contents.";
104 const char kCannotUpdateSupervisedProfileSettingsError[] = 104 const char kCannotUpdateSupervisedProfileSettingsError[] =
105 "Cannot change settings for a supervised profile."; 105 "Cannot change settings for a supervised profile.";
106 const char kCannotUpdatePolicyControlledProfileSettingsError[] =
107 "Cannot change policy-controlled settings.";
106 const char kNoOptionsPageForExtensionError[] = 108 const char kNoOptionsPageForExtensionError[] =
107 "Extension does not have an options page."; 109 "Extension does not have an options page.";
108 110
109 const char kUnpackedAppsFolder[] = "apps_target"; 111 const char kUnpackedAppsFolder[] = "apps_target";
110 const char kManifestFile[] = "manifest.json"; 112 const char kManifestFile[] = "manifest.json";
111 113
112 ExtensionService* GetExtensionService(content::BrowserContext* context) { 114 ExtensionService* GetExtensionService(content::BrowserContext* context) {
113 return ExtensionSystem::Get(context)->extension_service(); 115 return ExtensionSystem::Get(context)->extension_service();
114 } 116 }
115 117
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 InstallVerifier::Get(context)->VerifyAllExtensions(); 162 InstallVerifier::Get(context)->VerifyAllExtensions();
161 } 163 }
162 164
163 std::unique_ptr<developer::ProfileInfo> CreateProfileInfo(Profile* profile) { 165 std::unique_ptr<developer::ProfileInfo> CreateProfileInfo(Profile* profile) {
164 std::unique_ptr<developer::ProfileInfo> info(new developer::ProfileInfo()); 166 std::unique_ptr<developer::ProfileInfo> info(new developer::ProfileInfo());
165 info->is_supervised = profile->IsSupervised(); 167 info->is_supervised = profile->IsSupervised();
166 PrefService* prefs = profile->GetPrefs(); 168 PrefService* prefs = profile->GetPrefs();
167 info->is_incognito_available = 169 info->is_incognito_available =
168 IncognitoModePrefs::GetAvailability(prefs) != 170 IncognitoModePrefs::GetAvailability(prefs) !=
169 IncognitoModePrefs::DISABLED; 171 IncognitoModePrefs::DISABLED;
172 info->is_developer_mode_disabled_by_policy =
173 prefs->GetBoolean(prefs::kDevToolsDisabled);
170 info->in_developer_mode = 174 info->in_developer_mode =
171 !info->is_supervised && 175 !info->is_supervised &&
176 !info->is_developer_mode_disabled_by_policy &&
172 prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode); 177 prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode);
173 info->app_info_dialog_enabled = CanShowAppInfoDialog(); 178 info->app_info_dialog_enabled = CanShowAppInfoDialog();
174 info->can_load_unpacked = 179 info->can_load_unpacked =
175 !ExtensionManagementFactory::GetForBrowserContext(profile) 180 !ExtensionManagementFactory::GetForBrowserContext(profile)
176 ->BlacklistedByDefault(); 181 ->BlacklistedByDefault();
177 return info; 182 return info;
178 } 183 }
179 184
180 } // namespace 185 } // namespace
181 186
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 extension_management_observer_.Add( 232 extension_management_observer_.Add(
228 ExtensionManagementFactory::GetForBrowserContext(profile)); 233 ExtensionManagementFactory::GetForBrowserContext(profile));
229 command_service_observer_.Add(CommandService::Get(profile)); 234 command_service_observer_.Add(CommandService::Get(profile));
230 pref_change_registrar_.Init(profile->GetPrefs()); 235 pref_change_registrar_.Init(profile->GetPrefs());
231 // The unretained is safe, since the PrefChangeRegistrar unregisters the 236 // The unretained is safe, since the PrefChangeRegistrar unregisters the
232 // callback on destruction. 237 // callback on destruction.
233 pref_change_registrar_.Add( 238 pref_change_registrar_.Add(
234 prefs::kExtensionsUIDeveloperMode, 239 prefs::kExtensionsUIDeveloperMode,
235 base::Bind(&DeveloperPrivateEventRouter::OnProfilePrefChanged, 240 base::Bind(&DeveloperPrivateEventRouter::OnProfilePrefChanged,
236 base::Unretained(this))); 241 base::Unretained(this)));
242 pref_change_registrar_.Add(
243 prefs::kDevToolsDisabled,
244 base::Bind(&DeveloperPrivateEventRouter::OnDevToolsDisabledChanged,
245 base::Unretained(this)));
237 } 246 }
238 247
239 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() { 248 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() {
240 } 249 }
241 250
242 void DeveloperPrivateEventRouter::AddExtensionId( 251 void DeveloperPrivateEventRouter::AddExtensionId(
243 const std::string& extension_id) { 252 const std::string& extension_id) {
244 extension_ids_.insert(extension_id); 253 extension_ids_.insert(extension_id);
245 } 254 }
246 255
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 374
366 void DeveloperPrivateEventRouter::OnProfilePrefChanged() { 375 void DeveloperPrivateEventRouter::OnProfilePrefChanged() {
367 std::unique_ptr<base::ListValue> args(new base::ListValue()); 376 std::unique_ptr<base::ListValue> args(new base::ListValue());
368 args->Append(CreateProfileInfo(profile_)->ToValue()); 377 args->Append(CreateProfileInfo(profile_)->ToValue());
369 std::unique_ptr<Event> event( 378 std::unique_ptr<Event> event(
370 new Event(events::DEVELOPER_PRIVATE_ON_PROFILE_STATE_CHANGED, 379 new Event(events::DEVELOPER_PRIVATE_ON_PROFILE_STATE_CHANGED,
371 developer::OnProfileStateChanged::kEventName, std::move(args))); 380 developer::OnProfileStateChanged::kEventName, std::move(args)));
372 event_router_->BroadcastEvent(std::move(event)); 381 event_router_->BroadcastEvent(std::move(event));
373 } 382 }
374 383
384 void DeveloperPrivateEventRouter::OnDevToolsDisabledChanged() {
385 PrefService* prefs = profile_->GetPrefs();
386
387 // Ensure that the developer mode is off if it is disabled by policy
388 if (prefs->GetBoolean(prefs::kDevToolsDisabled))
389 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode, false);
Bernhard Bauer 2016/11/25 15:43:35 Could you set this value via the ConfigurationPoli
pmarko 2016/11/28 14:19:30 Thank you for pointing this out -- done. Your sugg
390
391 // Be sure to generate a notification to the UI to show/hide the
392 // 'controlled by policy' indicator
393 OnProfilePrefChanged();
394 }
395
375 void DeveloperPrivateEventRouter::BroadcastItemStateChanged( 396 void DeveloperPrivateEventRouter::BroadcastItemStateChanged(
376 developer::EventType event_type, 397 developer::EventType event_type,
377 const std::string& extension_id) { 398 const std::string& extension_id) {
378 std::unique_ptr<ExtensionInfoGenerator> info_generator( 399 std::unique_ptr<ExtensionInfoGenerator> info_generator(
379 new ExtensionInfoGenerator(profile_)); 400 new ExtensionInfoGenerator(profile_));
380 ExtensionInfoGenerator* info_generator_weak = info_generator.get(); 401 ExtensionInfoGenerator* info_generator_weak = info_generator.get();
381 info_generator_weak->CreateExtensionInfo( 402 info_generator_weak->CreateExtensionInfo(
382 extension_id, 403 extension_id,
383 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper, 404 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper,
384 weak_factory_.GetWeakPtr(), event_type, extension_id, 405 weak_factory_.GetWeakPtr(), event_type, extension_id,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 DeveloperPrivateUpdateProfileConfigurationFunction::Run() { 614 DeveloperPrivateUpdateProfileConfigurationFunction::Run() {
594 std::unique_ptr<developer::UpdateProfileConfiguration::Params> params( 615 std::unique_ptr<developer::UpdateProfileConfiguration::Params> params(
595 developer::UpdateProfileConfiguration::Params::Create(*args_)); 616 developer::UpdateProfileConfiguration::Params::Create(*args_));
596 EXTENSION_FUNCTION_VALIDATE(params); 617 EXTENSION_FUNCTION_VALIDATE(params);
597 618
598 const developer::ProfileConfigurationUpdate& update = params->update; 619 const developer::ProfileConfigurationUpdate& update = params->update;
599 PrefService* prefs = GetProfile()->GetPrefs(); 620 PrefService* prefs = GetProfile()->GetPrefs();
600 if (update.in_developer_mode) { 621 if (update.in_developer_mode) {
601 if (GetProfile()->IsSupervised()) 622 if (GetProfile()->IsSupervised())
602 return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError)); 623 return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError));
624 if (prefs->GetBoolean(prefs::kDevToolsDisabled))
625 return RespondNow(Error(
Bernhard Bauer 2016/11/25 15:43:35 This is a multi-line statement, so the block needs
pmarko 2016/11/28 14:19:30 Done.
626 kCannotUpdatePolicyControlledProfileSettingsError));
603 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode, 627 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode,
604 *update.in_developer_mode); 628 *update.in_developer_mode);
605 } 629 }
606 630
607 return RespondNow(NoArguments()); 631 return RespondNow(NoArguments());
608 } 632 }
609 633
610 DeveloperPrivateUpdateExtensionConfigurationFunction:: 634 DeveloperPrivateUpdateExtensionConfigurationFunction::
611 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {} 635 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {}
612 636
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 update.extension_id, update.command_name, *update.keybinding); 1477 update.extension_id, update.command_name, *update.keybinding);
1454 } 1478 }
1455 1479
1456 return RespondNow(NoArguments()); 1480 return RespondNow(NoArguments());
1457 } 1481 }
1458 1482
1459 1483
1460 } // namespace api 1484 } // namespace api
1461 1485
1462 } // namespace extensions 1486 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698