Commit 9824015a authored by finnur@chromium.org's avatar finnur@chromium.org

Set Extension Infobars to have a fixed height determined by the developer...

Set Extension Infobars to have a fixed height determined by the developer (clamped to sane min and max values).

BUG=92656
TEST=This needs to be tested with an Extension, which I can provide.
Review URL: http://codereview.chromium.org/7635019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97132 0039d316-1c4b-4281-b951-d872f2087c98
parent 2d9b71c3
......@@ -7,6 +7,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/infobar.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
......@@ -16,7 +17,8 @@
ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser,
TabContents* tab_contents,
const Extension* extension,
const GURL& url)
const GURL& url,
int height)
: InfoBarDelegate(tab_contents),
observer_(NULL),
extension_(extension),
......@@ -30,6 +32,18 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser,
Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
Source<Profile>(browser->profile()));
#if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK)
int default_height = InfoBar::kDefaultBarTargetHeight;
#elif defined(OS_MACOSX)
// TODO(pkasting): Once Infobars have been ported to Mac, we can remove the
// ifdefs and just use the Infobar constant below.
int default_height = 36;
#endif
height_ = std::max(0, height);
height_ = std::min(2 * default_height, height_);
if (height_ == 0)
height_ = default_height;
}
ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
......
......@@ -33,10 +33,12 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
ExtensionInfoBarDelegate(Browser* browser,
TabContents* contents,
const Extension* extension,
const GURL& url);
const GURL& url,
int height);
const Extension* extension() { return extension_; }
ExtensionHost* extension_host() { return extension_host_.get(); }
int height() { return height_; }
void set_observer(DelegateObserver* observer) { observer_ = observer; }
......@@ -69,6 +71,9 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
const Extension* extension_;
NotificationRegistrar registrar_;
// The requested height of the infobar (in pixels).
int height_;
// Whether we are currently animating to close. This is used to ignore
// ExtensionView::PreferredSizeChanged notifications.
bool closing_;
......
......@@ -33,6 +33,10 @@ bool ShowInfoBarFunction::RunImpl() {
std::string html_path;
EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path));
int height = 0;
if (args->HasKey(keys::kHeight))
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeight, &height));
const Extension* extension = GetExtension();
GURL url = extension->GetResourceURL(extension->url(), html_path);
......@@ -54,7 +58,7 @@ bool ShowInfoBarFunction::RunImpl() {
tab_contents->AddInfoBar(
new ExtensionInfoBarDelegate(browser, tab_contents->tab_contents(),
GetExtension(), url));
GetExtension(), url, height));
// TODO(finnur): Return the actual DOMWindow object. Bug 26463.
result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false));
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
......@@ -8,6 +8,7 @@ namespace extension_infobar_module_constants {
const char kHtmlPath[] = "path";
const char kTabId[] = "tabId";
const char kHeight[] = "height";
const char kNoCurrentWindowError[] = "No current browser window was found";
const char kTabNotFoundError[] = "Specified tab (or default tab) not found";
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
......@@ -13,6 +13,7 @@ namespace extension_infobar_module_constants {
// Keys.
extern const char kHtmlPath[];
extern const char kTabId[];
extern const char kHeight[];
// Errors.
extern const char kNoCurrentWindowError[];
......
......@@ -39,6 +39,7 @@ class InfoBar : public ui::AnimationDelegate {
virtual ~InfoBar();
// Platforms must define these.
static const int kDefaultBarTargetHeight;
static const int kSeparatorLineHeight;
static const int kDefaultArrowTargetHeight;
static const int kMaximumArrowTargetHeight;
......@@ -74,9 +75,6 @@ class InfoBar : public ui::AnimationDelegate {
int total_height() const { return arrow_height_ + bar_height_; }
protected:
// Platforms must define this.
static const int kDefaultBarTargetHeight;
// ui::AnimationDelegate:
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
......
......@@ -20,7 +20,6 @@ ExtensionInfoBarGtk::ExtensionInfoBarGtk(TabContentsWrapper* owner,
tracker_(this),
delegate_(delegate),
view_(NULL) {
delegate_->extension_host()->view()->SetContainer(this);
BuildWidgets();
}
......@@ -57,7 +56,7 @@ void ExtensionInfoBarGtk::BuildWidgets() {
Extension::EXTENSION_ICON_BITTY),
ImageLoadingTracker::DONT_CACHE);
} else {
OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|.
OnImageLoaded(NULL, icon_resource, 0); // |image|, ..., |index|.
}
ExtensionHost* extension_host = delegate_->extension_host();
......@@ -82,13 +81,6 @@ void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget,
->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(TabContentsWrapper* owner) {
return new ExtensionInfoBarGtk(owner, this);
}
......@@ -17,8 +17,7 @@ class ExtensionResource;
class ExtensionViewGtk;
class ExtensionInfoBarGtk : public InfoBarGtk,
public ImageLoadingTracker::Observer,
public ExtensionViewGtk::Container {
public ImageLoadingTracker::Observer {
public:
ExtensionInfoBarGtk(TabContentsWrapper* owner,
ExtensionInfoBarDelegate* delegate);
......@@ -28,10 +27,6 @@ class ExtensionInfoBarGtk : public InfoBarGtk,
virtual void OnImageLoaded(
SkBitmap* image, const ExtensionResource& resource, int index);
// ExtensionViewGtk::Container implementation
virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view,
const gfx::Size& new_size);
private:
// Build the widgets of the Infobar.
void BuildWidgets();
......
......@@ -42,19 +42,13 @@ ExtensionInfoBar::ExtensionInfoBar(TabContentsWrapper* owner,
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
delegate->set_observer(this);
ExtensionView* extension_view = delegate->extension_host()->view();
int height = extension_view->GetPreferredSize().height();
int height = delegate->height();
SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0);
// Get notified of resize events for the ExtensionView.
extension_view->SetContainer(this);
}
ExtensionInfoBar::~ExtensionInfoBar() {
if (GetDelegate()) {
GetDelegate()->extension_host()->view()->SetContainer(NULL);
if (GetDelegate())
GetDelegate()->set_observer(NULL);
}
}
void ExtensionInfoBar::Layout() {
......@@ -109,35 +103,6 @@ int ExtensionInfoBar::ContentMinimumWidth() const {
return menu_->GetPreferredSize().width() + kMenuHorizontalMargin;
}
void ExtensionInfoBar::OnExtensionMouseMove(ExtensionView* view) {
}
void ExtensionInfoBar::OnExtensionMouseLeave(ExtensionView* view) {
}
void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) {
ExtensionInfoBarDelegate* delegate = GetDelegate();
DCHECK_EQ(delegate->extension_host()->view(), view);
// When the infobar is closed, it animates to 0 vertical height. We'll
// continue to get size changed notifications from the ExtensionView, but we
// need to ignore them otherwise we'll try to re-animate open (and leak the
// infobar view).
if (delegate->closing())
return;
view->SetVisible(true);
if (height() == 0)
animation()->Reset(0.0);
// Clamp height to a min and a max size of between 1 and 2 InfoBars.
SetBarTargetHeight(std::min(2 * kDefaultBarTargetHeight,
std::max(kDefaultBarTargetHeight, view->GetPreferredSize().height())));
animation()->Show();
}
void ExtensionInfoBar::OnImageLoaded(SkBitmap* image,
const ExtensionResource& resource,
int index) {
......@@ -169,7 +134,6 @@ void ExtensionInfoBar::OnImageLoaded(SkBitmap* image,
}
void ExtensionInfoBar::OnDelegateDeleted() {
GetDelegate()->extension_host()->view()->SetContainer(NULL);
delegate_ = NULL;
}
......
......@@ -8,7 +8,6 @@
#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/ui/views/extensions/extension_view.h"
#include "chrome/browser/ui/views/infobars/infobar_view.h"
#include "views/controls/menu/view_menu_delegate.h"
......@@ -18,7 +17,6 @@ class MenuButton;
}
class ExtensionInfoBar : public InfoBarView,
public ExtensionView::Container,
public ImageLoadingTracker::Observer,
public ExtensionInfoBarDelegate::DelegateObserver,
public views::ViewMenuDelegate {
......@@ -34,11 +32,6 @@ class ExtensionInfoBar : public InfoBarView,
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
virtual int ContentMinimumWidth() const;
// ExtensionView::Container:
virtual void OnExtensionMouseMove(ExtensionView* view);
virtual void OnExtensionMouseLeave(ExtensionView* view);
virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
// ImageLoadingTracker::Observer:
virtual void OnImageLoaded(SkBitmap* image,
const ExtensionResource& resource,
......
......@@ -2162,6 +2162,13 @@
"path": {
"type": "string",
"description": "The html file that contains the infobar."
},
"height": {
"type": "integer",
"description": "The height (in pixels) of the infobar to show. If omitted, the default infobar height will be used.",
"optional": true,
"minimum": 0,
"maximum": 72
}
}
},
......
......@@ -589,6 +589,74 @@ For example:
<div></div>
</dd>
</div>
</div><div>
<div>
<dt>
<var>height</var>
<em>
<!-- TYPE -->
<div style="display:inline">
(
<span class="optional" style="display: none; ">optional</span>
<span class="enum" style="display: none; ">enumerated</span>
<span id="typeTemplate">
<span style="display: none; ">
<a> Type</a>
</span>
<span>
<span style="display: none; ">
array of <span><span></span></span>
</span>
<span>integer</span>
<span style="display: none; "></span>
</span>
</span>
)
</div>
</em>
</dt>
<dd class="todo" style="display: none; ">
Undocumented.
</dd>
<dd>The height (in pixels) of the infobar to show. A value of 0 means: use default infobar height.</dd>
<dd style="display: none; ">
This parameter was added in version
<b><span></span></b>.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
<a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
can ensure that your extension won't be run in an earlier browser version.
</dd>
<!-- OBJECT PROPERTIES -->
<dd style="display: none; ">
<dl>
<div>
<div>
</div>
</div>
</dl>
</dd>
<!-- OBJECT METHODS -->
<dd style="display: none; ">
<div></div>
</dd>
<!-- OBJECT EVENT FIELDS -->
<dd style="display: none; ">
<div></div>
</dd>
<!-- FUNCTION PARAMETERS -->
<dd style="display: none; ">
<div></div>
</dd>
</div>
</div>
</dl>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment