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

Side by Side Diff: chrome/browser/extensions/extensions_service.h

Issue 125004: Revert "BUG=12114" (Closed)
Patch Set: Created 11 years, 6 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 class GURL; 25 class GURL;
26 class PrefService; 26 class PrefService;
27 class Profile; 27 class Profile;
28 class ResourceDispatcherHost; 28 class ResourceDispatcherHost;
29 class SkBitmap; 29 class SkBitmap;
30 class SiteInstance; 30 class SiteInstance;
31 class UserScriptMaster; 31 class UserScriptMaster;
32 32
33 typedef std::vector<Extension*> ExtensionList; 33 typedef std::vector<Extension*> ExtensionList;
34 34
35
36 // Manages installed and running Chromium extensions. 35 // Manages installed and running Chromium extensions.
37 class ExtensionsService 36 class ExtensionsService
38 : public base::RefCountedThreadSafe<ExtensionsService> { 37 : public base::RefCountedThreadSafe<ExtensionsService> {
39 public: 38 public:
40
41 // TODO(port): Move Crx package definitions to ExtentionCreator. They are
42 // currently here because ExtensionCreator is excluded on linux & mac.
43
44 // The size of the magic character sequence at the beginning of each crx
45 // file, in bytes. This should be a multiple of 4.
46 static const size_t kExtensionHeaderMagicSize = 4;
47
48 // The maximum size the crx parser will tolerate for a public key.
49 static const size_t kMaxPublicKeySize = 1 << 16;
50
51 // The maximum size the crx parser will tolerate for a signature.
52 static const size_t kMaxSignatureSize = 1 << 16;
53
54 // The magic character sequence at the beginning of each crx file.
55 static const char kExtensionHeaderMagic[];
56
57 // The current version of the crx format.
58 static const uint32 kCurrentVersion = 2;
59
60 // This header is the first data at the beginning of an extension. Its
61 // contents are purposely 32-bit aligned so that it can just be slurped into
62 // a struct without manual parsing.
63 struct ExtensionHeader {
64 char magic[kExtensionHeaderMagicSize];
65 uint32 version;
66 size_t key_size; // The size of the public key, in bytes.
67 size_t signature_size; // The size of the signature, in bytes.
68 // An ASN.1-encoded PublicKeyInfo structure follows.
69 // The signature follows.
70 };
71
72 ExtensionsService(Profile* profile, 39 ExtensionsService(Profile* profile,
73 MessageLoop* frontend_loop, 40 MessageLoop* frontend_loop,
74 MessageLoop* backend_loop, 41 MessageLoop* backend_loop,
75 const std::string& registry_path); 42 const std::string& registry_path);
76 ~ExtensionsService(); 43 ~ExtensionsService();
77 44
78 // Gets the list of currently installed extensions. 45 // Gets the list of currently installed extensions.
79 const ExtensionList* extensions() const { 46 const ExtensionList* extensions() const {
80 return &extensions_; 47 return &extensions_;
81 } 48 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 101
135 private: 102 private:
136 // For OnExtensionLoaded, OnExtensionInstalled, and 103 // For OnExtensionLoaded, OnExtensionInstalled, and
137 // OnExtensionVersionReinstalled. 104 // OnExtensionVersionReinstalled.
138 friend class ExtensionsServiceBackend; 105 friend class ExtensionsServiceBackend;
139 106
140 // Called by the backend when extensions have been loaded. 107 // Called by the backend when extensions have been loaded.
141 void OnExtensionsLoaded(ExtensionList* extensions); 108 void OnExtensionsLoaded(ExtensionList* extensions);
142 109
143 // Called by the backend when an extensoin hsa been installed. 110 // Called by the backend when an extensoin hsa been installed.
144 void OnExtensionInstalled(Extension* extension, 111 void OnExtensionInstalled(Extension* extension, bool is_update);
145 Extension::InstallType install_type);
146 112
147 // Called by the backend when an external extension has been installed. 113 // Called by the backend when an external extension has been installed.
148 void OnExternalExtensionInstalled( 114 void OnExternalExtensionInstalled(
149 const std::string& id, Extension::Location location); 115 const std::string& id, Extension::Location location);
150 116
151 // Called by the backend when an attempt was made to reinstall the same 117 // Called by the backend when an extension has been reinstalled.
152 // version of an existing extension. 118 void OnExtensionVersionReinstalled(const std::string& id);
153 void OnExtensionOverinstallAttempted(const std::string& id);
154 119
155 // The name of the directory inside the profile where extensions are 120 // The name of the directory inside the profile where extensions are
156 // installed to. 121 // installed to.
157 static const char* kInstallDirectoryName; 122 static const char* kInstallDirectoryName;
158 123
159 // Preferences for the owning profile. 124 // Preferences for the owning profile.
160 PrefService* prefs_; 125 PrefService* prefs_;
161 126
162 // The message loop to use with the backend. 127 // The message loop to use with the backend.
163 MessageLoop* backend_loop_; 128 MessageLoop* backend_loop_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 191
227 // Deletes all versions of the extension from the filesystem. Note that only 192 // Deletes all versions of the extension from the filesystem. Note that only
228 // extensions whose location() == INTERNAL can be uninstalled. Attempting to 193 // extensions whose location() == INTERNAL can be uninstalled. Attempting to
229 // uninstall other extensions will silently fail. 194 // uninstall other extensions will silently fail.
230 void UninstallExtension(const std::string& extension_id); 195 void UninstallExtension(const std::string& extension_id);
231 196
232 private: 197 private:
233 class UnpackerClient; 198 class UnpackerClient;
234 friend class UnpackerClient; 199 friend class UnpackerClient;
235 200
236 // Utility function to read an extension manifest and return it as a
237 // DictionaryValue. If it fails, NULL is returned and |error| contains an
238 // appropriate message.
239 DictionaryValue* ReadManifest(FilePath manifest_path, std::string* error);
240
241 // Load a single extension from |extension_path|, the top directory of 201 // Load a single extension from |extension_path|, the top directory of
242 // a specific extension where its manifest file lives. 202 // a specific extension where its manifest file lives.
243 Extension* LoadExtension(const FilePath& extension_path, bool require_id); 203 Extension* LoadExtension(const FilePath& extension_path, bool require_id);
244 204
245 // Load a single extension from |extension_path|, the top directory of 205 // Load a single extension from |extension_path|, the top directory of
246 // a versioned extension where its Current Version file lives. 206 // a versioned extension where its Current Version file lives.
247 Extension* LoadExtensionCurrentVersion(const FilePath& extension_path); 207 Extension* LoadExtensionCurrentVersion(const FilePath& extension_path);
248 208
249 // Install a crx file at |extension_path|. If |expected_id| is not empty, it's 209 // Install a crx file at |extension_path|. If |expected_id| is not empty, it's
250 // verified against the extension's manifest before installation. If 210 // verified against the extension's manifest before installation. If
251 // |from_external| is true, this extension install is from an external source, 211 // |from_external| is true, this extension install is from an external source,
252 // ie the Windows registry, and will be marked as such. If the extension is 212 // ie the Windows registry, and will be marked as such. If the extension is
253 // already installed, install the new version only if its version number is 213 // already installed, install the new version only if its version number is
254 // greater than the current installed version. 214 // greater than the current installed version.
255 void InstallOrUpdateExtension(const FilePath& extension_path, 215 void InstallOrUpdateExtension(const FilePath& extension_path,
256 const std::string& expected_id, 216 const std::string& expected_id,
257 bool from_external); 217 bool from_external);
258 218
259 // Validates the signature of the extension in |extension_path|. Returns true
260 // and the public key (in |key|) if the signature validates, false otherwise.
261 bool ValidateSignature(const FilePath& extension_path, std::string* key_out);
262
263 // Finish installing an extension after it has been unpacked to 219 // Finish installing an extension after it has been unpacked to
264 // |temp_extension_dir| by our utility process. If |expected_id| is not 220 // |temp_extension_dir| by our utility process. If |expected_id| is not
265 // empty, it's verified against the extension's manifest before installation. 221 // empty, it's verified against the extension's manifest before installation.
266 // |manifest| and |images| are parsed information from the extension that 222 // |manifest| and |images| are parsed information from the extension that
267 // we want to write to disk in the browser process. 223 // we want to write to disk in the browser process.
268 void OnExtensionUnpacked( 224 void OnExtensionUnpacked(
269 const FilePath& extension_path, 225 const FilePath& extension_path,
270 const FilePath& temp_extension_dir, 226 const FilePath& temp_extension_dir,
271 const std::string expected_id, 227 const std::string expected_id,
272 bool from_external, 228 bool from_external,
273 const DictionaryValue& manifest, 229 const DictionaryValue& manifest,
274 const std::vector< Tuple2<SkBitmap, FilePath> >& images); 230 const std::vector< Tuple2<SkBitmap, FilePath> >& images);
275 231
276 // Notify the frontend that there was an error loading an extension. 232 // Notify the frontend that there was an error loading an extension.
277 void ReportExtensionLoadError(const FilePath& extension_path, 233 void ReportExtensionLoadError(const FilePath& extension_path,
278 const std::string& error); 234 const std::string& error);
279 235
280 // Notify the frontend that extensions were loaded. 236 // Notify the frontend that extensions were loaded.
281 void ReportExtensionsLoaded(ExtensionList* extensions); 237 void ReportExtensionsLoaded(ExtensionList* extensions);
282 238
283 // Notify the frontend that there was an error installing an extension. 239 // Notify the frontend that there was an error installing an extension.
284 void ReportExtensionInstallError(const FilePath& extension_path, 240 void ReportExtensionInstallError(const FilePath& extension_path,
285 const std::string& error); 241 const std::string& error);
286 242
287 // Notify the frontend that an attempt was made (but not carried out) to 243 // Notify the frontend that the extension had already been installed.
288 // install the same version of an existing extension. 244 void ReportExtensionVersionReinstalled(const std::string& id);
289 void ReportExtensionOverinstallAttempted(const std::string& id);
290 245
291 // Checks a set of strings (containing id's to ignore) in order to determine 246 // Checks a set of strings (containing id's to ignore) in order to determine
292 // if the extension should be installed. 247 // if the extension should be installed.
293 bool ShouldSkipInstallingExtension(const std::set<std::string>& ids_to_ignore, 248 bool ShouldSkipInstallingExtension(const std::set<std::string>& ids_to_ignore,
294 const std::string& id); 249 const std::string& id);
295 250
296 // Installs the extension if the extension is a newer version or if the 251 // Installs the extension if the extension is a newer version or if the
297 // extension hasn't been installed before. 252 // extension hasn't been installed before.
298 void CheckVersionAndInstallExtension(const std::string& id, 253 void CheckVersionAndInstallExtension(const std::string& id,
299 const std::string& extension_version, 254 const std::string& extension_version,
300 const FilePath& extension_path, 255 const FilePath& extension_path,
301 bool from_external); 256 bool from_external);
302 257
303 // Read the manifest from the front of the extension file. 258 // Read the manifest from the front of the extension file.
304 // Caller takes ownership of return value. 259 // Caller takes ownership of return value.
305 DictionaryValue* ReadManifest(const FilePath& extension_path); 260 DictionaryValue* ReadManifest(const FilePath& extension_path);
306 261
307 // Reads the Current Version file from |dir| into |version_string|. 262 // Reads the Current Version file from |dir| into |version_string|.
308 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); 263 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string);
309 264
310 // Look for an existing installation of the extension |id| & return 265 // Check that the version to be installed is greater than the current
311 // an InstallType that would result from installing |new_version_str|. 266 // installed extension.
312 Extension::InstallType CompareToInstalledVersion(const std::string& id, 267 bool CheckCurrentVersion(const std::string& version,
313 const std::string& new_version_str, std::string* current_version_str); 268 const std::string& current_version,
314 269 const FilePath& dest_dir);
315 // Does an existing installed extension need to be reinstalled.
316 bool NeedsReinstall(const std::string& id,
317 const std::string& current_version);
318 270
319 // Install the extension dir by moving it from |source| to |dest| safely. 271 // Install the extension dir by moving it from |source| to |dest| safely.
320 bool InstallDirSafely(const FilePath& source, 272 bool InstallDirSafely(const FilePath& source,
321 const FilePath& dest); 273 const FilePath& dest);
322 274
323 // Update the CurrentVersion file in |dest_dir| to |version|. 275 // Update the CurrentVersion file in |dest_dir| to |version|.
324 bool SetCurrentVersion(const FilePath& dest_dir, 276 bool SetCurrentVersion(const FilePath& dest_dir,
325 std::string version); 277 std::string version);
326 278
327 // For the extension in |version_path| with |id|, check to see if it's an 279 // For the extension in |version_path| with |id|, check to see if it's an
(...skipping 30 matching lines...) Expand all
358 310
359 // The path to look for externally registered extensions in. This is a 311 // The path to look for externally registered extensions in. This is a
360 // registry key on windows, but it could be a similar string for the 312 // registry key on windows, but it could be a similar string for the
361 // appropriate system on other platforms in the future. 313 // appropriate system on other platforms in the future.
362 std::string registry_path_; 314 std::string registry_path_;
363 315
364 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); 316 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend);
365 }; 317 };
366 318
367 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 319 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_uitest.cc ('k') | chrome/browser/extensions/extensions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698