| 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_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.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/browser/extension_registry.h" |
| 16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 17 | 18 |
| 18 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { | 19 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { |
| 19 } | 20 } |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 void ExtensionInfoBarDelegate::Create(content::WebContents* web_contents, | 23 void ExtensionInfoBarDelegate::Create(content::WebContents* web_contents, |
| 23 Browser* browser, | 24 Browser* browser, |
| 24 const extensions::Extension* extension, | 25 const extensions::Extension* extension, |
| 25 const GURL& url, | 26 const GURL& url, |
| 26 int height) { | 27 int height) { |
| 27 InfoBarService::FromWebContents(web_contents)->AddInfoBar( | 28 InfoBarService::FromWebContents(web_contents)->AddInfoBar( |
| 28 ExtensionInfoBarDelegate::CreateInfoBar( | 29 ExtensionInfoBarDelegate::CreateInfoBar( |
| 29 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( | 30 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( |
| 30 browser, extension, url, web_contents, height)))); | 31 browser, extension, url, web_contents, height)))); |
| 31 } | 32 } |
| 32 | 33 |
| 33 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( | 34 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( |
| 34 Browser* browser, | 35 Browser* browser, |
| 35 const extensions::Extension* extension, | 36 const extensions::Extension* extension, |
| 36 const GURL& url, | 37 const GURL& url, |
| 37 content::WebContents* web_contents, | 38 content::WebContents* web_contents, |
| 38 int height) | 39 int height) |
| 39 : infobars::InfoBarDelegate(), | 40 : infobars::InfoBarDelegate(), |
| 40 #if defined(TOOLKIT_VIEWS) | 41 #if defined(TOOLKIT_VIEWS) |
| 41 browser_(browser), | 42 browser_(browser), |
| 42 #endif | 43 #endif |
| 43 extension_(extension), | 44 extension_(extension), |
| 45 extension_registry_observer_(this), |
| 44 closing_(false) { | 46 closing_(false) { |
| 45 extension_view_host_.reset( | 47 extension_view_host_.reset( |
| 46 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); | 48 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); |
| 47 extension_view_host_->SetAssociatedWebContents(web_contents); | 49 extension_view_host_->SetAssociatedWebContents(web_contents); |
| 48 | 50 |
| 51 extension_registry_observer_.Add( |
| 52 extensions::ExtensionRegistry::Get(browser->profile())); |
| 49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 53 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 50 content::Source<Profile>(browser->profile())); | 54 content::Source<Profile>(browser->profile())); |
| 51 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 52 content::Source<Profile>(browser->profile())); | |
| 53 | 55 |
| 54 height_ = std::max(0, height); | 56 height_ = std::max(0, height); |
| 55 height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_); | 57 height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_); |
| 56 if (height_ == 0) | 58 if (height_ == 0) |
| 57 height_ = infobars::InfoBar::kDefaultBarTargetHeight; | 59 height_ = infobars::InfoBar::kDefaultBarTargetHeight; |
| 58 } | 60 } |
| 59 | 61 |
| 60 content::WebContents* ExtensionInfoBarDelegate::GetWebContents() { | 62 content::WebContents* ExtensionInfoBarDelegate::GetWebContents() { |
| 61 return InfoBarService::WebContentsFromInfoBar(infobar()); | 63 return InfoBarService::WebContentsFromInfoBar(infobar()); |
| 62 } | 64 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 infobars::InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() | 90 infobars::InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() |
| 89 const { | 91 const { |
| 90 return PAGE_ACTION_TYPE; | 92 return PAGE_ACTION_TYPE; |
| 91 } | 93 } |
| 92 | 94 |
| 93 ExtensionInfoBarDelegate* | 95 ExtensionInfoBarDelegate* |
| 94 ExtensionInfoBarDelegate::AsExtensionInfoBarDelegate() { | 96 ExtensionInfoBarDelegate::AsExtensionInfoBarDelegate() { |
| 95 return this; | 97 return this; |
| 96 } | 98 } |
| 97 | 99 |
| 100 void ExtensionInfoBarDelegate::OnExtensionUnloaded( |
| 101 content::BrowserContext* browser_context, |
| 102 const extensions::Extension* extension, |
| 103 extensions::UnloadedExtensionInfo::Reason reason) { |
| 104 if (extension_ == extension) |
| 105 infobar()->RemoveSelf(); |
| 106 } |
| 107 |
| 98 void ExtensionInfoBarDelegate::Observe( | 108 void ExtensionInfoBarDelegate::Observe( |
| 99 int type, | 109 int type, |
| 100 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
| 101 const content::NotificationDetails& details) { | 111 const content::NotificationDetails& details) { |
| 102 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | 112 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE); |
| 103 if (extension_view_host_.get() == | 113 if (extension_view_host_.get() == |
| 104 content::Details<extensions::ExtensionHost>(details).ptr()) | 114 content::Details<extensions::ExtensionHost>(details).ptr()) |
| 105 infobar()->RemoveSelf(); | 115 infobar()->RemoveSelf(); |
| 106 } else { | |
| 107 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED); | |
| 108 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( | |
| 109 details)->extension) | |
| 110 infobar()->RemoveSelf(); | |
| 111 } | |
| 112 } | 116 } |
| OLD | NEW |