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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
27 #include "extensions/browser/extension_util.h" | 27 #include "extensions/browser/extension_util.h" |
28 #include "extensions/browser/extensions_browser_client.h" | 28 #include "extensions/browser/extensions_browser_client.h" |
29 #include "extensions/browser/lazy_background_task_queue.h" | 29 #include "extensions/browser/lazy_background_task_queue.h" |
30 #include "extensions/browser/process_manager.h" | 30 #include "extensions/browser/process_manager.h" |
31 #include "extensions/common/api/runtime.h" | 31 #include "extensions/common/api/runtime.h" |
32 #include "extensions/common/error_utils.h" | 32 #include "extensions/common/error_utils.h" |
33 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
34 #include "extensions/common/manifest_handlers/background_info.h" | 34 #include "extensions/common/manifest_handlers/background_info.h" |
| 35 #include "extensions/common/manifest_handlers/shared_module_info.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
36 #include "webkit/browser/fileapi/isolated_context.h" | 37 #include "webkit/browser/fileapi/isolated_context.h" |
37 | 38 |
38 using content::BrowserContext; | 39 using content::BrowserContext; |
39 | 40 |
40 namespace extensions { | 41 namespace extensions { |
41 | 42 |
42 namespace runtime = core_api::runtime; | 43 namespace runtime = core_api::runtime; |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 const char kNoBackgroundPageError[] = "You do not have a background page."; | 47 const char kNoBackgroundPageError[] = "You do not have a background page."; |
47 const char kPageLoadError[] = "Background page failed to load."; | 48 const char kPageLoadError[] = "Background page failed to load."; |
| 49 const char kInstallId[] = "id"; |
48 const char kInstallReason[] = "reason"; | 50 const char kInstallReason[] = "reason"; |
49 const char kInstallReasonChromeUpdate[] = "chrome_update"; | 51 const char kInstallReasonChromeUpdate[] = "chrome_update"; |
50 const char kInstallReasonUpdate[] = "update"; | 52 const char kInstallReasonUpdate[] = "update"; |
51 const char kInstallReasonInstall[] = "install"; | 53 const char kInstallReasonInstall[] = "install"; |
| 54 const char kInstallReasonSharedModuleUpdate[] = "shared_module_update"; |
52 const char kInstallPreviousVersion[] = "previousVersion"; | 55 const char kInstallPreviousVersion[] = "previousVersion"; |
53 const char kInvalidUrlError[] = "Invalid URL."; | 56 const char kInvalidUrlError[] = "Invalid URL."; |
54 const char kPlatformInfoUnavailable[] = "Platform information unavailable."; | 57 const char kPlatformInfoUnavailable[] = "Platform information unavailable."; |
55 | 58 |
56 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; | 59 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
57 | 60 |
58 // A preference key storing the url loaded when an extension is uninstalled. | 61 // A preference key storing the url loaded when an extension is uninstalled. |
59 const char kUninstallUrl[] = "uninstall_url"; | 62 const char kUninstallUrl[] = "uninstall_url"; |
60 | 63 |
61 // The name of the directory to be returned by getPackageDirectoryEntry. This | 64 // The name of the directory to be returned by getPackageDirectoryEntry. This |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } else if (chrome_updated) { | 330 } else if (chrome_updated) { |
328 info->SetString(kInstallReason, kInstallReasonChromeUpdate); | 331 info->SetString(kInstallReason, kInstallReasonChromeUpdate); |
329 } else { | 332 } else { |
330 info->SetString(kInstallReason, kInstallReasonInstall); | 333 info->SetString(kInstallReason, kInstallReasonInstall); |
331 } | 334 } |
332 DCHECK(system->event_router()); | 335 DCHECK(system->event_router()); |
333 scoped_ptr<Event> event( | 336 scoped_ptr<Event> event( |
334 new Event(runtime::OnInstalled::kEventName, event_args.Pass())); | 337 new Event(runtime::OnInstalled::kEventName, event_args.Pass())); |
335 system->event_router()->DispatchEventWithLazyListener(extension_id, | 338 system->event_router()->DispatchEventWithLazyListener(extension_id, |
336 event.Pass()); | 339 event.Pass()); |
| 340 |
| 341 if (old_version.IsValid()) { |
| 342 const Extension* extension = |
| 343 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( |
| 344 extension_id); |
| 345 if (extension && SharedModuleInfo::IsSharedModule(extension)) { |
| 346 scoped_ptr<ExtensionSet> dependents = |
| 347 system->GetDependentExtensions(extension); |
| 348 for (ExtensionSet::const_iterator i = dependents->begin(); |
| 349 i != dependents->end(); |
| 350 i++) { |
| 351 scoped_ptr<base::ListValue> sm_event_args(new base::ListValue()); |
| 352 base::DictionaryValue* sm_info = new base::DictionaryValue(); |
| 353 sm_event_args->Append(sm_info); |
| 354 sm_info->SetString(kInstallReason, kInstallReasonSharedModuleUpdate); |
| 355 sm_info->SetString(kInstallPreviousVersion, old_version.GetString()); |
| 356 sm_info->SetString(kInstallId, extension_id); |
| 357 scoped_ptr<Event> sm_event( |
| 358 new Event(runtime::OnInstalled::kEventName, sm_event_args.Pass())); |
| 359 system->event_router()->DispatchEventWithLazyListener((*i)->id(), |
| 360 sm_event.Pass()); |
| 361 } |
| 362 } |
| 363 } |
337 } | 364 } |
338 | 365 |
339 // static | 366 // static |
340 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( | 367 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
341 content::BrowserContext* context, | 368 content::BrowserContext* context, |
342 const std::string& extension_id, | 369 const std::string& extension_id, |
343 const base::DictionaryValue* manifest) { | 370 const base::DictionaryValue* manifest) { |
344 ExtensionSystem* system = ExtensionSystem::Get(context); | 371 ExtensionSystem* system = ExtensionSystem::Get(context); |
345 if (!system) | 372 if (!system) |
346 return; | 373 return; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 content::ChildProcessSecurityPolicy* policy = | 534 content::ChildProcessSecurityPolicy* policy = |
508 content::ChildProcessSecurityPolicy::GetInstance(); | 535 content::ChildProcessSecurityPolicy::GetInstance(); |
509 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 536 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
510 base::DictionaryValue* dict = new base::DictionaryValue(); | 537 base::DictionaryValue* dict = new base::DictionaryValue(); |
511 dict->SetString("fileSystemId", filesystem_id); | 538 dict->SetString("fileSystemId", filesystem_id); |
512 dict->SetString("baseName", relative_path); | 539 dict->SetString("baseName", relative_path); |
513 return RespondNow(OneArgument(dict)); | 540 return RespondNow(OneArgument(dict)); |
514 } | 541 } |
515 | 542 |
516 } // namespace extensions | 543 } // namespace extensions |
OLD | NEW |