| OLD | NEW |
| 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/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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { | 64 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 void SimpleExtensionLoadPrompt::ShowPrompt() { | 67 void SimpleExtensionLoadPrompt::ShowPrompt() { |
| 68 install_ui_->ConfirmInstall( | 68 install_ui_->ConfirmInstall( |
| 69 this, extension_, ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 69 this, extension_, ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SimpleExtensionLoadPrompt::InstallUIProceed() { | 72 void SimpleExtensionLoadPrompt::InstallUIProceed() { |
| 73 if (service_weak_.get()) { | 73 if (service_weak_) { |
| 74 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); | 74 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); |
| 75 perms_updater.GrantActivePermissions(extension_); | 75 perms_updater.GrantActivePermissions(extension_); |
| 76 service_weak_->OnExtensionInstalled( | 76 service_weak_->OnExtensionInstalled( |
| 77 extension_, | 77 extension_, |
| 78 syncer::StringOrdinal(), | 78 syncer::StringOrdinal(), |
| 79 false /* no requirement errors */, | 79 false /* no requirement errors */, |
| 80 false /* don't wait for idle */); | 80 false /* don't wait for idle */); |
| 81 } | 81 } |
| 82 delete this; | 82 delete this; |
| 83 } | 83 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 extension_path_ = path_in; | 116 extension_path_ = path_in; |
| 117 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 117 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 118 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); | 118 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, | 121 void UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, |
| 122 bool launch_on_load) { | 122 bool launch_on_load) { |
| 123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 DCHECK(extension_path_.empty()); | 124 DCHECK(extension_path_.empty()); |
| 125 | 125 |
| 126 if (!service_weak_.get()) | 126 if (!service_weak_) |
| 127 return; | 127 return; |
| 128 // Load extensions from the command line synchronously to avoid a race | 128 // Load extensions from the command line synchronously to avoid a race |
| 129 // between extension loading and loading an URL from the command line. | 129 // between extension loading and loading an URL from the command line. |
| 130 base::ThreadRestrictions::ScopedAllowIO allow_io; | 130 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 131 | 131 |
| 132 extension_path_ = base::MakeAbsoluteFilePath(path_in); | 132 extension_path_ = base::MakeAbsoluteFilePath(path_in); |
| 133 | 133 |
| 134 if (!IsLoadingUnpackedAllowed()) { | 134 if (!IsLoadingUnpackedAllowed()) { |
| 135 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 135 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 std::string error; | 139 std::string error; |
| 140 extension_ = extension_file_util::LoadExtension( | 140 extension_ = extension_file_util::LoadExtension( |
| 141 extension_path_, | 141 extension_path_, |
| 142 Manifest::COMMAND_LINE, | 142 Manifest::COMMAND_LINE, |
| 143 GetFlags(), | 143 GetFlags(), |
| 144 &error); | 144 &error); |
| 145 | 145 |
| 146 if (!extension_.get()) { | 146 if (!extension_) { |
| 147 ReportExtensionLoadError(error); | 147 ReportExtensionLoadError(error); |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 launch_on_load_ = launch_on_load; | 151 launch_on_load_ = launch_on_load; |
| 152 | 152 |
| 153 CheckRequirements(); | 153 CheckRequirements(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void UnpackedInstaller::CheckRequirements() { | 156 void UnpackedInstaller::CheckRequirements() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 void UnpackedInstaller::LoadWithFileAccess(int flags) { | 223 void UnpackedInstaller::LoadWithFileAccess(int flags) { |
| 224 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 224 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 225 | 225 |
| 226 std::string error; | 226 std::string error; |
| 227 extension_ = extension_file_util::LoadExtension( | 227 extension_ = extension_file_util::LoadExtension( |
| 228 extension_path_, | 228 extension_path_, |
| 229 Manifest::UNPACKED, | 229 Manifest::UNPACKED, |
| 230 flags, | 230 flags, |
| 231 &error); | 231 &error); |
| 232 | 232 |
| 233 if (!extension_.get()) { | 233 if (!extension_) { |
| 234 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 234 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 235 base::Bind( | 235 base::Bind( |
| 236 &UnpackedInstaller::ReportExtensionLoadError, | 236 &UnpackedInstaller::ReportExtensionLoadError, |
| 237 this, error)); | 237 this, error)); |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 | 240 |
| 241 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 241 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 242 base::Bind(&UnpackedInstaller::CheckRequirements, this)); | 242 base::Bind(&UnpackedInstaller::CheckRequirements, this)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { | 245 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { |
| 246 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 247 if (!service_weak_.get()) | 247 if (!service_weak_) |
| 248 return; | 248 return; |
| 249 service_weak_->ReportExtensionLoadError(extension_path_, error, true); | 249 service_weak_->ReportExtensionLoadError(extension_path_, error, true); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void UnpackedInstaller::OnLoaded() { | 252 void UnpackedInstaller::OnLoaded() { |
| 253 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 if (!service_weak_.get()) | 254 if (!service_weak_) |
| 255 return; | 255 return; |
| 256 const ExtensionSet* disabled_extensions = | 256 const ExtensionSet* disabled_extensions = |
| 257 service_weak_->disabled_extensions(); | 257 service_weak_->disabled_extensions(); |
| 258 if (service_weak_->show_extensions_prompts() && | 258 if (service_weak_->show_extensions_prompts() && |
| 259 prompt_for_plugins_ && | 259 prompt_for_plugins_ && |
| 260 PluginInfo::HasPlugins(extension_) && | 260 PluginInfo::HasPlugins(extension_) && |
| 261 !disabled_extensions->Contains(extension_->id())) { | 261 !disabled_extensions->Contains(extension_->id())) { |
| 262 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 262 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 263 service_weak_->profile(), | 263 service_weak_->profile(), |
| 264 service_weak_, | 264 service_weak_, |
| 265 extension_); | 265 extension_); |
| 266 prompt->ShowPrompt(); | 266 prompt->ShowPrompt(); |
| 267 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* | 267 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* |
| 268 } | 268 } |
| 269 | 269 |
| 270 PermissionsUpdater perms_updater(service_weak_->profile()); | 270 PermissionsUpdater perms_updater(service_weak_->profile()); |
| 271 perms_updater.GrantActivePermissions(extension_); | 271 perms_updater.GrantActivePermissions(extension_); |
| 272 | 272 |
| 273 if (launch_on_load_) | 273 if (launch_on_load_) |
| 274 service_weak_->ScheduleLaunchOnLoad(extension_->id()); | 274 service_weak_->ScheduleLaunchOnLoad(extension_->id()); |
| 275 | 275 |
| 276 service_weak_->OnExtensionInstalled(extension_, | 276 service_weak_->OnExtensionInstalled(extension_, |
| 277 syncer::StringOrdinal(), | 277 syncer::StringOrdinal(), |
| 278 false /* no requirement errors */, | 278 false /* no requirement errors */, |
| 279 false /* don't wait for idle */); | 279 false /* don't wait for idle */); |
| 280 } | 280 } |
| 281 | 281 |
| 282 } // namespace extensions | 282 } // namespace extensions |
| OLD | NEW |