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 } | |
29 | 28 |
30 // This class installs a crx file into a profile. | 29 // This class installs a crx file into a profile. |
31 // | 30 // |
32 // Installing a CRX is a multi-step process, including unpacking the crx, | 31 // Installing a CRX is a multi-step process, including unpacking the crx, |
33 // validating it, prompting the user, and installing. Since many of these | 32 // validating it, prompting the user, and installing. Since many of these |
34 // steps must occur on the file thread, this class contains a copy of all data | 33 // steps must occur on the file thread, this class contains a copy of all data |
35 // necessary to do its job. (This also minimizes external dependencies for | 34 // necessary to do its job. (This also minimizes external dependencies for |
36 // easier testing). | 35 // easier testing). |
37 // | 36 // |
38 // Lifetime management: | 37 // Lifetime management: |
39 // | 38 // |
40 // This class is ref-counted by each call it makes to itself on another thread, | 39 // This class is ref-counted by each call it makes to itself on another thread, |
41 // and by UtilityProcessHost. | 40 // and by UtilityProcessHost. |
42 // | 41 // |
43 // Additionally, we hold a reference to our own client so that it lives at least | 42 // Additionally, we hold a reference to our own client so that it lives at least |
44 // long enough to receive the result of unpacking. | 43 // long enough to receive the result of unpacking. |
45 // | 44 // |
46 // IMPORTANT: Callers should keep a reference to a CrxInstaller while they are | 45 // IMPORTANT: Callers should keep a reference to a CrxInstaller while they are |
47 // working with it, eg: | 46 // working with it, eg: |
48 // | 47 // |
49 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); | 48 // scoped_refptr<CrxInstaller> installer(new CrxInstaller(...)); |
50 // installer->set_foo(); | 49 // installer->set_foo(); |
51 // installer->set_bar(); | 50 // installer->set_bar(); |
52 // installer->InstallCrx(...); | 51 // installer->InstallCrx(...); |
53 class CrxInstaller | 52 class CrxInstaller |
54 : public extensions::SandboxedUnpackerClient, | 53 : public SandboxedUnpackerClient, |
55 public ExtensionInstallPrompt::Delegate { | 54 public ExtensionInstallPrompt::Delegate { |
56 public: | 55 public: |
57 // Used in histograms; do not change order. | 56 // Used in histograms; do not change order. |
58 enum OffStoreInstallAllowReason { | 57 enum OffStoreInstallAllowReason { |
59 OffStoreInstallDisallowed, | 58 OffStoreInstallDisallowed, |
60 OffStoreInstallAllowedFromSettingsPage, | 59 OffStoreInstallAllowedFromSettingsPage, |
61 OffStoreInstallAllowedBecausePref, | 60 OffStoreInstallAllowedBecausePref, |
62 OffStoreInstallAllowedInTest, | 61 OffStoreInstallAllowedInTest, |
63 NumOffStoreInstallAllowReasons | 62 NumOffStoreInstallAllowReasons |
64 }; | 63 }; |
65 | 64 |
66 // Extensions will be installed into frontend->install_directory(), | 65 // Extensions will be installed into frontend->install_directory(), |
67 // then registered with |frontend|. Any install UI will be displayed | 66 // then registered with |frontend|. Any install UI will be displayed |
68 // using |client|. Pass NULL for |client| for silent install | 67 // using |client|. Pass NULL for |client| for silent install |
69 static scoped_refptr<CrxInstaller> Create( | 68 static scoped_refptr<CrxInstaller> Create( |
70 ExtensionService* frontend, | 69 ExtensionService* frontend, |
71 ExtensionInstallPrompt* client); | 70 ExtensionInstallPrompt* client); |
72 | 71 |
73 // Same as the previous method, except use the |approval| to bypass the | 72 // Same as the previous method, except use the |approval| to bypass the |
74 // prompt. Note that the caller retains ownership of |approval|. | 73 // prompt. Note that the caller retains ownership of |approval|. |
75 static scoped_refptr<CrxInstaller> Create( | 74 static scoped_refptr<CrxInstaller> Create( |
76 ExtensionService* frontend, | 75 ExtensionService* frontend, |
77 ExtensionInstallPrompt* client, | 76 ExtensionInstallPrompt* client, |
78 const extensions::WebstoreInstaller::Approval* approval); | 77 const WebstoreInstaller::Approval* approval); |
79 | 78 |
80 // Install the crx in |source_file|. | 79 // Install the crx in |source_file|. |
81 void InstallCrx(const FilePath& source_file); | 80 void InstallCrx(const FilePath& source_file); |
82 | 81 |
83 // Convert the specified user script into an extension and install it. | 82 // Convert the specified user script into an extension and install it. |
84 void InstallUserScript(const FilePath& source_file, | 83 void InstallUserScript(const FilePath& source_file, |
85 const GURL& download_url); | 84 const GURL& download_url); |
86 | 85 |
87 // Convert the specified web app into an extension and install it. | 86 // Convert the specified web app into an extension and install it. |
88 void InstallWebApp(const WebApplicationInfo& web_app); | 87 void InstallWebApp(const WebApplicationInfo& web_app); |
89 | 88 |
90 // Overridden from ExtensionInstallPrompt::Delegate: | 89 // Overridden from ExtensionInstallPrompt::Delegate: |
91 virtual void InstallUIProceed() OVERRIDE; | 90 virtual void InstallUIProceed() OVERRIDE; |
92 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 91 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
93 | 92 |
94 int creation_flags() const { return creation_flags_; } | 93 int creation_flags() const { return creation_flags_; } |
95 void set_creation_flags(int val) { creation_flags_ = val; } | 94 void set_creation_flags(int val) { creation_flags_ = val; } |
96 | 95 |
97 const GURL& download_url() const { return download_url_; } | 96 const GURL& download_url() const { return download_url_; } |
98 void set_download_url(const GURL& val) { download_url_ = val; } | 97 void set_download_url(const GURL& val) { download_url_ = val; } |
99 | 98 |
100 const FilePath& source_file() const { return source_file_; } | 99 const FilePath& source_file() const { return source_file_; } |
101 | 100 |
102 extensions::Extension::Location install_source() const { | 101 Extension::Location install_source() const { |
103 return install_source_; | 102 return install_source_; |
104 } | 103 } |
105 void set_install_source(extensions::Extension::Location source) { | 104 void set_install_source(Extension::Location source) { |
106 install_source_ = source; | 105 install_source_ = source; |
107 } | 106 } |
108 | 107 |
109 const std::string& expected_id() const { return expected_id_; } | 108 const std::string& expected_id() const { return expected_id_; } |
110 void set_expected_id(const std::string& val) { expected_id_ = val; } | 109 void set_expected_id(const std::string& val) { expected_id_ = val; } |
111 | 110 |
112 void set_expected_version(const Version& val) { | 111 void set_expected_version(const Version& val) { |
113 expected_version_.reset(new Version(val)); | 112 expected_version_.reset(new Version(val)); |
114 } | 113 } |
115 | 114 |
116 bool delete_source() const { return delete_source_; } | 115 bool delete_source() const { return delete_source_; } |
117 void set_delete_source(bool val) { delete_source_ = val; } | 116 void set_delete_source(bool val) { delete_source_ = val; } |
118 | 117 |
119 bool allow_silent_install() const { return allow_silent_install_; } | 118 bool allow_silent_install() const { return allow_silent_install_; } |
120 void set_allow_silent_install(bool val) { allow_silent_install_ = val; } | 119 void set_allow_silent_install(bool val) { allow_silent_install_ = val; } |
121 | 120 |
122 bool is_gallery_install() const { | 121 bool is_gallery_install() const { |
123 return (creation_flags_ & extensions::Extension::FROM_WEBSTORE) > 0; | 122 return (creation_flags_ & Extension::FROM_WEBSTORE) > 0; |
124 } | 123 } |
125 void set_is_gallery_install(bool val) { | 124 void set_is_gallery_install(bool val) { |
126 if (val) | 125 if (val) |
127 creation_flags_ |= extensions::Extension::FROM_WEBSTORE; | 126 creation_flags_ |= Extension::FROM_WEBSTORE; |
128 else | 127 else |
129 creation_flags_ &= ~extensions::Extension::FROM_WEBSTORE; | 128 creation_flags_ &= ~Extension::FROM_WEBSTORE; |
130 } | 129 } |
131 | 130 |
132 // The original download URL should be set when the WebstoreInstaller is | 131 // The original download URL should be set when the WebstoreInstaller is |
133 // tracking the installation. The WebstoreInstaller uses this URL to match | 132 // tracking the installation. The WebstoreInstaller uses this URL to match |
134 // failure notifications to the extension. | 133 // failure notifications to the extension. |
135 const GURL& original_download_url() const { return original_download_url_; } | 134 const GURL& original_download_url() const { return original_download_url_; } |
136 void set_original_download_url(const GURL& url) { | 135 void set_original_download_url(const GURL& url) { |
137 original_download_url_ = url; | 136 original_download_url_ = url; |
138 } | 137 } |
139 | 138 |
(...skipping 24 matching lines...) Expand all Loading... |
164 | 163 |
165 void set_page_ordinal(const StringOrdinal& page_ordinal) { | 164 void set_page_ordinal(const StringOrdinal& page_ordinal) { |
166 page_ordinal_ = page_ordinal; | 165 page_ordinal_ = page_ordinal; |
167 } | 166 } |
168 | 167 |
169 bool did_handle_successfully() const { return did_handle_successfully_; } | 168 bool did_handle_successfully() const { return did_handle_successfully_; } |
170 | 169 |
171 Profile* profile() { return profile_; } | 170 Profile* profile() { return profile_; } |
172 | 171 |
173 private: | 172 private: |
174 friend class extensions::ExtensionUpdaterTest; | 173 friend class ExtensionUpdaterTest; |
175 friend class ExtensionCrxInstallerTest; | 174 friend class ExtensionCrxInstallerTest; |
176 | 175 |
177 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 176 CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
178 ExtensionInstallPrompt* client, | 177 ExtensionInstallPrompt* client, |
179 const extensions::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 |