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 && |
| 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::ListValue> args(new base::ListValue()); |
| 325 args->Append(CreateProfileInfo(profile_)->ToValue()); |
| 326 scoped_ptr<Event> event(new Event( |
| 327 developer::OnProfileStateChanged::kEventName, args.Pass())); |
| 328 event_router_->BroadcastEvent(event.Pass()); |
| 329 } |
| 330 |
| 331 void DeveloperPrivateEventRouter::ExtensionWarningsChanged( |
| 332 const ExtensionIdSet& affected_extensions) { |
| 333 for (const ExtensionId& id : affected_extensions) |
| 334 BroadcastItemStateChanged(developer::EVENT_TYPE_WARNINGS_CHANGED, id); |
| 335 } |
| 336 |
294 void DeveloperPrivateEventRouter::BroadcastItemStateChanged( | 337 void DeveloperPrivateEventRouter::BroadcastItemStateChanged( |
295 developer::EventType event_type, | 338 developer::EventType event_type, |
296 const std::string& extension_id) { | 339 const std::string& extension_id) { |
297 scoped_ptr<ExtensionInfoGenerator> info_generator( | 340 scoped_ptr<ExtensionInfoGenerator> info_generator( |
298 new ExtensionInfoGenerator(profile_)); | 341 new ExtensionInfoGenerator(profile_)); |
299 ExtensionInfoGenerator* info_generator_weak = info_generator.get(); | 342 ExtensionInfoGenerator* info_generator_weak = info_generator.get(); |
300 info_generator_weak->CreateExtensionInfo( | 343 info_generator_weak->CreateExtensionInfo( |
301 extension_id, | 344 extension_id, |
302 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper, | 345 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper, |
303 weak_factory_.GetWeakPtr(), | 346 weak_factory_.GetWeakPtr(), |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 535 |
493 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list))); | 536 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list))); |
494 } | 537 } |
495 | 538 |
496 DeveloperPrivateGetProfileConfigurationFunction:: | 539 DeveloperPrivateGetProfileConfigurationFunction:: |
497 ~DeveloperPrivateGetProfileConfigurationFunction() { | 540 ~DeveloperPrivateGetProfileConfigurationFunction() { |
498 } | 541 } |
499 | 542 |
500 ExtensionFunction::ResponseAction | 543 ExtensionFunction::ResponseAction |
501 DeveloperPrivateGetProfileConfigurationFunction::Run() { | 544 DeveloperPrivateGetProfileConfigurationFunction::Run() { |
502 developer::ProfileInfo info; | 545 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 | 546 |
515 // If this is called from the chrome://extensions page, we use this as a | 547 // 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, | 548 // 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- | 549 // but there's a chance that it failed erroneously, so it's good to double- |
518 // check. | 550 // check. |
519 if (source_context_type() == Feature::WEBUI_CONTEXT) | 551 if (source_context_type() == Feature::WEBUI_CONTEXT) |
520 PerformVerificationCheck(browser_context()); | 552 PerformVerificationCheck(browser_context()); |
521 | 553 |
522 return RespondNow(OneArgument(info.ToValue())); | 554 return RespondNow(OneArgument(info->ToValue())); |
523 } | 555 } |
524 | 556 |
525 DeveloperPrivateUpdateProfileConfigurationFunction:: | 557 DeveloperPrivateUpdateProfileConfigurationFunction:: |
526 ~DeveloperPrivateUpdateProfileConfigurationFunction() { | 558 ~DeveloperPrivateUpdateProfileConfigurationFunction() { |
527 } | 559 } |
528 | 560 |
529 ExtensionFunction::ResponseAction | 561 ExtensionFunction::ResponseAction |
530 DeveloperPrivateUpdateProfileConfigurationFunction::Run() { | 562 DeveloperPrivateUpdateProfileConfigurationFunction::Run() { |
531 scoped_ptr<developer::UpdateProfileConfiguration::Params> params( | 563 scoped_ptr<developer::UpdateProfileConfiguration::Params> params( |
532 developer::UpdateProfileConfiguration::Params::Create(*args_)); | 564 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 | 1375 // We explicitly show manifest.json in order to work around an issue in OSX |
1344 // where opening the directory doesn't focus the Finder. | 1376 // where opening the directory doesn't focus the Finder. |
1345 platform_util::ShowItemInFolder(GetProfile(), | 1377 platform_util::ShowItemInFolder(GetProfile(), |
1346 extension->path().Append(kManifestFilename)); | 1378 extension->path().Append(kManifestFilename)); |
1347 return RespondNow(NoArguments()); | 1379 return RespondNow(NoArguments()); |
1348 } | 1380 } |
1349 | 1381 |
1350 } // namespace api | 1382 } // namespace api |
1351 | 1383 |
1352 } // namespace extensions | 1384 } // namespace extensions |
OLD | NEW |