| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_disabled_infobar_delegate.h" | 5 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
| 10 #include "chrome/browser/extensions/extension_file_util.h" | 10 #include "chrome/browser/extensions/extension_file_util.h" |
| 11 #include "chrome/browser/extensions/extension_install_ui.h" | 11 #include "chrome/browser/extensions/extension_install_ui.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" | 12 #include "chrome/browser/extensions/extensions_service.h" |
| 13 #include "chrome/browser/tab_contents/infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
| 17 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 | 20 |
| 21 class ExtensionDisabledDialogDelegate | 21 class ExtensionDisabledDialogDelegate |
| 22 : public ExtensionInstallUI::Delegate, | 22 : public ExtensionInstallUI::Delegate, |
| 23 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { | 23 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { |
| 24 public: | 24 public: |
| 25 ExtensionDisabledDialogDelegate(Profile* profile, | 25 ExtensionDisabledDialogDelegate(Profile* profile, |
| 26 ExtensionsService* service, | 26 ExtensionsService* service, |
| 27 Extension* extension) | 27 Extension* extension) |
| 28 : profile_(profile), service_(service), extension_(extension), | 28 : profile_(profile), service_(service), extension_(extension) { |
| 29 ui_loop_(MessageLoop::current()) { | |
| 30 AddRef(); // balanced in ContinueInstall or AbortInstall. | 29 AddRef(); // balanced in ContinueInstall or AbortInstall. |
| 31 | 30 |
| 32 // Do this now because we can't touch extension on the file loop. | 31 // Do this now because we can't touch extension on the file loop. |
| 33 install_icon_resource_ = | 32 install_icon_resource_ = |
| 34 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); | 33 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); |
| 35 | 34 |
| 36 ChromeThread::PostTask( | 35 ChromeThread::PostTask( |
| 37 ChromeThread::FILE, FROM_HERE, | 36 ChromeThread::FILE, FROM_HERE, |
| 38 NewRunnableMethod(this, &ExtensionDisabledDialogDelegate::Start)); | 37 NewRunnableMethod(this, &ExtensionDisabledDialogDelegate::Start)); |
| 39 } | 38 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 // Do nothing. The extension will remain disabled. | 49 // Do nothing. The extension will remain disabled. |
| 51 Release(); | 50 Release(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 void Start() { | 54 void Start() { |
| 56 // We start on the file thread so we can decode the install icon. | 55 // We start on the file thread so we can decode the install icon. |
| 57 FilePath install_icon_path = install_icon_resource_.GetFilePath(); | 56 FilePath install_icon_path = install_icon_resource_.GetFilePath(); |
| 58 CrxInstaller::DecodeInstallIcon(install_icon_path, &install_icon_); | 57 CrxInstaller::DecodeInstallIcon(install_icon_path, &install_icon_); |
| 59 // Then we display the UI on the UI thread. | 58 // Then we display the UI on the UI thread. |
| 60 ui_loop_->PostTask(FROM_HERE, | 59 ChromeThread::PostTask( |
| 61 NewRunnableMethod(this, | 60 ChromeThread::UI, FROM_HERE, |
| 62 &ExtensionDisabledDialogDelegate::ConfirmInstall)); | 61 NewRunnableMethod( |
| 62 this, &ExtensionDisabledDialogDelegate::ConfirmInstall)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ConfirmInstall() { | 65 void ConfirmInstall() { |
| 66 DCHECK(MessageLoop::current() == ui_loop_); | 66 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 67 ExtensionInstallUI ui(profile_); | 67 ExtensionInstallUI ui(profile_); |
| 68 ui.ConfirmInstall(this, extension_, install_icon_.get()); | 68 ui.ConfirmInstall(this, extension_, install_icon_.get()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 Profile* profile_; | 71 Profile* profile_; |
| 72 ExtensionsService* service_; | 72 ExtensionsService* service_; |
| 73 Extension* extension_; | 73 Extension* extension_; |
| 74 ExtensionResource install_icon_resource_; | 74 ExtensionResource install_icon_resource_; |
| 75 scoped_ptr<SkBitmap> install_icon_; | 75 scoped_ptr<SkBitmap> install_icon_; |
| 76 MessageLoop* ui_loop_; | |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 class ExtensionDisabledInfobarDelegate | 78 class ExtensionDisabledInfobarDelegate |
| 80 : public ConfirmInfoBarDelegate, | 79 : public ConfirmInfoBarDelegate, |
| 81 public NotificationObserver { | 80 public NotificationObserver { |
| 82 public: | 81 public: |
| 83 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, | 82 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, |
| 84 ExtensionsService* service, | 83 ExtensionsService* service, |
| 85 Extension* extension) | 84 Extension* extension) |
| 86 : ConfirmInfoBarDelegate(tab_contents), | 85 : ConfirmInfoBarDelegate(tab_contents), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if (!browser) | 146 if (!browser) |
| 148 return; | 147 return; |
| 149 | 148 |
| 150 TabContents* tab_contents = browser->GetSelectedTabContents(); | 149 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 151 if (!tab_contents) | 150 if (!tab_contents) |
| 152 return; | 151 return; |
| 153 | 152 |
| 154 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( | 153 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( |
| 155 tab_contents, service, extension)); | 154 tab_contents, service, extension)); |
| 156 } | 155 } |
| OLD | NEW |