summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 21:19:40 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 21:19:40 +0000
commit5d028b7b577d2efb96cd958ba4a7f1e5800fd9bb (patch)
tree044c1b66a3820e9a259a65782a6eeabe06559721 /chrome
parente2a011098d8eb2c682ee6673e543a5060f9bf6ff (diff)
downloadchromium_src-5d028b7b577d2efb96cd958ba4a7f1e5800fd9bb.zip
chromium_src-5d028b7b577d2efb96cd958ba4a7f1e5800fd9bb.tar.gz
chromium_src-5d028b7b577d2efb96cd958ba4a7f1e5800fd9bb.tar.bz2
Infobars on GTK (first part).
I got it to a point where we show HTML content from the extension within an infobar, but there are a few things missing. Missing pieces: - Infobar does not size based on the height of its content (between 36px and 72px). - Infobar content always has a fixed width, but needs to fill out into the available infobar area. - I've put in code to asynchronously fetch the image for the Infobar, but it needs to be shown and hooked up to the ExtensionAction context menu (same context menu we use for the browser action container icons). - The background for HTML content should have a gradient, but is just solid blue at the moment. BUG=39916 TEST=Infobars should show up on GTK. Review URL: http://codereview.chromium.org/2753005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_infobar_delegate.cc4
-rw-r--r--chrome/browser/gtk/extension_infobar_gtk.cc77
-rw-r--r--chrome/browser/gtk/extension_infobar_gtk.h45
-rwxr-xr-xchrome/chrome_browser.gypi2
4 files changed, 126 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc
index 09cd233..7bbc79b 100644
--- a/chrome/browser/extensions/extension_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_infobar_delegate.cc
@@ -57,12 +57,12 @@ void ExtensionInfoBarDelegate::InfoBarClosed() {
delete this;
}
-#if !defined(TOOLKIT_VIEWS)
+#if defined(OS_MACOSX)
InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
NOTIMPLEMENTED();
return NULL;
}
-#endif // !TOOLKIT_VIEWS
+#endif // OS_MACOSX
void ExtensionInfoBarDelegate::Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/gtk/extension_infobar_gtk.cc b/chrome/browser/gtk/extension_infobar_gtk.cc
new file mode 100644
index 0000000..f800e4a
--- /dev/null
+++ b/chrome/browser/gtk/extension_infobar_gtk.cc
@@ -0,0 +1,77 @@
+// 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/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) {
+ 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);
+
+ // TODO(finnur): Size the infobar based on HTML content (up to 72 pixels).
+}
+
+InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
+ return new ExtensionInfoBarGtk(this);
+}
diff --git a/chrome/browser/gtk/extension_infobar_gtk.h b/chrome/browser/gtk/extension_infobar_gtk.h
new file mode 100644
index 0000000..63ec1e1
--- /dev/null
+++ b/chrome/browser/gtk/extension_infobar_gtk.h
@@ -0,0 +1,45 @@
+// 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.
+
+#ifndef CHROME_BROWSER_GTK_EXTENSION_INFOBAR_GTK_H_
+#define CHROME_BROWSER_GTK_EXTENSION_INFOBAR_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/gtk/infobar_gtk.h"
+#include "chrome/browser/extensions/extension_infobar_delegate.h"
+#include "chrome/browser/extensions/image_loading_tracker.h"
+#include "gfx/gtk_util.h"
+
+class ExtensionInfobarDelegate;
+class ExtensionResource;
+class ExtensionViewGtk;
+
+class ExtensionInfoBarGtk : public InfoBar,
+ public ImageLoadingTracker::Observer {
+ public:
+ explicit ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate);
+ virtual ~ExtensionInfoBarGtk();
+
+ // Overridden from ImageLoadingTracker::Observer:
+ virtual void OnImageLoaded(
+ SkBitmap* image, ExtensionResource resource, int index);
+
+ private:
+ // Build the widgets of the Infobar.
+ void BuildWidgets();
+
+ CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, void, OnSizeAllocate,
+ GtkAllocation*);
+
+ ImageLoadingTracker tracker_;
+
+ ExtensionInfoBarDelegate* delegate_;
+
+ ExtensionViewGtk* view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarGtk);
+};
+
+#endif // CHROME_BROWSER_GTK_EXTENSION_INFOBAR_GTK_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 916a008..18065b3 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1317,6 +1317,8 @@
'browser/gtk/download_started_animation_gtk.cc',
'browser/gtk/edit_search_engine_dialog.cc',
'browser/gtk/edit_search_engine_dialog.h',
+ 'browser/gtk/extension_infobar_gtk.cc',
+ 'browser/gtk/extension_infobar_gtk.h',
'browser/gtk/extension_install_prompt_gtk.cc',
'browser/gtk/extension_install_prompt2_gtk.cc',
'browser/gtk/extension_installed_bubble_gtk.cc',