summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/extension_infobar_gtk.cc
blob: 7140afcdb34ca3a07211c511779d401af0b50922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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_icon_set.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.
  Extension* extension = delegate_->extension_host()->extension();
  ExtensionResource icon_resource = extension->GetIconResource(
      Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY);
  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(Extension::EXTENSION_ICON_BITTY,
                                 Extension::EXTENSION_ICON_BITTY),
                       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);
}