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/crx_installer_error.h" | 16 #include "chrome/browser/extensions/crx_installer_error.h" |
17 #include "chrome/browser/extensions/extension_install_prompt.h" | 17 #include "chrome/browser/extensions/extension_install_prompt.h" |
18 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 18 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
19 #include "chrome/browser/extensions/webstore_installer.h" | 19 #include "chrome/browser/extensions/webstore_installer.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/string_ordinal.h" | 21 #include "chrome/common/string_ordinal.h" |
22 #include "chrome/common/web_apps.h" | 22 #include "chrome/common/web_apps.h" |
23 | 23 |
24 class ExtensionService; | 24 class ExtensionService; |
25 class SkBitmap; | 25 class SkBitmap; |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 class ExtensionUpdaterTest; | 28 class ExtensionUpdaterTest; |
29 } | |
30 | 29 |
31 // This class installs a crx file into a profile. | 30 // This class installs a crx file into a profile. |
32 // | 31 // |
33 // 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, |
34 // validating it, prompting the user, and installing. Since many of these | 33 // validating it, prompting the user, and installing. Since many of these |
35 // 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 |
36 // necessary to do its job. (This also minimizes external dependencies for | 35 // necessary to do its job. (This also minimizes external dependencies for |
37 // easier testing). | 36 // easier testing). |
38 // | 37 // |
39 // Lifetime management: | 38 // Lifetime management: |
40 // | 39 // |
41 // This class is ref-counted by each call it makes to itself on another thread, | 40 // This class is ref-counted by each call it makes to itself on another thread, |
42 // and by UtilityProcessHost. | 41 // and by UtilityProcessHost. |
43 // | 42 // |
44 // Additionally, we hold a reference to our own client so that it lives at least | 43 // Additionally, we hold a reference to our own client so that it lives at least |
45 // long enough to receive the result of unpacking. | 44 // long enough to receive the result of unpacking. |
46 // | 45 // |
47 // 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 |
48 // working with it, eg: | 47 // working with it, eg: |
49 // | 48 // |
50 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); | 49 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); |
51 // installer->set_foo(); | 50 // installer->set_foo(); |
52 // installer->set_bar(); | 51 // installer->set_bar(); |
53 // installer->InstallCrx(...); | 52 // installer->InstallCrx(...); |
54 class CrxInstaller | 53 class CrxInstaller |
55 : public extensions::SandboxedUnpackerClient, | 54 : public SandboxedUnpackerClient, |
56 public ExtensionInstallPrompt::Delegate { | 55 public ExtensionInstallPrompt::Delegate { |
57 public: | 56 public: |
58 // Used in histograms; do not change order. | 57 // Used in histograms; do not change order. |
59 enum OffStoreInstallAllowReason { | 58 enum OffStoreInstallAllowReason { |
60 OffStoreInstallDisallowed, | 59 OffStoreInstallDisallowed, |
61 OffStoreInstallAllowedFromSettingsPage, | 60 OffStoreInstallAllowedFromSettingsPage, |
62 OffStoreInstallAllowedBecausePref, | 61 OffStoreInstallAllowedBecausePref, |
63 OffStoreInstallAllowedInTest, | 62 OffStoreInstallAllowedInTest, |
64 NumOffStoreInstallAllowReasons | 63 NumOffStoreInstallAllowReasons |
65 }; | 64 }; |
(...skipping 27 matching lines...) Expand all Loading... |
93 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 92 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
94 | 93 |
95 int creation_flags() const { return creation_flags_; } | 94 int creation_flags() const { return creation_flags_; } |
96 void set_creation_flags(int val) { creation_flags_ = val; } | 95 void set_creation_flags(int val) { creation_flags_ = val; } |
97 | 96 |
98 const GURL& download_url() const { return download_url_; } | 97 const GURL& download_url() const { return download_url_; } |
99 void set_download_url(const GURL& val) { download_url_ = val; } | 98 void set_download_url(const GURL& val) { download_url_ = val; } |
100 | 99 |
101 const FilePath& source_file() const { return source_file_; } | 100 const FilePath& source_file() const { return source_file_; } |
102 | 101 |
103 extensions::Extension::Location install_source() const { | 102 Extension::Location install_source() const { |
104 return install_source_; | 103 return install_source_; |
105 } | 104 } |
106 void set_install_source(extensions::Extension::Location source) { | 105 void set_install_source(Extension::Location source) { |
107 install_source_ = source; | 106 install_source_ = source; |
108 } | 107 } |
109 | 108 |
110 const std::string& expected_id() const { return expected_id_; } | 109 const std::string& expected_id() const { return expected_id_; } |
111 void set_expected_id(const std::string& val) { expected_id_ = val; } | 110 void set_expected_id(const std::string& val) { expected_id_ = val; } |
112 | 111 |
113 void set_expected_version(const Version& val) { | 112 void set_expected_version(const Version& val) { |
114 expected_version_.reset(val.Clone()); | 113 expected_version_.reset(val.Clone()); |
115 } | 114 } |
116 | 115 |
117 bool delete_source() const { return delete_source_; } | 116 bool delete_source() const { return delete_source_; } |
118 void set_delete_source(bool val) { delete_source_ = val; } | 117 void set_delete_source(bool val) { delete_source_ = val; } |
119 | 118 |
120 bool allow_silent_install() const { return allow_silent_install_; } | 119 bool allow_silent_install() const { return allow_silent_install_; } |
121 void set_allow_silent_install(bool val) { allow_silent_install_ = val; } | 120 void set_allow_silent_install(bool val) { allow_silent_install_ = val; } |
122 | 121 |
123 bool is_gallery_install() const { | 122 bool is_gallery_install() const { |
124 return (creation_flags_ & extensions::Extension::FROM_WEBSTORE) > 0; | 123 return (creation_flags_ & Extension::FROM_WEBSTORE) > 0; |
125 } | 124 } |
126 void set_is_gallery_install(bool val) { | 125 void set_is_gallery_install(bool val) { |
127 if (val) | 126 if (val) |
128 creation_flags_ |= extensions::Extension::FROM_WEBSTORE; | 127 creation_flags_ |= Extension::FROM_WEBSTORE; |
129 else | 128 else |
130 creation_flags_ &= ~extensions::Extension::FROM_WEBSTORE; | 129 creation_flags_ &= ~Extension::FROM_WEBSTORE; |
131 } | 130 } |
132 | 131 |
133 // The original download URL should be set when the WebstoreInstaller is | 132 // The original download URL should be set when the WebstoreInstaller is |
134 // tracking the installation. The WebstoreInstaller uses this URL to match | 133 // tracking the installation. The WebstoreInstaller uses this URL to match |
135 // failure notifications to the extension. | 134 // failure notifications to the extension. |
136 const GURL& original_download_url() const { return original_download_url_; } | 135 const GURL& original_download_url() const { return original_download_url_; } |
137 void set_original_download_url(const GURL& url) { | 136 void set_original_download_url(const GURL& url) { |
138 original_download_url_ = url; | 137 original_download_url_ = url; |
139 } | 138 } |
140 | 139 |
(...skipping 24 matching lines...) Expand all Loading... |
165 | 164 |
166 void set_page_ordinal(const StringOrdinal& page_ordinal) { | 165 void set_page_ordinal(const StringOrdinal& page_ordinal) { |
167 page_ordinal_ = page_ordinal; | 166 page_ordinal_ = page_ordinal; |
168 } | 167 } |
169 | 168 |
170 bool did_handle_successfully() const { return did_handle_successfully_; } | 169 bool did_handle_successfully() const { return did_handle_successfully_; } |
171 | 170 |
172 Profile* profile() { return profile_; } | 171 Profile* profile() { return profile_; } |
173 | 172 |
174 private: | 173 private: |
175 friend class extensions::ExtensionUpdaterTest; | 174 friend class ExtensionUpdaterTest; |
176 | 175 |
177 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 176 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
178 ExtensionInstallPrompt* client, | 177 ExtensionInstallPrompt* client, |
179 const WebstoreInstaller::Approval* approval); | 178 const WebstoreInstaller::Approval* approval); |
180 virtual ~CrxInstaller(); | 179 virtual ~CrxInstaller(); |
181 | 180 |
182 // Converts the source user script to an extension. | 181 // Converts the source user script to an extension. |
183 void ConvertUserScriptOnFileThread(); | 182 void ConvertUserScriptOnFileThread(); |
184 | 183 |
185 // Converts the source web app to an extension. | 184 // Converts the source web app to an extension. |
186 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); | 185 void ConvertWebAppOnFileThread(const WebApplicationInfo& web_app); |
187 | 186 |
188 // Called after OnUnpackSuccess as a last check to see whether the install | 187 // Called after OnUnpackSuccess as a last check to see whether the install |
189 // should complete. | 188 // should complete. |
190 CrxInstallerError AllowInstall(const extensions::Extension* extension); | 189 CrxInstallerError AllowInstall(const Extension* extension); |
191 | 190 |
192 // SandboxedUnpackerClient | 191 // SandboxedUnpackerClient |
193 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; | 192 virtual void OnUnpackFailure(const string16& error_message) OVERRIDE; |
194 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 193 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
195 const FilePath& extension_dir, | 194 const FilePath& extension_dir, |
196 const base::DictionaryValue* original_manifest, | 195 const base::DictionaryValue* original_manifest, |
197 const extensions::Extension* extension) OVERRIDE; | 196 const Extension* extension) OVERRIDE; |
198 | 197 |
199 // Returns true if we can skip confirmation because the install was | 198 // Returns true if we can skip confirmation because the install was |
200 // whitelisted. | 199 // whitelisted. |
201 bool CanSkipConfirmation(); | 200 bool CanSkipConfirmation(); |
202 | 201 |
203 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) | 202 // Runs on the UI thread. Confirms with the user (via ExtensionInstallPrompt) |
204 // that it is OK to install this extension. | 203 // that it is OK to install this extension. |
205 void ConfirmInstall(); | 204 void ConfirmInstall(); |
206 | 205 |
207 // Runs on File thread. Install the unpacked extension into the profile and | 206 // Runs on File thread. Install the unpacked extension into the profile and |
208 // notify the frontend. | 207 // notify the frontend. |
209 void CompleteInstall(); | 208 void CompleteInstall(); |
210 | 209 |
211 // Result reporting. | 210 // Result reporting. |
212 void ReportFailureFromFileThread(const CrxInstallerError& error); | 211 void ReportFailureFromFileThread(const CrxInstallerError& error); |
213 void ReportFailureFromUIThread(const CrxInstallerError& error); | 212 void ReportFailureFromUIThread(const CrxInstallerError& error); |
214 void ReportSuccessFromFileThread(); | 213 void ReportSuccessFromFileThread(); |
215 void ReportSuccessFromUIThread(); | 214 void ReportSuccessFromUIThread(); |
216 void NotifyCrxInstallComplete(const extensions::Extension* extension); | 215 void NotifyCrxInstallComplete(const Extension* extension); |
217 | 216 |
218 // The file we're installing. | 217 // The file we're installing. |
219 FilePath source_file_; | 218 FilePath source_file_; |
220 | 219 |
221 // The URL the file was downloaded from. | 220 // The URL the file was downloaded from. |
222 GURL download_url_; | 221 GURL download_url_; |
223 | 222 |
224 // The directory extensions are installed to. | 223 // The directory extensions are installed to. |
225 FilePath install_directory_; | 224 FilePath install_directory_; |
226 | 225 |
227 // The location the installation came from (bundled with Chromium, registry, | 226 // The location the installation came from (bundled with Chromium, registry, |
228 // manual install, etc). This metadata is saved with the installation if | 227 // manual install, etc). This metadata is saved with the installation if |
229 // successful. Defaults to INTERNAL. | 228 // successful. Defaults to INTERNAL. |
230 extensions::Extension::Location install_source_; | 229 Extension::Location install_source_; |
231 | 230 |
232 // Indicates whether the user has already approved the extension to be | 231 // Indicates whether the user has already approved the extension to be |
233 // installed. If true, |expected_manifest_| and |expected_id_| must match | 232 // installed. If true, |expected_manifest_| and |expected_id_| must match |
234 // those of the CRX. | 233 // those of the CRX. |
235 bool approved_; | 234 bool approved_; |
236 | 235 |
237 // For updates, external and webstore installs we have an ID we're expecting | 236 // For updates, external and webstore installs we have an ID we're expecting |
238 // the extension to contain. | 237 // the extension to contain. |
239 std::string expected_id_; | 238 std::string expected_id_; |
240 | 239 |
(...skipping 20 matching lines...) Expand all Loading... |
261 // The download URL, before redirects, if this is a gallery install. | 260 // The download URL, before redirects, if this is a gallery install. |
262 GURL original_download_url_; | 261 GURL original_download_url_; |
263 | 262 |
264 // Whether to create an app shortcut after successful installation. This is | 263 // Whether to create an app shortcut after successful installation. This is |
265 // set based on the user's selection in the UI and can only ever be true for | 264 // set based on the user's selection in the UI and can only ever be true for |
266 // apps. | 265 // apps. |
267 bool create_app_shortcut_; | 266 bool create_app_shortcut_; |
268 | 267 |
269 // The extension we're installing. We own this and either pass it off to | 268 // The extension we're installing. We own this and either pass it off to |
270 // ExtensionService on success, or delete it on failure. | 269 // ExtensionService on success, or delete it on failure. |
271 scoped_refptr<const extensions::Extension> extension_; | 270 scoped_refptr<const Extension> extension_; |
272 | 271 |
273 // The ordinal of the NTP apps page |extension_| will be shown on. | 272 // The ordinal of the NTP apps page |extension_| will be shown on. |
274 StringOrdinal page_ordinal_; | 273 StringOrdinal page_ordinal_; |
275 | 274 |
276 // A parsed copy of the unmodified original manifest, before any | 275 // A parsed copy of the unmodified original manifest, before any |
277 // transformations like localization have taken place. | 276 // transformations like localization have taken place. |
278 scoped_ptr<base::DictionaryValue> original_manifest_; | 277 scoped_ptr<base::DictionaryValue> original_manifest_; |
279 | 278 |
280 // If non-empty, contains the current version of the extension we're | 279 // If non-empty, contains the current version of the extension we're |
281 // installing (for upgrades). | 280 // installing (for upgrades). |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // there was an error; if there was an error that rejects installation we | 335 // there was an error; if there was an error that rejects installation we |
337 // still consider the installation 'handled'. | 336 // still consider the installation 'handled'. |
338 bool did_handle_successfully_; | 337 bool did_handle_successfully_; |
339 | 338 |
340 // Whether we should record an oauth2 grant upon successful install. | 339 // Whether we should record an oauth2 grant upon successful install. |
341 bool record_oauth2_grant_; | 340 bool record_oauth2_grant_; |
342 | 341 |
343 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); | 342 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
344 }; | 343 }; |
345 | 344 |
| 345 } // namespace extensions |
| 346 |
346 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ | 347 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
OLD | NEW |