Commit 967c7ad4 authored by tfarina@chromium.org's avatar tfarina@chromium.org

Eliminate the LinkInfoBar[Delegate] classes entirely.

And switch to the existing AlternateNavInfoBar[Delegate] classes.

BUG=164772
R=pkasting@chromium.org
TBR=ben@chromium.org
NOTRY=True # ios_dbg_simulator seems to be broken in lkgm?

Review URL: https://codereview.chromium.org/11721003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175313 0039d316-1c4b-4281-b951-d872f2087c98
parent f8d31b7f
......@@ -4,9 +4,8 @@
#include "chrome/browser/alternate_nav_url_fetcher.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
#include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
#include "chrome/browser/intranet_redirect_detector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
......@@ -15,88 +14,12 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/load_flags.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
using content::NavigationController;
using content::OpenURLParams;
using content::Referrer;
// AlternateNavInfoBarDelegate ------------------------------------------------
class AlternateNavInfoBarDelegate : public LinkInfoBarDelegate {
public:
AlternateNavInfoBarDelegate(InfoBarService* owner,
const GURL& alternate_nav_url);
virtual ~AlternateNavInfoBarDelegate();
private:
// LinkInfoBarDelegate
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const OVERRIDE;
virtual string16 GetLinkText() const OVERRIDE;
virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
GURL alternate_nav_url_;
DISALLOW_COPY_AND_ASSIGN(AlternateNavInfoBarDelegate);
};
AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate(
InfoBarService* owner,
const GURL& alternate_nav_url)
: LinkInfoBarDelegate(owner),
alternate_nav_url_(alternate_nav_url) {
}
AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() {
}
gfx::Image* AlternateNavInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_ALT_NAV_URL);
}
InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset(
size_t* link_offset) const {
const string16 label = l10n_util::GetStringFUTF16(
IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset);
return label;
}
string16 AlternateNavInfoBarDelegate::GetLinkText() const {
return UTF8ToUTF16(alternate_nav_url_.spec());
}
bool AlternateNavInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
OpenURLParams params(
alternate_nav_url_, Referrer(), disposition,
// Pretend the user typed this URL, so that navigating to
// it will be the default action when it's typed again in
// the future.
content::PAGE_TRANSITION_TYPED,
false);
owner()->GetWebContents()->OpenURL(params);
// We should always close, even if the navigation did not occur within this
// WebContents.
return true;
}
// AlternateNavURLFetcher -----------------------------------------------------
AlternateNavURLFetcher::AlternateNavURLFetcher(
const GURL& alternate_nav_url)
......
......@@ -51,6 +51,10 @@ InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const {
return WARNING_TYPE;
}
AlternateNavInfoBarDelegate* InfoBarDelegate::AsAlternateNavInfoBarDelegate() {
return NULL;
}
AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() {
return NULL;
}
......@@ -68,10 +72,6 @@ InsecureContentInfoBarDelegate*
return NULL;
}
LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() {
return NULL;
}
MediaStreamInfoBarDelegate* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
return NULL;
}
......
......@@ -9,13 +9,13 @@
#include "base/string16.h"
#include "webkit/glue/window_open_disposition.h"
class AlternateNavInfoBarDelegate;
class AutoLoginInfoBarDelegate;
class ConfirmInfoBarDelegate;
class ExtensionInfoBarDelegate;
class InfoBar;
class InfoBarService;
class InsecureContentInfoBarDelegate;
class LinkInfoBarDelegate;
class MediaStreamInfoBarDelegate;
class PluginInstallerInfoBarDelegate;
class RegisterProtocolHandlerInfoBarDelegate;
......@@ -33,9 +33,9 @@ struct LoadCommittedDetails;
// An interface implemented by objects wishing to control an InfoBar.
// Implementing this interface is not sufficient to use an InfoBar, since it
// does not map to a specific InfoBar type. Instead, you must implement either
// LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own
// delegate for your own InfoBar variety.
// does not map to a specific InfoBar type. Instead, you must implement
// ConfirmInfoBarDelegate, or override with your own delegate for your own
// InfoBar variety.
class InfoBarDelegate {
public:
// The type of the infobar. It controls its appearance, such as its background
......@@ -97,11 +97,11 @@ class InfoBarDelegate {
virtual Type GetInfoBarType() const;
// Type-checking downcast routines:
virtual AlternateNavInfoBarDelegate* AsAlternateNavInfoBarDelegate();
virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate();
virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
virtual RegisterProtocolHandlerInfoBarDelegate*
AsRegisterProtocolHandlerInfoBarDelegate();
......
// 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.
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
bool LinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
return true;
}
LinkInfoBarDelegate::LinkInfoBarDelegate(InfoBarService* infobar_service)
: InfoBarDelegate(infobar_service) {
}
LinkInfoBarDelegate::~LinkInfoBarDelegate() {
}
LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() {
return this;
}
// 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.
#ifndef CHROME_BROWSER_API_INFOBARS_LINK_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_API_INFOBARS_LINK_INFOBAR_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/string16.h"
#include "chrome/browser/api/infobars/infobar_delegate.h"
// An interface derived from InfoBarDelegate implemented by objects wishing to
// control a LinkInfoBar.
class LinkInfoBarDelegate : public InfoBarDelegate {
public:
// Returns the message string to be displayed in the InfoBar. |link_offset|
// is the position where the link should be inserted.
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const = 0;
// Returns the text of the link to be displayed.
virtual string16 GetLinkText() const = 0;
// Called when the Link is clicked. The |disposition| specifies how the
// resulting document should be loaded (based on the event flags present when
// the link was clicked). If this function returns true, the infobar is then
// immediately closed. Subclasses MUST NOT return true if in handling this
// call something triggers the infobar to begin closing.
virtual bool LinkClicked(WindowOpenDisposition disposition);
protected:
explicit LinkInfoBarDelegate(InfoBarService* infobar_service);
virtual ~LinkInfoBarDelegate();
private:
// InfoBarDelegate:
virtual InfoBar* CreateInfoBar(InfoBarService* infobar_service) OVERRIDE;
virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate);
};
#endif // CHROME_BROWSER_API_INFOBARS_LINK_INFOBAR_DELEGATE_H_
......@@ -27,7 +27,6 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
#include "chrome/browser/autocomplete/autocomplete_controller.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_result.h"
......@@ -2163,10 +2162,6 @@ ListValue* TestingAutomationProvider::GetInfobarsInfo(WebContents* wc) {
buttons_list->Append(button_label);
}
infobar_item->Set("buttons", buttons_list);
} else if (infobar->AsLinkInfoBarDelegate()) {
infobar_item->SetString("type", "link_infobar");
LinkInfoBarDelegate* link_infobar = infobar->AsLinkInfoBarDelegate();
infobar_item->SetString("link_text", link_infobar->GetLinkText());
} else if (infobar->AsExtensionInfoBarDelegate()) {
infobar_item->SetString("type", "extension_infobar");
} else {
......
// Copyright 2012 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/infobars/alternate_nav_infobar_delegate.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/api/infobars/infobar_service.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate(
InfoBarService* owner,
const GURL& alternate_nav_url)
: InfoBarDelegate(owner),
alternate_nav_url_(alternate_nav_url) {
}
AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() {
}
string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset(
size_t* link_offset) const {
const string16 label = l10n_util::GetStringFUTF16(
IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset);
return label;
}
string16 AlternateNavInfoBarDelegate::GetLinkText() const {
return UTF8ToUTF16(alternate_nav_url_.spec());
}
bool AlternateNavInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
content::OpenURLParams params(
alternate_nav_url_, content::Referrer(), disposition,
// Pretend the user typed this URL, so that navigating to
// it will be the default action when it's typed again in
// the future.
content::PAGE_TRANSITION_TYPED,
false);
owner()->GetWebContents()->OpenURL(params);
// We should always close, even if the navigation did not occur within this
// WebContents.
return true;
}
AlternateNavInfoBarDelegate*
AlternateNavInfoBarDelegate::AsAlternateNavInfoBarDelegate() {
return this;
}
gfx::Image* AlternateNavInfoBarDelegate::GetIcon() const {
return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_ALT_NAV_URL);
}
InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
// Copyright 2012 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_INFOBARS_ALTERNATE_NAV_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_INFOBARS_ALTERNATE_NAV_INFOBAR_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/api/infobars/infobar_delegate.h"
#include "googleurl/src/gurl.h"
class AlternateNavInfoBarDelegate : public InfoBarDelegate {
public:
AlternateNavInfoBarDelegate(InfoBarService* owner,
const GURL& alternate_nav_url);
virtual ~AlternateNavInfoBarDelegate();
string16 GetMessageTextWithOffset(size_t* link_offset) const;
string16 GetLinkText() const;
bool LinkClicked(WindowOpenDisposition disposition);
private:
// InfoBarDelegate:
virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
virtual AlternateNavInfoBarDelegate* AsAlternateNavInfoBarDelegate() OVERRIDE;
GURL alternate_nav_url_;
DISALLOW_COPY_AND_ASSIGN(AlternateNavInfoBarDelegate);
};
#endif // CHROME_BROWSER_INFOBARS_ALTERNATE_NAV_INFOBAR_DELEGATE_H_
......@@ -8,7 +8,6 @@
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
#include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
#include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h"
#import "chrome/browser/ui/cocoa/view_resizer_pong.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
......@@ -54,29 +53,14 @@ TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
// After each step check to make sure we have the correct number of
// infobar subviews.
// These delegates delete themselves when they're told their infobars have
// closed.
InfoBarDelegate* linkDelegate = new MockLinkInfoBarDelegate(NULL);
InfoBarDelegate* linkDelegate2 = new MockLinkInfoBarDelegate(NULL);
// This delegate deletes itself when they're told their infobars have closed.
InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL);
[controller_ addInfoBar:linkDelegate->CreateInfoBar(NULL) animate:NO];
EXPECT_EQ(1U, [[view subviews] count]);
[controller_ addInfoBar:confirmDelegate->CreateInfoBar(NULL) animate:NO];
EXPECT_EQ(2U, [[view subviews] count]);
[controller_ addInfoBar:linkDelegate2->CreateInfoBar(NULL) animate:NO];
EXPECT_EQ(3U, [[view subviews] count]);
EXPECT_EQ(1U, [[view subviews] count]);
// Just to mix things up, remove them in a different order.
[controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO];
EXPECT_EQ(2U, [[view subviews] count]);
[controller_ closeInfoBarsForDelegate:linkDelegate animate:NO];
EXPECT_EQ(1U, [[view subviews] count]);
[controller_ closeInfoBarsForDelegate:linkDelegate2 animate:NO];
EXPECT_EQ(0U, [[view subviews] count]);
}
......@@ -87,19 +71,17 @@ TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) {
// removeAllInfobars does not close these, so we stack-allocate them so
// they'll get cleaned up.
MockLinkInfoBarDelegate linkDelegate(NULL);
MockConfirmInfoBarDelegate confirmDelegate(NULL);
MockConfirmInfoBarDelegate confirmDelegate2(NULL);
InfoBarDelegate* linkDelegatePtr = &linkDelegate;
InfoBarDelegate* confirmDelegatePtr = &confirmDelegate;
InfoBarDelegate* confirmDelegate2Ptr = &confirmDelegate2;
[controller_ addInfoBar:linkDelegatePtr->CreateInfoBar(NULL) animate:NO];
[controller_ addInfoBar:confirmDelegatePtr->CreateInfoBar(NULL) animate:NO];
[controller_ addInfoBar:confirmDelegate2Ptr->CreateInfoBar(NULL) animate:NO];
EXPECT_EQ(3U, [[view subviews] count]);
EXPECT_EQ(2U, [[view subviews] count]);
[controller_ removeAllInfoBars];
EXPECT_EQ(0U, [[view subviews] count]);
}
} // namespace
......@@ -107,7 +107,7 @@ class InfoBarService;
// subclass. Each of these subclasses overrides addAdditionalControls to
// configure its view as necessary.
@interface LinkInfoBarController : InfoBarController
@interface AlternateNavInfoBarController : InfoBarController
// Called when there is a click on the link in the infobar.
- (void)linkClicked;
@end
......
......@@ -11,7 +11,7 @@
#include "grit/ui_resources.h"
#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
#include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
#import "chrome/browser/ui/cocoa/animatable_view.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/event_utils.h"
......@@ -287,9 +287,9 @@ const float kAnimateCloseDuration = 0.12;
/////////////////////////////////////////////////////////////////////////
// LinkInfoBarController implementation
// AlternateNavInfoBarController implementation
@implementation LinkInfoBarController
@implementation AlternateNavInfoBarController
// Link infobars have a text message, of which part is linkified. We
// use an NSAttributedString to display styled text, and we set a
......@@ -301,7 +301,8 @@ const float kAnimateCloseDuration = 0.12;
// No buttons.
[self removeButtons];
LinkInfoBarDelegate* delegate = delegate_->AsLinkInfoBarDelegate();
AlternateNavInfoBarDelegate* delegate =
delegate_->AsAlternateNavInfoBarDelegate();
DCHECK(delegate);
size_t offset = string16::npos;
string16 message = delegate->GetMessageTextWithOffset(&offset);
......@@ -319,13 +320,13 @@ const float kAnimateCloseDuration = 0.12;
// Called when someone clicks on the link in the infobar. This method
// is called by the InfobarTextField on its delegate (the
// LinkInfoBarController).
// AlternateNavInfoBarController).
- (void)linkClicked {
if (![self isOwned])
return;
WindowOpenDisposition disposition =
event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
if (delegate_->AsLinkInfoBarDelegate()->LinkClicked(disposition))
if (delegate_->AsAlternateNavInfoBarDelegate()->LinkClicked(disposition))
[self removeSelf];
}
......@@ -446,7 +447,7 @@ const float kAnimateCloseDuration = 0.12;
// Called when someone clicks on the link in the infobar. This method
// is called by the InfobarTextField on its delegate (the
// LinkInfoBarController).
// AlternateNavInfoBarController).
- (void)linkClicked {
if (![self isOwned])
return;
......@@ -462,9 +463,9 @@ const float kAnimateCloseDuration = 0.12;
//////////////////////////////////////////////////////////////////////////
// CreateInfoBar() implementations
InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
LinkInfoBarController* controller =
[[LinkInfoBarController alloc] initWithDelegate:this owner:owner];
InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
AlternateNavInfoBarController* controller =
[[AlternateNavInfoBarController alloc] initWithDelegate:this owner:owner];
return new InfoBar(controller, this);
}
......
......@@ -13,7 +13,6 @@
#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
#import "chrome/browser/ui/cocoa/infobars/infobar_controller.h"
#include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
#include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h"
#include "chrome/browser/ui/cocoa/run_loop_testing.h"
#import "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
......@@ -66,19 +65,6 @@ using content::WebContents;
}
@end
// Calls to removeSelf normally start an animation, which removes the infobar
// completely when finished. For testing purposes, we create a mock controller
// which calls close: immediately, rather than kicking off an animation.
@interface TestLinkInfoBarController : LinkInfoBarController
- (void)removeSelf;
@end
@implementation TestLinkInfoBarController
- (void)removeSelf {
[self close];
}
@end
@interface TestConfirmInfoBarController : ConfirmInfoBarController
- (void)removeSelf;
@end
......@@ -91,54 +77,6 @@ using content::WebContents;
namespace {
///////////////////////////////////////////////////////////////////////////
// Test fixtures
class LinkInfoBarControllerTest : public CocoaProfileTest,
public MockLinkInfoBarDelegate::Owner {
public:
virtual void SetUp() {
CocoaProfileTest::SetUp();
web_contents_.reset(
WebContents::Create(WebContents::CreateParams(profile())));
InfoBarService::CreateForWebContents(web_contents_.get());
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents_.get());
delegate_ = new MockLinkInfoBarDelegate(this);
controller_.reset([[TestLinkInfoBarController alloc]
initWithDelegate:delegate_ owner:infobar_service]);
container_.reset(
[[InfoBarContainerTest alloc] initWithController:controller_]);
[controller_ setContainerController:container_];
[[test_window() contentView] addSubview:[controller_ view]];
closed_delegate_link_clicked_ = false;
}
virtual void TearDown() {
if (delegate_)
delete delegate_;
CocoaProfileTest::TearDown();
}
protected:
// Hopefully-obvious: If this returns true, you must not deref |delegate_|!
bool delegate_closed() const { return delegate_ == NULL; }
MockLinkInfoBarDelegate* delegate_; // Owns itself.
scoped_nsobject<id> container_;
scoped_nsobject<LinkInfoBarController> controller_;
bool closed_delegate_link_clicked_;
private:
virtual void OnInfoBarDelegateClosed() {
closed_delegate_link_clicked_ = delegate_->link_clicked();
delegate_ = NULL;
}
scoped_ptr<WebContents> web_contents_;
};
class ConfirmInfoBarControllerTest : public CocoaProfileTest,
public MockConfirmInfoBarDelegate::Owner {
public:
......@@ -191,52 +129,6 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest,
};
////////////////////////////////////////////////////////////////////////////
// Tests
TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]);
TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) {
// Make sure someone looked at the message, link, and icon.
EXPECT_TRUE(delegate_->message_text_accessed());
EXPECT_TRUE(delegate_->link_text_accessed());
EXPECT_TRUE(delegate_->icon_accessed());
// Check that dismissing the infobar deletes the delegate.
[controller_ removeSelf];
ASSERT_TRUE(delegate_closed());
EXPECT_FALSE(closed_delegate_link_clicked_);
}
TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) {
// Check that clicking on the link calls LinkClicked() on the
// delegate. It should also close the infobar.
[controller_ linkClicked];
// Spin the runloop because the invocation for closing the infobar is done on
// a 0-timer delayed selector.
chrome::testing::NSRunLoopRunAllPending();
ASSERT_TRUE(delegate_closed());
EXPECT_TRUE(closed_delegate_link_clicked_);
}
TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) {
delegate_->set_dont_close_on_action();
// Check that clicking on the link calls LinkClicked() on the
// delegate. It should not close the infobar.
[controller_ linkClicked];
ASSERT_FALSE(delegate_closed());
EXPECT_TRUE(delegate_->link_clicked());
}
TEST_F(LinkInfoBarControllerTest, DeallocController) {
// Test that dealloc'ing the controller does not delete the delegate.
controller_.reset(nil);
ASSERT_FALSE(delegate_closed());
}
TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]);
TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
......
// Copyright (c) 2012 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/ui/cocoa/infobars/mock_link_infobar_delegate.h"
#include "base/utf_string_conversions.h"
const char MockLinkInfoBarDelegate::kMessage[] = "MockLinkInfoBarMessage ";
const char MockLinkInfoBarDelegate::kLink[] = "http://dev.chromium.org";
MockLinkInfoBarDelegate::MockLinkInfoBarDelegate(Owner* owner)
: LinkInfoBarDelegate(NULL),
owner_(owner),
closes_on_action_(true),
icon_accessed_(false),
message_text_accessed_(false),
link_text_accessed_(false),
link_clicked_(false) {
}
MockLinkInfoBarDelegate::~MockLinkInfoBarDelegate() {
if (owner_)
owner_->OnInfoBarDelegateClosed();
}
gfx::Image* MockLinkInfoBarDelegate::GetIcon() const {
icon_accessed_ = true;
return NULL;
}
string16 MockLinkInfoBarDelegate::GetMessageTextWithOffset(
size_t* link_offset) const {
message_text_accessed_ = true;
*link_offset = arraysize(kMessage) - 1;
return ASCIIToUTF16(kMessage);
}
string16 MockLinkInfoBarDelegate::GetLinkText() const {
link_text_accessed_ = true;
return ASCIIToUTF16(kLink);
}
bool MockLinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
link_clicked_ = true;
return closes_on_action_;
}
// 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.
#ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_MOCK_LINK_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_UI_COCOA_INFOBARS_MOCK_LINK_INFOBAR_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/string16.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
public:
// Called when |this| is about to be destroyed.
class Owner {
public:
virtual void OnInfoBarDelegateClosed() = 0;
protected:
virtual ~Owner() {}
};
explicit MockLinkInfoBarDelegate(Owner* owner);
virtual ~MockLinkInfoBarDelegate();
void set_dont_close_on_action() { closes_on_action_ = false; }
bool icon_accessed() const { return icon_accessed_; }
bool message_text_accessed() const { return message_text_accessed_; }
bool link_text_accessed() const { return link_text_accessed_; }
bool link_clicked() const { return link_clicked_; }
static const char kMessage[];
static const char kLink[];
private:
// LinkInfoBarDelegate:
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const OVERRIDE;
virtual string16 GetLinkText() const OVERRIDE;
virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
Owner* owner_;
// Determines whether the infobar closes when an action is taken or not.
bool closes_on_action_;
mutable bool icon_accessed_;
mutable bool message_text_accessed_;
mutable bool link_text_accessed_;
bool link_clicked_;
DISALLOW_COPY_AND_ASSIGN(MockLinkInfoBarDelegate);
};
#endif // CHROME_BROWSER_UI_COCOA_INFOBARS_MOCK_LINK_INFOBAR_DELEGATE_H_
......@@ -2,21 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/gtk/infobars/link_infobar_gtk.h"
#include "chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
#include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
#include "chrome/browser/ui/gtk/event_utils.h"
// LinkInfoBarDelegate ---------------------------------------------------------
// AlternateNavInfoBarDelegate -------------------------------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
return new LinkInfoBarGtk(owner, this);
InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
return new AlternateNavInfoBarGtk(owner, this);
}
// LinkInfoBarGtk --------------------------------------------------------------
// AlternateNavInfoBarGtk ------------------------------------------------------
LinkInfoBarGtk::LinkInfoBarGtk(InfoBarService* owner,
LinkInfoBarDelegate* delegate)
AlternateNavInfoBarGtk::AlternateNavInfoBarGtk(
InfoBarService* owner,
AlternateNavInfoBarDelegate* delegate)
: InfoBarGtk(owner, delegate) {
size_t link_offset;
string16 display_text = delegate->GetMessageTextWithOffset(&link_offset);
......@@ -25,15 +26,15 @@ LinkInfoBarGtk::LinkInfoBarGtk(InfoBarService* owner,
G_CALLBACK(OnLinkClickedThunk));
}
LinkInfoBarGtk::~LinkInfoBarGtk() {
AlternateNavInfoBarGtk::~AlternateNavInfoBarGtk() {
}
void LinkInfoBarGtk::OnLinkClicked(GtkWidget* button) {
void AlternateNavInfoBarGtk::OnLinkClicked(GtkWidget* button) {
if (GetDelegate()->LinkClicked(
event_utils::DispositionForCurrentButtonPressEvent()))
RemoveSelf();
}
LinkInfoBarDelegate* LinkInfoBarGtk::GetDelegate() {
return delegate()->AsLinkInfoBarDelegate();
AlternateNavInfoBarDelegate* AlternateNavInfoBarGtk::GetDelegate() {
return delegate()->AsAlternateNavInfoBarDelegate();
}
......@@ -2,28 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_INFOBARS_LINK_INFOBAR_GTK_H_
#define CHROME_BROWSER_UI_GTK_INFOBARS_LINK_INFOBAR_GTK_H_
#ifndef CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_
#define CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_
#include "base/basictypes.h"
#include "chrome/browser/ui/gtk/infobars/infobar_gtk.h"
#include "ui/base/gtk/gtk_signal.h"
class LinkInfoBarDelegate;
class AlternateNavInfoBarDelegate;
// An infobar that shows a string with an embedded link.
class LinkInfoBarGtk : public InfoBarGtk {
class AlternateNavInfoBarGtk : public InfoBarGtk {
public:
LinkInfoBarGtk(InfoBarService* owner, LinkInfoBarDelegate* delegate);
AlternateNavInfoBarGtk(InfoBarService* owner,
AlternateNavInfoBarDelegate* delegate);
private:
virtual ~LinkInfoBarGtk();
virtual ~AlternateNavInfoBarGtk();
CHROMEGTK_CALLBACK_0(LinkInfoBarGtk, void, OnLinkClicked);
CHROMEGTK_CALLBACK_0(AlternateNavInfoBarGtk, void, OnLinkClicked);
LinkInfoBarDelegate* GetDelegate();
AlternateNavInfoBarDelegate* GetDelegate();
DISALLOW_COPY_AND_ASSIGN(LinkInfoBarGtk);
DISALLOW_COPY_AND_ASSIGN(AlternateNavInfoBarGtk);
};
#endif // CHROME_BROWSER_UI_GTK_INFOBARS_LINK_INFOBAR_GTK_H_
#endif // CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_
......@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/infobars/link_infobar.h"
#include "chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h"
#include "base/logging.h"
#include "chrome/browser/api/infobars/link_infobar_delegate.h"
#include "chrome/browser/event_disposition.h"
#include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
// LinkInfoBarDelegate --------------------------------------------------------
// AlternateNavInfoBarDelegate -------------------------------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
return new LinkInfoBar(owner, this);
InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
return new AlternateNavInfoBarView(owner, this);
}
// LinkInfoBar ----------------------------------------------------------------
// AlternateNavInfoBarView -----------------------------------------------------
LinkInfoBar::LinkInfoBar(InfoBarService* owner,
LinkInfoBarDelegate* delegate)
AlternateNavInfoBarView::AlternateNavInfoBarView(
InfoBarService* owner,
AlternateNavInfoBarDelegate* delegate)
: InfoBarView(owner, delegate),
label_1_(NULL),
link_(NULL),
label_2_(NULL) {
}
LinkInfoBar::~LinkInfoBar() {
AlternateNavInfoBarView::~AlternateNavInfoBarView() {
}
void LinkInfoBar::Layout() {
void AlternateNavInfoBarView::Layout() {
InfoBarView::Layout();
// TODO(pkasting): This isn't perfect; there are points when we should elide a
......@@ -50,9 +51,11 @@ void LinkInfoBar::Layout() {
std::min(label_2_size.width(), available_width), label_2_size.height());
}
void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
void AlternateNavInfoBarView::ViewHierarchyChanged(bool is_add,
View* parent,
View* child) {
if (is_add && (child == this) && (label_1_ == NULL)) {
LinkInfoBarDelegate* delegate = GetDelegate();
AlternateNavInfoBarDelegate* delegate = GetDelegate();
size_t offset;
string16 message_text = delegate->GetMessageTextWithOffset(&offset);
DCHECK_NE(string16::npos, offset);
......@@ -71,7 +74,8 @@ void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
InfoBarView::ViewHierarchyChanged(is_add, parent, child);
}
void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) {
void AlternateNavInfoBarView::LinkClicked(views::Link* source,
int event_flags) {
if (!owned())
return; // We're closing; don't call anything, it might access the owner.
DCHECK(link_ != NULL);
......@@ -81,6 +85,6 @@ void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) {
RemoveSelf();
}
LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
return delegate()->AsLinkInfoBarDelegate();
AlternateNavInfoBarDelegate* AlternateNavInfoBarView::GetDelegate() {
return delegate()->AsAlternateNavInfoBarDelegate();
}
......@@ -2,24 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_
#define CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_
#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/ui/views/infobars/infobar_view.h"
#include "ui/views/controls/link_listener.h"
class LinkInfoBarDelegate;
class AlternateNavInfoBarDelegate;
// An infobar that shows a string with an embedded link.
class LinkInfoBar : public InfoBarView,
public views::LinkListener {
class AlternateNavInfoBarView : public InfoBarView,
public views::LinkListener {
public:
LinkInfoBar(InfoBarService* owner, LinkInfoBarDelegate* delegate);
AlternateNavInfoBarView(InfoBarService* owner,
AlternateNavInfoBarDelegate* delegate);
private:
virtual ~LinkInfoBar();
virtual ~AlternateNavInfoBarView();
// InfoBarView:
virtual void Layout() OVERRIDE;
......@@ -30,13 +31,13 @@ class LinkInfoBar : public InfoBarView,
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
LinkInfoBarDelegate* GetDelegate();
AlternateNavInfoBarDelegate* GetDelegate();
views::Label* label_1_;
views::Link* link_;
views::Label* label_2_;
DISALLOW_COPY_AND_ASSIGN(LinkInfoBar);
DISALLOW_COPY_AND_ASSIGN(AlternateNavInfoBarView);
};
#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_
#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_
......@@ -110,8 +110,6 @@
'browser/api/infobars/infobar_delegate.cc',
'browser/api/infobars/infobar_delegate.h',
'browser/api/infobars/infobar_service.h',
'browser/api/infobars/link_infobar_delegate.cc',
'browser/api/infobars/link_infobar_delegate.h',
'browser/api/infobars/one_click_signin_infobar_delegate.cc',
'browser/api/infobars/one_click_signin_infobar_delegate.h',
'browser/api/infobars/simple_alert_infobar_delegate.cc',
......@@ -913,6 +911,8 @@
'browser/importer/toolbar_importer.h',
'browser/importer/toolbar_importer_utils.cc',
'browser/importer/toolbar_importer_utils.h',
'browser/infobars/alternate_nav_infobar_delegate.cc',
'browser/infobars/alternate_nav_infobar_delegate.h',
'browser/infobars/infobar.cc',
'browser/infobars/infobar.h',
'browser/infobars/infobar_container.cc',
......
......@@ -583,8 +583,6 @@
'browser/ui/cocoa/infobars/infobar.h',
'browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc',
'browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h',
'browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc',
'browser/ui/cocoa/infobars/mock_link_infobar_delegate.h',
'browser/ui/cocoa/infobars/translate_infobar_base.h',
'browser/ui/cocoa/infobars/translate_infobar_base.mm',
'browser/ui/cocoa/infobars/translate_message_infobar_controller.h',
......@@ -988,6 +986,8 @@
'browser/ui/gtk/importer/import_progress_dialog_gtk.h',
'browser/ui/gtk/infobars/after_translate_infobar_gtk.cc',
'browser/ui/gtk/infobars/after_translate_infobar_gtk.h',
'browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc',
'browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h',
'browser/ui/gtk/infobars/before_translate_infobar_gtk.cc',
'browser/ui/gtk/infobars/before_translate_infobar_gtk.h',
'browser/ui/gtk/infobars/confirm_infobar_gtk.cc',
......@@ -998,8 +998,6 @@
'browser/ui/gtk/infobars/infobar_container_gtk.h',
'browser/ui/gtk/infobars/infobar_gtk.cc',
'browser/ui/gtk/infobars/infobar_gtk.h',
'browser/ui/gtk/infobars/link_infobar_gtk.cc',
'browser/ui/gtk/infobars/link_infobar_gtk.h',
'browser/ui/gtk/infobars/translate_infobar_base_gtk.cc',
'browser/ui/gtk/infobars/translate_infobar_base_gtk.h',
'browser/ui/gtk/infobars/translate_message_infobar_gtk.cc',
......@@ -1538,6 +1536,8 @@
'browser/ui/views/importer/import_lock_dialog_view.h',
'browser/ui/views/importer/import_progress_dialog_view.cc',
'browser/ui/views/importer/import_progress_dialog_view.h',
'browser/ui/views/infobars/alternate_nav_infobar_view.cc',
'browser/ui/views/infobars/alternate_nav_infobar_view.h',
'browser/ui/views/infobars/after_translate_infobar.cc',
'browser/ui/views/infobars/after_translate_infobar.h',
'browser/ui/views/infobars/before_translate_infobar.cc',
......@@ -1554,8 +1554,6 @@
'browser/ui/views/infobars/infobar_container_view.h',
'browser/ui/views/infobars/infobar_view.cc',
'browser/ui/views/infobars/infobar_view.h',
'browser/ui/views/infobars/link_infobar.cc',
'browser/ui/views/infobars/link_infobar.h',
'browser/ui/views/infobars/one_click_signin_infobar.cc',
'browser/ui/views/infobars/one_click_signin_infobar.h',
'browser/ui/views/infobars/translate_infobar_base.cc',
......
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