| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/version.h" | 14 #include "base/version.h" |
| 15 #include "chrome/browser/extensions/crx_installer_error.h" | 15 #include "chrome/browser/extensions/crx_installer_error.h" |
| 16 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 17 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 17 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
| 18 #include "chrome/browser/extensions/webstore_installer.h" | 18 #include "chrome/browser/extensions/webstore_installer.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/string_ordinal.h" | 20 #include "chrome/common/string_ordinal.h" |
| 21 #include "chrome/common/web_apps.h" | 21 #include "chrome/common/web_apps.h" |
| 22 | 22 |
| 23 class ExtensionService; | 23 class ExtensionService; |
| 24 class SkBitmap; | 24 class SkBitmap; |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 class ExtensionUpdaterTest; | 27 class ExtensionUpdaterTest; |
| 28 class RequirementsChecker; |
| 28 | 29 |
| 29 // This class installs a crx file into a profile. | 30 // This class installs a crx file into a profile. |
| 30 // | 31 // |
| 31 // Installing a CRX is a multi-step process, including unpacking the crx, | 32 // Installing a CRX is a multi-step process, including unpacking the crx, |
| 32 // validating it, prompting the user, and installing. Since many of these | 33 // validating it, prompting the user, and installing. Since many of these |
| 33 // steps must occur on the file thread, this class contains a copy of all data | 34 // steps must occur on the file thread, this class contains a copy of all data |
| 34 // necessary to do its job. (This also minimizes external dependencies for | 35 // necessary to do its job. (This also minimizes external dependencies for |
| 35 // easier testing). | 36 // easier testing). |
| 36 // | 37 // |
| 37 // Lifetime management: | 38 // Lifetime management: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 return off_store_install_allow_reason_; | 159 return off_store_install_allow_reason_; |
| 159 } | 160 } |
| 160 void set_off_store_install_allow_reason(OffStoreInstallAllowReason reason) { | 161 void set_off_store_install_allow_reason(OffStoreInstallAllowReason reason) { |
| 161 off_store_install_allow_reason_ = reason; | 162 off_store_install_allow_reason_ = reason; |
| 162 } | 163 } |
| 163 | 164 |
| 164 void set_page_ordinal(const StringOrdinal& page_ordinal) { | 165 void set_page_ordinal(const StringOrdinal& page_ordinal) { |
| 165 page_ordinal_ = page_ordinal; | 166 page_ordinal_ = page_ordinal; |
| 166 } | 167 } |
| 167 | 168 |
| 169 void set_error_on_unsupported_requirements(bool val) { |
| 170 error_on_unsupported_requirements_ = val; |
| 171 } |
| 172 |
| 168 bool did_handle_successfully() const { return did_handle_successfully_; } | 173 bool did_handle_successfully() const { return did_handle_successfully_; } |
| 169 | 174 |
| 170 Profile* profile() { return profile_; } | 175 Profile* profile() { return profile_; } |
| 171 | 176 |
| 172 private: | 177 private: |
| 173 friend class ExtensionUpdaterTest; | 178 friend class ExtensionUpdaterTest; |
| 174 friend class ExtensionCrxInstallerTest; | 179 friend class ExtensionCrxInstallerTest; |
| 175 | 180 |
| 176 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 181 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
| 177 ExtensionInstallPrompt* client, | 182 ExtensionInstallPrompt* client, |
| 178 const WebstoreInstaller::Approval* approval); | 183 const WebstoreInstaller::Approval* approval); |
| 179 virtual ~CrxInstaller(); | 184 virtual ~CrxInstaller(); |
| 180 | 185 |
| 181 // Converts the source user script to an extension. | 186 // Converts the source user script to an extension. |
| 182 void ConvertUserScriptOnFileThread(); | 187 void ConvertUserScriptOnFileThread(); |
| 183 | 188 |
| 184 // Converts the source web app to an extension. | 189 // Converts the source web app to an extension. |
| 185 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); | 190 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); |
| 186 | 191 |
| 187 // Called after OnUnpackSuccess as a last check to see whether the install | 192 // Called after OnUnpackSuccess as a last check to see whether the install |
| 188 // should complete. | 193 // should complete. |
| 189 CrxInstallerError AllowInstall(const Extension* extension); | 194 CrxInstallerError AllowInstall(Extension* extension); |
| 190 | 195 |
| 191 // SandboxedUnpackerClient | 196 // SandboxedUnpackerClient |
| 192 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; | 197 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; |
| 193 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 198 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 194 const FilePath& extension_dir, | 199 const FilePath& extension_dir, |
| 195 const base::DictionaryValue* original_manifest, | 200 const base::DictionaryValue* original_manifest, |
| 196 const Extension* extension) OVERRIDE; | 201 Extension* extension) OVERRIDE; |
| 197 | 202 |
| 198 // Returns true if we can skip confirmation because the install was | 203 // Returns true if we can skip confirmation because the install was |
| 199 // whitelisted. | 204 // whitelisted. |
| 200 bool CanSkipConfirmation(); | 205 bool CanSkipConfirmation(); |
| 201 | 206 |
| 207 // Called on the UI thread to start the requirements check on the extension. |
| 208 void CheckRequirements(); |
| 209 |
| 210 // Runs on the FILE thread. Callback from RequirementsChecker. |
| 211 void RequirementsChecked(std::vector<std::string> errors); |
| 212 |
| 202 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) | 213 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) |
| 203 // that it is OK to install this extension. | 214 // that it is OK to install this extension. |
| 204 void ConfirmInstall(); | 215 void ConfirmInstall(); |
| 205 | 216 |
| 206 // Runs on File thread. Install the unpacked extension into the profile and | 217 // Runs on File thread. Install the unpacked extension into the profile and |
| 207 // notify the frontend. | 218 // notify the frontend. |
| 208 void CompleteInstall(); | 219 void CompleteInstall(); |
| 209 | 220 |
| 210 // Result reporting. | 221 // Result reporting. |
| 211 void ReportFailureFromFileThread(const CrxInstallerError& error); | 222 void ReportFailureFromFileThread(const CrxInstallerError& error); |
| 212 void ReportFailureFromUIThread(const CrxInstallerError& error); | 223 void ReportFailureFromUIThread(const CrxInstallerError& error); |
| 213 void ReportSuccessFromFileThread(); | 224 void ReportSuccessFromFileThread(); |
| 214 void ReportSuccessFromUIThread(); | 225 void ReportSuccessFromUIThread(); |
| 215 void NotifyCrxInstallComplete(const Extension* extension); | 226 void NotifyCrxInstallComplete(Extension* extension); |
| 216 | 227 |
| 217 // The file we're installing. | 228 // The file we're installing. |
| 218 FilePath source_file_; | 229 FilePath source_file_; |
| 219 | 230 |
| 220 // The URL the file was downloaded from. | 231 // The URL the file was downloaded from. |
| 221 GURL download_url_; | 232 GURL download_url_; |
| 222 | 233 |
| 223 // The directory extensions are installed to. | 234 // The directory extensions are installed to. |
| 224 FilePath install_directory_; | 235 FilePath install_directory_; |
| 225 | 236 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // The download URL, before redirects, if this is a gallery install. | 271 // The download URL, before redirects, if this is a gallery install. |
| 261 GURL original_download_url_; | 272 GURL original_download_url_; |
| 262 | 273 |
| 263 // Whether to create an app shortcut after successful installation. This is | 274 // Whether to create an app shortcut after successful installation. This is |
| 264 // set based on the user's selection in the UI and can only ever be true for | 275 // set based on the user's selection in the UI and can only ever be true for |
| 265 // apps. | 276 // apps. |
| 266 bool create_app_shortcut_; | 277 bool create_app_shortcut_; |
| 267 | 278 |
| 268 // The extension we're installing. We own this and either pass it off to | 279 // The extension we're installing. We own this and either pass it off to |
| 269 // ExtensionService on success, or delete it on failure. | 280 // ExtensionService on success, or delete it on failure. |
| 270 scoped_refptr<const Extension> extension_; | 281 scoped_refptr<Extension> extension_; |
| 271 | 282 |
| 272 // The ordinal of the NTP apps page |extension_| will be shown on. | 283 // The ordinal of the NTP apps page |extension_| will be shown on. |
| 273 StringOrdinal page_ordinal_; | 284 StringOrdinal page_ordinal_; |
| 274 | 285 |
| 275 // A parsed copy of the unmodified original manifest, before any | 286 // A parsed copy of the unmodified original manifest, before any |
| 276 // transformations like localization have taken place. | 287 // transformations like localization have taken place. |
| 277 scoped_ptr<base::DictionaryValue> original_manifest_; | 288 scoped_ptr<base::DictionaryValue> original_manifest_; |
| 278 | 289 |
| 279 // If non-empty, contains the current version of the extension we're | 290 // If non-empty, contains the current version of the extension we're |
| 280 // installing (for upgrades). | 291 // installing (for upgrades). |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // Whether the installation was handled successfully. This is used to | 343 // Whether the installation was handled successfully. This is used to |
| 333 // indicate to the client whether the file should be removed and any UI | 344 // indicate to the client whether the file should be removed and any UI |
| 334 // initiating the installation can be removed. This is different than whether | 345 // initiating the installation can be removed. This is different than whether |
| 335 // there was an error; if there was an error that rejects installation we | 346 // there was an error; if there was an error that rejects installation we |
| 336 // still consider the installation 'handled'. | 347 // still consider the installation 'handled'. |
| 337 bool did_handle_successfully_; | 348 bool did_handle_successfully_; |
| 338 | 349 |
| 339 // Whether we should record an oauth2 grant upon successful install. | 350 // Whether we should record an oauth2 grant upon successful install. |
| 340 bool record_oauth2_grant_; | 351 bool record_oauth2_grant_; |
| 341 | 352 |
| 353 // Whether we should produce an error if the manifest declares requirements |
| 354 // that are not met. If false and there is an unmet requirement, the install |
| 355 // will continue but the extension will be distabled. |
| 356 bool error_on_unsupported_requirements_; |
| 357 |
| 358 scoped_ptr<RequirementsChecker> requirements_checker_; |
| 359 |
| 360 std::vector<std::string> requirement_errors_; |
| 361 |
| 342 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); | 362 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
| 343 }; | 363 }; |
| 344 | 364 |
| 345 } // namespace extensions | 365 } // namespace extensions |
| 346 | 366 |
| 347 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 367 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| OLD | NEW |