| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "chrome/browser/extensions/extension_install_ui.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 17 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 17 #include "chrome/browser/extensions/sandboxed_extension_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 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 // | 45 // |
| 46 // IMPORTANT: Callers should keep a reference to a CrxInstaller while they are | 46 // IMPORTANT: Callers should keep a reference to a CrxInstaller while they are |
| 47 // working with it, eg: | 47 // working with it, eg: |
| 48 // | 48 // |
| 49 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); | 49 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); |
| 50 // installer->set_foo(); | 50 // installer->set_foo(); |
| 51 // installer->set_bar(); | 51 // installer->set_bar(); |
| 52 // installer->InstallCrx(...); | 52 // installer->InstallCrx(...); |
| 53 class CrxInstaller | 53 class CrxInstaller |
| 54 : public SandboxedExtensionUnpackerClient, | 54 : public SandboxedExtensionUnpackerClient, |
| 55 public ExtensionInstallUI::Delegate { | 55 public ExtensionInstallPrompt::Delegate { |
| 56 public: | 56 public: |
| 57 // Extensions will be installed into frontend->install_directory(), | 57 // Extensions will be installed into frontend->install_directory(), |
| 58 // then registered with |frontend|. Any install UI will be displayed | 58 // then registered with |frontend|. Any install UI will be displayed |
| 59 // using |client|. Pass NULL for |client| for silent install | 59 // using |client|. Pass NULL for |client| for silent install |
| 60 static scoped_refptr<CrxInstaller> Create( | 60 static scoped_refptr<CrxInstaller> Create( |
| 61 ExtensionService* frontend, | 61 ExtensionService* frontend, |
| 62 ExtensionInstallUI* client); | 62 ExtensionInstallPrompt* client); |
| 63 | 63 |
| 64 // Same as the previous method, except use the |approval| to bypass the | 64 // Same as the previous method, except use the |approval| to bypass the |
| 65 // prompt. Note that the caller retains ownership of |approval|. | 65 // prompt. Note that the caller retains ownership of |approval|. |
| 66 static scoped_refptr<CrxInstaller> Create( | 66 static scoped_refptr<CrxInstaller> Create( |
| 67 ExtensionService* frontend, | 67 ExtensionService* frontend, |
| 68 ExtensionInstallUI* client, | 68 ExtensionInstallPrompt* client, |
| 69 const WebstoreInstaller::Approval* approval); | 69 const WebstoreInstaller::Approval* approval); |
| 70 | 70 |
| 71 // Install the crx in |source_file|. | 71 // Install the crx in |source_file|. |
| 72 void InstallCrx(const FilePath& source_file); | 72 void InstallCrx(const FilePath& source_file); |
| 73 | 73 |
| 74 // Convert the specified user script into an extension and install it. | 74 // Convert the specified user script into an extension and install it. |
| 75 void InstallUserScript(const FilePath& source_file, | 75 void InstallUserScript(const FilePath& source_file, |
| 76 const GURL& download_url); | 76 const GURL& download_url); |
| 77 | 77 |
| 78 // Convert the specified web app into an extension and install it. | 78 // Convert the specified web app into an extension and install it. |
| 79 void InstallWebApp(const WebApplicationInfo& web_app); | 79 void InstallWebApp(const WebApplicationInfo& web_app); |
| 80 | 80 |
| 81 // Overridden from ExtensionInstallUI::Delegate: | 81 // Overridden from ExtensionInstallPrompt::Delegate: |
| 82 virtual void InstallUIProceed() OVERRIDE; | 82 virtual void InstallUIProceed() OVERRIDE; |
| 83 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 83 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 84 | 84 |
| 85 int creation_flags() const { return creation_flags_; } | 85 int creation_flags() const { return creation_flags_; } |
| 86 void set_creation_flags(int val) { creation_flags_ = val; } | 86 void set_creation_flags(int val) { creation_flags_ = val; } |
| 87 | 87 |
| 88 const GURL& download_url() const { return download_url_; } | 88 const GURL& download_url() const { return download_url_; } |
| 89 void set_download_url(const GURL& val) { download_url_ = val; } | 89 void set_download_url(const GURL& val) { download_url_ = val; } |
| 90 | 90 |
| 91 const FilePath& source_file() const { return source_file_; } | 91 const FilePath& source_file() const { return source_file_; } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void set_page_ordinal(const StringOrdinal& page_ordinal) { | 150 void set_page_ordinal(const StringOrdinal& page_ordinal) { |
| 151 page_ordinal_ = page_ordinal; | 151 page_ordinal_ = page_ordinal; |
| 152 } | 152 } |
| 153 | 153 |
| 154 Profile* profile() { return profile_; } | 154 Profile* profile() { return profile_; } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 friend class extensions::ExtensionUpdaterTest; | 157 friend class extensions::ExtensionUpdaterTest; |
| 158 | 158 |
| 159 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 159 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
| 160 ExtensionInstallUI* client, | 160 ExtensionInstallPrompt* client, |
| 161 const WebstoreInstaller::Approval* approval); | 161 const WebstoreInstaller::Approval* approval); |
| 162 virtual ~CrxInstaller(); | 162 virtual ~CrxInstaller(); |
| 163 | 163 |
| 164 // Converts the source user script to an extension. | 164 // Converts the source user script to an extension. |
| 165 void ConvertUserScriptOnFileThread(); | 165 void ConvertUserScriptOnFileThread(); |
| 166 | 166 |
| 167 // Converts the source web app to an extension. | 167 // Converts the source web app to an extension. |
| 168 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); | 168 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); |
| 169 | 169 |
| 170 // Called after OnUnpackSuccess as a last check to see whether the install | 170 // Called after OnUnpackSuccess as a last check to see whether the install |
| 171 // should complete. | 171 // should complete. |
| 172 bool AllowInstall(const extensions::Extension* extension, string16* error); | 172 bool AllowInstall(const extensions::Extension* extension, string16* error); |
| 173 | 173 |
| 174 // SandboxedExtensionUnpackerClient | 174 // SandboxedExtensionUnpackerClient |
| 175 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; | 175 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; |
| 176 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 176 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 177 const FilePath& extension_dir, | 177 const FilePath& extension_dir, |
| 178 const base::DictionaryValue* original_manifest, | 178 const base::DictionaryValue* original_manifest, |
| 179 const extensions::Extension* extension) OVERRIDE; | 179 const extensions::Extension* extension) OVERRIDE; |
| 180 | 180 |
| 181 // Returns true if we can skip confirmation because the install was | 181 // Returns true if we can skip confirmation because the install was |
| 182 // whitelisted. | 182 // whitelisted. |
| 183 bool CanSkipConfirmation(); | 183 bool CanSkipConfirmation(); |
| 184 | 184 |
| 185 // Runs on the UI thread. Confirms with the user (via ExtensionInstallUI) that | 185 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) |
| 186 // it is OK to install this extension. | 186 // that it is OK to install this extension. |
| 187 void ConfirmInstall(); | 187 void ConfirmInstall(); |
| 188 | 188 |
| 189 // Runs on File thread. Install the unpacked extension into the profile and | 189 // Runs on File thread. Install the unpacked extension into the profile and |
| 190 // notify the frontend. | 190 // notify the frontend. |
| 191 void CompleteInstall(); | 191 void CompleteInstall(); |
| 192 | 192 |
| 193 // Result reporting. | 193 // Result reporting. |
| 194 void ReportFailureFromFileThread(const string16& error); | 194 void ReportFailureFromFileThread(const string16& error); |
| 195 void ReportFailureFromUIThread(const string16& error); | 195 void ReportFailureFromUIThread(const string16& error); |
| 196 void ReportSuccessFromFileThread(); | 196 void ReportSuccessFromFileThread(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // The frontend we will report results back to. | 273 // The frontend we will report results back to. |
| 274 base::WeakPtr<ExtensionService> frontend_weak_; | 274 base::WeakPtr<ExtensionService> frontend_weak_; |
| 275 | 275 |
| 276 // The Profile where the extension is being installed in. | 276 // The Profile where the extension is being installed in. |
| 277 Profile* profile_; | 277 Profile* profile_; |
| 278 | 278 |
| 279 // The client we will work with to do the installation. This can be NULL, in | 279 // The client we will work with to do the installation. This can be NULL, in |
| 280 // which case the install is silent. | 280 // which case the install is silent. |
| 281 // NOTE: we may be deleted on the file thread. To ensure the UI is deleted on | 281 // NOTE: we may be deleted on the file thread. To ensure the UI is deleted on |
| 282 // the main thread we don't use a scoped_ptr here. | 282 // the main thread we don't use a scoped_ptr here. |
| 283 ExtensionInstallUI* client_; | 283 ExtensionInstallPrompt* client_; |
| 284 | 284 |
| 285 // The root of the unpacked extension directory. This is a subdirectory of | 285 // The root of the unpacked extension directory. This is a subdirectory of |
| 286 // temp_dir_, so we don't have to delete it explicitly. | 286 // temp_dir_, so we don't have to delete it explicitly. |
| 287 FilePath unpacked_extension_root_; | 287 FilePath unpacked_extension_root_; |
| 288 | 288 |
| 289 // True when the CRX being installed was just downloaded. | 289 // True when the CRX being installed was just downloaded. |
| 290 // Used to trigger extra checks before installing. | 290 // Used to trigger extra checks before installing. |
| 291 bool apps_require_extension_mime_type_; | 291 bool apps_require_extension_mime_type_; |
| 292 | 292 |
| 293 // Allows for the possibility of a normal install (one in which a |client| | 293 // Allows for the possibility of a normal install (one in which a |client| |
| (...skipping 12 matching lines...) Expand all Loading... |
| 306 extension_misc::CrxInstallCause install_cause_; | 306 extension_misc::CrxInstallCause install_cause_; |
| 307 | 307 |
| 308 // Creation flags to use for the extension. These flags will be used | 308 // Creation flags to use for the extension. These flags will be used |
| 309 // when calling Extenion::Create() by the crx installer. | 309 // when calling Extenion::Create() by the crx installer. |
| 310 int creation_flags_; | 310 int creation_flags_; |
| 311 | 311 |
| 312 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); | 312 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 315 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| OLD | NEW |