| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_infobar_delegate.h" | 5 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/notification_details.h" | 12 #include "chrome/common/notification_details.h" |
| 13 #include "chrome/common/notification_source.h" | 13 #include "chrome/common/notification_source.h" |
| 14 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
| 15 | 15 |
| 16 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser, | 16 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser, |
| 17 TabContents* tab_contents, | 17 TabContents* tab_contents, |
| 18 const Extension* extension, | 18 const Extension* extension, |
| 19 const GURL& url) | 19 const GURL& url) |
| 20 : InfoBarDelegate(tab_contents), | 20 : InfoBarDelegate(tab_contents), |
| 21 observer_(NULL), | |
| 22 extension_(extension), | 21 extension_(extension), |
| 23 tab_contents_(tab_contents), | 22 tab_contents_(tab_contents) { |
| 24 closing_(false) { | |
| 25 ExtensionProcessManager* manager = | 23 ExtensionProcessManager* manager = |
| 26 browser->profile()->GetExtensionProcessManager(); | 24 browser->profile()->GetExtensionProcessManager(); |
| 27 extension_host_.reset(manager->CreateInfobar(url, browser)); | 25 extension_host_.reset(manager->CreateInfobar(url, browser)); |
| 28 extension_host_->set_associated_tab_contents(tab_contents); | 26 extension_host_->set_associated_tab_contents(tab_contents); |
| 29 | 27 |
| 30 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 28 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 31 Source<Profile>(browser->profile())); | 29 Source<Profile>(browser->profile())); |
| 32 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 30 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 33 Source<Profile>(browser->profile())); | 31 Source<Profile>(browser->profile())); |
| 34 } | 32 } |
| 35 | 33 |
| 36 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { | 34 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { |
| 37 if (observer_) | |
| 38 observer_->OnDelegateDeleted(); | |
| 39 } | 35 } |
| 40 | 36 |
| 41 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 37 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 42 ExtensionInfoBarDelegate* extension_delegate = | 38 ExtensionInfoBarDelegate* extension_delegate = |
| 43 delegate->AsExtensionInfoBarDelegate(); | 39 delegate->AsExtensionInfoBarDelegate(); |
| 44 // When an extension crashes, an InfoBar is shown (for the crashed extension). | 40 // When an extension crashes, an InfoBar is shown (for the crashed extension). |
| 45 // That will result in a call to this function (to see if this InfoBarDelegate | 41 // That will result in a call to this function (to see if this InfoBarDelegate |
| 46 // is already showing the 'extension crashed InfoBar', which it never is), but | 42 // is already showing the 'extension crashed InfoBar', which it never is), but |
| 47 // if it is our extension that crashes, the extension delegate is NULL so | 43 // if it is our extension that crashes, the extension delegate is NULL so |
| 48 // we cannot check. | 44 // we cannot check. |
| 49 if (!extension_delegate) | 45 if (!extension_delegate) |
| 50 return false; | 46 return false; |
| 51 | 47 |
| 52 // Only allow one InfoBar at a time per extension. | 48 // Only allow one InfoBar at a time per extension. |
| 53 return extension_delegate->extension_host()->extension() == | 49 return extension_delegate->extension_host()->extension() == |
| 54 extension_host_->extension(); | 50 extension_host_->extension(); |
| 55 } | 51 } |
| 56 | 52 |
| 57 void ExtensionInfoBarDelegate::InfoBarClosed() { | 53 void ExtensionInfoBarDelegate::InfoBarClosed() { |
| 58 delete this; | 54 delete this; |
| 59 } | 55 } |
| 60 | 56 |
| 61 ExtensionInfoBarDelegate* | 57 ExtensionInfoBarDelegate* |
| 62 ExtensionInfoBarDelegate::AsExtensionInfoBarDelegate() { | 58 ExtensionInfoBarDelegate::AsExtensionInfoBarDelegate() { |
| 63 return this; | 59 return this; |
| 64 } | 60 } |
| 65 | 61 |
| 66 InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() { | 62 InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() { |
| 67 return PAGE_ACTION_TYPE; | 63 return PAGE_ACTION_TYPE; |
| 68 } | 64 } |
| 69 | 65 |
| 70 void ExtensionInfoBarDelegate::Observe(NotificationType type, | 66 void ExtensionInfoBarDelegate::Observe(NotificationType type, |
| 71 const NotificationSource& source, | 67 const NotificationSource& source, |
| 72 const NotificationDetails& details) { | 68 const NotificationDetails& details) { |
| 73 switch (type.value) { | 69 switch (type.value) { |
| 74 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 70 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
| 75 const ExtensionHost* result = Details<ExtensionHost>(details).ptr(); | 71 const ExtensionHost* result = Details<ExtensionHost>(details).ptr(); |
| 76 if (extension_host_.get() == result) | 72 if (extension_host_.get() == result) |
| 77 tab_contents_->RemoveInfoBar(this); | 73 tab_contents_->RemoveInfoBar(this); |
| 78 break; | 74 break; |
| 79 } | 75 } |
| 80 case NotificationType::EXTENSION_UNLOADED: { | 76 case NotificationType::EXTENSION_UNLOADED: { |
| 81 const Extension* extension = Details<const Extension>(details).ptr(); | 77 const Extension* extension = Details<const Extension>(details).ptr(); |
| 82 if (extension_ == extension) | 78 if (extension_ == extension) |
| 83 tab_contents_->RemoveInfoBar(this); | 79 tab_contents_->RemoveInfoBar(this); |
| 84 break; | 80 break; |
| 85 } | 81 } |
| 86 default: { | 82 default: { |
| 87 NOTREACHED() << "Unknown message"; | 83 NOTREACHED() << "Unknown message"; |
| 88 break; | 84 break; |
| 89 } | 85 } |
| 90 } | 86 } |
| 91 } | 87 } |
| OLD | NEW |