Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/gtk/extension_infobar_gtk.cc

Issue 4767001: Make TabContents own its infobar delegates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/gtk/extension_infobar_gtk.h" 5 #include "chrome/browser/gtk/extension_infobar_gtk.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/renderer_host/render_view_host.h" 9 #include "chrome/browser/renderer_host/render_view_host.h"
10 #include "chrome/browser/renderer_host/render_widget_host_view.h" 10 #include "chrome/browser/renderer_host/render_widget_host_view.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_icon_set.h" 12 #include "chrome/common/extensions/extension_icon_set.h"
13 #include "chrome/common/extensions/extension_resource.h" 13 #include "chrome/common/extensions/extension_resource.h"
14 #include "gfx/gtk_util.h" 14 #include "gfx/gtk_util.h"
15 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 16
17 ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate) 17 ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate)
18 : InfoBar(delegate), 18 : InfoBar(delegate),
19 tracker_(this), 19 tracker_(this),
20 delegate_(delegate),
21 view_(NULL) { 20 view_(NULL) {
22 delegate_->extension_host()->view()->SetContainer(this); 21 delegate->extension_host()->view()->SetContainer(this);
23 BuildWidgets(); 22 BuildWidgets();
24 } 23 }
25 24
26 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { 25 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() {
27 // This view is not owned by us, so unparent.
28 gtk_widget_unparent(view_->native_view());
29 } 26 }
30 27
31 void ExtensionInfoBarGtk::OnImageLoaded( 28 void ExtensionInfoBarGtk::OnImageLoaded(SkBitmap* image,
32 SkBitmap* image, ExtensionResource resource, int index) { 29 ExtensionResource resource,
33 if (!delegate_) 30 int index) {
34 return; // The delegate can go away while we asynchronously load images.
35
36 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 31 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
37 32
38 SkBitmap* icon; 33 SkBitmap* icon;
39 if (!image || image->empty()) 34 if (!image || image->empty())
40 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); 35 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
41 else 36 else
42 icon = image; 37 icon = image;
43 38
44 // TODO(finnur): We now have the icon for the menu button, show the menu 39 // TODO(finnur): We now have the icon for the menu button, show the menu
45 // button and layout. 40 // button and layout.
46 } 41 }
47 42
48 void ExtensionInfoBarGtk::BuildWidgets() { 43 void ExtensionInfoBarGtk::BuildWidgets() {
49 // Start loading the image for the menu button. 44 // Start loading the image for the menu button.
50 const Extension* extension = delegate_->extension_host()->extension(); 45 ExtensionHost* extension_host = GetDelegate()->extension_host();
46 const Extension* extension = extension_host->extension();
51 ExtensionResource icon_resource = extension->GetIconResource( 47 ExtensionResource icon_resource = extension->GetIconResource(
52 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); 48 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY);
53 if (!icon_resource.relative_path().empty()) { 49 if (!icon_resource.relative_path().empty()) {
54 // Create a tracker to load the image. It will report back on OnImageLoaded. 50 // Create a tracker to load the image. It will report back on OnImageLoaded.
55 tracker_.LoadImage(extension, icon_resource, 51 tracker_.LoadImage(extension, icon_resource,
56 gfx::Size(Extension::EXTENSION_ICON_BITTY, 52 gfx::Size(Extension::EXTENSION_ICON_BITTY,
57 Extension::EXTENSION_ICON_BITTY), 53 Extension::EXTENSION_ICON_BITTY),
58 ImageLoadingTracker::DONT_CACHE); 54 ImageLoadingTracker::DONT_CACHE);
59 } else { 55 } else {
60 OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. 56 OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|.
61 } 57 }
62 58
63 ExtensionHost* extension_host = delegate_->extension_host();
64 view_ = extension_host->view(); 59 view_ = extension_host->view();
65 gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0); 60 gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0);
66 61
67 g_signal_connect(view_->native_view(), "size_allocate", 62 g_signal_connect(view_->native_view(), "size_allocate",
68 G_CALLBACK(&OnSizeAllocateThunk), this); 63 G_CALLBACK(&OnSizeAllocateThunk), this);
69 } 64 }
70 65
71 void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget, 66 void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget,
72 GtkAllocation* allocation) { 67 GtkAllocation* allocation) {
73 gfx::Size new_size(allocation->width, allocation->height); 68 if (delegate()) {
74 69 GetDelegate()->extension_host()->view()->render_view_host()->view()->
75 delegate_->extension_host()->view()->render_view_host()->view() 70 SetSize(gfx::Size(allocation->width, allocation->height));
76 ->SetSize(new_size); 71 }
77 } 72 }
78 73
79 void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged( 74 void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged(
80 ExtensionViewGtk* view, 75 ExtensionViewGtk* view,
81 const gfx::Size& new_size) { 76 const gfx::Size& new_size) {
82 // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size 77 // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size
83 // of the content. 78 // of the content.
84 } 79 }
85 80
86 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { 81 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
87 return new ExtensionInfoBarGtk(this); 82 return new ExtensionInfoBarGtk(this);
88 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698