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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 182253010: Register a Service Worker when an extension is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to r261176 Created 6 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #include "extensions/browser/extension_host.h" 74 #include "extensions/browser/extension_host.h"
75 #include "extensions/browser/extension_registry.h" 75 #include "extensions/browser/extension_registry.h"
76 #include "extensions/browser/extension_system.h" 76 #include "extensions/browser/extension_system.h"
77 #include "extensions/browser/extensions_browser_client.h" 77 #include "extensions/browser/extensions_browser_client.h"
78 #include "extensions/browser/external_provider_interface.h" 78 #include "extensions/browser/external_provider_interface.h"
79 #include "extensions/browser/management_policy.h" 79 #include "extensions/browser/management_policy.h"
80 #include "extensions/browser/pref_names.h" 80 #include "extensions/browser/pref_names.h"
81 #include "extensions/browser/process_manager.h" 81 #include "extensions/browser/process_manager.h"
82 #include "extensions/browser/process_map.h" 82 #include "extensions/browser/process_map.h"
83 #include "extensions/browser/runtime_data.h" 83 #include "extensions/browser/runtime_data.h"
84 #include "extensions/browser/service_worker_manager.h"
84 #include "extensions/browser/update_observer.h" 85 #include "extensions/browser/update_observer.h"
85 #include "extensions/common/constants.h" 86 #include "extensions/common/constants.h"
86 #include "extensions/common/error_utils.h" 87 #include "extensions/common/error_utils.h"
87 #include "extensions/common/extension.h" 88 #include "extensions/common/extension.h"
88 #include "extensions/common/extension_messages.h" 89 #include "extensions/common/extension_messages.h"
89 #include "extensions/common/extensions_client.h" 90 #include "extensions/common/extensions_client.h"
90 #include "extensions/common/feature_switch.h" 91 #include "extensions/common/feature_switch.h"
91 #include "extensions/common/manifest.h" 92 #include "extensions/common/manifest.h"
92 #include "extensions/common/manifest_constants.h" 93 #include "extensions/common/manifest_constants.h"
93 #include "extensions/common/manifest_handlers/background_info.h" 94 #include "extensions/common/manifest_handlers/background_info.h"
(...skipping 10 matching lines...) Expand all
104 105
105 #if defined(OS_CHROMEOS) 106 #if defined(OS_CHROMEOS)
106 #include "chrome/browser/chromeos/extensions/install_limiter.h" 107 #include "chrome/browser/chromeos/extensions/install_limiter.h"
107 #include "webkit/browser/fileapi/file_system_backend.h" 108 #include "webkit/browser/fileapi/file_system_backend.h"
108 #include "webkit/browser/fileapi/file_system_context.h" 109 #include "webkit/browser/fileapi/file_system_context.h"
109 #endif 110 #endif
110 111
111 using content::BrowserContext; 112 using content::BrowserContext;
112 using content::BrowserThread; 113 using content::BrowserThread;
113 using content::DevToolsAgentHost; 114 using content::DevToolsAgentHost;
115 using extensions::BackgroundInfo;
114 using extensions::CrxInstaller; 116 using extensions::CrxInstaller;
115 using extensions::Extension; 117 using extensions::Extension;
116 using extensions::ExtensionIdSet; 118 using extensions::ExtensionIdSet;
117 using extensions::ExtensionInfo; 119 using extensions::ExtensionInfo;
118 using extensions::ExtensionRegistry; 120 using extensions::ExtensionRegistry;
119 using extensions::ExtensionSet; 121 using extensions::ExtensionSet;
120 using extensions::FeatureSwitch; 122 using extensions::FeatureSwitch;
121 using extensions::InstallVerifier; 123 using extensions::InstallVerifier;
122 using extensions::ManagementPolicy; 124 using extensions::ManagementPolicy;
123 using extensions::Manifest; 125 using extensions::Manifest;
124 using extensions::PermissionMessage; 126 using extensions::PermissionMessage;
125 using extensions::PermissionMessages; 127 using extensions::PermissionMessages;
126 using extensions::PermissionSet; 128 using extensions::PermissionSet;
129 using extensions::ServiceWorkerManager;
127 using extensions::SharedModuleInfo; 130 using extensions::SharedModuleInfo;
128 using extensions::UnloadedExtensionInfo; 131 using extensions::UnloadedExtensionInfo;
129 132
130 namespace errors = extensions::manifest_errors; 133 namespace errors = extensions::manifest_errors;
131 134
132 namespace { 135 namespace {
133 136
134 // Histogram values for logging events related to externally installed 137 // Histogram values for logging events related to externally installed
135 // extensions. 138 // extensions.
136 enum ExternalExtensionEvent { 139 enum ExternalExtensionEvent {
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 if (!extension) 908 if (!extension)
906 return; 909 return;
907 910
908 // The extension is either enabled or terminated. 911 // The extension is either enabled or terminated.
909 DCHECK(registry_->enabled_extensions().Contains(extension->id()) || 912 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
910 registry_->terminated_extensions().Contains(extension->id())); 913 registry_->terminated_extensions().Contains(extension->id()));
911 914
912 // Move it over to the disabled list. Don't send a second unload notification 915 // Move it over to the disabled list. Don't send a second unload notification
913 // for terminated extensions being disabled. 916 // for terminated extensions being disabled.
914 registry_->AddDisabled(make_scoped_refptr(extension)); 917 registry_->AddDisabled(make_scoped_refptr(extension));
918
919 if (BackgroundInfo::HasServiceWorker(extension))
920 ServiceWorkerManager::Get(profile_)->UnregisterExtension(extension);
921
915 if (registry_->enabled_extensions().Contains(extension->id())) { 922 if (registry_->enabled_extensions().Contains(extension->id())) {
916 registry_->RemoveEnabled(extension->id()); 923 registry_->RemoveEnabled(extension->id());
917 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); 924 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
918 } else { 925 } else {
919 registry_->RemoveTerminated(extension->id()); 926 registry_->RemoveTerminated(extension->id());
920 } 927 }
921 928
922 if (extension_sync_service_) 929 if (extension_sync_service_)
923 extension_sync_service_->SyncDisableExtension(*extension); 930 extension_sync_service_->SyncDisableExtension(*extension);
924 } 931 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 if (host_profile->GetOriginalProfile() == 1023 if (host_profile->GetOriginalProfile() ==
1017 profile_->GetOriginalProfile()) { 1024 profile_->GetOriginalProfile()) {
1018 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions( 1025 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1019 1, ExtensionMsg_Loaded_Params(extension)); 1026 1, ExtensionMsg_Loaded_Params(extension));
1020 host->Send( 1027 host->Send(
1021 new ExtensionMsg_Loaded(loaded_extensions)); 1028 new ExtensionMsg_Loaded(loaded_extensions));
1022 } 1029 }
1023 } 1030 }
1024 } 1031 }
1025 1032
1033 if (BackgroundInfo::HasServiceWorker(extension))
1034 ServiceWorkerManager::Get(profile_)->RegisterExtension(extension);
1035
1026 // Tell subsystems that use the EXTENSION_LOADED notification about the new 1036 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1027 // extension. 1037 // extension.
1028 // 1038 //
1029 // NOTE: It is important that this happen after notifying the renderers about 1039 // NOTE: It is important that this happen after notifying the renderers about
1030 // the new extensions so that if we navigate to an extension URL in 1040 // the new extensions so that if we navigate to an extension URL in
1031 // ExtensionRegistryObserver::OnLoaded or NOTIFICATION_EXTENSION_LOADED, the 1041 // ExtensionRegistryObserver::OnLoaded or NOTIFICATION_EXTENSION_LOADED, the
1032 // renderer is guaranteed to know about it. 1042 // renderer is guaranteed to know about it.
1033 registry_->TriggerOnLoaded(extension); 1043 registry_->TriggerOnLoaded(extension);
1034 1044
1035 content::NotificationService::current()->Notify( 1045 content::NotificationService::current()->Notify(
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 registry_->RemoveDisabled(extension->id()); 1514 registry_->RemoveDisabled(extension->id());
1505 // Make sure the profile cleans up its RequestContexts when an already 1515 // Make sure the profile cleans up its RequestContexts when an already
1506 // disabled extension is unloaded (since they are also tracking the disabled 1516 // disabled extension is unloaded (since they are also tracking the disabled
1507 // extensions). 1517 // extensions).
1508 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1518 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1509 // Don't send the unloaded notification. It was sent when the extension 1519 // Don't send the unloaded notification. It was sent when the extension
1510 // was disabled. 1520 // was disabled.
1511 } else { 1521 } else {
1512 // Remove the extension from the enabled list. 1522 // Remove the extension from the enabled list.
1513 registry_->RemoveEnabled(extension->id()); 1523 registry_->RemoveEnabled(extension->id());
1524
1525 if (BackgroundInfo::HasServiceWorker(extension)) {
1526 switch (reason) {
1527 case UnloadedExtensionInfo::REASON_DISABLE:
1528 case UnloadedExtensionInfo::REASON_UNINSTALL:
1529 case UnloadedExtensionInfo::REASON_BLACKLIST:
1530 ServiceWorkerManager::Get(profile_)->UnregisterExtension(extension);
1531 break;
1532 case UnloadedExtensionInfo::REASON_UPDATE:
1533 case UnloadedExtensionInfo::REASON_TERMINATE:
1534 break;
1535 }
1536 }
1514 NotifyExtensionUnloaded(extension.get(), reason); 1537 NotifyExtensionUnloaded(extension.get(), reason);
1515 } 1538 }
1516 1539
1517 content::NotificationService::current()->Notify( 1540 content::NotificationService::current()->Notify(
1518 chrome::NOTIFICATION_EXTENSION_REMOVED, 1541 chrome::NOTIFICATION_EXTENSION_REMOVED,
1519 content::Source<Profile>(profile_), 1542 content::Source<Profile>(profile_),
1520 content::Details<const Extension>(extension.get())); 1543 content::Details<const Extension>(extension.get()));
1521 } 1544 }
1522 1545
1523 void ExtensionService::RemoveComponentExtension( 1546 void ExtensionService::RemoveComponentExtension(
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 void ExtensionService::UnloadAllExtensionsInternal() { 2683 void ExtensionService::UnloadAllExtensionsInternal() {
2661 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2684 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2662 2685
2663 registry_->ClearAll(); 2686 registry_->ClearAll();
2664 system_->runtime_data()->ClearAll(); 2687 system_->runtime_data()->ClearAll();
2665 2688
2666 // TODO(erikkay) should there be a notification for this? We can't use 2689 // TODO(erikkay) should there be a notification for this? We can't use
2667 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2690 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2668 // or uninstalled. 2691 // or uninstalled.
2669 } 2692 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698