| 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/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 2020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2031 app_sync_bundle_.SyncChangeIfNeeded(extension); | 2031 app_sync_bundle_.SyncChangeIfNeeded(extension); |
| 2032 } else if (extension_sync_bundle_.HandlesExtension(extension)) { | 2032 } else if (extension_sync_bundle_.HandlesExtension(extension)) { |
| 2033 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 2033 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
| 2034 } | 2034 } |
| 2035 } | 2035 } |
| 2036 | 2036 |
| 2037 void ExtensionService::OnLoadedInstalledExtensions() { | 2037 void ExtensionService::OnLoadedInstalledExtensions() { |
| 2038 if (updater_.get()) | 2038 if (updater_.get()) |
| 2039 updater_->Start(); | 2039 updater_->Start(); |
| 2040 | 2040 |
| 2041 OnBlacklistUpdated(); |
| 2042 |
| 2041 ready_ = true; | 2043 ready_ = true; |
| 2042 content::NotificationService::current()->Notify( | 2044 content::NotificationService::current()->Notify( |
| 2043 chrome::NOTIFICATION_EXTENSIONS_READY, | 2045 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 2044 content::Source<Profile>(profile_), | 2046 content::Source<Profile>(profile_), |
| 2045 content::NotificationService::NoDetails()); | 2047 content::NotificationService::NoDetails()); |
| 2046 } | 2048 } |
| 2047 | 2049 |
| 2048 void ExtensionService::AddExtension(const Extension* extension) { | 2050 void ExtensionService::AddExtension(const Extension* extension) { |
| 2049 // TODO(jstritar): We may be able to get rid of this branch by overriding the | 2051 // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 2050 // default extension state to DISABLED when the --disable-extensions flag | 2052 // default extension state to DISABLED when the --disable-extensions flag |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2069 EnableExtension(extension->id()); | 2071 EnableExtension(extension->id()); |
| 2070 | 2072 |
| 2071 // Check if the extension's privileges have changed and disable the | 2073 // Check if the extension's privileges have changed and disable the |
| 2072 // extension if necessary. | 2074 // extension if necessary. |
| 2073 InitializePermissions(extension); | 2075 InitializePermissions(extension); |
| 2074 | 2076 |
| 2075 // If this extension is a sideloaded extension and we've not performed a | 2077 // If this extension is a sideloaded extension and we've not performed a |
| 2076 // wipeout before, we might disable this extension here. | 2078 // wipeout before, we might disable this extension here. |
| 2077 MaybeWipeout(extension); | 2079 MaybeWipeout(extension); |
| 2078 | 2080 |
| 2079 // Communicated to the Blacklist. | |
| 2080 std::set<std::string> already_in_blacklist; | |
| 2081 | |
| 2082 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { | 2081 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
| 2083 // Don't check the Blacklist yet because it's asynchronous (we do it at | 2082 // Don't check the Blacklist yet because it's asynchronous (we do it at |
| 2084 // the end). This pre-emptive check is because we will always store the | 2083 // the end). This pre-emptive check is because we will always store the |
| 2085 // blacklisted state of *installed* extensions in prefs, and it's important | 2084 // blacklisted state of *installed* extensions in prefs, and it's important |
| 2086 // not to re-enable blacklisted extensions. | 2085 // not to re-enable blacklisted extensions. |
| 2087 blacklisted_extensions_.Insert(extension); | 2086 blacklisted_extensions_.Insert(extension); |
| 2088 already_in_blacklist.insert(extension->id()); | |
| 2089 } else if (extension_prefs_->IsExtensionDisabled(extension->id())) { | 2087 } else if (extension_prefs_->IsExtensionDisabled(extension->id())) { |
| 2090 disabled_extensions_.Insert(extension); | 2088 disabled_extensions_.Insert(extension); |
| 2091 SyncExtensionChangeIfNeeded(*extension); | 2089 SyncExtensionChangeIfNeeded(*extension); |
| 2092 content::NotificationService::current()->Notify( | 2090 content::NotificationService::current()->Notify( |
| 2093 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 2091 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 2094 content::Source<Profile>(profile_), | 2092 content::Source<Profile>(profile_), |
| 2095 content::Details<const Extension>(extension)); | 2093 content::Details<const Extension>(extension)); |
| 2096 | 2094 |
| 2097 // Show the extension disabled error if a permissions increase was the | 2095 // Show the extension disabled error if a permissions increase was the |
| 2098 // only reason it was disabled. | 2096 // only reason it was disabled. |
| 2099 if (extension_prefs_->GetDisableReasons(extension->id()) == | 2097 if (extension_prefs_->GetDisableReasons(extension->id()) == |
| 2100 Extension::DISABLE_PERMISSIONS_INCREASE) { | 2098 Extension::DISABLE_PERMISSIONS_INCREASE) { |
| 2101 extensions::AddExtensionDisabledError(this, extension); | 2099 extensions::AddExtensionDisabledError(this, extension); |
| 2102 } | 2100 } |
| 2103 } else { | 2101 } else { |
| 2104 // All apps that are displayed in the launcher are ordered by their ordinals | 2102 // All apps that are displayed in the launcher are ordered by their ordinals |
| 2105 // so we must ensure they have valid ordinals. | 2103 // so we must ensure they have valid ordinals. |
| 2106 if (extension->RequiresSortOrdinal()) { | 2104 if (extension->RequiresSortOrdinal()) { |
| 2107 extension_prefs_->extension_sorting()->EnsureValidOrdinals( | 2105 extension_prefs_->extension_sorting()->EnsureValidOrdinals( |
| 2108 extension->id(), syncer::StringOrdinal()); | 2106 extension->id(), syncer::StringOrdinal()); |
| 2109 } | 2107 } |
| 2110 | 2108 |
| 2111 extensions_.Insert(extension); | 2109 extensions_.Insert(extension); |
| 2112 SyncExtensionChangeIfNeeded(*extension); | 2110 SyncExtensionChangeIfNeeded(*extension); |
| 2113 NotifyExtensionLoaded(extension); | 2111 NotifyExtensionLoaded(extension); |
| 2114 DoPostLoadTasks(extension); | 2112 DoPostLoadTasks(extension); |
| 2115 } | 2113 } |
| 2116 | |
| 2117 // Lastly, begin the process for checking the blacklist status of extensions. | |
| 2118 // This may need to go to other threads so is asynchronous. | |
| 2119 std::set<std::string> id_set; | |
| 2120 id_set.insert(extension->id()); | |
| 2121 blacklist_->GetBlacklistedIDs( | |
| 2122 id_set, | |
| 2123 base::Bind(&ExtensionService::ManageBlacklist, | |
| 2124 AsWeakPtr(), | |
| 2125 already_in_blacklist)); | |
| 2126 } | 2114 } |
| 2127 | 2115 |
| 2128 void ExtensionService::AddComponentExtension(const Extension* extension) { | 2116 void ExtensionService::AddComponentExtension(const Extension* extension) { |
| 2129 const std::string old_version_string( | 2117 const std::string old_version_string( |
| 2130 extension_prefs_->GetVersionString(extension->id())); | 2118 extension_prefs_->GetVersionString(extension->id())); |
| 2131 const Version old_version(old_version_string); | 2119 const Version old_version(old_version_string); |
| 2132 | 2120 |
| 2133 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 2121 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
| 2134 VLOG(1) << "Component extension " << extension->name() << " (" | 2122 VLOG(1) << "Component extension " << extension->name() << " (" |
| 2135 << extension->id() << ") installing/upgrading from '" | 2123 << extension->id() << ") installing/upgrading from '" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 // Unpacked extensions default to allowing file access, but if that has been | 2462 // Unpacked extensions default to allowing file access, but if that has been |
| 2475 // overridden, don't reset the value. | 2463 // overridden, don't reset the value. |
| 2476 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && | 2464 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
| 2477 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { | 2465 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
| 2478 extension_prefs_->SetAllowFileAccess(extension->id(), true); | 2466 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 2479 } | 2467 } |
| 2480 | 2468 |
| 2481 AddExtension(extension); | 2469 AddExtension(extension); |
| 2482 | 2470 |
| 2483 #if defined(ENABLE_THEMES) | 2471 #if defined(ENABLE_THEMES) |
| 2484 // We do this here since AddExtension() is always called on browser | 2472 // We do this here since AddExtension() is always called on browser startup, |
| 2485 // startup, and we only really care about the last theme installed. | 2473 // and we only really care about the last theme installed. |
| 2486 // If that ever changes and we have to move this code somewhere | 2474 // If that ever changes and we have to move this code somewhere |
| 2487 // else, it should be somewhere that's not in the startup path. | 2475 // else, it should be somewhere that's not in the startup path. |
| 2488 if (extension->is_theme() && extensions_.GetByID(extension->id())) { | 2476 if (extension->is_theme() && extensions_.GetByID(extension->id())) { |
| 2489 DCHECK_EQ(extensions_.GetByID(extension->id()), extension); | 2477 DCHECK_EQ(extensions_.GetByID(extension->id()), extension); |
| 2490 // Now that the theme extension is visible from outside the | 2478 // Now that the theme extension is visible from outside the |
| 2491 // ExtensionService, notify the ThemeService about the | 2479 // ExtensionService, notify the ThemeService about the |
| 2492 // newly-installed theme. | 2480 // newly-installed theme. |
| 2493 ThemeServiceFactory::GetForProfile(profile_)->SetTheme(extension); | 2481 ThemeServiceFactory::GetForProfile(profile_)->SetTheme(extension); |
| 2494 } | 2482 } |
| 2495 #endif | 2483 #endif |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3115 scoped_refptr<const Extension> extension = GetInstalledExtension(*it); | 3103 scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
| 3116 DCHECK(extension); | 3104 DCHECK(extension); |
| 3117 if (!extension) | 3105 if (!extension) |
| 3118 continue; | 3106 continue; |
| 3119 blacklisted_extensions_.Insert(extension); | 3107 blacklisted_extensions_.Insert(extension); |
| 3120 UnloadExtension(*it, extension_misc::UNLOAD_REASON_BLACKLIST); | 3108 UnloadExtension(*it, extension_misc::UNLOAD_REASON_BLACKLIST); |
| 3121 } | 3109 } |
| 3122 | 3110 |
| 3123 IdentifyAlertableExtensions(); | 3111 IdentifyAlertableExtensions(); |
| 3124 } | 3112 } |
| OLD | NEW |