| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/extension_infobar_gtk.h" | |
| 6 | |
| 7 #include "app/resource_bundle.h" | |
| 8 #include "chrome/browser/extensions/extension_host.h" | |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 10 #include "chrome/browser/renderer_host/render_widget_host_view.h" | |
| 11 #include "chrome/common/extensions/extension.h" | |
| 12 #include "chrome/common/extensions/extension_icon_set.h" | |
| 13 #include "chrome/common/extensions/extension_resource.h" | |
| 14 #include "gfx/gtk_util.h" | |
| 15 #include "grit/theme_resources.h" | |
| 16 | |
| 17 ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate) | |
| 18 : InfoBar(delegate), | |
| 19 tracker_(this), | |
| 20 delegate_(delegate), | |
| 21 view_(NULL) { | |
| 22 delegate_->extension_host()->view()->SetContainer(this); | |
| 23 BuildWidgets(); | |
| 24 } | |
| 25 | |
| 26 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { | |
| 27 // This view is not owned by us, so unparent. | |
| 28 gtk_widget_unparent(view_->native_view()); | |
| 29 } | |
| 30 | |
| 31 void ExtensionInfoBarGtk::OnImageLoaded( | |
| 32 SkBitmap* image, ExtensionResource resource, int index) { | |
| 33 if (!delegate_) | |
| 34 return; // The delegate can go away while we asynchronously load images. | |
| 35 | |
| 36 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 37 | |
| 38 SkBitmap* icon; | |
| 39 if (!image || image->empty()) | |
| 40 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | |
| 41 else | |
| 42 icon = image; | |
| 43 | |
| 44 // TODO(finnur): We now have the icon for the menu button, show the menu | |
| 45 // button and layout. | |
| 46 } | |
| 47 | |
| 48 void ExtensionInfoBarGtk::BuildWidgets() { | |
| 49 // Start loading the image for the menu button. | |
| 50 const Extension* extension = delegate_->extension_host()->extension(); | |
| 51 ExtensionResource icon_resource = extension->GetIconResource( | |
| 52 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); | |
| 53 if (!icon_resource.relative_path().empty()) { | |
| 54 // Create a tracker to load the image. It will report back on OnImageLoaded. | |
| 55 tracker_.LoadImage(extension, icon_resource, | |
| 56 gfx::Size(Extension::EXTENSION_ICON_BITTY, | |
| 57 Extension::EXTENSION_ICON_BITTY), | |
| 58 ImageLoadingTracker::DONT_CACHE); | |
| 59 } else { | |
| 60 OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. | |
| 61 } | |
| 62 | |
| 63 ExtensionHost* extension_host = delegate_->extension_host(); | |
| 64 view_ = extension_host->view(); | |
| 65 if (gtk_widget_get_parent(view_->native_view())) { | |
| 66 gtk_widget_reparent(view_->native_view(), hbox_); | |
| 67 gtk_box_set_child_packing(GTK_BOX(hbox_), view_->native_view(), | |
| 68 TRUE, TRUE, 0, GTK_PACK_START); | |
| 69 } else { | |
| 70 gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0); | |
| 71 } | |
| 72 | |
| 73 g_signal_connect(view_->native_view(), "size_allocate", | |
| 74 G_CALLBACK(&OnSizeAllocateThunk), this); | |
| 75 } | |
| 76 | |
| 77 void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget, | |
| 78 GtkAllocation* allocation) { | |
| 79 gfx::Size new_size(allocation->width, allocation->height); | |
| 80 | |
| 81 delegate_->extension_host()->view()->render_view_host()->view() | |
| 82 ->SetSize(new_size); | |
| 83 } | |
| 84 | |
| 85 void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged( | |
| 86 ExtensionViewGtk* view, | |
| 87 const gfx::Size& new_size) { | |
| 88 // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size | |
| 89 // of the content. | |
| 90 } | |
| 91 | |
| 92 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { | |
| 93 return new ExtensionInfoBarGtk(this); | |
| 94 } | |
| OLD | NEW |