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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "sync/api/string_ordinal.h" | 30 #include "sync/api/string_ordinal.h" |
31 | 31 |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 using extensions::Extension; | 33 using extensions::Extension; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const char kUnpackedExtensionsBlacklistedError[] = | 37 const char kUnpackedExtensionsBlacklistedError[] = |
38 "Loading of unpacked extensions is disabled by the administrator."; | 38 "Loading of unpacked extensions is disabled by the administrator."; |
39 | 39 |
| 40 const int kInstallFlags = extensions::kInstallFlagInstallImmediately; |
| 41 |
40 // Manages an ExtensionInstallPrompt for a particular extension. | 42 // Manages an ExtensionInstallPrompt for a particular extension. |
41 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { | 43 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { |
42 public: | 44 public: |
43 SimpleExtensionLoadPrompt(const Extension* extension, | 45 SimpleExtensionLoadPrompt(const Extension* extension, |
44 Profile* profile, | 46 Profile* profile, |
45 const base::Closure& callback); | 47 const base::Closure& callback); |
46 virtual ~SimpleExtensionLoadPrompt(); | 48 virtual ~SimpleExtensionLoadPrompt(); |
47 | 49 |
48 void ShowPrompt(); | 50 void ShowPrompt(); |
49 | 51 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 extension_path_ = base::MakeAbsoluteFilePath(path_in); | 148 extension_path_ = base::MakeAbsoluteFilePath(path_in); |
147 | 149 |
148 if (!IsLoadingUnpackedAllowed()) { | 150 if (!IsLoadingUnpackedAllowed()) { |
149 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 151 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
150 return false; | 152 return false; |
151 } | 153 } |
152 | 154 |
153 std::string error; | 155 std::string error; |
154 install_checker_.set_extension( | 156 install_checker_.set_extension( |
155 file_util::LoadExtension( | 157 file_util::LoadExtension( |
156 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get()); | 158 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get(), |
| 159 kInstallFlags); |
157 | 160 |
158 if (!extension() || | 161 if (!extension() || |
159 !extension_l10n_util::ValidateExtensionLocales( | 162 !extension_l10n_util::ValidateExtensionLocales( |
160 extension_path_, extension()->manifest()->value(), &error)) { | 163 extension_path_, extension()->manifest()->value(), &error)) { |
161 ReportExtensionLoadError(error); | 164 ReportExtensionLoadError(error); |
162 return false; | 165 return false; |
163 } | 166 } |
164 | 167 |
165 ShowInstallPrompt(); | 168 ShowInstallPrompt(); |
166 | 169 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 FROM_HERE, | 275 FROM_HERE, |
273 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); | 276 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); |
274 } | 277 } |
275 | 278 |
276 void UnpackedInstaller::LoadWithFileAccess(int flags) { | 279 void UnpackedInstaller::LoadWithFileAccess(int flags) { |
277 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 280 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
278 | 281 |
279 std::string error; | 282 std::string error; |
280 install_checker_.set_extension( | 283 install_checker_.set_extension( |
281 file_util::LoadExtension( | 284 file_util::LoadExtension( |
282 extension_path_, Manifest::UNPACKED, flags, &error).get()); | 285 extension_path_, Manifest::UNPACKED, flags, &error).get(), |
| 286 kInstallFlags); |
283 | 287 |
284 if (!extension() || | 288 if (!extension() || |
285 !extension_l10n_util::ValidateExtensionLocales( | 289 !extension_l10n_util::ValidateExtensionLocales( |
286 extension_path_, extension()->manifest()->value(), &error)) { | 290 extension_path_, extension()->manifest()->value(), &error)) { |
287 BrowserThread::PostTask( | 291 BrowserThread::PostTask( |
288 BrowserThread::UI, | 292 BrowserThread::UI, |
289 FROM_HERE, | 293 FROM_HERE, |
290 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); | 294 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); |
291 return; | 295 return; |
292 } | 296 } |
(...skipping 18 matching lines...) Expand all Loading... |
311 } | 315 } |
312 } | 316 } |
313 | 317 |
314 void UnpackedInstaller::InstallExtension() { | 318 void UnpackedInstaller::InstallExtension() { |
315 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
316 | 320 |
317 PermissionsUpdater perms_updater(service_weak_->profile()); | 321 PermissionsUpdater perms_updater(service_weak_->profile()); |
318 perms_updater.GrantActivePermissions(extension()); | 322 perms_updater.GrantActivePermissions(extension()); |
319 | 323 |
320 service_weak_->OnExtensionInstalled( | 324 service_weak_->OnExtensionInstalled( |
321 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 325 extension(), syncer::StringOrdinal(), kInstallFlags); |
322 } | 326 } |
323 | 327 |
324 } // namespace extensions | 328 } // namespace extensions |
OLD | NEW |