Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/extensions/unpacked_installer.cc

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/extensions/extension_install_prompt.h" 11 #include "chrome/browser/extensions/extension_install_prompt.h"
11 #include "chrome/browser/extensions/extension_install_ui.h" 12 #include "chrome/browser/extensions/extension_install_ui.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 13 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/permissions_updater.h" 15 #include "chrome/browser/extensions/permissions_updater.h"
16 #include "chrome/browser/extensions/requirements_checker.h"
15 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
17 #include "chrome/common/string_ordinal.h" 19 #include "chrome/common/string_ordinal.h"
18 20
19 using content::BrowserThread; 21 using content::BrowserThread;
20 using extensions::Extension; 22 using extensions::Extension;
21 23
22 namespace { 24 namespace {
23 25
24 const char kUnpackedExtensionsBlacklistedError[] = 26 const char kUnpackedExtensionsBlacklistedError[] =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 61
60 void SimpleExtensionLoadPrompt::ShowPrompt() { 62 void SimpleExtensionLoadPrompt::ShowPrompt() {
61 install_ui_->ConfirmInstall(this, extension_); 63 install_ui_->ConfirmInstall(this, extension_);
62 } 64 }
63 65
64 void SimpleExtensionLoadPrompt::InstallUIProceed() { 66 void SimpleExtensionLoadPrompt::InstallUIProceed() {
65 if (service_weak_.get()) { 67 if (service_weak_.get()) {
66 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); 68 extensions::PermissionsUpdater perms_updater(service_weak_->profile());
67 perms_updater.GrantActivePermissions(extension_, false); 69 perms_updater.GrantActivePermissions(extension_, false);
68 service_weak_->OnExtensionInstalled( 70 service_weak_->OnExtensionInstalled(
69 extension_, false, StringOrdinal()); // Not from web store. 71 extension_,
72 false, // Not from web store.
73 StringOrdinal(),
74 std::vector<std::string>());
70 } 75 }
71 delete this; 76 delete this;
72 } 77 }
73 78
74 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { 79 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
75 delete this; 80 delete this;
76 } 81 }
77 82
78 } // namespace 83 } // namespace
79 84
80 namespace extensions { 85 namespace extensions {
81 86
82 // static 87 // static
83 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( 88 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
84 ExtensionService* extension_service) { 89 ExtensionService* extension_service) {
85 return scoped_refptr<UnpackedInstaller>( 90 return scoped_refptr<UnpackedInstaller>(
86 new UnpackedInstaller(extension_service)); 91 new UnpackedInstaller(extension_service));
87 } 92 }
88 93
89 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 94 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
90 : service_weak_(extension_service->AsWeakPtr()), 95 : service_weak_(extension_service->AsWeakPtr()),
91 prompt_for_plugins_(true) { 96 prompt_for_plugins_(true),
97 requirements_checker_(new RequirementsChecker()) {
92 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
93 } 99 }
94 100
95 UnpackedInstaller::~UnpackedInstaller() { 101 UnpackedInstaller::~UnpackedInstaller() {
96 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 102 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
97 BrowserThread::CurrentlyOn(BrowserThread::FILE)); 103 BrowserThread::CurrentlyOn(BrowserThread::FILE));
98 } 104 }
99 105
100 void UnpackedInstaller::Load(const FilePath& path_in) { 106 void UnpackedInstaller::Load(const FilePath& path_in) {
101 extension_path_ = path_in; 107 extension_path_ = path_in;
102 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 108 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
103 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); 109 base::Bind(&UnpackedInstaller::GetAbsolutePath, this));
104 } 110 }
105 111
106 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) { 112 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) {
113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
114
107 if (!service_weak_.get()) 115 if (!service_weak_.get())
108 return; 116 return;
109 // Load extensions from the command line synchronously to avoid a race 117 // Load extensions from the command line synchronously to avoid a race
110 // between extension loading and loading an URL from the command line. 118 // between extension loading and loading an URL from the command line.
111 base::ThreadRestrictions::ScopedAllowIO allow_io; 119 base::ThreadRestrictions::ScopedAllowIO allow_io;
112 120
113 extension_path_ = path_in; 121 extension_path_ = path_in;
114 file_util::AbsolutePath(&extension_path_); 122 file_util::AbsolutePath(&extension_path_);
115 123
116 if (!IsLoadingUnpackedAllowed()) { 124 if (!IsLoadingUnpackedAllowed()) {
117 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 125 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
118 return; 126 return;
119 } 127 }
120 128
121 std::string id = Extension::GenerateIdForPath(extension_path_); 129 std::string id = Extension::GenerateIdForPath(extension_path_);
122 bool allow_file_access = 130 bool allow_file_access =
123 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); 131 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD);
124 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id)) 132 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
125 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id); 133 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
126 134
127 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION; 135 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION;
128 if (allow_file_access) 136 if (allow_file_access)
129 flags |= Extension::ALLOW_FILE_ACCESS; 137 flags |= Extension::ALLOW_FILE_ACCESS;
130 138
131 std::string error; 139 std::string error;
132 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 140 extension_ = extension_file_util::LoadExtension(
133 extension_path_, 141 extension_path_,
134 Extension::LOAD, 142 Extension::LOAD,
135 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 143 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
136 &error)); 144 &error);
137 145
138 if (!extension) { 146 if (!extension_.get()) {
139 ReportExtensionLoadError(error); 147 ReportExtensionLoadError(error);
140 return; 148 return;
141 } 149 }
142 150
143 OnLoaded(extension); 151 RunRequirementsChecker();
152 }
153
154 void UnpackedInstaller::RunRequirementsChecker() {
155 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
156 requirements_checker_->Check(
157 extension_,
158 base::Bind(&UnpackedInstaller::RequirementsChecked,
159 this),
160 BrowserThread::UI);
161 }
162
163 void UnpackedInstaller::RequirementsChecked(std::vector<std::string> errors) {
164 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165
166 if (!errors.empty()) {
167 ReportExtensionLoadError(JoinString(errors, ' '));
168 return;
169 }
170
171 OnLoaded();
144 } 172 }
145 173
146 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const { 174 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const {
147 if (!service_weak_) 175 if (!service_weak_)
148 return true; 176 return true;
149 // If there is a "*" in the extension blacklist, then no extensions should be 177 // If there is a "*" in the extension blacklist, then no extensions should be
150 // allowed at all (except explicitly whitelisted extensions). 178 // allowed at all (except explicitly whitelisted extensions).
151 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault(); 179 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault();
152 } 180 }
153 181
(...skipping 29 matching lines...) Expand all
183 &UnpackedInstaller::LoadWithFileAccess, 211 &UnpackedInstaller::LoadWithFileAccess,
184 this, allow_file_access)); 212 this, allow_file_access));
185 } 213 }
186 214
187 void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) { 215 void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) {
188 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 216 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
189 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION; 217 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION;
190 if (allow_file_access) 218 if (allow_file_access)
191 flags |= Extension::ALLOW_FILE_ACCESS; 219 flags |= Extension::ALLOW_FILE_ACCESS;
192 std::string error; 220 std::string error;
193 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 221 extension_ = extension_file_util::LoadExtension(
194 extension_path_, 222 extension_path_,
195 Extension::LOAD, 223 Extension::LOAD,
196 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 224 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
197 &error)); 225 &error);
198 226
199 if (!extension) { 227 if (!extension_.get()) {
200 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 228 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
201 base::Bind( 229 base::Bind(
202 &UnpackedInstaller::ReportExtensionLoadError, 230 &UnpackedInstaller::ReportExtensionLoadError,
203 this, error)); 231 this, error));
204 return; 232 return;
205 } 233 }
206 234
207 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 235 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
208 base::Bind( 236 base::Bind(&UnpackedInstaller::RunRequirementsChecker, this));
209 &UnpackedInstaller::OnLoaded,
210 this, extension));
211 } 237 }
212 238
213 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { 239 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) {
214 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 if (!service_weak_.get()) 241 if (!service_weak_.get())
216 return; 242 return;
217 service_weak_->ReportExtensionLoadError(extension_path_, error, true); 243 service_weak_->ReportExtensionLoadError(extension_path_, error, true);
218 } 244 }
219 245
220 void UnpackedInstaller::OnLoaded( 246 void UnpackedInstaller::OnLoaded() {
221 const scoped_refptr<const Extension>& extension) {
222 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 if (!service_weak_.get()) 248 if (!service_weak_.get())
224 return; 249 return;
225 const ExtensionSet* disabled_extensions = 250 const ExtensionSet* disabled_extensions =
226 service_weak_->disabled_extensions(); 251 service_weak_->disabled_extensions();
227 if (service_weak_->show_extensions_prompts() && 252 if (service_weak_->show_extensions_prompts() &&
228 prompt_for_plugins_ && 253 prompt_for_plugins_ &&
229 !extension->plugins().empty() && 254 !extension_->plugins().empty() &&
230 !disabled_extensions->Contains(extension->id())) { 255 !disabled_extensions->Contains(extension_->id())) {
231 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 256 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
232 service_weak_->profile(), 257 service_weak_->profile(),
233 service_weak_, 258 service_weak_,
234 extension); 259 extension_);
235 prompt->ShowPrompt(); 260 prompt->ShowPrompt();
236 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* 261 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt*
237 } 262 }
238 263
239 PermissionsUpdater perms_updater(service_weak_->profile()); 264 PermissionsUpdater perms_updater(service_weak_->profile());
240 perms_updater.GrantActivePermissions(extension, false); 265 perms_updater.GrantActivePermissions(extension_, false);
241 service_weak_->OnExtensionInstalled(extension, 266 service_weak_->OnExtensionInstalled(extension_,
242 false, // Not from web store. 267 false, // Not from web store.
243 StringOrdinal()); 268 StringOrdinal(),
269 std::vector<std::string>());
244 } 270 }
245 271
246 } // namespace extensions 272 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698