OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" | 5 #include "extensions/browser/api/runtime/runtime_api.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 const std::string& extension_id, | 511 const std::string& extension_id, |
512 const base::Version& old_version, | 512 const base::Version& old_version, |
513 bool chrome_updated) { | 513 bool chrome_updated) { |
514 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) | 514 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) |
515 return; | 515 return; |
516 ExtensionSystem* system = ExtensionSystem::Get(context); | 516 ExtensionSystem* system = ExtensionSystem::Get(context); |
517 if (!system) | 517 if (!system) |
518 return; | 518 return; |
519 | 519 |
520 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); | 520 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
521 base::DictionaryValue* info = new base::DictionaryValue(); | 521 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue()); |
522 event_args->Append(info); | |
523 if (old_version.IsValid()) { | 522 if (old_version.IsValid()) { |
524 info->SetString(kInstallReason, kInstallReasonUpdate); | 523 info->SetString(kInstallReason, kInstallReasonUpdate); |
525 info->SetString(kInstallPreviousVersion, old_version.GetString()); | 524 info->SetString(kInstallPreviousVersion, old_version.GetString()); |
526 } else if (chrome_updated) { | 525 } else if (chrome_updated) { |
527 info->SetString(kInstallReason, kInstallReasonChromeUpdate); | 526 info->SetString(kInstallReason, kInstallReasonChromeUpdate); |
528 } else { | 527 } else { |
529 info->SetString(kInstallReason, kInstallReasonInstall); | 528 info->SetString(kInstallReason, kInstallReasonInstall); |
530 } | 529 } |
| 530 event_args->Append(std::move(info)); |
531 EventRouter* event_router = EventRouter::Get(context); | 531 EventRouter* event_router = EventRouter::Get(context); |
532 DCHECK(event_router); | 532 DCHECK(event_router); |
533 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_INSTALLED, | 533 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_INSTALLED, |
534 runtime::OnInstalled::kEventName, | 534 runtime::OnInstalled::kEventName, |
535 std::move(event_args))); | 535 std::move(event_args))); |
536 event_router->DispatchEventWithLazyListener(extension_id, std::move(event)); | 536 event_router->DispatchEventWithLazyListener(extension_id, std::move(event)); |
537 | 537 |
538 if (old_version.IsValid()) { | 538 if (old_version.IsValid()) { |
539 const Extension* extension = | 539 const Extension* extension = |
540 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( | 540 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( |
541 extension_id); | 541 extension_id); |
542 if (extension && SharedModuleInfo::IsSharedModule(extension)) { | 542 if (extension && SharedModuleInfo::IsSharedModule(extension)) { |
543 std::unique_ptr<ExtensionSet> dependents = | 543 std::unique_ptr<ExtensionSet> dependents = |
544 system->GetDependentExtensions(extension); | 544 system->GetDependentExtensions(extension); |
545 for (ExtensionSet::const_iterator i = dependents->begin(); | 545 for (ExtensionSet::const_iterator i = dependents->begin(); |
546 i != dependents->end(); | 546 i != dependents->end(); |
547 i++) { | 547 i++) { |
548 std::unique_ptr<base::ListValue> sm_event_args(new base::ListValue()); | 548 std::unique_ptr<base::ListValue> sm_event_args(new base::ListValue()); |
549 base::DictionaryValue* sm_info = new base::DictionaryValue(); | 549 std::unique_ptr<base::DictionaryValue> sm_info( |
550 sm_event_args->Append(sm_info); | 550 new base::DictionaryValue()); |
551 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate); | 551 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate); |
552 sm_info->SetString(kInstallPreviousVersion, old_version.GetString()); | 552 sm_info->SetString(kInstallPreviousVersion, old_version.GetString()); |
553 sm_info->SetString(kInstallId, extension_id); | 553 sm_info->SetString(kInstallId, extension_id); |
| 554 sm_event_args->Append(std::move(sm_info)); |
554 std::unique_ptr<Event> sm_event(new Event( | 555 std::unique_ptr<Event> sm_event(new Event( |
555 events::RUNTIME_ON_INSTALLED, runtime::OnInstalled::kEventName, | 556 events::RUNTIME_ON_INSTALLED, runtime::OnInstalled::kEventName, |
556 std::move(sm_event_args))); | 557 std::move(sm_event_args))); |
557 event_router->DispatchEventWithLazyListener((*i)->id(), | 558 event_router->DispatchEventWithLazyListener((*i)->id(), |
558 std::move(sm_event)); | 559 std::move(sm_event)); |
559 } | 560 } |
560 } | 561 } |
561 } | 562 } |
562 } | 563 } |
563 | 564 |
564 // static | 565 // static |
565 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( | 566 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
566 content::BrowserContext* context, | 567 content::BrowserContext* context, |
567 const std::string& extension_id, | 568 const std::string& extension_id, |
568 const base::DictionaryValue* manifest) { | 569 const base::DictionaryValue* manifest) { |
569 ExtensionSystem* system = ExtensionSystem::Get(context); | 570 ExtensionSystem* system = ExtensionSystem::Get(context); |
570 if (!system) | 571 if (!system) |
571 return; | 572 return; |
572 | 573 |
573 std::unique_ptr<base::ListValue> args(new base::ListValue); | 574 std::unique_ptr<base::ListValue> args(new base::ListValue); |
574 args->Append(manifest->DeepCopy()); | 575 args->Append(manifest->CreateDeepCopy()); |
575 EventRouter* event_router = EventRouter::Get(context); | 576 EventRouter* event_router = EventRouter::Get(context); |
576 DCHECK(event_router); | 577 DCHECK(event_router); |
577 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_UPDATE_AVAILABLE, | 578 std::unique_ptr<Event> event(new Event(events::RUNTIME_ON_UPDATE_AVAILABLE, |
578 runtime::OnUpdateAvailable::kEventName, | 579 runtime::OnUpdateAvailable::kEventName, |
579 std::move(args))); | 580 std::move(args))); |
580 event_router->DispatchEventToExtension(extension_id, std::move(event)); | 581 event_router->DispatchEventToExtension(extension_id, std::move(event)); |
581 } | 582 } |
582 | 583 |
583 // static | 584 // static |
584 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( | 585 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 content::ChildProcessSecurityPolicy* policy = | 785 content::ChildProcessSecurityPolicy* policy = |
785 content::ChildProcessSecurityPolicy::GetInstance(); | 786 content::ChildProcessSecurityPolicy::GetInstance(); |
786 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 787 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
787 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 788 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
788 dict->SetString("fileSystemId", filesystem_id); | 789 dict->SetString("fileSystemId", filesystem_id); |
789 dict->SetString("baseName", relative_path); | 790 dict->SetString("baseName", relative_path); |
790 return RespondNow(OneArgument(std::move(dict))); | 791 return RespondNow(OneArgument(std::move(dict))); |
791 } | 792 } |
792 | 793 |
793 } // namespace extensions | 794 } // namespace extensions |
OLD | NEW |