diff options
Diffstat (limited to 'chrome/browser/gtk/extension_infobar_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/extension_infobar_gtk.cc | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/chrome/browser/gtk/extension_infobar_gtk.cc b/chrome/browser/gtk/extension_infobar_gtk.cc new file mode 100644 index 0000000..cdc9561 --- /dev/null +++ b/chrome/browser/gtk/extension_infobar_gtk.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/gtk/extension_infobar_gtk.h" + +#include "app/resource_bundle.h" +#include "chrome/browser/extensions/extension_host.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/render_widget_host_view.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_resource.h" +#include "gfx/gtk_util.h" +#include "grit/theme_resources.h" + +ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate) + : InfoBar(delegate), + tracker_(this), + delegate_(delegate), + view_(NULL) { + delegate_->extension_host()->view()->SetContainer(this); + BuildWidgets(); +} + +ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { + // This view is not owned by us, so unparent. + gtk_widget_unparent(view_->native_view()); +} + +void ExtensionInfoBarGtk::OnImageLoaded( + SkBitmap* image, ExtensionResource resource, int index) { + if (!delegate_) + return; // The delegate can go away while we asynchronously load images. + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + + SkBitmap* icon; + if (!image || image->empty()) + icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); + else + icon = image; + + // TODO(finnur): We now have the icon for the menu button, show the menu + // button and layout. +} + +void ExtensionInfoBarGtk::BuildWidgets() { + // Start loading the image for the menu button. + ExtensionResource icon_resource; + Extension* extension = delegate_->extension_host()->extension(); + Extension::Icons size = + extension->GetIconPathAllowLargerSize(&icon_resource, + Extension::EXTENSION_ICON_BITTY); + if (!icon_resource.relative_path().empty()) { + // Create a tracker to load the image. It will report back on OnImageLoaded. + tracker_.LoadImage(extension, icon_resource, gfx::Size(size, size), + ImageLoadingTracker::DONT_CACHE); + } else { + OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. + } + + ExtensionHost* extension_host = delegate_->extension_host(); + view_ = extension_host->view(); + gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0); + + g_signal_connect(view_->native_view(), "size_allocate", + G_CALLBACK(&OnSizeAllocateThunk), this); + gtk_widget_show_all(border_bin_.get()); +} + +void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) { + gfx::Size new_size(allocation->width, allocation->height); + + delegate_->extension_host()->view()->render_view_host()->view() + ->SetSize(new_size); +} + +void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged( + ExtensionViewGtk* view, + const gfx::Size& new_size) { + // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size + // of the content. +} + +InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { + return new ExtensionInfoBarGtk(this); +} |