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

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

Issue 10912041: Disallow packing or loading unpacked manifest v1 extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blarh Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/unpacked_installer.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // static 83 // static
84 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( 84 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
85 ExtensionService* extension_service) { 85 ExtensionService* extension_service) {
86 return scoped_refptr<UnpackedInstaller>( 86 return scoped_refptr<UnpackedInstaller>(
87 new UnpackedInstaller(extension_service)); 87 new UnpackedInstaller(extension_service));
88 } 88 }
89 89
90 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 90 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
91 : service_weak_(extension_service->AsWeakPtr()), 91 : service_weak_(extension_service->AsWeakPtr()),
92 prompt_for_plugins_(true) { 92 prompt_for_plugins_(true),
93 require_modern_manifest_version_(true) {
93 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
94 } 95 }
95 96
96 UnpackedInstaller::~UnpackedInstaller() { 97 UnpackedInstaller::~UnpackedInstaller() {
97 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 98 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
98 BrowserThread::CurrentlyOn(BrowserThread::FILE)); 99 BrowserThread::CurrentlyOn(BrowserThread::FILE));
99 } 100 }
100 101
101 void UnpackedInstaller::Load(const FilePath& path_in) { 102 void UnpackedInstaller::Load(const FilePath& path_in) {
102 extension_path_ = path_in; 103 extension_path_ = path_in;
103 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 104 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
104 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); 105 base::Bind(&UnpackedInstaller::GetAbsolutePath, this));
105 } 106 }
106 107
107 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) { 108 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) {
108 if (!service_weak_.get()) 109 if (!service_weak_.get())
109 return; 110 return;
110 // Load extensions from the command line synchronously to avoid a race 111 // Load extensions from the command line synchronously to avoid a race
111 // between extension loading and loading an URL from the command line. 112 // between extension loading and loading an URL from the command line.
112 base::ThreadRestrictions::ScopedAllowIO allow_io; 113 base::ThreadRestrictions::ScopedAllowIO allow_io;
113 114
114 extension_path_ = path_in; 115 extension_path_ = path_in;
115 file_util::AbsolutePath(&extension_path_); 116 file_util::AbsolutePath(&extension_path_);
116 117
117 if (!IsLoadingUnpackedAllowed()) { 118 if (!IsLoadingUnpackedAllowed()) {
118 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 119 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
119 return; 120 return;
120 } 121 }
121 122
122 std::string id = Extension::GenerateIdForPath(extension_path_);
123 bool allow_file_access =
124 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD);
125 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
126 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
127
128 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION;
129 if (allow_file_access)
130 flags |= Extension::ALLOW_FILE_ACCESS;
131
132 std::string error; 123 std::string error;
133 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 124 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
134 extension_path_, 125 extension_path_,
135 Extension::LOAD, 126 Extension::LOAD,
136 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 127 GetFlags(),
137 &error)); 128 &error));
138 129
139 if (!extension) { 130 if (!extension) {
140 ReportExtensionLoadError(error); 131 ReportExtensionLoadError(error);
141 return; 132 return;
142 } 133 }
143 134
144 OnLoaded(extension); 135 OnLoaded(extension);
145 } 136 }
146 137
138 int UnpackedInstaller::GetFlags() {
139 std::string id = Extension::GenerateIdForPath(extension_path_);
140 bool allow_file_access =
141 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD);
142 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
143 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
144
145 int result = Extension::FOLLOW_SYMLINKS_ANYWHERE;
146 if (allow_file_access)
147 result |= Extension::ALLOW_FILE_ACCESS;
148 if (require_modern_manifest_version_)
149 result |= Extension::REQUIRE_MODERN_MANIFEST_VERSION;
150
151 return result;
152 }
153
147 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const { 154 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const {
148 if (!service_weak_) 155 if (!service_weak_)
149 return true; 156 return true;
150 // If there is a "*" in the extension blacklist, then no extensions should be 157 // If there is a "*" in the extension blacklist, then no extensions should be
151 // allowed at all (except explicitly whitelisted extensions). 158 // allowed at all (except explicitly whitelisted extensions).
152 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault(); 159 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault();
153 } 160 }
154 161
155 void UnpackedInstaller::GetAbsolutePath() { 162 void UnpackedInstaller::GetAbsolutePath() {
156 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 163 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
157 164
158 file_util::AbsolutePath(&extension_path_); 165 file_util::AbsolutePath(&extension_path_);
159 166
160 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 167 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
161 base::Bind(&UnpackedInstaller::CheckExtensionFileAccess, this)); 168 base::Bind(&UnpackedInstaller::CheckExtensionFileAccess, this));
162 } 169 }
163 170
164 void UnpackedInstaller::CheckExtensionFileAccess() { 171 void UnpackedInstaller::CheckExtensionFileAccess() {
165 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 172 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
166 if (!service_weak_) 173 if (!service_weak_)
167 return; 174 return;
168 175
169 if (!IsLoadingUnpackedAllowed()) { 176 if (!IsLoadingUnpackedAllowed()) {
170 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 177 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
171 return; 178 return;
172 } 179 }
173 180
174 std::string id = Extension::GenerateIdForPath(extension_path_);
175 // Unpacked extensions default to allowing file access, but if that has been
176 // overridden, don't reset the value.
177 bool allow_file_access =
178 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD);
179 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
180 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
181
182 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 181 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
183 base::Bind( 182 base::Bind(
184 &UnpackedInstaller::LoadWithFileAccess, 183 &UnpackedInstaller::LoadWithFileAccess, this, GetFlags()));
185 this, allow_file_access));
186 } 184 }
187 185
188 void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) { 186 void UnpackedInstaller::LoadWithFileAccess(int flags) {
189 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 187 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
190 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION; 188
191 if (allow_file_access)
192 flags |= Extension::ALLOW_FILE_ACCESS;
193 std::string error; 189 std::string error;
194 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 190 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
195 extension_path_, 191 extension_path_,
196 Extension::LOAD, 192 Extension::LOAD,
197 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 193 flags,
198 &error)); 194 &error));
199 195
200 if (!extension) { 196 if (!extension) {
201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 197 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
202 base::Bind( 198 base::Bind(
203 &UnpackedInstaller::ReportExtensionLoadError, 199 &UnpackedInstaller::ReportExtensionLoadError,
204 this, error)); 200 this, error));
205 return; 201 return;
206 } 202 }
207 203
(...skipping 30 matching lines...) Expand all
238 } 234 }
239 235
240 PermissionsUpdater perms_updater(service_weak_->profile()); 236 PermissionsUpdater perms_updater(service_weak_->profile());
241 perms_updater.GrantActivePermissions(extension, false); 237 perms_updater.GrantActivePermissions(extension, false);
242 service_weak_->OnExtensionInstalled(extension, 238 service_weak_->OnExtensionInstalled(extension,
243 false, // Not from web store. 239 false, // Not from web store.
244 StringOrdinal()); 240 StringOrdinal());
245 } 241 }
246 242
247 } // namespace extensions 243 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/unpacked_installer.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698