Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_infobar_delegate.cc
index f5ae968..e769519 100644 (file)
@@ -7,12 +7,13 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/extensions/extension_view_host.h"
 #include "chrome/browser/extensions/extension_view_host_factory.h"
-#include "chrome/browser/infobars/infobar.h"
 #include "chrome/browser/infobars/infobar_service.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/ui/browser.h"
+#include "components/infobars/core/infobar.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/notification_source.h"
+#include "extensions/browser/extension_registry.h"
 #include "extensions/common/extension.h"
 
 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
@@ -36,31 +37,37 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
     const GURL& url,
     content::WebContents* web_contents,
     int height)
-    : InfoBarDelegate(),
+    : infobars::InfoBarDelegate(),
 #if defined(TOOLKIT_VIEWS)
       browser_(browser),
 #endif
       extension_(extension),
+      extension_registry_observer_(this),
       closing_(false) {
   extension_view_host_.reset(
       extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser));
   extension_view_host_->SetAssociatedWebContents(web_contents);
 
+  extension_registry_observer_.Add(
+      extensions::ExtensionRegistry::Get(browser->profile()));
   registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
                  content::Source<Profile>(browser->profile()));
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
-                 content::Source<Profile>(browser->profile()));
 
   height_ = std::max(0, height);
-  height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_);
+  height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_);
   if (height_ == 0)
-    height_ = InfoBar::kDefaultBarTargetHeight;
+    height_ = infobars::InfoBar::kDefaultBarTargetHeight;
+}
+
+content::WebContents* ExtensionInfoBarDelegate::GetWebContents() {
+  return InfoBarService::WebContentsFromInfoBar(infobar());
 }
 
 // ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific
 // files.
 
-bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
+bool ExtensionInfoBarDelegate::EqualsDelegate(
+    infobars::InfoBarDelegate* delegate) const {
   ExtensionInfoBarDelegate* extension_delegate =
       delegate->AsExtensionInfoBarDelegate();
   // When an extension crashes, an InfoBar is shown (for the crashed extension).
@@ -80,7 +87,8 @@ void ExtensionInfoBarDelegate::InfoBarDismissed() {
   closing_ = true;
 }
 
-InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() const {
+infobars::InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType()
+    const {
   return PAGE_ACTION_TYPE;
 }
 
@@ -89,18 +97,20 @@ ExtensionInfoBarDelegate*
   return this;
 }
 
+void ExtensionInfoBarDelegate::OnExtensionUnloaded(
+    content::BrowserContext* browser_context,
+    const extensions::Extension* extension,
+    extensions::UnloadedExtensionInfo::Reason reason) {
+  if (extension_ == extension)
+    infobar()->RemoveSelf();
+}
+
 void ExtensionInfoBarDelegate::Observe(
     int type,
     const content::NotificationSource& source,
     const content::NotificationDetails& details) {
-  if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) {
-    if (extension_view_host_.get() ==
-        content::Details<extensions::ExtensionHost>(details).ptr())
-      infobar()->RemoveSelf();
-  } else {
-    DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
-    if (extension_ == content::Details<extensions::UnloadedExtensionInfo>(
-        details)->extension)
-      infobar()->RemoveSelf();
-  }
+  DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE);
+  if (extension_view_host_.get() ==
+      content::Details<extensions::ExtensionHost>(details).ptr())
+    infobar()->RemoveSelf();
 }