| 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/extension_infobar_delegate.h" | 5 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_view_host.h" | 8 #include "chrome/browser/extensions/extension_view_host.h" |
| 9 #include "chrome/browser/extensions/extension_view_host_factory.h" | 9 #include "chrome/browser/extensions/extension_view_host_factory.h" |
| 10 #include "chrome/browser/infobars/infobar.h" | 10 #include "chrome/browser/infobars/infobar.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 | 17 |
| 18 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { | 18 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { |
| 19 if (observer_) |
| 20 observer_->OnDelegateDeleted(); |
| 19 } | 21 } |
| 20 | 22 |
| 21 // static | 23 // static |
| 22 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service, | 24 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 23 Browser* browser, | 25 Browser* browser, |
| 24 const extensions::Extension* extension, | 26 const extensions::Extension* extension, |
| 25 const GURL& url, | 27 const GURL& url, |
| 26 int height) { | 28 int height) { |
| 27 infobar_service->AddInfoBar(ExtensionInfoBarDelegate::CreateInfoBar( | 29 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 28 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( | 30 new ExtensionInfoBarDelegate(browser, infobar_service, extension, url, |
| 29 browser, extension, url, infobar_service->web_contents(), height)))); | 31 infobar_service->web_contents(), height))); |
| 30 } | 32 } |
| 31 | 33 |
| 32 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( | 34 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( |
| 33 Browser* browser, | 35 Browser* browser, |
| 36 InfoBarService* infobar_service, |
| 34 const extensions::Extension* extension, | 37 const extensions::Extension* extension, |
| 35 const GURL& url, | 38 const GURL& url, |
| 36 content::WebContents* web_contents, | 39 content::WebContents* web_contents, |
| 37 int height) | 40 int height) |
| 38 : InfoBarDelegate(), | 41 : InfoBarDelegate(infobar_service), |
| 39 #if defined(TOOLKIT_VIEWS) | 42 #if defined(TOOLKIT_VIEWS) |
| 40 browser_(browser), | 43 browser_(browser), |
| 41 #endif | 44 #endif |
| 45 observer_(NULL), |
| 42 extension_(extension), | 46 extension_(extension), |
| 43 closing_(false) { | 47 closing_(false) { |
| 44 extension_view_host_.reset( | 48 extension_view_host_.reset( |
| 45 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); | 49 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); |
| 46 extension_view_host_->SetAssociatedWebContents(web_contents); | 50 extension_view_host_->SetAssociatedWebContents(web_contents); |
| 47 | 51 |
| 48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 49 content::Source<Profile>(browser->profile())); | 53 content::Source<Profile>(browser->profile())); |
| 50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 51 content::Source<Profile>(browser->profile())); | 55 content::Source<Profile>(browser->profile())); |
| 52 | 56 |
| 57 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) || defined(OS_ANDROID) |
| 58 // TODO(dtrainor): On Android, this is not used. Might need to pull this from |
| 59 // Android UI level in the future. Tracked via issue 115303. |
| 60 int default_height = InfoBar::kDefaultBarTargetHeight; |
| 61 #elif defined(OS_MACOSX) |
| 62 // TODO(pkasting): Once Infobars have been ported to Mac, we can remove the |
| 63 // ifdefs and just use the Infobar constant below. |
| 64 int default_height = 36; |
| 65 #endif |
| 53 height_ = std::max(0, height); | 66 height_ = std::max(0, height); |
| 54 height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_); | 67 height_ = std::min(2 * default_height, height_); |
| 55 if (height_ == 0) | 68 if (height_ == 0) |
| 56 height_ = InfoBar::kDefaultBarTargetHeight; | 69 height_ = default_height; |
| 57 } | 70 } |
| 58 | 71 |
| 59 // ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific | |
| 60 // files. | |
| 61 | |
| 62 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 72 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 63 ExtensionInfoBarDelegate* extension_delegate = | 73 ExtensionInfoBarDelegate* extension_delegate = |
| 64 delegate->AsExtensionInfoBarDelegate(); | 74 delegate->AsExtensionInfoBarDelegate(); |
| 65 // When an extension crashes, an InfoBar is shown (for the crashed extension). | 75 // When an extension crashes, an InfoBar is shown (for the crashed extension). |
| 66 // That will result in a call to this function (to see if this InfoBarDelegate | 76 // That will result in a call to this function (to see if this InfoBarDelegate |
| 67 // is already showing the 'extension crashed InfoBar', which it never is), but | 77 // is already showing the 'extension crashed InfoBar', which it never is), but |
| 68 // if it is our extension that crashes, the extension delegate is NULL so | 78 // if it is our extension that crashes, the extension delegate is NULL so |
| 69 // we cannot check. | 79 // we cannot check. |
| 70 if (!extension_delegate) | 80 if (!extension_delegate) |
| 71 return false; | 81 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 return this; | 98 return this; |
| 89 } | 99 } |
| 90 | 100 |
| 91 void ExtensionInfoBarDelegate::Observe( | 101 void ExtensionInfoBarDelegate::Observe( |
| 92 int type, | 102 int type, |
| 93 const content::NotificationSource& source, | 103 const content::NotificationSource& source, |
| 94 const content::NotificationDetails& details) { | 104 const content::NotificationDetails& details) { |
| 95 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | 105 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { |
| 96 if (extension_view_host_.get() == | 106 if (extension_view_host_.get() == |
| 97 content::Details<extensions::ExtensionHost>(details).ptr()) | 107 content::Details<extensions::ExtensionHost>(details).ptr()) |
| 98 infobar()->RemoveSelf(); | 108 RemoveSelf(); |
| 99 } else { | 109 } else { |
| 100 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); | 110 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); |
| 101 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( | 111 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( |
| 102 details)->extension) | 112 details)->extension) |
| 103 infobar()->RemoveSelf(); | 113 RemoveSelf(); |
| 104 } | 114 } |
| 105 } | 115 } |
| OLD | NEW |