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