| OLD | NEW |
| 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_CRX_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "chrome/browser/extensions/extensions_service.h" | 13 #include "chrome/browser/extensions/extensions_service.h" |
| 14 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 14 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 | 16 |
| 17 // Classes that want to know about install completion, or that want to have an |
| 18 // opportunity to reject the unpacked extension before installation, should |
| 19 // implement this interface. |
| 20 class CrxInstallerClient |
| 21 : public base::RefCountedThreadSafe<CrxInstallerClient> { |
| 22 public: |
| 23 virtual ~CrxInstallerClient() {} |
| 24 |
| 25 // Return true to indicate that installation should proceed, false otherwise. |
| 26 virtual bool ConfirmInstall(Extension* extension) = 0; |
| 27 |
| 28 // Installation was successful. |
| 29 virtual void OnInstallSuccess(Extension* extension) = 0; |
| 30 |
| 31 // Intallation failed. |
| 32 virtual void OnInstallFailure(const std::string& error) = 0; |
| 33 |
| 34 // The install was rejected because the same extension/version is already |
| 35 // installed. |
| 36 virtual void OnOverinstallAttempted(Extension* extension) = 0; |
| 37 }; |
| 38 |
| 17 // This class installs a crx file into a profile. | 39 // This class installs a crx file into a profile. |
| 18 // | 40 // |
| 19 // Installing a CRX is a multi-step process, including unpacking the crx, | 41 // Installing a CRX is a multi-step process, including unpacking the crx, |
| 20 // validating it, prompting the user, and installing. Since many of these | 42 // validating it, prompting the user, and installing. Since many of these |
| 21 // steps must occur on the file thread, this class contains a copy of all data | 43 // steps must occur on the file thread, this class contains a copy of all data |
| 22 // necessary to do its job. (This also minimizes external dependencies for | 44 // necessary to do its job. (This also minimizes external dependencies for |
| 23 // easier testing). | 45 // easier testing). |
| 24 // | 46 // |
| 25 // | |
| 26 // Lifetime management: | 47 // Lifetime management: |
| 27 // | 48 // |
| 28 // This class is ref-counted by each call it makes to itself on another thread, | 49 // This class is ref-counted by each call it makes to itself on another thread, |
| 29 // and by UtilityProcessHost. | 50 // and by UtilityProcessHost. |
| 30 // | 51 // |
| 31 // Additionally, we hold a reference to our own client so that it lives at least | 52 // Additionally, we hold a reference to our own client so that it lives at least |
| 32 // long enough to receive the result of unpacking. | 53 // long enough to receive the result of unpacking. |
| 33 // | |
| 34 // | 54 // |
| 35 // NOTE: This class is rather huge at the moment because it is handling all | |
| 36 // types of installation (external, autoupdate, and manual). In the future, | |
| 37 // manual installation will probably pulled out of it. | |
| 38 // | |
| 39 // TODO(aa): Pull out the manual installation bits. | |
| 40 // TODO(aa): Pull out a frontend interface for testing? | 55 // TODO(aa): Pull out a frontend interface for testing? |
| 41 class CrxInstaller : public SandboxedExtensionUnpackerClient { | 56 class CrxInstaller : public SandboxedExtensionUnpackerClient { |
| 42 public: | 57 public: |
| 58 // Starts the installation of the crx file in |crx_path| into |
| 59 // |install_directory|. |
| 60 // |
| 61 // Other params: |
| 62 // install_source: The source of the install (external, --load-extension, etc |
| 63 // expected_id: Optional. If the caller knows what the ID of this extension |
| 64 // should be after unpacking, it can be specified here as a |
| 65 // sanity check. |
| 66 // delete_crx: Whether the crx should be deleted on completion. |
| 67 // file_loop: The message loop to do file IO on. |
| 68 // frontend: The ExtensionsService to report the successfully installed |
| 69 // extension to. |
| 70 // client: Optional. If specified, will be used to confirm installation and |
| 71 // also notified of success/fail. Note that we hold a reference to |
| 72 // this, so it can outlive its creator (eg the UI). |
| 73 static void Start(const FilePath& crx_path, |
| 74 const FilePath& install_directory, |
| 75 Extension::Location install_source, |
| 76 const std::string& expected_id, |
| 77 bool delete_crx, |
| 78 MessageLoop* file_loop, |
| 79 ExtensionsService* frontend, |
| 80 CrxInstallerClient* client); |
| 81 |
| 82 private: |
| 43 CrxInstaller(const FilePath& crx_path, | 83 CrxInstaller(const FilePath& crx_path, |
| 44 const FilePath& install_directory, | 84 const FilePath& install_directory, |
| 45 Extension::Location install_source, | 85 Extension::Location install_source, |
| 46 const std::string& expected_id, | 86 const std::string& expected_id, |
| 47 bool extensions_enabled, | |
| 48 bool is_from_gallery, | |
| 49 bool show_prompts, | |
| 50 bool delete_crx, | 87 bool delete_crx, |
| 51 MessageLoop* file_loop, | 88 MessageLoop* file_loop, |
| 52 ExtensionsService* frontend); | 89 ExtensionsService* frontend, |
| 53 ~CrxInstaller() { | 90 CrxInstallerClient* client); |
| 54 // This is only here for debugging purposes, as a convenient place to set | 91 ~CrxInstaller(); |
| 55 // breakpoints. | |
| 56 } | |
| 57 | 92 |
| 58 private: | |
| 59 // SandboxedExtensionUnpackerClient | 93 // SandboxedExtensionUnpackerClient |
| 60 virtual void OnUnpackFailure(const std::string& error_message); | 94 virtual void OnUnpackFailure(const std::string& error_message); |
| 61 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 95 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 62 const FilePath& extension_dir, | 96 const FilePath& extension_dir, |
| 63 Extension* extension); | 97 Extension* extension); |
| 64 | 98 |
| 65 // Confirm with the user that it is OK to install this extension. | 99 // Runs on the UI thread. Confirms with the user (via CrxInstallerClient) that |
| 66 // | 100 // it is OK to install this extension. |
| 67 // Note that this runs on the file thread. It happens to be OK to do this on | 101 void ConfirmInstall(); |
| 68 // Windows and Mac, and although ugly, we leave it because this is all getting | |
| 69 // pulled out soon, anyway. | |
| 70 // | |
| 71 // TODO(aa): Pull this up, closer to the UI layer. | |
| 72 bool ConfirmInstall(); | |
| 73 | 102 |
| 74 // Runs on File thread. Install the unpacked extension into the profile and | 103 // Runs on File thread. Install the unpacked extension into the profile and |
| 75 // notify the frontend. | 104 // notify the frontend. |
| 76 void CompleteInstall(); | 105 void CompleteInstall(); |
| 77 | 106 |
| 78 // Result reporting. | 107 // Result reporting. |
| 79 void ReportFailureFromFileThread(const std::string& error); | 108 void ReportFailureFromFileThread(const std::string& error); |
| 80 void ReportFailureFromUIThread(const std::string& error); | 109 void ReportFailureFromUIThread(const std::string& error); |
| 81 void ReportOverinstallFromFileThread(); | 110 void ReportOverinstallFromFileThread(); |
| 111 void ReportOverinstallFromUIThread(); |
| 82 void ReportSuccessFromFileThread(); | 112 void ReportSuccessFromFileThread(); |
| 113 void ReportSuccessFromUIThread(); |
| 83 | 114 |
| 84 // The crx file we're installing. | 115 // The crx file we're installing. |
| 85 FilePath crx_path_; | 116 FilePath crx_path_; |
| 86 | 117 |
| 87 // The directory extensions are installed to. | 118 // The directory extensions are installed to. |
| 88 FilePath install_directory_; | 119 FilePath install_directory_; |
| 89 | 120 |
| 90 // The location the installation came from (bundled with Chromium, registry, | 121 // The location the installation came from (bundled with Chromium, registry, |
| 91 // manual install, etc). This metadata is saved with the installation if | 122 // manual install, etc). This metadata is saved with the installation if |
| 92 // successful. | 123 // successful. |
| 93 Extension::Location install_source_; | 124 Extension::Location install_source_; |
| 94 | 125 |
| 95 // For updates and external installs we have an ID we're expecting the | 126 // For updates and external installs we have an ID we're expecting the |
| 96 // extension to contain. | 127 // extension to contain. |
| 97 std::string expected_id_; | 128 std::string expected_id_; |
| 98 | 129 |
| 99 // Whether extension installation is set. We can't just check this before | 130 // Whether manual extension installation is enabled. We can't just check this |
| 100 // trying to install because themes are special-cased to always be allowed. | 131 // before trying to install because themes are special-cased to always be |
| 132 // allowed. |
| 101 bool extensions_enabled_; | 133 bool extensions_enabled_; |
| 102 | 134 |
| 103 // Whether this installation was initiated from the gallery. We trust it more | |
| 104 // and have special UI if it was. | |
| 105 bool is_from_gallery_; | |
| 106 | |
| 107 // Whether we shoud should show prompts. This is sometimes false for testing | |
| 108 // and autoupdate. | |
| 109 bool show_prompts_; | |
| 110 | |
| 111 // Whether we're supposed to delete the source crx file on destruction. | 135 // Whether we're supposed to delete the source crx file on destruction. |
| 112 bool delete_crx_; | 136 bool delete_crx_; |
| 113 | 137 |
| 114 // The message loop to use for file IO. | 138 // The message loop to use for file IO. |
| 115 MessageLoop* file_loop_; | 139 MessageLoop* file_loop_; |
| 116 | 140 |
| 117 // The message loop the UI is running on. | 141 // The message loop the UI is running on. |
| 118 MessageLoop* ui_loop_; | 142 MessageLoop* ui_loop_; |
| 119 | 143 |
| 120 // The extension we're installing. We own this and either pass it off to | 144 // The extension we're installing. We own this and either pass it off to |
| 121 // ExtensionsService on success, or delete it on failure. | 145 // ExtensionsService on success, or delete it on failure. |
| 122 scoped_ptr<Extension> extension_; | 146 scoped_ptr<Extension> extension_; |
| 123 | 147 |
| 124 // The temp directory extension resources were unpacked to. We own this and | 148 // The temp directory extension resources were unpacked to. We own this and |
| 125 // must delete it when we are done with it. | 149 // must delete it when we are done with it. |
| 126 FilePath temp_dir_; | 150 FilePath temp_dir_; |
| 127 | 151 |
| 128 // The frontend we will report results back to. | 152 // The frontend we will report results back to. |
| 129 scoped_refptr<ExtensionsService> frontend_; | 153 scoped_refptr<ExtensionsService> frontend_; |
| 130 | 154 |
| 155 // The client we will work with to do the installation. This can be NULL, in |
| 156 // which case the install is silent. |
| 157 scoped_refptr<CrxInstallerClient> client_; |
| 158 |
| 131 // The root of the unpacked extension directory. This is a subdirectory of | 159 // The root of the unpacked extension directory. This is a subdirectory of |
| 132 // temp_dir_, so we don't have to delete it explicitly. | 160 // temp_dir_, so we don't have to delete it explicitly. |
| 133 FilePath unpacked_extension_root_; | 161 FilePath unpacked_extension_root_; |
| 134 | 162 |
| 135 // The unpacker we will use to unpack the extension. | 163 // The unpacker we will use to unpack the extension. |
| 136 SandboxedExtensionUnpacker* unpacker_; | 164 SandboxedExtensionUnpacker* unpacker_; |
| 137 | 165 |
| 138 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); | 166 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
| 139 }; | 167 }; |
| 140 | 168 |
| 141 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| OLD | NEW |