OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tab_contents/infobar.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
13 #include "content/common/notification_details.h" | 14 #include "content/common/notification_details.h" |
14 #include "content/common/notification_source.h" | 15 #include "content/common/notification_source.h" |
15 | 16 |
16 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser, | 17 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser, |
17 TabContents* tab_contents, | 18 TabContents* tab_contents, |
18 const Extension* extension, | 19 const Extension* extension, |
19 const GURL& url) | 20 const GURL& url, |
| 21 int height) |
20 : InfoBarDelegate(tab_contents), | 22 : InfoBarDelegate(tab_contents), |
21 observer_(NULL), | 23 observer_(NULL), |
22 extension_(extension), | 24 extension_(extension), |
23 closing_(false) { | 25 closing_(false) { |
24 ExtensionProcessManager* manager = | 26 ExtensionProcessManager* manager = |
25 browser->profile()->GetExtensionProcessManager(); | 27 browser->profile()->GetExtensionProcessManager(); |
26 extension_host_.reset(manager->CreateInfobarHost(url, browser)); | 28 extension_host_.reset(manager->CreateInfobarHost(url, browser)); |
27 extension_host_->set_associated_tab_contents(tab_contents); | 29 extension_host_->set_associated_tab_contents(tab_contents); |
28 | 30 |
29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
30 Source<Profile>(browser->profile())); | 32 Source<Profile>(browser->profile())); |
31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
32 Source<Profile>(browser->profile())); | 34 Source<Profile>(browser->profile())); |
| 35 |
| 36 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) |
| 37 int default_height = InfoBar::kDefaultBarTargetHeight; |
| 38 #elif defined(OS_MACOSX) |
| 39 // TODO(pkasting): Once Infobars have been ported to Mac, we can remove the |
| 40 // ifdefs and just use the Infobar constant below. |
| 41 int default_height = 36; |
| 42 #endif |
| 43 height_ = std::max(0, height); |
| 44 height_ = std::min(2 * default_height, height_); |
| 45 if (height_ == 0) |
| 46 height_ = default_height; |
33 } | 47 } |
34 | 48 |
35 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { | 49 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { |
36 if (observer_) | 50 if (observer_) |
37 observer_->OnDelegateDeleted(); | 51 observer_->OnDelegateDeleted(); |
38 } | 52 } |
39 | 53 |
40 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 54 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
41 ExtensionInfoBarDelegate* extension_delegate = | 55 ExtensionInfoBarDelegate* extension_delegate = |
42 delegate->AsExtensionInfoBarDelegate(); | 56 delegate->AsExtensionInfoBarDelegate(); |
(...skipping 28 matching lines...) Expand all Loading... |
71 const NotificationDetails& details) { | 85 const NotificationDetails& details) { |
72 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | 86 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { |
73 if (extension_host_.get() == Details<ExtensionHost>(details).ptr()) | 87 if (extension_host_.get() == Details<ExtensionHost>(details).ptr()) |
74 RemoveSelf(); | 88 RemoveSelf(); |
75 } else { | 89 } else { |
76 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); | 90 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); |
77 if (extension_ == Details<UnloadedExtensionInfo>(details)->extension) | 91 if (extension_ == Details<UnloadedExtensionInfo>(details)->extension) |
78 RemoveSelf(); | 92 RemoveSelf(); |
79 } | 93 } |
80 } | 94 } |
OLD | NEW |