[email protected] | 8e7b2cf4 | 2012-04-18 14:26:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/file_path.h" |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/memory/weak_ptr.h" |
| 13 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 14 | class ExtensionService; |
| 15 | |
| 16 | namespace extensions { |
| 17 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 18 | class Extension; |
| 19 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 20 | // Installs and loads an unpacked extension. |
| 21 | // TODO(erikkay): It might be useful to be able to load a packed extension |
| 22 | // (presumably into memory) without installing it. |
| 23 | class UnpackedInstaller |
| 24 | : public base::RefCountedThreadSafe<UnpackedInstaller> { |
| 25 | public: |
| 26 | static scoped_refptr<UnpackedInstaller> Create( |
| 27 | ExtensionService* extension_service); |
| 28 | |
| 29 | // Loads the extension from the directory |extension_path|, which is |
| 30 | // the top directory of a specific extension where its manifest file lives. |
| 31 | // Errors are reported through ExtensionErrorReporter. On success, |
| 32 | // ExtensionService::AddExtension() is called. |
| 33 | void Load(const FilePath& extension_path); |
| 34 | |
| 35 | // Loads the extension from the directory |extension_path|; |
| 36 | // for use with command line switch --load-extension=path. |
| 37 | // This is equivalent to Load, except that it runs synchronously. |
| 38 | void LoadFromCommandLine(const FilePath& extension_path); |
| 39 | |
| 40 | // Allows prompting for plugins to be disabled; intended for testing only. |
| 41 | bool prompt_for_plugins() { return prompt_for_plugins_; } |
| 42 | void set_prompt_for_plugins(bool val) { prompt_for_plugins_ = val; } |
| 43 | |
[email protected] | b7462f3 | 2012-09-02 15:18:12 | [diff] [blame^] | 44 | // Allows overriding of whether modern manifest versions are required; |
| 45 | // intended for testing. |
| 46 | bool require_modern_manifest_version() const { |
| 47 | return require_modern_manifest_version_; |
| 48 | } |
| 49 | void set_require_modern_manifest_version(bool val) { |
| 50 | require_modern_manifest_version_ = val; |
| 51 | } |
| 52 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 53 | private: |
| 54 | friend class base::RefCountedThreadSafe<UnpackedInstaller>; |
| 55 | |
| 56 | explicit UnpackedInstaller(ExtensionService* extension_service); |
| 57 | virtual ~UnpackedInstaller(); |
| 58 | |
[email protected] | 8e7b2cf4 | 2012-04-18 14:26:58 | [diff] [blame] | 59 | // Verifies if loading unpacked extensions is allowed. |
| 60 | bool IsLoadingUnpackedAllowed() const; |
| 61 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 62 | // We change the input extension path to an absolute path, on the file thread. |
| 63 | // Then we need to check the file access preference, which needs |
| 64 | // to happen back on the UI thread, so it posts CheckExtensionFileAccess on |
| 65 | // the UI thread. In turn, once that gets the pref, it goes back to the |
| 66 | // file thread with LoadWithFileAccess. |
| 67 | // TODO(yoz): It would be nice to remove this ping-pong, but we need to know |
| 68 | // what file access flags to pass to extension_file_util::LoadExtension. |
| 69 | void GetAbsolutePath(); |
| 70 | void CheckExtensionFileAccess(); |
[email protected] | b7462f3 | 2012-09-02 15:18:12 | [diff] [blame^] | 71 | void LoadWithFileAccess(int flags); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 72 | |
| 73 | // Notify the frontend that there was an error loading an extension. |
| 74 | void ReportExtensionLoadError(const std::string& error); |
| 75 | |
| 76 | // Called when an unpacked extension has been loaded and installed. |
| 77 | void OnLoaded(const scoped_refptr<const Extension>& extension); |
| 78 | |
[email protected] | b7462f3 | 2012-09-02 15:18:12 | [diff] [blame^] | 79 | // Helper to get the Extension::CreateFlags for the installing extension. |
| 80 | int GetFlags(); |
| 81 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 82 | base::WeakPtr<ExtensionService> service_weak_; |
| 83 | |
| 84 | // The pathname of the directory to load from, which is an absolute path |
| 85 | // after GetAbsolutePath has been called. |
| 86 | FilePath extension_path_; |
| 87 | |
| 88 | // If true and the extension contains plugins, we prompt the user before |
| 89 | // loading. |
| 90 | bool prompt_for_plugins_; |
| 91 | |
[email protected] | b7462f3 | 2012-09-02 15:18:12 | [diff] [blame^] | 92 | // Whether to require the extension installed to have a modern manifest |
| 93 | // version. |
| 94 | bool require_modern_manifest_version_; |
| 95 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(UnpackedInstaller); |
| 97 | }; |
| 98 | |
| 99 | } // namespace extensions |
| 100 | |
| 101 | #endif // CHROME_BROWSER_EXTENSIONS_UNPACKED_INSTALLER_H_ |