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