| 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/installed_loader.h" | 5 #include "chrome/browser/extensions/installed_loader.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 *info.extension_manifest, | 100 *info.extension_manifest, |
| 101 GetCreationFlags(&info), | 101 GetCreationFlags(&info), |
| 102 &error); | 102 &error); |
| 103 } else { | 103 } else { |
| 104 error = errors::kManifestUnreadable; | 104 error = errors::kManifestUnreadable; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by | 107 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by |
| 108 // updating the 'key' field in their manifest). | 108 // updating the 'key' field in their manifest). |
| 109 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. | 109 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. |
| 110 if (extension && | 110 if (extension.get() && !Manifest::IsUnpackedLocation(extension->location()) && |
| 111 !Manifest::IsUnpackedLocation(extension->location()) && | |
| 112 info.extension_id != extension->id()) { | 111 info.extension_id != extension->id()) { |
| 113 error = errors::kCannotChangeExtensionID; | 112 error = errors::kCannotChangeExtensionID; |
| 114 extension = NULL; | 113 extension = NULL; |
| 115 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); | 114 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); |
| 116 } | 115 } |
| 117 | 116 |
| 118 // Check policy on every load in case an extension was blacklisted while | 117 // Check policy on every load in case an extension was blacklisted while |
| 119 // Chrome was not running. | 118 // Chrome was not running. |
| 120 const ManagementPolicy* policy = extensions::ExtensionSystem::Get( | 119 const ManagementPolicy* policy = extensions::ExtensionSystem::Get( |
| 121 extension_service_->profile())->management_policy(); | 120 extension_service_->profile())->management_policy(); |
| 122 if (extension && | 121 if (extension.get() && !policy->UserMayLoad(extension.get(), NULL)) { |
| 123 !policy->UserMayLoad(extension, NULL)) { | |
| 124 // The error message from UserMayInstall() often contains the extension ID | 122 // The error message from UserMayInstall() often contains the extension ID |
| 125 // and is therefore not well suited to this UI. | 123 // and is therefore not well suited to this UI. |
| 126 error = errors::kDisabledByPolicy; | 124 error = errors::kDisabledByPolicy; |
| 127 extension = NULL; | 125 extension = NULL; |
| 128 } | 126 } |
| 129 | 127 |
| 130 if (!extension) { | 128 if (!extension.get()) { |
| 131 extension_service_-> | 129 extension_service_->ReportExtensionLoadError( |
| 132 ReportExtensionLoadError(info.extension_path, error, false); | 130 info.extension_path, error, false); |
| 133 return; | 131 return; |
| 134 } | 132 } |
| 135 | 133 |
| 136 if (write_to_prefs) | 134 if (write_to_prefs) |
| 137 extension_prefs_->UpdateManifest(extension); | 135 extension_prefs_->UpdateManifest(extension.get()); |
| 138 | 136 |
| 139 extension_service_->AddExtension(extension); | 137 extension_service_->AddExtension(extension.get()); |
| 140 } | 138 } |
| 141 | 139 |
| 142 void InstalledLoader::LoadAllExtensions() { | 140 void InstalledLoader::LoadAllExtensions() { |
| 143 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 144 | 142 |
| 145 base::TimeTicks start_time = base::TimeTicks::Now(); | 143 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 146 | 144 |
| 147 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | 145 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 148 extension_prefs_->GetInstalledExtensionsInfo()); | 146 extension_prefs_->GetInstalledExtensionsInfo()); |
| 149 | 147 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 base::ThreadRestrictions::ScopedAllowIO allow_io; | 197 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 200 | 198 |
| 201 std::string error; | 199 std::string error; |
| 202 scoped_refptr<const Extension> extension( | 200 scoped_refptr<const Extension> extension( |
| 203 extension_file_util::LoadExtension( | 201 extension_file_util::LoadExtension( |
| 204 info->extension_path, | 202 info->extension_path, |
| 205 info->extension_location, | 203 info->extension_location, |
| 206 GetCreationFlags(info), | 204 GetCreationFlags(info), |
| 207 &error)); | 205 &error)); |
| 208 | 206 |
| 209 if (!extension) { | 207 if (!extension.get()) { |
| 210 extension_service_-> | 208 extension_service_->ReportExtensionLoadError( |
| 211 ReportExtensionLoadError(info->extension_path, error, false); | 209 info->extension_path, error, false); |
| 212 continue; | 210 continue; |
| 213 } | 211 } |
| 214 | 212 |
| 215 extensions_info->at(i)->extension_manifest.reset( | 213 extensions_info->at(i)->extension_manifest.reset( |
| 216 static_cast<DictionaryValue*>( | 214 static_cast<DictionaryValue*>( |
| 217 extension->manifest()->value()->DeepCopy())); | 215 extension->manifest()->value()->DeepCopy())); |
| 218 should_write_prefs = true; | 216 should_write_prefs = true; |
| 219 } | 217 } |
| 220 } | 218 } |
| 221 | 219 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { | 378 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { |
| 381 int flags = extension_prefs_->GetCreationFlags(info->extension_id); | 379 int flags = extension_prefs_->GetCreationFlags(info->extension_id); |
| 382 if (!Manifest::IsUnpackedLocation(info->extension_location)) | 380 if (!Manifest::IsUnpackedLocation(info->extension_location)) |
| 383 flags |= Extension::REQUIRE_KEY; | 381 flags |= Extension::REQUIRE_KEY; |
| 384 if (extension_prefs_->AllowFileAccess(info->extension_id)) | 382 if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 385 flags |= Extension::ALLOW_FILE_ACCESS; | 383 flags |= Extension::ALLOW_FILE_ACCESS; |
| 386 return flags; | 384 return flags; |
| 387 } | 385 } |
| 388 | 386 |
| 389 } // namespace extensions | 387 } // namespace extensions |
| OLD | NEW |