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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 using content::BrowserThread; | 34 using content::BrowserThread; |
35 using extensions::Extension; | 35 using extensions::Extension; |
36 using extensions::SharedModuleInfo; | 36 using extensions::SharedModuleInfo; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kUnpackedExtensionsBlacklistedError[] = | 40 const char kUnpackedExtensionsBlacklistedError[] = |
41 "Loading of unpacked extensions is disabled by the administrator."; | 41 "Loading of unpacked extensions is disabled by the administrator."; |
42 | 42 |
43 const char kUnpackedExtensionInsteadOfAppError[] = | |
44 "App loading flags cannot be used to load extensions. Please use " | |
45 "--load-extension instead."; | |
46 | |
47 const char kImportMinVersionNewer[] = | 43 const char kImportMinVersionNewer[] = |
48 "'import' version requested is newer than what is installed."; | 44 "'import' version requested is newer than what is installed."; |
49 const char kImportMissing[] = "'import' extension is not installed."; | 45 const char kImportMissing[] = "'import' extension is not installed."; |
50 const char kImportNotSharedModule[] = "'import' is not a shared module."; | 46 const char kImportNotSharedModule[] = "'import' is not a shared module."; |
51 | 47 |
52 // Manages an ExtensionInstallPrompt for a particular extension. | 48 // Manages an ExtensionInstallPrompt for a particular extension. |
53 class SimpleExtensionLoadPrompt { | 49 class SimpleExtensionLoadPrompt { |
54 public: | 50 public: |
55 SimpleExtensionLoadPrompt(const Extension* extension, | 51 SimpleExtensionLoadPrompt(const Extension* extension, |
56 Profile* profile, | 52 Profile* profile, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void UnpackedInstaller::Load(const base::FilePath& path_in) { | 123 void UnpackedInstaller::Load(const base::FilePath& path_in) { |
128 DCHECK(extension_path_.empty()); | 124 DCHECK(extension_path_.empty()); |
129 extension_path_ = path_in; | 125 extension_path_ = path_in; |
130 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
131 BrowserThread::FILE, | 127 BrowserThread::FILE, |
132 FROM_HERE, | 128 FROM_HERE, |
133 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); | 129 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); |
134 } | 130 } |
135 | 131 |
136 bool UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, | 132 bool UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, |
137 std::string* extension_id, | 133 std::string* extension_id) { |
138 bool only_allow_apps) { | |
139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
140 DCHECK(extension_path_.empty()); | 135 DCHECK(extension_path_.empty()); |
141 | 136 |
142 if (!service_weak_.get()) | 137 if (!service_weak_.get()) |
143 return false; | 138 return false; |
144 // Load extensions from the command line synchronously to avoid a race | 139 // Load extensions from the command line synchronously to avoid a race |
145 // between extension loading and loading an URL from the command line. | 140 // between extension loading and loading an URL from the command line. |
146 base::ThreadRestrictions::ScopedAllowIO allow_io; | 141 base::ThreadRestrictions::ScopedAllowIO allow_io; |
147 | 142 |
148 extension_path_ = base::MakeAbsoluteFilePath(path_in); | 143 extension_path_ = base::MakeAbsoluteFilePath(path_in); |
149 | 144 |
150 if (!IsLoadingUnpackedAllowed()) { | 145 if (!IsLoadingUnpackedAllowed()) { |
151 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 146 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
152 return false; | 147 return false; |
153 } | 148 } |
154 | 149 |
155 std::string error; | 150 std::string error; |
156 install_checker_.set_extension( | 151 install_checker_.set_extension( |
157 file_util::LoadExtension( | 152 file_util::LoadExtension( |
158 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get()); | 153 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get()); |
159 | 154 |
160 if (only_allow_apps && !extension()->is_platform_app()) { | |
161 #if defined(GOOGLE_CHROME_BUILD) | |
162 // Avoid crashing for users with hijacked shortcuts. | |
163 return true; | |
164 #else | |
165 ReportExtensionLoadError(kUnpackedExtensionInsteadOfAppError); | |
166 return false; | |
167 #endif | |
168 } | |
169 | |
170 if (!extension() || | 155 if (!extension() || |
171 !extension_l10n_util::ValidateExtensionLocales( | 156 !extension_l10n_util::ValidateExtensionLocales( |
172 extension_path_, extension()->manifest()->value(), &error)) { | 157 extension_path_, extension()->manifest()->value(), &error)) { |
173 ReportExtensionLoadError(error); | 158 ReportExtensionLoadError(error); |
174 return false; | 159 return false; |
175 } | 160 } |
176 | 161 |
177 extension()->permissions_data()->BindToCurrentThread(); | 162 extension()->permissions_data()->BindToCurrentThread(); |
178 PermissionsUpdater( | 163 PermissionsUpdater( |
179 service_weak_->profile(), PermissionsUpdater::INIT_FLAG_TRANSIENT) | 164 service_weak_->profile(), PermissionsUpdater::INIT_FLAG_TRANSIENT) |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 service_weak_->OnExtensionInstalled( | 361 service_weak_->OnExtensionInstalled( |
377 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 362 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); |
378 | 363 |
379 if (!callback_.is_null()) { | 364 if (!callback_.is_null()) { |
380 callback_.Run(extension(), extension_path_, std::string()); | 365 callback_.Run(extension(), extension_path_, std::string()); |
381 callback_.Reset(); | 366 callback_.Reset(); |
382 } | 367 } |
383 } | 368 } |
384 | 369 |
385 } // namespace extensions | 370 } // namespace extensions |
OLD | NEW |