| 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/unpacked_installer.h" | 5 #include "chrome/browser/extensions/unpacked_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "chrome/browser/extensions/extension_install_prompt.h" | 12 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 13 #include "chrome/browser/extensions/extension_install_ui.h" | 13 #include "chrome/browser/extensions/extension_install_ui.h" |
| 14 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/permissions_updater.h" | 16 #include "chrome/browser/extensions/permissions_updater.h" |
| 17 #include "chrome/browser/extensions/requirements_checker.h" | 17 #include "chrome/browser/extensions/requirements_checker.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_file_util.h" | 19 #include "chrome/common/extensions/extension_file_util.h" |
| 20 #include "chrome/common/extensions/manifest.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "sync/api/string_ordinal.h" | 22 #include "sync/api/string_ordinal.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 using extensions::Extension; | 25 using extensions::Extension; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const char kUnpackedExtensionsBlacklistedError[] = | 29 const char kUnpackedExtensionsBlacklistedError[] = |
| 29 "Loading of unpacked extensions is disabled by the administrator."; | 30 "Loading of unpacked extensions is disabled by the administrator."; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 file_util::AbsolutePath(&extension_path_); | 129 file_util::AbsolutePath(&extension_path_); |
| 129 | 130 |
| 130 if (!IsLoadingUnpackedAllowed()) { | 131 if (!IsLoadingUnpackedAllowed()) { |
| 131 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 132 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
| 132 return; | 133 return; |
| 133 } | 134 } |
| 134 | 135 |
| 135 std::string error; | 136 std::string error; |
| 136 extension_ = extension_file_util::LoadExtension( | 137 extension_ = extension_file_util::LoadExtension( |
| 137 extension_path_, | 138 extension_path_, |
| 138 Extension::LOAD, | 139 Manifest::LOAD, |
| 139 GetFlags(), | 140 GetFlags(), |
| 140 &error); | 141 &error); |
| 141 | 142 |
| 142 if (!extension_.get()) { | 143 if (!extension_.get()) { |
| 143 ReportExtensionLoadError(error); | 144 ReportExtensionLoadError(error); |
| 144 return; | 145 return; |
| 145 } | 146 } |
| 146 | 147 |
| 147 CheckRequirements(); | 148 CheckRequirements(); |
| 148 } | 149 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 162 ReportExtensionLoadError(JoinString(requirement_errors, ' ')); | 163 ReportExtensionLoadError(JoinString(requirement_errors, ' ')); |
| 163 return; | 164 return; |
| 164 } | 165 } |
| 165 | 166 |
| 166 OnLoaded(); | 167 OnLoaded(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 int UnpackedInstaller::GetFlags() { | 170 int UnpackedInstaller::GetFlags() { |
| 170 std::string id = Extension::GenerateIdForPath(extension_path_); | 171 std::string id = Extension::GenerateIdForPath(extension_path_); |
| 171 bool allow_file_access = | 172 bool allow_file_access = |
| 172 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); | 173 Manifest::ShouldAlwaysAllowFileAccess(Manifest::LOAD); |
| 173 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id)) | 174 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id)) |
| 174 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id); | 175 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id); |
| 175 | 176 |
| 176 int result = Extension::FOLLOW_SYMLINKS_ANYWHERE; | 177 int result = Extension::FOLLOW_SYMLINKS_ANYWHERE; |
| 177 if (allow_file_access) | 178 if (allow_file_access) |
| 178 result |= Extension::ALLOW_FILE_ACCESS; | 179 result |= Extension::ALLOW_FILE_ACCESS; |
| 179 if (require_modern_manifest_version_) | 180 if (require_modern_manifest_version_) |
| 180 result |= Extension::REQUIRE_MODERN_MANIFEST_VERSION; | 181 result |= Extension::REQUIRE_MODERN_MANIFEST_VERSION; |
| 181 | 182 |
| 182 return result; | 183 return result; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 213 base::Bind( | 214 base::Bind( |
| 214 &UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); | 215 &UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void UnpackedInstaller::LoadWithFileAccess(int flags) { | 218 void UnpackedInstaller::LoadWithFileAccess(int flags) { |
| 218 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 219 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 219 | 220 |
| 220 std::string error; | 221 std::string error; |
| 221 extension_ = extension_file_util::LoadExtension( | 222 extension_ = extension_file_util::LoadExtension( |
| 222 extension_path_, | 223 extension_path_, |
| 223 Extension::LOAD, | 224 Manifest::LOAD, |
| 224 flags, | 225 flags, |
| 225 &error); | 226 &error); |
| 226 | 227 |
| 227 if (!extension_.get()) { | 228 if (!extension_.get()) { |
| 228 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 229 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 229 base::Bind( | 230 base::Bind( |
| 230 &UnpackedInstaller::ReportExtensionLoadError, | 231 &UnpackedInstaller::ReportExtensionLoadError, |
| 231 this, error)); | 232 this, error)); |
| 232 return; | 233 return; |
| 233 } | 234 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 263 | 264 |
| 264 PermissionsUpdater perms_updater(service_weak_->profile()); | 265 PermissionsUpdater perms_updater(service_weak_->profile()); |
| 265 perms_updater.GrantActivePermissions(extension_, false); | 266 perms_updater.GrantActivePermissions(extension_, false); |
| 266 service_weak_->OnExtensionInstalled(extension_, | 267 service_weak_->OnExtensionInstalled(extension_, |
| 267 syncer::StringOrdinal(), | 268 syncer::StringOrdinal(), |
| 268 false /* no requirement errors */, | 269 false /* no requirement errors */, |
| 269 false /* don't wait for idle */); | 270 false /* don't wait for idle */); |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |