| 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(); | |
| 21 } | 19 } |
| 22 | 20 |
| 23 // static | 21 // static |
| 24 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service, | 22 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 25 Browser* browser, | 23 Browser* browser, |
| 26 const extensions::Extension* extension, | 24 const extensions::Extension* extension, |
| 27 const GURL& url, | 25 const GURL& url, |
| 28 int height) { | 26 int height) { |
| 29 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 27 infobar_service->AddInfoBar(ExtensionInfoBarDelegate::CreateInfoBar( |
| 30 new ExtensionInfoBarDelegate(browser, infobar_service, extension, url, | 28 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( |
| 31 infobar_service->web_contents(), height))); | 29 browser, extension, url, infobar_service->web_contents(), height)))); |
| 32 } | 30 } |
| 33 | 31 |
| 34 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( | 32 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( |
| 35 Browser* browser, | 33 Browser* browser, |
| 36 InfoBarService* infobar_service, | |
| 37 const extensions::Extension* extension, | 34 const extensions::Extension* extension, |
| 38 const GURL& url, | 35 const GURL& url, |
| 39 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
| 40 int height) | 37 int height) |
| 41 : InfoBarDelegate(infobar_service), | 38 : InfoBarDelegate(), |
| 42 #if defined(TOOLKIT_VIEWS) | 39 #if defined(TOOLKIT_VIEWS) |
| 43 browser_(browser), | 40 browser_(browser), |
| 44 #endif | 41 #endif |
| 45 observer_(NULL), | |
| 46 extension_(extension), | 42 extension_(extension), |
| 47 closing_(false) { | 43 closing_(false) { |
| 48 extension_view_host_.reset( | 44 extension_view_host_.reset( |
| 49 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); | 45 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); |
| 50 extension_view_host_->SetAssociatedWebContents(web_contents); | 46 extension_view_host_->SetAssociatedWebContents(web_contents); |
| 51 | 47 |
| 52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 53 content::Source<Profile>(browser->profile())); | 49 content::Source<Profile>(browser->profile())); |
| 54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 55 content::Source<Profile>(browser->profile())); | 51 content::Source<Profile>(browser->profile())); |
| 56 | 52 |
| 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 | |
| 66 height_ = std::max(0, height); | 53 height_ = std::max(0, height); |
| 67 height_ = std::min(2 * default_height, height_); | 54 height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_); |
| 68 if (height_ == 0) | 55 if (height_ == 0) |
| 69 height_ = default_height; | 56 height_ = InfoBar::kDefaultBarTargetHeight; |
| 70 } | 57 } |
| 71 | 58 |
| 59 // ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific |
| 60 // files. |
| 61 |
| 72 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 62 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 73 ExtensionInfoBarDelegate* extension_delegate = | 63 ExtensionInfoBarDelegate* extension_delegate = |
| 74 delegate->AsExtensionInfoBarDelegate(); | 64 delegate->AsExtensionInfoBarDelegate(); |
| 75 // When an extension crashes, an InfoBar is shown (for the crashed extension). | 65 // When an extension crashes, an InfoBar is shown (for the crashed extension). |
| 76 // That will result in a call to this function (to see if this InfoBarDelegate | 66 // That will result in a call to this function (to see if this InfoBarDelegate |
| 77 // is already showing the 'extension crashed InfoBar', which it never is), but | 67 // is already showing the 'extension crashed InfoBar', which it never is), but |
| 78 // if it is our extension that crashes, the extension delegate is NULL so | 68 // if it is our extension that crashes, the extension delegate is NULL so |
| 79 // we cannot check. | 69 // we cannot check. |
| 80 if (!extension_delegate) | 70 if (!extension_delegate) |
| 81 return false; | 71 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 98 return this; | 88 return this; |
| 99 } | 89 } |
| 100 | 90 |
| 101 void ExtensionInfoBarDelegate::Observe( | 91 void ExtensionInfoBarDelegate::Observe( |
| 102 int type, | 92 int type, |
| 103 const content::NotificationSource& source, | 93 const content::NotificationSource& source, |
| 104 const content::NotificationDetails& details) { | 94 const content::NotificationDetails& details) { |
| 105 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | 95 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { |
| 106 if (extension_view_host_.get() == | 96 if (extension_view_host_.get() == |
| 107 content::Details<extensions::ExtensionHost>(details).ptr()) | 97 content::Details<extensions::ExtensionHost>(details).ptr()) |
| 108 RemoveSelf(); | 98 infobar()->RemoveSelf(); |
| 109 } else { | 99 } else { |
| 110 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); | 100 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); |
| 111 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( | 101 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( |
| 112 details)->extension) | 102 details)->extension) |
| 113 RemoveSelf(); | 103 infobar()->RemoveSelf(); |
| 114 } | 104 } |
| 115 } | 105 } |
| OLD | NEW |