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