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