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 #include "chrome/browser/extensions/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (!BrowserThread::PostTask( | 175 if (!BrowserThread::PostTask( |
176 BrowserThread::FILE, FROM_HERE, | 176 BrowserThread::FILE, FROM_HERE, |
177 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) | 177 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) |
178 NOTREACHED(); | 178 NOTREACHED(); |
179 } | 179 } |
180 | 180 |
181 void CrxInstaller::ConvertUserScriptOnFileThread() { | 181 void CrxInstaller::ConvertUserScriptOnFileThread() { |
182 string16 error; | 182 string16 error; |
183 scoped_refptr<Extension> extension = ConvertUserScriptToExtension( | 183 scoped_refptr<Extension> extension = ConvertUserScriptToExtension( |
184 source_file_, download_url_, install_directory_, &error); | 184 source_file_, download_url_, install_directory_, &error); |
185 if (!extension) { | 185 if (!extension.get()) { |
186 ReportFailureFromFileThread(CrxInstallerError(error)); | 186 ReportFailureFromFileThread(CrxInstallerError(error)); |
187 return; | 187 return; |
188 } | 188 } |
189 | 189 |
190 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); | 190 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension.get()); |
191 } | 191 } |
192 | 192 |
193 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { | 193 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { |
194 if (!BrowserThread::PostTask( | 194 if (!BrowserThread::PostTask( |
195 BrowserThread::FILE, FROM_HERE, | 195 BrowserThread::FILE, FROM_HERE, |
196 base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, | 196 base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, |
197 this, | 197 this, |
198 web_app, | 198 web_app, |
199 install_directory_))) | 199 install_directory_))) |
200 NOTREACHED(); | 200 NOTREACHED(); |
201 } | 201 } |
202 | 202 |
203 void CrxInstaller::ConvertWebAppOnFileThread( | 203 void CrxInstaller::ConvertWebAppOnFileThread( |
204 const WebApplicationInfo& web_app, const FilePath& install_directory) { | 204 const WebApplicationInfo& web_app, const FilePath& install_directory) { |
205 string16 error; | 205 string16 error; |
206 scoped_refptr<Extension> extension( | 206 scoped_refptr<Extension> extension( |
207 ConvertWebAppToExtension(web_app, base::Time::Now(), install_directory)); | 207 ConvertWebAppToExtension(web_app, base::Time::Now(), install_directory)); |
208 if (!extension) { | 208 if (!extension.get()) { |
209 // Validation should have stopped any potential errors before getting here. | 209 // Validation should have stopped any potential errors before getting here. |
210 NOTREACHED() << "Could not convert web app to extension."; | 210 NOTREACHED() << "Could not convert web app to extension."; |
211 return; | 211 return; |
212 } | 212 } |
213 | 213 |
214 // TODO(aa): conversion data gets lost here :( | 214 // TODO(aa): conversion data gets lost here :( |
215 | 215 |
216 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); | 216 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension.get()); |
217 } | 217 } |
218 | 218 |
219 CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { | 219 CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
221 | 221 |
222 // Make sure the expected ID matches if one was supplied or if we want to | 222 // Make sure the expected ID matches if one was supplied or if we want to |
223 // bypass the prompt. | 223 // bypass the prompt. |
224 if ((approved_ || !expected_id_.empty()) && | 224 if ((approved_ || !expected_id_.empty()) && |
225 expected_id_ != extension->id()) { | 225 expected_id_ != extension->id()) { |
226 return CrxInstallerError( | 226 return CrxInstallerError( |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 UserMayLoad(extension_, &error)) { | 438 UserMayLoad(extension_, &error)) { |
439 ReportFailureFromUIThread(CrxInstallerError(error)); | 439 ReportFailureFromUIThread(CrxInstallerError(error)); |
440 return; | 440 return; |
441 } | 441 } |
442 | 442 |
443 GURL overlapping_url; | 443 GURL overlapping_url; |
444 const Extension* overlapping_extension = | 444 const Extension* overlapping_extension = |
445 frontend_weak_->extensions()-> | 445 frontend_weak_->extensions()-> |
446 GetHostedAppByOverlappingWebExtent(extension_->web_extent()); | 446 GetHostedAppByOverlappingWebExtent(extension_->web_extent()); |
447 if (overlapping_extension && | 447 if (overlapping_extension && |
448 overlapping_extension->id() != extension_->id()) { | 448 overlapping_extension_.get()>id() != extension_->id()) { |
449 ReportFailureFromUIThread( | 449 ReportFailureFromUIThread( |
450 CrxInstallerError( | 450 CrxInstallerError( |
451 l10n_util::GetStringFUTF16( | 451 l10n_util::GetStringFUTF16( |
452 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, | 452 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, |
453 UTF8ToUTF16(overlapping_extension->name())))); | 453 UTF8ToUTF16(overlapping_extension->name())))); |
454 return; | 454 return; |
455 } | 455 } |
456 | 456 |
457 current_version_ = | 457 current_version_ = |
458 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); | 458 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); |
(...skipping 27 matching lines...) Expand all Loading... |
486 extension_, histogram_name.c_str()); | 486 extension_, histogram_name.c_str()); |
487 | 487 |
488 // Kill the theme loading bubble. | 488 // Kill the theme loading bubble. |
489 content::NotificationService* service = | 489 content::NotificationService* service = |
490 content::NotificationService::current(); | 490 content::NotificationService::current(); |
491 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, | 491 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, |
492 content::Source<CrxInstaller>(this), | 492 content::Source<CrxInstaller>(this), |
493 content::NotificationService::NoDetails()); | 493 content::NotificationService::NoDetails()); |
494 | 494 |
495 NotifyCrxInstallComplete(NULL); | 495 NotifyCrxInstallComplete(NULL); |
496 | 496 extension_.get() |
497 Release(); // balanced in ConfirmInstall(). | 497 Release(); // balanced in ConfirmInstall(). |
498 | 498 |
499 // We're done. Since we don't post any more tasks to ourself, our ref count | 499 // We're done. Since we don't post any more tasks to ourself, our ref count |
500 // should go to zero and we die. The destructor will clean up the temp dir. | 500 // should go to zero and we die. The destructor will clean up the temp dir. |
501 } | 501 } |
502 | 502 |
503 void CrxInstaller::CompleteInstall() { | 503 void CrxInstaller::CompleteInstall() { |
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
505 | 505 |
506 if (!current_version_.empty()) { | 506 if (!current_version_.empty()) { |
507 Version current_version(current_version_); | 507 Version current_version(current_version_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 if (extension_) { | 553 if (extension_) { |
554 ReportSuccessFromFileThread(); | 554 ReportSuccessFromFileThread(); |
555 } else { | 555 } else { |
556 LOG(ERROR) << error << " " << extension_id << " " << download_url_.spec(); | 556 LOG(ERROR) << error << " " << extension_id << " " << download_url_.spec(); |
557 ReportFailureFromFileThread(CrxInstallerError(UTF8ToUTF16(error))); | 557 ReportFailureFromFileThread(CrxInstallerError(UTF8ToUTF16(error))); |
558 } | 558 } |
559 | 559 |
560 } | 560 } |
561 | 561 |
562 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { | 562 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { |
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 563 DCHEextension_.get()Thread::CurrentlyOn(BrowserThread::FILE)); |
564 if (!BrowserThread::PostTask( | 564 if (!BrowserThread::PostTask( |
565 BrowserThread::UI, FROM_HERE, | 565 BrowserThread::UI, FROM_HERE, |
566 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { | 566 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { |
567 NOTREACHED(); | 567 NOTREACHED(); |
568 } | 568 } |
569 } | 569 } |
570 | 570 |
571 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallerError& error) { | 571 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallerError& error) { |
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
573 | 573 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 frontend_weak_->OnExtensionInstalled(extension_, | 631 frontend_weak_->OnExtensionInstalled(extension_, |
632 page_ordinal_, | 632 page_ordinal_, |
633 has_requirement_errors_); | 633 has_requirement_errors_); |
634 | 634 |
635 NotifyCrxInstallComplete(extension_.get()); | 635 NotifyCrxInstallComplete(extension_.get()); |
636 | 636 |
637 extension_ = NULL; | 637 extension_ = NULL; |
638 | 638 |
639 // We're done. We don't post any more tasks to ourselves so we are deleted | 639 // We're done. We don't post any more tasks to ourselves so we are deleted |
640 // soon. | 640 // soon. |
641 } | 641 }extension_.get() |
642 | 642 |
643 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 643 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
644 // Some users (such as the download shelf) need to know when a | 644 // Some users (such as the download shelf) need to know when a |
645 // CRXInstaller is done. Listening for the EXTENSION_* events | 645 // CRXInstaller is done. Listening for the EXTENSION_* events |
646 // is problematic because they don't know anything about the | 646 // is problematic because they don't extension_.get()ing about the |
647 // extension before it is unpacked, so they cannot filter based | 647 // extension before it is unpacked, so they cannot filter based |
648 // on the extension. | 648 // on the extension. |
649 content::NotificationService::current()->Notify( | 649 content::NotificationService::current()->Notify( |
650 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 650 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
651 content::Source<CrxInstaller>(this), | 651 content::Source<CrxInstaller>(this), |
652 content::Details<const Extension>(extension)); | 652 content::Details<const Extension>(extension)); |
653 } | 653 } |
654 | 654 |
655 } // namespace extensions | 655 } // namespace extensions |
OLD | NEW |