Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 break; | 148 break; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", | 152 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", |
| 153 should_do_verification_check); | 153 should_do_verification_check); |
| 154 if (should_do_verification_check) | 154 if (should_do_verification_check) |
| 155 InstallVerifier::Get(context)->VerifyAllExtensions(); | 155 InstallVerifier::Get(context)->VerifyAllExtensions(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 scoped_ptr<developer::ProfileInfo> CreateProfileInfo(Profile* profile) { | |
| 159 scoped_ptr<developer::ProfileInfo> info(new developer::ProfileInfo()); | |
| 160 info->is_supervised = profile->IsSupervised(); | |
| 161 PrefService* prefs = profile->GetPrefs(); | |
| 162 info->is_incognito_available = | |
| 163 IncognitoModePrefs::GetAvailability(prefs) != | |
| 164 IncognitoModePrefs::DISABLED; | |
| 165 info->in_developer_mode = | |
| 166 !info->is_supervised && | |
|
not at google - send to devlin
2015/05/19 20:35:04
I wonder why supervised users are called out here.
Devlin
2015/05/19 22:01:08
(Since this isn't a behavior change, I'll commit n
Marc Treib
2015/05/20 08:07:27
This is from before my time, so I might be missing
not at google - send to devlin
2015/05/20 21:32:32
Yeah seems like a perfectly reasonable thing for s
| |
| 167 prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
| 168 info->app_info_dialog_enabled = CanShowAppInfoDialog(); | |
| 169 info->can_load_unpacked = | |
| 170 !ExtensionManagementFactory::GetForBrowserContext(profile) | |
| 171 ->BlacklistedByDefault(); | |
| 172 return info.Pass(); | |
| 173 } | |
| 174 | |
| 158 } // namespace | 175 } // namespace |
| 159 | 176 |
| 160 namespace ChoosePath = api::developer_private::ChoosePath; | 177 namespace ChoosePath = api::developer_private::ChoosePath; |
| 161 namespace GetItemsInfo = api::developer_private::GetItemsInfo; | 178 namespace GetItemsInfo = api::developer_private::GetItemsInfo; |
| 162 namespace PackDirectory = api::developer_private::PackDirectory; | 179 namespace PackDirectory = api::developer_private::PackDirectory; |
| 163 namespace Reload = api::developer_private::Reload; | 180 namespace Reload = api::developer_private::Reload; |
| 164 | 181 |
| 165 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > | 182 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > |
| 166 g_factory = LAZY_INSTANCE_INITIALIZER; | 183 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 167 | 184 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 181 : profile_(Profile::FromBrowserContext(context)) { | 198 : profile_(Profile::FromBrowserContext(context)) { |
| 182 RegisterNotifications(); | 199 RegisterNotifications(); |
| 183 } | 200 } |
| 184 | 201 |
| 185 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) | 202 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) |
| 186 : extension_registry_observer_(this), | 203 : extension_registry_observer_(this), |
| 187 error_console_observer_(this), | 204 error_console_observer_(this), |
| 188 process_manager_observer_(this), | 205 process_manager_observer_(this), |
| 189 app_window_registry_observer_(this), | 206 app_window_registry_observer_(this), |
| 190 extension_action_api_observer_(this), | 207 extension_action_api_observer_(this), |
| 208 warning_service_observer_(this), | |
| 209 extension_prefs_observer_(this), | |
| 210 extension_management_observer_(this), | |
| 191 profile_(profile), | 211 profile_(profile), |
| 192 event_router_(EventRouter::Get(profile_)), | 212 event_router_(EventRouter::Get(profile_)), |
| 193 weak_factory_(this) { | 213 weak_factory_(this) { |
| 194 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 214 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 195 error_console_observer_.Add(ErrorConsole::Get(profile)); | 215 error_console_observer_.Add(ErrorConsole::Get(profile)); |
| 196 process_manager_observer_.Add(ProcessManager::Get(profile)); | 216 process_manager_observer_.Add(ProcessManager::Get(profile)); |
| 197 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); | 217 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); |
| 198 extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile)); | 218 extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile)); |
| 219 warning_service_observer_.Add(WarningService::Get(profile)); | |
| 220 extension_prefs_observer_.Add(ExtensionPrefs::Get(profile)); | |
| 221 extension_management_observer_.Add( | |
| 222 ExtensionManagementFactory::GetForBrowserContext(profile)); | |
| 199 } | 223 } |
| 200 | 224 |
| 201 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() { | 225 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() { |
| 202 } | 226 } |
| 203 | 227 |
| 204 void DeveloperPrivateEventRouter::AddExtensionId( | 228 void DeveloperPrivateEventRouter::AddExtensionId( |
| 205 const std::string& extension_id) { | 229 const std::string& extension_id) { |
| 206 extension_ids_.insert(extension_id); | 230 extension_ids_.insert(extension_id); |
| 207 } | 231 } |
| 208 | 232 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_UNREGISTERED, | 308 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_UNREGISTERED, |
| 285 window->extension_id()); | 309 window->extension_id()); |
| 286 } | 310 } |
| 287 | 311 |
| 288 void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged( | 312 void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged( |
| 289 const std::string& extension_id, | 313 const std::string& extension_id, |
| 290 bool is_now_visible) { | 314 bool is_now_visible) { |
| 291 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); | 315 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); |
| 292 } | 316 } |
| 293 | 317 |
| 318 void DeveloperPrivateEventRouter::OnExtensionDisableReasonsChanged( | |
| 319 const std::string& extension_id, int disable_reasons) { | |
| 320 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); | |
| 321 } | |
| 322 | |
| 323 void DeveloperPrivateEventRouter::OnExtensionManagementSettingsChanged() { | |
| 324 scoped_ptr<base::DictionaryValue> dict = | |
| 325 CreateProfileInfo(profile_)->ToValue(); | |
| 326 scoped_ptr<base::ListValue> args(new base::ListValue()); | |
| 327 args->Append(dict.release()); | |
|
not at google - send to devlin
2015/05/19 20:35:04
I'd prefer inlining |dict| as just CreateProfileIn
Devlin
2015/05/19 22:01:07
I'm not sure I buy your safety argument, but I lik
| |
| 328 scoped_ptr<Event> event(new Event( | |
| 329 developer::OnProfileStateChanged::kEventName, args.Pass())); | |
| 330 event_router_->BroadcastEvent(event.Pass()); | |
| 331 } | |
| 332 | |
| 333 void DeveloperPrivateEventRouter::ExtensionWarningsChanged( | |
| 334 const std::set<std::string>& affected_extensions) { | |
| 335 for (const std::string& id : affected_extensions) | |
| 336 BroadcastItemStateChanged(developer::EVENT_TYPE_WARNINGS_CHANGED, id); | |
|
not at google - send to devlin
2015/05/19 20:35:04
These event broadcasts in loops make me sad. We sh
Devlin
2015/05/19 22:01:07
We should be, but that's a much larger change. An
| |
| 337 } | |
| 338 | |
| 294 void DeveloperPrivateEventRouter::BroadcastItemStateChanged( | 339 void DeveloperPrivateEventRouter::BroadcastItemStateChanged( |
| 295 developer::EventType event_type, | 340 developer::EventType event_type, |
| 296 const std::string& extension_id) { | 341 const std::string& extension_id) { |
| 297 scoped_ptr<ExtensionInfoGenerator> info_generator( | 342 scoped_ptr<ExtensionInfoGenerator> info_generator( |
| 298 new ExtensionInfoGenerator(profile_)); | 343 new ExtensionInfoGenerator(profile_)); |
| 299 ExtensionInfoGenerator* info_generator_weak = info_generator.get(); | 344 ExtensionInfoGenerator* info_generator_weak = info_generator.get(); |
| 300 info_generator_weak->CreateExtensionInfo( | 345 info_generator_weak->CreateExtensionInfo( |
| 301 extension_id, | 346 extension_id, |
| 302 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper, | 347 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper, |
| 303 weak_factory_.GetWeakPtr(), | 348 weak_factory_.GetWeakPtr(), |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 537 |
| 493 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list))); | 538 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list))); |
| 494 } | 539 } |
| 495 | 540 |
| 496 DeveloperPrivateGetProfileConfigurationFunction:: | 541 DeveloperPrivateGetProfileConfigurationFunction:: |
| 497 ~DeveloperPrivateGetProfileConfigurationFunction() { | 542 ~DeveloperPrivateGetProfileConfigurationFunction() { |
| 498 } | 543 } |
| 499 | 544 |
| 500 ExtensionFunction::ResponseAction | 545 ExtensionFunction::ResponseAction |
| 501 DeveloperPrivateGetProfileConfigurationFunction::Run() { | 546 DeveloperPrivateGetProfileConfigurationFunction::Run() { |
| 502 developer::ProfileInfo info; | 547 scoped_ptr<developer::ProfileInfo> info = CreateProfileInfo(GetProfile()); |
| 503 info.is_supervised = GetProfile()->IsSupervised(); | |
| 504 info.is_incognito_available = | |
| 505 IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs()) != | |
| 506 IncognitoModePrefs::DISABLED; | |
| 507 info.in_developer_mode = | |
| 508 !info.is_supervised && | |
| 509 GetProfile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
| 510 info.app_info_dialog_enabled = CanShowAppInfoDialog(); | |
| 511 info.can_load_unpacked = | |
| 512 !ExtensionManagementFactory::GetForBrowserContext(browser_context()) | |
| 513 ->BlacklistedByDefault(); | |
| 514 | 548 |
| 515 // If this is called from the chrome://extensions page, we use this as a | 549 // If this is called from the chrome://extensions page, we use this as a |
| 516 // heuristic that it's a good time to verify installs. We do this on startup, | 550 // heuristic that it's a good time to verify installs. We do this on startup, |
| 517 // but there's a chance that it failed erroneously, so it's good to double- | 551 // but there's a chance that it failed erroneously, so it's good to double- |
| 518 // check. | 552 // check. |
| 519 if (source_context_type() == Feature::WEBUI_CONTEXT) | 553 if (source_context_type() == Feature::WEBUI_CONTEXT) |
| 520 PerformVerificationCheck(browser_context()); | 554 PerformVerificationCheck(browser_context()); |
| 521 | 555 |
| 522 return RespondNow(OneArgument(info.ToValue())); | 556 return RespondNow(OneArgument(info->ToValue())); |
| 523 } | 557 } |
| 524 | 558 |
| 525 DeveloperPrivateUpdateProfileConfigurationFunction:: | 559 DeveloperPrivateUpdateProfileConfigurationFunction:: |
| 526 ~DeveloperPrivateUpdateProfileConfigurationFunction() { | 560 ~DeveloperPrivateUpdateProfileConfigurationFunction() { |
| 527 } | 561 } |
| 528 | 562 |
| 529 ExtensionFunction::ResponseAction | 563 ExtensionFunction::ResponseAction |
| 530 DeveloperPrivateUpdateProfileConfigurationFunction::Run() { | 564 DeveloperPrivateUpdateProfileConfigurationFunction::Run() { |
| 531 scoped_ptr<developer::UpdateProfileConfiguration::Params> params( | 565 scoped_ptr<developer::UpdateProfileConfiguration::Params> params( |
| 532 developer::UpdateProfileConfiguration::Params::Create(*args_)); | 566 developer::UpdateProfileConfiguration::Params::Create(*args_)); |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1343 // We explicitly show manifest.json in order to work around an issue in OSX | 1377 // We explicitly show manifest.json in order to work around an issue in OSX |
| 1344 // where opening the directory doesn't focus the Finder. | 1378 // where opening the directory doesn't focus the Finder. |
| 1345 platform_util::ShowItemInFolder(GetProfile(), | 1379 platform_util::ShowItemInFolder(GetProfile(), |
| 1346 extension->path().Append(kManifestFilename)); | 1380 extension->path().Append(kManifestFilename)); |
| 1347 return RespondNow(NoArguments()); | 1381 return RespondNow(NoArguments()); |
| 1348 } | 1382 } |
| 1349 | 1383 |
| 1350 } // namespace api | 1384 } // namespace api |
| 1351 | 1385 |
| 1352 } // namespace extensions | 1386 } // namespace extensions |
| OLD | NEW |