| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void set_page_ordinal(const StringOrdinal& page_ordinal) { | 152 void set_page_ordinal(const StringOrdinal& page_ordinal) { |
| 153 page_ordinal_ = page_ordinal; | 153 page_ordinal_ = page_ordinal; |
| 154 } | 154 } |
| 155 | 155 |
| 156 Profile* profile() { return profile_; } | 156 Profile* profile() { return profile_; } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 friend class extensions::ExtensionUpdaterTest; | 159 friend class extensions::ExtensionUpdaterTest; |
| 160 | 160 |
| 161 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 161 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
| 162 ExtensionInstallUI* client, | 162 ExtensionInstallPrompt* client, |
| 163 const WebstoreInstaller::Approval* approval); | 163 const WebstoreInstaller::Approval* approval); |
| 164 virtual ~CrxInstaller(); | 164 virtual ~CrxInstaller(); |
| 165 | 165 |
| 166 // Converts the source user script to an extension. | 166 // Converts the source user script to an extension. |
| 167 void ConvertUserScriptOnFileThread(); | 167 void ConvertUserScriptOnFileThread(); |
| 168 | 168 |
| 169 // Converts the source web app to an extension. | 169 // Converts the source web app to an extension. |
| 170 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); | 170 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); |
| 171 | 171 |
| 172 // Called after OnUnpackSuccess as a last check to see whether the install | 172 // Called after OnUnpackSuccess as a last check to see whether the install |
| 173 // should complete. | 173 // should complete. |
| 174 bool AllowInstall(const extensions::Extension* extension, string16* error); | 174 bool AllowInstall(const extensions::Extension* extension, string16* error); |
| 175 | 175 |
| 176 // SandboxedExtensionUnpackerClient | 176 // SandboxedExtensionUnpackerClient |
| 177 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; | 177 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; |
| 178 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 178 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 179 const FilePath& extension_dir, | 179 const FilePath& extension_dir, |
| 180 const base::DictionaryValue* original_manifest, | 180 const base::DictionaryValue* original_manifest, |
| 181 const extensions::Extension* extension) OVERRIDE; | 181 const extensions::Extension* extension) OVERRIDE; |
| 182 | 182 |
| 183 // Returns true if we can skip confirmation because the install was | 183 // Returns true if we can skip confirmation because the install was |
| 184 // whitelisted. | 184 // whitelisted. |
| 185 bool CanSkipConfirmation(); | 185 bool CanSkipConfirmation(); |
| 186 | 186 |
| 187 // Runs on the UI thread. Confirms with the user (via ExtensionInstallUI) that | 187 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) |
| 188 // it is OK to install this extension. | 188 // that it is OK to install this extension. |
| 189 void ConfirmInstall(); | 189 void ConfirmInstall(); |
| 190 | 190 |
| 191 // Runs on File thread. Install the unpacked extension into the profile and | 191 // Runs on File thread. Install the unpacked extension into the profile and |
| 192 // notify the frontend. | 192 // notify the frontend. |
| 193 void CompleteInstall(); | 193 void CompleteInstall(); |
| 194 | 194 |
| 195 // Result reporting. | 195 // Result reporting. |
| 196 void ReportFailureFromFileThread(const string16& error); | 196 void ReportFailureFromFileThread(const string16& error); |
| 197 void ReportFailureFromUIThread(const string16& error); | 197 void ReportFailureFromUIThread(const string16& error); |
| 198 void ReportSuccessFromFileThread(); | 198 void ReportSuccessFromFileThread(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // The frontend we will report results back to. | 275 // The frontend we will report results back to. |
| 276 base::WeakPtr<ExtensionService> frontend_weak_; | 276 base::WeakPtr<ExtensionService> frontend_weak_; |
| 277 | 277 |
| 278 // The Profile where the extension is being installed in. | 278 // The Profile where the extension is being installed in. |
| 279 Profile* profile_; | 279 Profile* profile_; |
| 280 | 280 |
| 281 // The client we will work with to do the installation. This can be NULL, in | 281 // The client we will work with to do the installation. This can be NULL, in |
| 282 // which case the install is silent. | 282 // which case the install is silent. |
| 283 // NOTE: we may be deleted on the file thread. To ensure the UI is deleted on | 283 // NOTE: we may be deleted on the file thread. To ensure the UI is deleted on |
| 284 // the main thread we don't use a scoped_ptr here. | 284 // the main thread we don't use a scoped_ptr here. |
| 285 ExtensionInstallUI* client_; | 285 ExtensionInstallPrompt* client_; |
| 286 | 286 |
| 287 // The root of the unpacked extension directory. This is a subdirectory of | 287 // The root of the unpacked extension directory. This is a subdirectory of |
| 288 // temp_dir_, so we don't have to delete it explicitly. | 288 // temp_dir_, so we don't have to delete it explicitly. |
| 289 FilePath unpacked_extension_root_; | 289 FilePath unpacked_extension_root_; |
| 290 | 290 |
| 291 // True when the CRX being installed was just downloaded. | 291 // True when the CRX being installed was just downloaded. |
| 292 // Used to trigger extra checks before installing. | 292 // Used to trigger extra checks before installing. |
| 293 bool apps_require_extension_mime_type_; | 293 bool apps_require_extension_mime_type_; |
| 294 | 294 |
| 295 // Allows for the possibility of a normal install (one in which a |client| | 295 // Allows for the possibility of a normal install (one in which a |client| |
| (...skipping 15 matching lines...) Expand all Loading... |
| 311 // when calling Extenion::Create() by the crx installer. | 311 // when calling Extenion::Create() by the crx installer. |
| 312 int creation_flags_; | 312 int creation_flags_; |
| 313 | 313 |
| 314 // Whether to allow off store installation. | 314 // Whether to allow off store installation. |
| 315 bool allow_off_store_install_; | 315 bool allow_off_store_install_; |
| 316 | 316 |
| 317 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); | 317 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 320 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| OLD | NEW |