| 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/ui/views/infobars/extension_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/extension_infobar.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_context_menu_model.h" | 7 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" | 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 ExtensionInfoBar::ExtensionInfoBar(TabContentsWrapper* owner, | 37 ExtensionInfoBar::ExtensionInfoBar(TabContentsWrapper* owner, |
| 38 ExtensionInfoBarDelegate* delegate) | 38 ExtensionInfoBarDelegate* delegate) |
| 39 : InfoBarView(owner, delegate), | 39 : InfoBarView(owner, delegate), |
| 40 delegate_(delegate), | 40 delegate_(delegate), |
| 41 menu_(NULL), | 41 menu_(NULL), |
| 42 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 42 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
| 43 delegate->set_observer(this); | 43 delegate->set_observer(this); |
| 44 | 44 |
| 45 ExtensionView* extension_view = delegate->extension_host()->view(); | 45 int height = delegate->height(); |
| 46 int height = extension_view->GetPreferredSize().height(); | |
| 47 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); | 46 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); |
| 48 | |
| 49 // Get notified of resize events for the ExtensionView. | |
| 50 extension_view->SetContainer(this); | |
| 51 } | 47 } |
| 52 | 48 |
| 53 ExtensionInfoBar::~ExtensionInfoBar() { | 49 ExtensionInfoBar::~ExtensionInfoBar() { |
| 54 if (GetDelegate()) { | 50 if (GetDelegate()) |
| 55 GetDelegate()->extension_host()->view()->SetContainer(NULL); | |
| 56 GetDelegate()->set_observer(NULL); | 51 GetDelegate()->set_observer(NULL); |
| 57 } | |
| 58 } | 52 } |
| 59 | 53 |
| 60 void ExtensionInfoBar::Layout() { | 54 void ExtensionInfoBar::Layout() { |
| 61 InfoBarView::Layout(); | 55 InfoBarView::Layout(); |
| 62 | 56 |
| 63 gfx::Size menu_size = menu_->GetPreferredSize(); | 57 gfx::Size menu_size = menu_->GetPreferredSize(); |
| 64 menu_->SetBounds(StartX(), OffsetY(menu_size), menu_size.width(), | 58 menu_->SetBounds(StartX(), OffsetY(menu_size), menu_size.width(), |
| 65 menu_size.height()); | 59 menu_size.height()); |
| 66 | 60 |
| 67 GetDelegate()->extension_host()->view()->SetBounds( | 61 GetDelegate()->extension_host()->view()->SetBounds( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); | 96 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); |
| 103 } else { | 97 } else { |
| 104 OnImageLoaded(NULL, icon_resource, 0); | 98 OnImageLoaded(NULL, icon_resource, 0); |
| 105 } | 99 } |
| 106 } | 100 } |
| 107 | 101 |
| 108 int ExtensionInfoBar::ContentMinimumWidth() const { | 102 int ExtensionInfoBar::ContentMinimumWidth() const { |
| 109 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; | 103 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; |
| 110 } | 104 } |
| 111 | 105 |
| 112 void ExtensionInfoBar::OnExtensionMouseMove(ExtensionView* view) { | |
| 113 } | |
| 114 | |
| 115 void ExtensionInfoBar::OnExtensionMouseLeave(ExtensionView* view) { | |
| 116 } | |
| 117 | |
| 118 void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) { | |
| 119 ExtensionInfoBarDelegate* delegate = GetDelegate(); | |
| 120 DCHECK_EQ(delegate->extension_host()->view(), view); | |
| 121 | |
| 122 // When the infobar is closed, it animates to 0 vertical height. We'll | |
| 123 // continue to get size changed notifications from the ExtensionView, but we | |
| 124 // need to ignore them otherwise we'll try to re-animate open (and leak the | |
| 125 // infobar view). | |
| 126 if (delegate->closing()) | |
| 127 return; | |
| 128 | |
| 129 view->SetVisible(true); | |
| 130 | |
| 131 if (height() == 0) | |
| 132 animation()->Reset(0.0); | |
| 133 | |
| 134 // Clamp height to a min and a max size of between 1 and 2 InfoBars. | |
| 135 SetBarTargetHeight(std::min(2 * kDefaultBarTargetHeight, | |
| 136 std::max(kDefaultBarTargetHeight, view->GetPreferredSize().height()))); | |
| 137 | |
| 138 animation()->Show(); | |
| 139 } | |
| 140 | |
| 141 void ExtensionInfoBar::OnImageLoaded(SkBitmap* image, | 106 void ExtensionInfoBar::OnImageLoaded(SkBitmap* image, |
| 142 const ExtensionResource& resource, | 107 const ExtensionResource& resource, |
| 143 int index) { | 108 int index) { |
| 144 if (!GetDelegate()) | 109 if (!GetDelegate()) |
| 145 return; // The delegate can go away while we asynchronously load images. | 110 return; // The delegate can go away while we asynchronously load images. |
| 146 | 111 |
| 147 SkBitmap* icon = image; | 112 SkBitmap* icon = image; |
| 148 // Fall back on the default extension icon on failure. | 113 // Fall back on the default extension icon on failure. |
| 149 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 114 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 150 if (!image || image->empty()) | 115 if (!image || image->empty()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 image_size, image_size, false); | 127 image_size, image_size, false); |
| 163 canvas->DrawBitmapInt(*drop_image, image_size + kDropArrowLeftMargin, | 128 canvas->DrawBitmapInt(*drop_image, image_size + kDropArrowLeftMargin, |
| 164 image_size / 2); | 129 image_size / 2); |
| 165 menu_->SetIcon(canvas->ExtractBitmap()); | 130 menu_->SetIcon(canvas->ExtractBitmap()); |
| 166 menu_->SetVisible(true); | 131 menu_->SetVisible(true); |
| 167 | 132 |
| 168 Layout(); | 133 Layout(); |
| 169 } | 134 } |
| 170 | 135 |
| 171 void ExtensionInfoBar::OnDelegateDeleted() { | 136 void ExtensionInfoBar::OnDelegateDeleted() { |
| 172 GetDelegate()->extension_host()->view()->SetContainer(NULL); | |
| 173 delegate_ = NULL; | 137 delegate_ = NULL; |
| 174 } | 138 } |
| 175 | 139 |
| 176 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { | 140 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { |
| 177 const Extension* extension = GetDelegate()->extension_host()->extension(); | 141 const Extension* extension = GetDelegate()->extension_host()->extension(); |
| 178 if (!extension->ShowConfigureContextMenus()) | 142 if (!extension->ShowConfigureContextMenus()) |
| 179 return; | 143 return; |
| 180 | 144 |
| 181 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( | 145 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( |
| 182 platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))-> | 146 platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))-> |
| 183 browser(); | 147 browser(); |
| 184 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 148 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 185 new ExtensionContextMenuModel(extension, browser, NULL); | 149 new ExtensionContextMenuModel(extension, browser, NULL); |
| 186 views::MenuModelAdapter options_menu_delegate(options_menu_contents.get()); | 150 views::MenuModelAdapter options_menu_delegate(options_menu_contents.get()); |
| 187 views::MenuItemView options_menu(&options_menu_delegate); | 151 views::MenuItemView options_menu(&options_menu_delegate); |
| 188 options_menu_delegate.BuildMenu(&options_menu); | 152 options_menu_delegate.BuildMenu(&options_menu); |
| 189 | 153 |
| 190 gfx::Point screen_point; | 154 gfx::Point screen_point; |
| 191 views::View::ConvertPointToScreen(menu_, &screen_point); | 155 views::View::ConvertPointToScreen(menu_, &screen_point); |
| 192 options_menu.RunMenuAt(GetWidget(), menu_, | 156 options_menu.RunMenuAt(GetWidget(), menu_, |
| 193 gfx::Rect(screen_point, menu_->size()), views::MenuItemView::TOPLEFT, | 157 gfx::Rect(screen_point, menu_->size()), views::MenuItemView::TOPLEFT, |
| 194 true); | 158 true); |
| 195 } | 159 } |
| 196 | 160 |
| 197 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 161 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 198 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 162 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; |
| 199 } | 163 } |
| OLD | NEW |