summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.cc1
-rw-r--r--chrome/browser/autofill/autofill_cc_infobar_delegate.h5
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc4
-rw-r--r--chrome/browser/automation/automation_provider_observers.h6
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc34
-rw-r--r--chrome/browser/automation/testing_automation_provider.h6
-rw-r--r--chrome/browser/download/download_request_infobar_delegate.cc13
-rw-r--r--chrome/browser/download/download_request_infobar_delegate.h1
-rw-r--r--chrome/browser/download/download_request_infobar_delegate_unittest.cc12
-rw-r--r--chrome/browser/download/download_request_limiter.cc3
-rw-r--r--chrome/browser/extensions/crashed_extension_infobar.cc2
-rw-r--r--chrome/browser/extensions/crashed_extension_infobar.h7
-rw-r--r--chrome/browser/extensions/extension_crash_recovery_browsertest.cc44
-rw-r--r--chrome/browser/extensions/extension_infobar_delegate.h3
-rw-r--r--chrome/browser/extensions/extension_install_ui.cc2
-rw-r--r--chrome/browser/extensions/extension_install_ui_browsertest.cc4
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.cc2
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.h2
-rw-r--r--chrome/browser/geolocation/geolocation_browsertest.cc10
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc18
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context_unittest.cc303
-rw-r--r--chrome/browser/google/google_url_tracker.h4
-rw-r--r--chrome/browser/notifications/notifications_interactive_uitest.cc6
-rw-r--r--chrome/browser/omnibox_search_hint.cc1
-rw-r--r--chrome/browser/plugin_installer_infobar_delegate.cc27
-rw-r--r--chrome/browser/plugin_installer_infobar_delegate.h6
-rw-r--r--chrome/browser/plugin_observer.cc207
-rw-r--r--chrome/browser/plugin_observer.h4
-rw-r--r--chrome/browser/tab_contents/infobar_delegate.cc5
-rw-r--r--chrome/browser/tab_contents/infobar_delegate.h2
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc15
-rw-r--r--chrome/browser/tab_contents/tab_contents.h7
-rw-r--r--chrome/browser/tab_contents/tab_contents_ssl_helper.cc15
-rw-r--r--chrome/browser/task_manager/task_manager_browsertest.cc2
-rw-r--r--chrome/browser/translate/languages_menu_model.cc14
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.cc27
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.h24
-rw-r--r--chrome/browser/translate/translate_infobar_view.h6
-rw-r--r--chrome/browser/translate/translate_manager.cc2
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc10
-rw-r--r--chrome/browser/ui/browser.cc2
-rw-r--r--chrome/browser/ui/browser_init.cc6
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm2
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_test_helper.h4
-rw-r--r--chrome/browser/ui/cocoa/keystone_infobar.mm2
-rw-r--r--chrome/browser/ui/cocoa/tabpose_window.mm4
-rw-r--r--chrome/browser/ui/cocoa/translate/translate_infobar_base.mm20
-rw-r--r--chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc8
-rw-r--r--chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc8
-rw-r--r--chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h4
-rw-r--r--chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc2
-rw-r--r--chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc14
-rw-r--r--chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h17
-rw-r--r--chrome/browser/ui/views/extensions/extension_view.cc3
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.cc117
-rw-r--r--chrome/browser/ui/views/infobars/after_translate_infobar.h26
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.cc135
-rw-r--r--chrome/browser/ui/views/infobars/before_translate_infobar.h22
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.cc99
-rw-r--r--chrome/browser/ui/views/infobars/confirm_infobar.h23
-rw-r--r--chrome/browser/ui/views/infobars/extension_infobar.cc153
-rw-r--r--chrome/browser/ui/views/infobars/extension_infobar.h42
-rw-r--r--chrome/browser/ui/views/infobars/infobar_background.cc32
-rw-r--r--chrome/browser/ui/views/infobars/infobar_background.h9
-rw-r--r--chrome/browser/ui/views/infobars/infobar_button_border.cc64
-rw-r--r--chrome/browser/ui/views/infobars/infobar_button_border.h12
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.cc12
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.h8
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.cc254
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.h94
-rw-r--r--chrome/browser/ui/views/infobars/link_infobar.cc58
-rw-r--r--chrome/browser/ui/views/infobars/link_infobar.h13
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.cc157
-rw-r--r--chrome/browser/ui/views/infobars/translate_infobar_base.h43
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.cc39
-rw-r--r--chrome/browser/ui/views/infobars/translate_message_infobar.h7
-rw-r--r--chrome/common/automation_messages_internal.h4
-rw-r--r--chrome/test/automation/tab_proxy.cc8
-rw-r--r--chrome/test/automation/tab_proxy.h8
79 files changed, 1125 insertions, 1276 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc
index 4085d47..7ebbb00 100644
--- a/chrome/browser/alternate_nav_url_fetcher.cc
+++ b/chrome/browser/alternate_nav_url_fetcher.cc
@@ -166,6 +166,5 @@ void AlternateNavURLFetcher::ShowInfobarIfPossible() {
infobar_contents_ = controller_->tab_contents();
StoreActiveEntryUniqueID(infobar_contents_);
- // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed).
infobar_contents_->AddInfoBar(this);
}
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
index 4916335..196be3f 100644
--- a/chrome/browser/autofill/autofill_cc_infobar_delegate.h
+++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
@@ -22,13 +22,12 @@ class AutoFillCCInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
- const NavigationController::LoadCommittedDetails& details) const;
+ const NavigationController::LoadCommittedDetails& details) const;
virtual void InfoBarClosed();
virtual SkBitmap* GetIcon() const;
virtual Type GetInfoBarType() const;
virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(
- ConfirmInfoBarDelegate::InfoBarButton button) const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
virtual bool Cancel();
virtual string16 GetLinkText();
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index ee3040a..dfc29f5 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -1110,7 +1110,7 @@ void TabLanguageDeterminedObserver::Observe(
InfoBarCountObserver::InfoBarCountObserver(AutomationProvider* automation,
IPC::Message* reply_message,
TabContents* tab_contents,
- int target_count)
+ size_t target_count)
: automation_(automation),
reply_message_(reply_message),
tab_contents_(tab_contents),
@@ -1130,7 +1130,7 @@ void InfoBarCountObserver::Observe(NotificationType type,
}
void InfoBarCountObserver::CheckCount() {
- if (tab_contents_->infobar_delegate_count() != target_count_)
+ if (tab_contents_->infobar_count() != target_count_)
return;
AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, true);
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index 8fdc74d..fcb955b 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -1,4 +1,4 @@
-// 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.
@@ -597,7 +597,7 @@ class InfoBarCountObserver : public NotificationObserver {
InfoBarCountObserver(AutomationProvider* automation,
IPC::Message* reply_message,
TabContents* tab_contents,
- int target_count);
+ size_t target_count);
// NotificationObserver interface.
virtual void Observe(NotificationType type,
@@ -614,7 +614,7 @@ class InfoBarCountObserver : public NotificationObserver {
IPC::Message* reply_message_;
TabContents* tab_contents_;
- const int target_count_;
+ const size_t target_count_;
DISALLOW_COPY_AND_ASSIGN(InfoBarCountObserver);
};
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 5690dfc..12c752c 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -1671,26 +1671,25 @@ void TestingAutomationProvider::RemoveBookmark(int handle,
*success = false;
}
-void TestingAutomationProvider::GetInfoBarCount(int handle, int* count) {
- *count = -1; // -1 means error.
+void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) {
+ *count = static_cast<size_t>(-1); // -1 means error.
if (tab_tracker_->ContainsHandle(handle)) {
NavigationController* nav_controller = tab_tracker_->GetResource(handle);
if (nav_controller)
- *count = nav_controller->tab_contents()->infobar_delegate_count();
+ *count = nav_controller->tab_contents()->infobar_count();
}
}
void TestingAutomationProvider::ClickInfoBarAccept(
int handle,
- int info_bar_index,
+ size_t info_bar_index,
bool wait_for_navigation,
IPC::Message* reply_message) {
bool success = false;
if (tab_tracker_->ContainsHandle(handle)) {
NavigationController* nav_controller = tab_tracker_->GetResource(handle);
if (nav_controller) {
- if (info_bar_index >= 0 && info_bar_index < nav_controller->
- tab_contents()->infobar_delegate_count()) {
+ if (info_bar_index < nav_controller->tab_contents()->infobar_count()) {
if (wait_for_navigation)
AddNavigationStatusListener(nav_controller, reply_message, 1, false);
InfoBarDelegate* delegate =
@@ -2165,7 +2164,7 @@ void TestingAutomationProvider::SetWindowDimensions(
ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) {
// Each infobar may have different properties depending on the type.
ListValue* infobars = new ListValue;
- for (int i = 0; i < tc->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tc->infobar_count(); ++i) {
DictionaryValue* infobar_item = new DictionaryValue;
InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(i);
if (infobar->AsConfirmInfoBarDelegate()) {
@@ -2224,10 +2223,10 @@ void TestingAutomationProvider::PerformActionOnInfobar(
IPC::Message* reply_message) {
AutomationJSONReply reply(this, reply_message);
int tab_index;
- int infobar_index;
+ int infobar_index_int;
std::string action;
if (!args->GetInteger("tab_index", &tab_index) ||
- !args->GetInteger("infobar_index", &infobar_index) ||
+ !args->GetInteger("infobar_index", &infobar_index_int) ||
!args->GetString("action", &action)) {
reply.SendError("Invalid or missing args");
return;
@@ -2238,10 +2237,11 @@ void TestingAutomationProvider::PerformActionOnInfobar(
return;
}
InfoBarDelegate* infobar = NULL;
- if (infobar_index < 0 ||
- infobar_index >= tab_contents->infobar_delegate_count() ||
+ size_t infobar_index = static_cast<size_t>(infobar_index_int);
+ if (infobar_index >= tab_contents->infobar_count() ||
!(infobar = tab_contents->GetInfoBarDelegateAt(infobar_index))) {
- reply.SendError(StringPrintf("No such infobar at index %d", infobar_index));
+ reply.SendError(StringPrintf("No such infobar at index %" PRIuS,
+ infobar_index));
return;
}
if ("dismiss" == action) {
@@ -3408,7 +3408,7 @@ namespace {
// Get the TranslateInfoBarDelegate from TabContents.
TranslateInfoBarDelegate* GetTranslateInfoBarDelegate(
TabContents* tab_contents) {
- for (int i = 0; i < tab_contents->infobar_delegate_count(); i++) {
+ for (size_t i = 0; i < tab_contents->infobar_count(); i++) {
InfoBarDelegate* infobar = tab_contents->GetInfoBarDelegateAt(i);
if (infobar->AsTranslateInfoBarDelegate())
return infobar->AsTranslateInfoBarDelegate();
@@ -3535,14 +3535,14 @@ void TestingAutomationProvider::SelectTranslateOption(
return;
}
// Get the target language index based off of the language name.
- int target_language_index = -1;
- for (int i = 0; i < translate_bar->GetLanguageCount(); i++) {
+ size_t target_language_index = TranslateInfoBarDelegate::kNoIndex;
+ for (size_t i = 0; i < translate_bar->GetLanguageCount(); i++) {
if (translate_bar->GetLanguageDisplayableNameAt(i) == target_language) {
target_language_index = i;
break;
}
}
- if (target_language_index == -1) {
+ if (target_language_index == TranslateInfoBarDelegate::kNoIndex) {
AutomationJSONReply(this, reply_message)
.SendError("Invalid target language string.");
return;
@@ -4517,7 +4517,7 @@ void TestingAutomationProvider::WaitForTabCountToBecome(
void TestingAutomationProvider::WaitForInfoBarCount(
int tab_handle,
- int target_count,
+ size_t target_count,
IPC::Message* reply_message) {
if (!tab_tracker_->ContainsHandle(tab_handle)) {
AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, false);
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index e4a690c..bd42171 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -290,13 +290,13 @@ class TestingAutomationProvider : public AutomationProvider,
bool* success);
// Retrieves the number of info-bars currently showing in |count|.
- void GetInfoBarCount(int handle, int* count);
+ void GetInfoBarCount(int handle, size_t* count);
// Causes a click on the "accept" button of the info-bar at |info_bar_index|.
// If |wait_for_navigation| is true, it sends the reply after a navigation has
// occurred.
void ClickInfoBarAccept(int handle,
- int info_bar_index,
+ size_t info_bar_index,
bool wait_for_navigation,
IPC::Message* reply_message);
@@ -778,7 +778,7 @@ class TestingAutomationProvider : public AutomationProvider,
IPC::Message* reply_message);
void WaitForInfoBarCount(int tab_handle,
- int target_count,
+ size_t target_count,
IPC::Message* reply_message);
// Gets the current used encoding name of the page in the specified tab.
diff --git a/chrome/browser/download/download_request_infobar_delegate.cc b/chrome/browser/download/download_request_infobar_delegate.cc
index 1601b9f..4d39ad3 100644
--- a/chrome/browser/download/download_request_infobar_delegate.cc
+++ b/chrome/browser/download/download_request_infobar_delegate.cc
@@ -15,15 +15,14 @@ DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
DownloadRequestLimiter::TabDownloadState* host)
: ConfirmInfoBarDelegate(tab),
host_(host) {
- if (tab)
- tab->AddInfoBar(this);
}
DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
}
void DownloadRequestInfoBarDelegate::InfoBarClosed() {
- Cancel();
+ if (host_)
+ host_->Cancel();
// This will delete us.
ConfirmInfoBarDelegate::InfoBarClosed();
}
@@ -51,11 +50,3 @@ bool DownloadRequestInfoBarDelegate::Accept() {
return !host_;
}
-
-bool DownloadRequestInfoBarDelegate::Cancel() {
- if (host_) {
- host_->Cancel();
- host_ = NULL;
- }
- return true;
-}
diff --git a/chrome/browser/download/download_request_infobar_delegate.h b/chrome/browser/download/download_request_infobar_delegate.h
index 60d2132..16d3f4b 100644
--- a/chrome/browser/download/download_request_infobar_delegate.h
+++ b/chrome/browser/download/download_request_infobar_delegate.h
@@ -35,7 +35,6 @@ class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual string16 GetMessageText() const;
virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
- virtual bool Cancel();
DownloadRequestLimiter::TabDownloadState* host_;
diff --git a/chrome/browser/download/download_request_infobar_delegate_unittest.cc b/chrome/browser/download/download_request_infobar_delegate_unittest.cc
index 90ec2af..5a8b251 100644
--- a/chrome/browser/download/download_request_infobar_delegate_unittest.cc
+++ b/chrome/browser/download/download_request_infobar_delegate_unittest.cc
@@ -20,6 +20,14 @@ class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState {
ConfirmInfoBarDelegate* infobar() {
return infobar_->AsConfirmInfoBarDelegate();
}
+ void close_infobar() {
+ // TODO(pkasting): Right now InfoBarDelegates delete themselves via
+ // InfoBarClosed(); once InfoBars own their delegates, this can become a
+ // simple reset() call and ~MockTabDownloadState() will no longer need to
+ // call it.
+ if (infobar_ != NULL)
+ infobar_.release()->InfoBarClosed();
+ }
bool responded() const { return responded_; }
bool accepted() const { return accepted_; }
@@ -41,6 +49,7 @@ MockTabDownloadState::MockTabDownloadState()
}
MockTabDownloadState::~MockTabDownloadState() {
+ close_infobar();
EXPECT_TRUE(responded_);
}
@@ -54,6 +63,7 @@ void MockTabDownloadState::Accept() {
EXPECT_FALSE(responded_);
responded_ = true;
accepted_ = true;
+ static_cast<DownloadRequestInfoBarDelegate*>(infobar_.get())->set_host(NULL);
}
@@ -73,6 +83,6 @@ TEST(DownloadRequestInfobarDelegate, CancelTest) {
TEST(DownloadRequestInfobarDelegate, CloseTest) {
MockTabDownloadState state;
- state.infobar()->InfoBarClosed();
+ state.close_infobar();
EXPECT_FALSE(state.accepted());
}
diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc
index fae07c9..075d103 100644
--- a/chrome/browser/download/download_request_limiter.cc
+++ b/chrome/browser/download/download_request_limiter.cc
@@ -1,4 +1,4 @@
-// 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.
@@ -71,6 +71,7 @@ void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload(
NotifyCallbacks(DownloadRequestLimiter::delegate_->ShouldAllowDownload());
} else {
infobar_ = new DownloadRequestInfoBarDelegate(tab, this);
+ tab->AddInfoBar(infobar_);
}
}
diff --git a/chrome/browser/extensions/crashed_extension_infobar.cc b/chrome/browser/extensions/crashed_extension_infobar.cc
index 3e88d28..19db635 100644
--- a/chrome/browser/extensions/crashed_extension_infobar.cc
+++ b/chrome/browser/extensions/crashed_extension_infobar.cc
@@ -50,7 +50,7 @@ CrashedExtensionInfoBarDelegate*
string16 CrashedExtensionInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(IDS_EXTENSION_CRASHED_INFOBAR_MESSAGE,
- UTF8ToUTF16(extension_name_));
+ UTF8ToUTF16(extension_name_));
}
int CrashedExtensionInfoBarDelegate::GetButtons() const {
diff --git a/chrome/browser/extensions/crashed_extension_infobar.h b/chrome/browser/extensions/crashed_extension_infobar.h
index 892a04d..d4d08a7 100644
--- a/chrome/browser/extensions/crashed_extension_infobar.h
+++ b/chrome/browser/extensions/crashed_extension_infobar.h
@@ -29,9 +29,9 @@ class CrashedExtensionInfoBarDelegate : public ConfirmInfoBarDelegate {
const std::string extension_id() { return extension_id_; }
private:
- virtual ~CrashedExtensionInfoBarDelegate();
+ virtual ~CrashedExtensionInfoBarDelegate();
- // ConfirmInfoBarDelegate
+ // ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
const NavigationController::LoadCommittedDetails& details) const;
virtual void InfoBarClosed();
@@ -39,8 +39,7 @@ class CrashedExtensionInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate();
virtual string16 GetMessageText() const;
virtual int GetButtons() const;
- virtual string16 GetButtonLabel(
- ConfirmInfoBarDelegate::InfoBarButton button) const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
ExtensionService* extensions_service_;
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
index bd01595..121bd0f 100644
--- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
+++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
@@ -28,20 +28,20 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
return browser()->profile()->GetExtensionProcessManager();
}
- ConfirmInfoBarDelegate* GetInfoBarDelegate(int index) {
+ ConfirmInfoBarDelegate* GetInfoBarDelegate(size_t index) {
TabContents* current_tab = browser()->GetSelectedTabContents();
- EXPECT_LT(index, current_tab->infobar_delegate_count());
+ EXPECT_LT(index, current_tab->infobar_count());
return current_tab->GetInfoBarDelegateAt(index)->AsConfirmInfoBarDelegate();
}
- void AcceptInfoBar(int index) {
+ void AcceptInfoBar(size_t index) {
ConfirmInfoBarDelegate* infobar = GetInfoBarDelegate(index);
ASSERT_TRUE(infobar);
infobar->Accept();
WaitForExtensionLoad();
}
- void CancelInfoBar(int index) {
+ void CancelInfoBar(size_t index) {
ConfirmInfoBarDelegate* infobar = GetInfoBarDelegate(index);
ASSERT_TRUE(infobar);
infobar->Cancel();
@@ -157,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
// The infobar should automatically hide after the extension is successfully
// reloaded.
- ASSERT_EQ(0, current_tab->infobar_delegate_count());
+ ASSERT_EQ(0U, current_tab->infobar_count());
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -169,14 +169,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
TabContents* original_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(original_tab);
- ASSERT_EQ(1, original_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, original_tab->infobar_count());
// Open a new tab so the info bar will not be in the current tab.
browser()->NewTab();
TabContents* new_current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(new_current_tab);
ASSERT_NE(new_current_tab, original_tab);
- ASSERT_EQ(0, new_current_tab->infobar_delegate_count());
+ ASSERT_EQ(0U, new_current_tab->infobar_count());
ReloadExtension(first_extension_id_);
@@ -185,7 +185,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// The infobar should automatically hide after the extension is successfully
// reloaded.
- ASSERT_EQ(0, original_tab->infobar_delegate_count());
+ ASSERT_EQ(0U, original_tab->infobar_count());
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -197,13 +197,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
// Navigate to another page.
ui_test_utils::NavigateToURL(browser(),
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(FILE_PATH_LITERAL("title1.html"))));
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
ReloadExtension(first_extension_id_);
@@ -212,7 +212,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// The infobar should automatically hide after the extension is successfully
// reloaded.
- ASSERT_EQ(0, current_tab->infobar_delegate_count());
+ ASSERT_EQ(0U, current_tab->infobar_count());
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -228,11 +228,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
TabContents* current_tab2 = browser2->GetSelectedTabContents();
ASSERT_TRUE(current_tab2);
- ASSERT_EQ(1, current_tab2->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab2->infobar_count());
ReloadExtension(first_extension_id_);
@@ -241,8 +241,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// Both infobars should automatically hide after the extension is successfully
// reloaded.
- ASSERT_EQ(0, current_tab->infobar_delegate_count());
- ASSERT_EQ(0, current_tab2->infobar_delegate_count());
+ ASSERT_EQ(0U, current_tab->infobar_count());
+ ASSERT_EQ(0U, current_tab2->infobar_count());
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -258,11 +258,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
TabContents* current_tab2 = browser2->GetSelectedTabContents();
ASSERT_TRUE(current_tab2);
- ASSERT_EQ(1, current_tab2->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab2->infobar_count());
// Move second window into first browser so there will be multiple tabs
// with the info bar for the same extension in one browser.
@@ -270,7 +270,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
browser2->tabstrip_model()->DetachTabContentsAt(0);
browser()->tabstrip_model()->AppendTabContents(contents, true);
current_tab2 = browser()->GetSelectedTabContents();
- ASSERT_EQ(1, current_tab2->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab2->infobar_count());
ASSERT_NE(current_tab2, current_tab);
ReloadExtension(first_extension_id_);
@@ -280,10 +280,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// Both infobars should automatically hide after the extension is successfully
// reloaded.
- ASSERT_EQ(0, current_tab2->infobar_delegate_count());
+ ASSERT_EQ(0U, current_tab2->infobar_count());
browser()->SelectPreviousTab();
ASSERT_EQ(current_tab, browser()->GetSelectedTabContents());
- ASSERT_EQ(0, current_tab->infobar_delegate_count());
+ ASSERT_EQ(0U, current_tab->infobar_count());
}
// Make sure that when we don't do anything about the crashed extension
@@ -422,10 +422,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
// At the beginning we should have one infobar displayed for each extension.
- ASSERT_EQ(2, current_tab->infobar_delegate_count());
+ ASSERT_EQ(2U, current_tab->infobar_count());
ReloadExtension(first_extension_id_);
// One of the infobars should hide after the extension is reloaded.
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
CheckExtensionConsistency(size_before);
}
diff --git a/chrome/browser/extensions/extension_infobar_delegate.h b/chrome/browser/extensions/extension_infobar_delegate.h
index 43ca959..95f73aa 100644
--- a/chrome/browser/extensions/extension_infobar_delegate.h
+++ b/chrome/browser/extensions/extension_infobar_delegate.h
@@ -31,12 +31,13 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
TabContents* contents,
const Extension* extension,
const GURL& url);
+
const Extension* extension() { return extension_; }
ExtensionHost* extension_host() { return extension_host_.get(); }
void set_observer(DelegateObserver* observer) { observer_ = observer; }
- bool closing() { return closing_; }
+ bool closing() const { return closing_; }
private:
virtual ~ExtensionInfoBarDelegate();
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc
index 0ab5692..61e9ce2 100644
--- a/chrome/browser/extensions/extension_install_ui.cc
+++ b/chrome/browser/extensions/extension_install_ui.cc
@@ -248,7 +248,7 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id,
// First find any previous theme preview infobars.
InfoBarDelegate* old_delegate = NULL;
- for (int i = 0; i < tab_contents->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab_contents->infobar_count(); ++i) {
InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i);
ThemeInstalledInfoBarDelegate* theme_infobar =
delegate->AsThemePreviewInfobarDelegate();
diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc
index 327a923..3cf6564 100644
--- a/chrome/browser/extensions/extension_install_ui_browsertest.cc
+++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc
@@ -22,12 +22,12 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest {
void VerifyThemeInfoBarAndUndoInstall() {
TabContents* tab_contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(tab_contents);
- ASSERT_EQ(1, tab_contents->infobar_delegate_count());
+ ASSERT_EQ(1U, tab_contents->infobar_count());
ConfirmInfoBarDelegate* delegate =
tab_contents->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(delegate);
delegate->Cancel();
- ASSERT_EQ(0, tab_contents->infobar_delegate_count());
+ ASSERT_EQ(0U, tab_contents->infobar_count());
}
};
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
index 402e108..308516c 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
@@ -33,7 +33,7 @@ ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
NotificationService::AllSources());
}
-bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) {
+bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) const {
return theme && (theme->id() == theme_id_);
}
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h
index 94db6bb..c565a33 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.h
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h
@@ -24,7 +24,7 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
// Returns true if the given theme is the same as the one associated with this
// info bar.
- bool MatchesTheme(const Extension* theme);
+ bool MatchesTheme(const Extension* theme) const;
protected:
virtual ~ThemeInstalledInfoBarDelegate();
diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc
index a93d9e0..43c2eab 100644
--- a/chrome/browser/geolocation/geolocation_browsertest.cc
+++ b/chrome/browser/geolocation/geolocation_browsertest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -552,12 +552,12 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
iframe_xpath_ = L"//iframe[@id='iframe_1']";
AddGeolocationWatch(true);
- int num_infobars_before_cancel =
- current_browser_->GetSelectedTabContents()->infobar_delegate_count();
+ size_t num_infobars_before_cancel =
+ current_browser_->GetSelectedTabContents()->infobar_count();
// Change the iframe, and ensure the infobar is gone.
IFrameLoader change_iframe_1(current_browser_, 1, current_url_);
- int num_infobars_after_cancel =
- current_browser_->GetSelectedTabContents()->infobar_delegate_count();
+ size_t num_infobars_after_cancel =
+ current_browser_->GetSelectedTabContents()->infobar_count();
EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1);
}
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index 5d52abb..e8f7e4c 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -104,18 +104,11 @@ class GeolocationInfoBarQueueController : NotificationObserver {
PendingInfoBarRequests pending_infobar_requests_;
};
-namespace {
-
-const char kGeolocationLearnMoreUrl[] =
-#if defined(OS_CHROMEOS)
- "http://www.google.com/support/chromeos/bin/answer.py?answer=142065";
-#else
- "http://www.google.com/support/chrome/bin/answer.py?answer=142065";
-#endif
-
// GeolocationConfirmInfoBarDelegate ------------------------------------------
+namespace {
+
class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
GeolocationConfirmInfoBarDelegate(
@@ -218,6 +211,13 @@ string16 GeolocationConfirmInfoBarDelegate::GetLinkText() {
bool GeolocationConfirmInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
+ const char kGeolocationLearnMoreUrl[] =
+#if defined(OS_CHROMEOS)
+ "http://www.google.com/support/chromeos/bin/answer.py?answer=142065";
+#else
+ "http://www.google.com/support/chrome/bin/answer.py?answer=142065";
+#endif
+
// Ignore the click disposition and always open in a new top level tab.
tab_contents_->OpenURL(
google_util::AppendGoogleLocaleParam(GURL(kGeolocationLearnMoreUrl)),
diff --git a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
index d4c214a..92e3124 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -22,6 +22,8 @@
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
+// TestTabContentsWithPendingInfoBar ------------------------------------------
+
namespace {
// TestTabContents short-circuits TAB_CONTENTS_INFOBAR_REMOVED to call
@@ -29,150 +31,175 @@ namespace {
// later.
class TestTabContentsWithPendingInfoBar : public TestTabContents {
public:
- TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance)
- : TestTabContents(profile, instance),
- removed_infobar_delegate_(NULL) {
- }
+ TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance);
+ virtual ~TestTabContentsWithPendingInfoBar();
- void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- // We need to special case TAB_CONTENTS_INFOBAR_REMOVED to track which
- // delegate was removed and avoid calling InfoBarClosed() supplied in the
- // base class. All other notification types are delegated to the base class.
- switch (type.value) {
- case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
- removed_infobar_delegate_ = Details<InfoBarDelegate>(details).ptr();
- break;
- default:
- TestTabContents::Observe(type, source, details);
- break;
- }
- }
+ // TestTabContents:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
InfoBarDelegate* removed_infobar_delegate_;
};
-// This class sets up GeolocationArbitrator and injects
-// TestTabContentsWithPendingInfoBar.
-class GeolocationPermissionContextTests : public RenderViewHostTestHarness {
- public:
- GeolocationPermissionContextTests()
- : RenderViewHostTestHarness(),
- ui_thread_(BrowserThread::UI, MessageLoop::current()),
- tab_contents_with_pending_infobar_(NULL),
- dependency_factory_(
- new GeolocationArbitratorDependencyFactoryWithLocationProvider(
- &NewAutoSuccessMockNetworkLocationProvider)) {
- }
+TestTabContentsWithPendingInfoBar::TestTabContentsWithPendingInfoBar(
+ Profile* profile,
+ SiteInstance* instance)
+ : TestTabContents(profile, instance),
+ removed_infobar_delegate_(NULL) {
+}
- virtual ~GeolocationPermissionContextTests() {
- }
+TestTabContentsWithPendingInfoBar::~TestTabContentsWithPendingInfoBar() {
+}
- // testing::Test
- virtual void SetUp() {
- RenderViewHostTestHarness::SetUp();
- GeolocationArbitrator::SetDependencyFactoryForTest(
- dependency_factory_.get());
-
- SiteInstance* site_instance = contents_->GetSiteInstance();
- tab_contents_with_pending_infobar_ =
- new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance);
- contents_.reset(tab_contents_with_pending_infobar_);
- geolocation_permission_context_ =
- new GeolocationPermissionContext(profile());
- }
+void TestTabContentsWithPendingInfoBar::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED)
+ removed_infobar_delegate_ = Details<InfoBarDelegate>(details).ptr();
+ else
+ TestTabContents::Observe(type, source, details);
+}
- // testing::Test
- virtual void TearDown() {
- GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
- RenderViewHostTestHarness::TearDown();
- }
+} // namespace
- int process_id() {
- return contents()->render_view_host()->process()->id();
- }
+
+// GeolocationPermissionContextTests ------------------------------------------
+
+// This class sets up GeolocationArbitrator.
+class GeolocationPermissionContextTests : public RenderViewHostTestHarness {
+ public:
+ GeolocationPermissionContextTests();
+
+ protected:
+ virtual ~GeolocationPermissionContextTests();
+
+ int process_id() { return contents()->render_view_host()->process()->id(); }
int process_id_for_tab(int tab) {
return extra_tabs_[tab]->render_view_host()->process()->id();
}
-
- int render_id() {
- return contents()->render_view_host()->routing_id();
- }
+ int render_id() { return contents()->render_view_host()->routing_id(); }
int render_id_for_tab(int tab) {
return extra_tabs_[tab]->render_view_host()->routing_id();
}
+ int bridge_id() const { return 42; } // Not relevant at this level.
- int bridge_id() {
- // Bridge id is not relevant at this level.
- return 42;
- }
-
- void CheckPermissionMessageSent(int bridge_id, bool allowed) {
- CheckPermissionMessageSentInternal(process(), bridge_id, allowed);
- }
- void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed) {
- CheckPermissionMessageSentInternal(
- static_cast<MockRenderProcessHost*>(
- extra_tabs_[tab]->render_view_host()->process()),
- bridge_id, allowed);
- }
-
+ void CheckPermissionMessageSent(int bridge_id, bool allowed);
+ void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
int bridge_id,
- bool allowed) {
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
- MessageLoop::current()->Run();
- const IPC::Message* message =
- process->sink().GetFirstMessageMatching(
- ViewMsg_Geolocation_PermissionSet::ID);
- ASSERT_TRUE(message);
- ViewMsg_Geolocation_PermissionSet::Param param;
- ViewMsg_Geolocation_PermissionSet::Read(message, &param);
- EXPECT_EQ(bridge_id, param.a);
- EXPECT_EQ(allowed, param.b);
- process->sink().ClearMessages();
- }
-
- void AddNewTab(const GURL& url) {
- TestTabContentsWithPendingInfoBar* new_tab =
- new TestTabContentsWithPendingInfoBar(profile(), NULL);
- new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED);
- static_cast<TestRenderViewHost*>(new_tab->render_manager()->
- current_host())->SendNavigate(extra_tabs_.size() + 1, url);
- extra_tabs_.push_back(new_tab);
- }
-
+ bool allowed);
+ void AddNewTab(const GURL& url);
void CheckTabContentsState(const GURL& requesting_frame,
- ContentSetting expected_content_setting) {
- TabSpecificContentSettings* content_settings =
- contents()->GetTabSpecificContentSettings();
- const GeolocationSettingsState::StateMap& state_map =
- content_settings->geolocation_settings_state().state_map();
- EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
- EXPECT_EQ(0U, state_map.count(requesting_frame));
- GeolocationSettingsState::StateMap::const_iterator settings =
- state_map.find(requesting_frame.GetOrigin());
- ASSERT_FALSE(settings == state_map.end())
- << "geolocation state not found " << requesting_frame;
- EXPECT_EQ(expected_content_setting, settings->second);
- }
+ ContentSetting expected_content_setting);
- protected:
- BrowserThread ui_thread_;
TestTabContentsWithPendingInfoBar* tab_contents_with_pending_infobar_;
scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
ScopedVector<TestTabContentsWithPendingInfoBar> extra_tabs_;
+
+ private:
+ // RenderViewHostTestHarness:
+ virtual void SetUp();
+ virtual void TearDown();
+
+ BrowserThread ui_thread_;
scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_;
};
+GeolocationPermissionContextTests::GeolocationPermissionContextTests()
+ : RenderViewHostTestHarness(),
+ tab_contents_with_pending_infobar_(NULL),
+ ui_thread_(BrowserThread::UI, MessageLoop::current()),
+ dependency_factory_(
+ new GeolocationArbitratorDependencyFactoryWithLocationProvider(
+ &NewAutoSuccessMockNetworkLocationProvider)) {
+}
+
+GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
+}
+
+void GeolocationPermissionContextTests::CheckPermissionMessageSent(
+ int bridge_id,
+ bool allowed) {
+ CheckPermissionMessageSentInternal(process(), bridge_id, allowed);
+}
+void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab(
+ int tab,
+ int bridge_id,
+ bool allowed) {
+ CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>(
+ extra_tabs_[tab]->render_view_host()->process()), bridge_id, allowed);
+}
+
+void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal(
+ MockRenderProcessHost* process,
+ int bridge_id,
+ bool allowed) {
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+ MessageLoop::current()->Run();
+ const IPC::Message* message = process->sink().GetFirstMessageMatching(
+ ViewMsg_Geolocation_PermissionSet::ID);
+ ASSERT_TRUE(message);
+ ViewMsg_Geolocation_PermissionSet::Param param;
+ ViewMsg_Geolocation_PermissionSet::Read(message, &param);
+ EXPECT_EQ(bridge_id, param.a);
+ EXPECT_EQ(allowed, param.b);
+ process->sink().ClearMessages();
+}
+
+void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
+ TestTabContentsWithPendingInfoBar* new_tab =
+ new TestTabContentsWithPendingInfoBar(profile(), NULL);
+ new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED);
+ static_cast<TestRenderViewHost*>(new_tab->render_manager()->current_host())->
+ SendNavigate(extra_tabs_.size() + 1, url);
+ extra_tabs_.push_back(new_tab);
+}
+
+void GeolocationPermissionContextTests::CheckTabContentsState(
+ const GURL& requesting_frame,
+ ContentSetting expected_content_setting) {
+ TabSpecificContentSettings* content_settings =
+ contents()->GetTabSpecificContentSettings();
+ const GeolocationSettingsState::StateMap& state_map =
+ content_settings->geolocation_settings_state().state_map();
+ EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
+ EXPECT_EQ(0U, state_map.count(requesting_frame));
+ GeolocationSettingsState::StateMap::const_iterator settings =
+ state_map.find(requesting_frame.GetOrigin());
+ ASSERT_FALSE(settings == state_map.end())
+ << "geolocation state not found " << requesting_frame;
+ EXPECT_EQ(expected_content_setting, settings->second);
+}
+
+void GeolocationPermissionContextTests::SetUp() {
+ RenderViewHostTestHarness::SetUp();
+ GeolocationArbitrator::SetDependencyFactoryForTest(
+ dependency_factory_.get());
+ SiteInstance* site_instance = contents_->GetSiteInstance();
+ tab_contents_with_pending_infobar_ =
+ new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance);
+ contents_.reset(tab_contents_with_pending_infobar_);
+ geolocation_permission_context_ =
+ new GeolocationPermissionContext(profile());
+}
+
+void GeolocationPermissionContextTests::TearDown() {
+ GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
+ RenderViewHostTestHarness::TearDown();
+}
+
+
+// Tests ----------------------------------------------------------------------
+
TEST_F(GeolocationPermissionContextTests, SinglePermission) {
GURL requesting_frame("http://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame);
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
}
TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
@@ -186,14 +213,14 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
requesting_frame_1, requesting_frame_0));
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
// Ensure only one infobar is created.
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
ConfirmInfoBarDelegate* infobar_0 =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
@@ -209,7 +236,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
tab_contents_with_pending_infobar_->removed_infobar_delegate_);
infobar_0->InfoBarClosed();
// Now we should have a new infobar for the second frame.
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
ConfirmInfoBarDelegate* infobar_1 =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
@@ -225,7 +252,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
EXPECT_EQ(infobar_1,
tab_contents_with_pending_infobar_->removed_infobar_delegate_);
infobar_1->InfoBarClosed();
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
@@ -246,13 +273,13 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
requesting_frame_1, requesting_frame_0));
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
ConfirmInfoBarDelegate* infobar_0 =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
@@ -266,7 +293,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
EXPECT_EQ(infobar_0,
tab_contents_with_pending_infobar_->removed_infobar_delegate_);
infobar_0->InfoBarClosed();
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
ConfirmInfoBarDelegate* infobar_1 =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
@@ -282,7 +309,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
EXPECT_EQ(infobar_1,
tab_contents_with_pending_infobar_->removed_infobar_delegate_);
infobar_1->InfoBarClosed();
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ASK,
profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
@@ -296,10 +323,10 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) {
GURL invalid_embedder;
GURL requesting_frame("about:blank");
NavigateAndCommit(invalid_embedder);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
CheckPermissionMessageSent(bridge_id(), false);
}
@@ -310,18 +337,18 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
AddNewTab(url_b);
AddNewTab(url_a);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), url_a);
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b);
- EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a);
- EXPECT_EQ(1, extra_tabs_[1]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[1]->infobar_count());
ConfirmInfoBarDelegate* removed_infobar =
extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
@@ -337,13 +364,13 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
tab_contents_with_pending_infobar_->removed_infobar_delegate_);
infobar_0->InfoBarClosed();
// Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0, extra_tabs_[1]->infobar_delegate_count());
+ EXPECT_EQ(0U, extra_tabs_[1]->infobar_count());
CheckPermissionMessageSentForTab(1, bridge_id(), true);
// Destroy the infobar that has just been removed.
removed_infobar->InfoBarClosed();
// But the other tab should still have the info bar...
- EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
extra_tabs_.reset();
}
@@ -353,18 +380,18 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
NavigateAndCommit(url_a);
AddNewTab(url_a);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), url_a);
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a);
- EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b);
- EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
ConfirmInfoBarDelegate* removed_infobar =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
@@ -380,13 +407,13 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
extra_tabs_[0]->removed_infobar_delegate_);
infobar_0->InfoBarClosed();
// Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
CheckPermissionMessageSent(bridge_id(), true);
// Destroy the infobar that has just been removed.
removed_infobar->InfoBarClosed();
// And we should have the queued infobar displayed now.
- EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
// Accept the second infobar.
ConfirmInfoBarDelegate* infobar_1 =
@@ -415,14 +442,14 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
requesting_frame_1, requesting_frame_0));
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
// Ensure only one infobar is created.
- EXPECT_EQ(1, contents()->infobar_delegate_count());
+ EXPECT_EQ(1U, contents()->infobar_count());
ConfirmInfoBarDelegate* infobar_0 =
contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
@@ -431,5 +458,3 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
// Delete the tab contents.
DeleteContents();
}
-
-} // namespace
diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h
index e12ee00..5edc75a 100644
--- a/chrome/browser/google/google_url_tracker.h
+++ b/chrome/browser/google/google_url_tracker.h
@@ -171,7 +171,7 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
GoogleURLTracker* google_url_tracker,
const GURL& new_google_url);
- // ConfirmInfoBarDelegate
+ // ConfirmInfoBarDelegate:
virtual bool Accept();
virtual bool Cancel();
virtual void InfoBarClosed();
@@ -183,7 +183,7 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
const GURL new_google_url_;
private:
- // ConfirmInfoBarDelegate
+ // ConfirmInfoBarDelegate:
virtual string16 GetMessageText() const;
virtual string16 GetButtonLabel(InfoBarButton button) const;
diff --git a/chrome/browser/notifications/notifications_interactive_uitest.cc b/chrome/browser/notifications/notifications_interactive_uitest.cc
index e0925442bc..d2ace68 100644
--- a/chrome/browser/notifications/notifications_interactive_uitest.cc
+++ b/chrome/browser/notifications/notifications_interactive_uitest.cc
@@ -1,4 +1,4 @@
-// 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.
@@ -61,7 +61,7 @@ TEST_F(NotificationsPermissionTest, FLAKY_TestNoUserGestureInfobar) {
"files/notifications/notifications_request_inline.html")));
WaitUntilTabCount(1);
- int info_bar_count;
+ size_t info_bar_count;
ASSERT_TRUE(tab->GetInfoBarCount(&info_bar_count));
- EXPECT_EQ(0, info_bar_count);
+ EXPECT_EQ(0U, info_bar_count);
}
diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc
index 1df6d4f..eed1a48 100644
--- a/chrome/browser/omnibox_search_hint.cc
+++ b/chrome/browser/omnibox_search_hint.cc
@@ -93,6 +93,7 @@ HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint)
method_factory_.NewRunnableMethod(&HintInfoBar::AllowExpiry),
8000); // 8 seconds.
}
+
HintInfoBar::~HintInfoBar() {
}
diff --git a/chrome/browser/plugin_installer_infobar_delegate.cc b/chrome/browser/plugin_installer_infobar_delegate.cc
index 8a035ed..3898e0c 100644
--- a/chrome/browser/plugin_installer_infobar_delegate.cc
+++ b/chrome/browser/plugin_installer_infobar_delegate.cc
@@ -11,7 +11,6 @@
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-#include "webkit/plugins/npapi/default_plugin_shared.h"
PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
TabContents* tab_contents)
@@ -20,27 +19,6 @@ PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
}
PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() {
- // Remove any InfoBars we may be showing.
- tab_contents_->RemoveInfoBar(this);
-}
-
-void PluginInstallerInfoBarDelegate::OnMissingPluginStatus(int status) {
- switch (status) {
- case webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE: {
- tab_contents_->AddInfoBar(this);
- break;
- }
- case webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD: {
- // Hide the InfoBar if user already started download/install of the
- // missing plugin.
- tab_contents_->RemoveInfoBar(this);
- break;
- }
- default: {
- NOTREACHED();
- break;
- }
- }
}
SkBitmap* PluginInstallerInfoBarDelegate::GetIcon() const {
@@ -48,6 +26,11 @@ SkBitmap* PluginInstallerInfoBarDelegate::GetIcon() const {
IDR_INFOBAR_PLUGIN_INSTALL);
}
+PluginInstallerInfoBarDelegate*
+ PluginInstallerInfoBarDelegate::AsPluginInstallerInfoBarDelegate() {
+ return this;
+}
+
string16 PluginInstallerInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_MISSINGPLUGIN_PROMPT);
}
diff --git a/chrome/browser/plugin_installer_infobar_delegate.h b/chrome/browser/plugin_installer_infobar_delegate.h
index a7771c3..631831b 100644
--- a/chrome/browser/plugin_installer_infobar_delegate.h
+++ b/chrome/browser/plugin_installer_infobar_delegate.h
@@ -15,13 +15,13 @@ class TabContents;
class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
explicit PluginInstallerInfoBarDelegate(TabContents* tab_contents);
- virtual ~PluginInstallerInfoBarDelegate();
-
- void OnMissingPluginStatus(int status);
private:
+ virtual ~PluginInstallerInfoBarDelegate();
+
// ConfirmInfoBarDelegate:
virtual SkBitmap* GetIcon() const;
+ virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate();
virtual string16 GetMessageText() const;
virtual int GetButtons() const;
virtual string16 GetButtonLabel(InfoBarButton button) const;
diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc
index d23542ff..058dff2 100644
--- a/chrome/browser/plugin_observer.cc
+++ b/chrome/browser/plugin_observer.cc
@@ -17,79 +17,82 @@
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "webkit/plugins/npapi/default_plugin_shared.h"
#include "webkit/plugins/npapi/plugin_list.h"
#include "webkit/plugins/npapi/webplugininfo.h"
namespace {
-// PluginInfoBar --------------------------------------------------------------
+// PluginInfoBarDelegate ------------------------------------------------------
-class PluginInfoBar : public ConfirmInfoBarDelegate {
+class PluginInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- PluginInfoBar(TabContents* tab_contents, const string16& name);
-
- // ConfirmInfoBarDelegate:
- virtual SkBitmap* GetIcon() const;
- virtual int GetButtons() const;
- virtual string16 GetLinkText();
+ PluginInfoBarDelegate(TabContents* tab_contents, const string16& name);
protected:
- virtual ~PluginInfoBar();
+ virtual ~PluginInfoBarDelegate();
- void CommonCancel();
- void CommonClose();
- void CommonLearnMore(WindowOpenDisposition disposition);
+ virtual void InfoBarClosed();
+ virtual bool Cancel();
+ virtual bool LinkClicked(WindowOpenDisposition disposition);
string16 name_;
TabContents* tab_contents_;
private:
- DISALLOW_COPY_AND_ASSIGN(PluginInfoBar);
+ // ConfirmInfoBarDelegate:
+ virtual SkBitmap* GetIcon() const;
+ virtual string16 GetLinkText();
+
+ DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate);
};
-PluginInfoBar::PluginInfoBar(TabContents* tab_contents, const string16& name)
+PluginInfoBarDelegate::PluginInfoBarDelegate(TabContents* tab_contents,
+ const string16& name)
: ConfirmInfoBarDelegate(tab_contents),
name_(name),
tab_contents_(tab_contents) {
}
-PluginInfoBar::~PluginInfoBar() {
+PluginInfoBarDelegate::~PluginInfoBarDelegate() {
}
-void PluginInfoBar::CommonClose() {
+void PluginInfoBarDelegate::InfoBarClosed() {
delete this;
}
-SkBitmap* PluginInfoBar::GetIcon() const {
- return ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_INFOBAR_PLUGIN_INSTALL);
+bool PluginInfoBarDelegate::Cancel() {
+ tab_contents_->render_view_host()->LoadBlockedPlugins();
+ return true;
}
-int PluginInfoBar::GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL;
+bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
+ // TODO(bauerb): Navigate to a help page explaining why we disabled
+ // or blocked the plugin, once we have one.
+ return false;
}
-void PluginInfoBar::CommonCancel() {
- tab_contents_->render_view_host()->LoadBlockedPlugins();
+SkBitmap* PluginInfoBarDelegate::GetIcon() const {
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_INFOBAR_PLUGIN_INSTALL);
}
-string16 PluginInfoBar::GetLinkText() {
+string16 PluginInfoBarDelegate::GetLinkText() {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
-void PluginInfoBar::CommonLearnMore(WindowOpenDisposition disposition) {
- // TODO(bauerb): Navigate to a help page explaining why we disabled
- // or blocked the plugin, once we have one.
-}
-// BlockedPluginInfoBar -------------------------------------------------------
+// BlockedPluginInfoBarDelegate -----------------------------------------------
-class BlockedPluginInfoBar : public PluginInfoBar {
+class BlockedPluginInfoBarDelegate : public PluginInfoBarDelegate {
public:
- BlockedPluginInfoBar(TabContents* tab_contents,
- const string16& name);
+ BlockedPluginInfoBarDelegate(TabContents* tab_contents,
+ const string16& name);
- // ConfirmInfoBarDelegate:
+ private:
+ virtual ~BlockedPluginInfoBarDelegate();
+
+ // PluginInfoBarDelegate:
virtual string16 GetMessageText() const;
virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
@@ -97,33 +100,30 @@ class BlockedPluginInfoBar : public PluginInfoBar {
virtual void InfoBarClosed();
virtual bool LinkClicked(WindowOpenDisposition disposition);
- protected:
- virtual ~BlockedPluginInfoBar();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar);
+ DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate);
};
-BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents,
- const string16& name)
- : PluginInfoBar(tab_contents, name) {
- tab_contents->AddInfoBar(this);
+BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate(
+ TabContents* tab_contents,
+ const string16& name)
+ : PluginInfoBarDelegate(tab_contents, name) {
UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown"));
}
-BlockedPluginInfoBar::~BlockedPluginInfoBar() {
+BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() {
}
-string16 BlockedPluginInfoBar::GetMessageText() const {
+string16 BlockedPluginInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_);
}
-string16 BlockedPluginInfoBar::GetButtonLabel(InfoBarButton button) const {
+string16 BlockedPluginInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_PLUGIN_ENABLE_ALWAYS : IDS_PLUGIN_ENABLE_TEMPORARILY);
}
-bool BlockedPluginInfoBar::Accept() {
+bool BlockedPluginInfoBarDelegate::Accept() {
UserMetrics::RecordAction(
UserMetricsAction("BlockedPluginInfobar.AlwaysAllow"));
tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL(
@@ -133,34 +133,36 @@ bool BlockedPluginInfoBar::Accept() {
return true;
}
-bool BlockedPluginInfoBar::Cancel() {
+bool BlockedPluginInfoBarDelegate::Cancel() {
UserMetrics::RecordAction(
UserMetricsAction("BlockedPluginInfobar.AllowThisTime"));
- CommonCancel();
- return true;
+ return PluginInfoBarDelegate::Cancel();
}
-void BlockedPluginInfoBar::InfoBarClosed() {
+void BlockedPluginInfoBarDelegate::InfoBarClosed() {
UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
- CommonClose();
+ PluginInfoBarDelegate::InfoBarClosed();
}
-bool BlockedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) {
+bool BlockedPluginInfoBarDelegate::LinkClicked(
+ WindowOpenDisposition disposition) {
UserMetrics::RecordAction(
UserMetricsAction("BlockedPluginInfobar.LearnMore"));
- CommonLearnMore(disposition);
- return false;
+ return PluginInfoBarDelegate::LinkClicked(disposition);
}
-// OutdatedPluginInfoBar ------------------------------------------------------
+// OutdatedPluginInfoBarDelegate ----------------------------------------------
-class OutdatedPluginInfoBar : public PluginInfoBar {
+class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate {
public:
- OutdatedPluginInfoBar(TabContents* tab_contents,
- const string16& name,
- const GURL& update_url);
+ OutdatedPluginInfoBarDelegate(TabContents* tab_contents,
+ const string16& name,
+ const GURL& update_url);
- // ConfirmInfoBarDelegate:
+ private:
+ virtual ~OutdatedPluginInfoBarDelegate();
+
+ // PluginInfoBarDelegate:
virtual string16 GetMessageText() const;
virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
@@ -168,67 +170,68 @@ class OutdatedPluginInfoBar : public PluginInfoBar {
virtual void InfoBarClosed();
virtual bool LinkClicked(WindowOpenDisposition disposition);
- protected:
- virtual ~OutdatedPluginInfoBar();
-
- private:
GURL update_url_;
- DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar);
+ DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate);
};
-OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents,
- const string16& name,
- const GURL& update_url)
- : PluginInfoBar(tab_contents, name), update_url_(update_url) {
- tab_contents->AddInfoBar(this);
+OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate(
+ TabContents* tab_contents,
+ const string16& name,
+ const GURL& update_url)
+ : PluginInfoBarDelegate(tab_contents, name), update_url_(update_url) {
UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown"));
}
-OutdatedPluginInfoBar::~OutdatedPluginInfoBar() {
+OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() {
}
-string16 OutdatedPluginInfoBar::GetMessageText() const {
+string16 OutdatedPluginInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
}
-string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const {
+string16 OutdatedPluginInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY);
}
-bool OutdatedPluginInfoBar::Accept() {
+bool OutdatedPluginInfoBarDelegate::Accept() {
UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update"));
tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB,
PageTransition::LINK);
return false;
}
-bool OutdatedPluginInfoBar::Cancel() {
+bool OutdatedPluginInfoBarDelegate::Cancel() {
UserMetrics::RecordAction(
UserMetricsAction("OutdatedPluginInfobar.AllowThisTime"));
- CommonCancel();
- return true;
+ return PluginInfoBarDelegate::Cancel();
}
-void OutdatedPluginInfoBar::InfoBarClosed() {
+void OutdatedPluginInfoBarDelegate::InfoBarClosed() {
UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
- CommonClose();
+ PluginInfoBarDelegate::InfoBarClosed();
}
-bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) {
+bool OutdatedPluginInfoBarDelegate::LinkClicked(
+ WindowOpenDisposition disposition) {
UserMetrics::RecordAction(
UserMetricsAction("OutdatedPluginInfobar.LearnMore"));
- CommonLearnMore(disposition);
- return false;
+ return PluginInfoBarDelegate::LinkClicked(disposition);
}
} // namespace
+
+// PluginObserver -------------------------------------------------------------
+
PluginObserver::PluginObserver(TabContents* tab_contents)
- : tab_contents_(tab_contents) { }
+ : tab_contents_(tab_contents) {
+}
-PluginObserver::~PluginObserver() { }
+PluginObserver::~PluginObserver() {
+}
bool PluginObserver::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
@@ -243,15 +246,29 @@ bool PluginObserver::OnMessageReceived(const IPC::Message& message) {
}
PluginInstallerInfoBarDelegate* PluginObserver::GetPluginInstaller() {
- if (plugin_installer_.get() == NULL)
+ if (plugin_installer_ == NULL)
plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents_));
- return plugin_installer_.get();
+ return plugin_installer_->AsPluginInstallerInfoBarDelegate();
}
void PluginObserver::OnMissingPluginStatus(int status) {
+ // TODO(PORT): pull in when plug-ins work
#if defined(OS_WIN)
-// TODO(PORT): pull in when plug-ins work
- GetPluginInstaller()->OnMissingPluginStatus(status);
+ if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
+ tab_contents_->AddInfoBar(
+ new PluginInstallerInfoBarDelegate(tab_contents_));
+ return;
+ }
+
+ DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD,
+ status);
+ for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
+ InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
+ if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) {
+ tab_contents_->RemoveInfoBar(delegate);
+ return;
+ }
+ }
#endif
}
@@ -274,17 +291,17 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) {
}
SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
IDR_INFOBAR_PLUGIN_CRASHED);
- tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(
- tab_contents_, crash_icon,
+ tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents_,
+ crash_icon,
l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
true));
}
void PluginObserver::OnBlockedOutdatedPlugin(const string16& name,
- const GURL& update_url) {
- if (!update_url.is_empty())
- new OutdatedPluginInfoBar(tab_contents_, name, update_url);
- else
- new BlockedPluginInfoBar(tab_contents_, name);
+ const GURL& update_url) {
+ tab_contents_->AddInfoBar(update_url.is_empty() ?
+ static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate(
+ tab_contents_, name)) :
+ new OutdatedPluginInfoBarDelegate(tab_contents_, name, update_url));
}
diff --git a/chrome/browser/plugin_observer.h b/chrome/browser/plugin_observer.h
index 97f0295..9f7a6be 100644
--- a/chrome/browser/plugin_observer.h
+++ b/chrome/browser/plugin_observer.h
@@ -10,6 +10,7 @@
class FilePath;
class GURL;
+class InfoBarDelegate;
class PluginInstallerInfoBarDelegate;
class TabContents;
@@ -30,8 +31,7 @@ class PluginObserver : public TabContentsObserver {
void OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url);
TabContents* tab_contents_; // Weak, owns us.
- // PluginInstallerInfoBarDelegate, lazily created.
- scoped_ptr<PluginInstallerInfoBarDelegate> plugin_installer_;
+ scoped_ptr<InfoBarDelegate> plugin_installer_; // Lazily created.
DISALLOW_COPY_AND_ASSIGN(PluginObserver);
};
diff --git a/chrome/browser/tab_contents/infobar_delegate.cc b/chrome/browser/tab_contents/infobar_delegate.cc
index 6a5eeae..b6115d1 100644
--- a/chrome/browser/tab_contents/infobar_delegate.cc
+++ b/chrome/browser/tab_contents/infobar_delegate.cc
@@ -59,6 +59,11 @@ LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() {
return NULL;
}
+PluginInstallerInfoBarDelegate*
+ InfoBarDelegate::AsPluginInstallerInfoBarDelegate() {
+ return NULL;
+}
+
ThemeInstalledInfoBarDelegate*
InfoBarDelegate::AsThemePreviewInfobarDelegate() {
return NULL;
diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h
index 889fbf4..04b58b2 100644
--- a/chrome/browser/tab_contents/infobar_delegate.h
+++ b/chrome/browser/tab_contents/infobar_delegate.h
@@ -16,6 +16,7 @@ class CrashedExtensionInfoBarDelegate;
class ExtensionInfoBarDelegate;
class InfoBar;
class LinkInfoBarDelegate;
+class PluginInstallerInfoBarDelegate;
class SkBitmap;
class ThemeInstalledInfoBarDelegate;
class TranslateInfoBarDelegate;
@@ -91,6 +92,7 @@ class InfoBarDelegate {
virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate();
virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
+ virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate();
virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2f946be..f8828a1 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -413,7 +413,7 @@ TabContents::~TabContents() {
// notification may trigger infobars calls that access their delegate. (and
// some implementations of InfoBarDelegate do delete themselves on
// InfoBarClosed()).
- for (int i = 0; i < infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < infobar_count(); ++i) {
InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
delegate->InfoBarClosed();
}
@@ -1115,7 +1115,7 @@ void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
// Look through the existing InfoBarDelegates we have for a match. If we've
// already got one that matches, then we don't add the new one.
- for (int i = 0; i < infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < infobar_count(); ++i) {
if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
// Tell the new infobar to close so that it can clean itself up.
delegate->InfoBarClosed();
@@ -1721,8 +1721,11 @@ void TabContents::ExpireInfoBars(
if (!details.is_user_initiated_main_frame_load())
return;
- for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
- InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
+ // NOTE: It is not safe to change the following code to count upwards or use
+ // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
+ // list.
+ for (size_t i = infobar_count(); i > 0; --i) {
+ InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
if (delegate->ShouldExpire(details))
RemoveInfoBar(delegate);
}
@@ -2306,8 +2309,8 @@ void TabContents::RenderViewGone(RenderViewHost* rvh,
SetIsCrashed(status, error_code);
// Remove all infobars.
- for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
- RemoveInfoBar(GetInfoBarDelegateAt(i));
+ while (!infobar_delegates_.empty())
+ RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
// Tell the view that we've crashed so it can prepare the sad tab page.
// Only do this if we're not in browser shutdown, so that TabContents
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 918b063..f9b34c8 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -480,9 +480,10 @@ class TabContents : public PageNavigator,
InfoBarDelegate* new_delegate);
// Enumeration and access functions.
- int infobar_delegate_count() const { return infobar_delegates_.size(); }
- InfoBarDelegate* GetInfoBarDelegateAt(int index) {
- return infobar_delegates_.at(index);
+ size_t infobar_count() const { return infobar_delegates_.size(); }
+ // WARNING: This does not sanity-check |index|!
+ InfoBarDelegate* GetInfoBarDelegateAt(size_t index) {
+ return infobar_delegates_[index];
}
// Toolbars and such ---------------------------------------------------------
diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
index aaf7c4f..8dba414 100644
--- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
+++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
@@ -49,10 +49,8 @@ class SSLCertAddedInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
- // The TabContents we are attached to
- TabContents* tab_contents_;
- // The cert we added.
- scoped_refptr<net::X509Certificate> cert_;
+ TabContents* tab_contents_; // The TabContents we are attached to.
+ scoped_refptr<net::X509Certificate> cert_; // The cert we added.
};
SSLCertAddedInfoBarDelegate::SSLCertAddedInfoBarDelegate(
@@ -107,7 +105,7 @@ bool SSLCertAddedInfoBarDelegate::Accept() {
class TabContentsSSLHelper::SSLAddCertData : public NotificationObserver {
public:
- SSLAddCertData(TabContents* tab, SSLAddCertHandler* handler);
+ explicit SSLAddCertData(TabContents* tab);
virtual ~SSLAddCertData();
// Displays |delegate| as an infobar in |tab_|, replacing our current one if
@@ -125,17 +123,14 @@ class TabContentsSSLHelper::SSLAddCertData : public NotificationObserver {
const NotificationDetails& details);
TabContents* tab_contents_;
- scoped_refptr<SSLAddCertHandler> handler_; // The handler we call back to.
InfoBarDelegate* infobar_delegate_;
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
};
-TabContentsSSLHelper::SSLAddCertData::SSLAddCertData(TabContents* tab_contents,
- SSLAddCertHandler* handler)
+TabContentsSSLHelper::SSLAddCertData::SSLAddCertData(TabContents* tab_contents)
: tab_contents_(tab_contents),
- handler_(handler),
infobar_delegate_(NULL) {
Source<TabContents> source(tab_contents_);
registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source);
@@ -236,6 +231,6 @@ TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData(
request_id_to_add_cert_data_[handler->network_request_id()];
// Fill it if necessary.
if (!ptr_ref.get())
- ptr_ref.reset(new SSLAddCertData(tab_contents_, handler));
+ ptr_ref.reset(new SSLAddCertData(tab_contents_));
return ptr_ref.get();
}
diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc
index b385525..4243aba 100644
--- a/chrome/browser/task_manager/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest.cc
@@ -385,7 +385,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
// manager is still visible. Make sure we don't crash and the extension
// gets reloaded and noticed in the task manager.
TabContents* current_tab = browser()->GetSelectedTabContents();
- ASSERT_EQ(1, current_tab->infobar_delegate_count());
+ ASSERT_EQ(1U, current_tab->infobar_count());
ConfirmInfoBarDelegate* delegate =
current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(delegate);
diff --git a/chrome/browser/translate/languages_menu_model.cc b/chrome/browser/translate/languages_menu_model.cc
index bd3ec10..8e5eb436 100644
--- a/chrome/browser/translate/languages_menu_model.cc
+++ b/chrome/browser/translate/languages_menu_model.cc
@@ -13,22 +13,23 @@ LanguagesMenuModel::LanguagesMenuModel(
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
translate_infobar_delegate_(translate_delegate),
language_type_(language_type) {
- for (int i = 0; i < translate_delegate->GetLanguageCount(); ++i)
- AddCheckItem(i, translate_delegate->GetLanguageDisplayableNameAt(i));
+ for (size_t i = 0; i < translate_delegate->GetLanguageCount(); ++i)
+ AddCheckItem(static_cast<int>(i),
+ translate_delegate->GetLanguageDisplayableNameAt(i));
}
LanguagesMenuModel::~LanguagesMenuModel() {
}
bool LanguagesMenuModel::IsCommandIdChecked(int command_id) const {
- return command_id == ((language_type_ == ORIGINAL) ?
+ return static_cast<size_t>(command_id) == ((language_type_ == ORIGINAL) ?
translate_infobar_delegate_->original_language_index() :
translate_infobar_delegate_->target_language_index());
}
bool LanguagesMenuModel::IsCommandIdEnabled(int command_id) const {
// Prevent the same language from being selectable in original and target.
- return command_id != ((language_type_ == ORIGINAL) ?
+ return static_cast<size_t>(command_id) != ((language_type_ == ORIGINAL) ?
translate_infobar_delegate_->target_language_index() :
translate_infobar_delegate_->original_language_index());
}
@@ -40,11 +41,12 @@ bool LanguagesMenuModel::GetAcceleratorForCommandId(
}
void LanguagesMenuModel::ExecuteCommand(int command_id) {
+ size_t command_id_size_t = static_cast<size_t>(command_id);
if (language_type_ == ORIGINAL) {
UMA_HISTOGRAM_COUNTS("Translate.ModifyOriginalLang", 1);
- translate_infobar_delegate_->SetOriginalLanguage(command_id);
+ translate_infobar_delegate_->SetOriginalLanguage(command_id_size_t);
return;
}
UMA_HISTOGRAM_COUNTS("Translate.ModifyTargetLang", 1);
- translate_infobar_delegate_->SetTargetLanguage(command_id);
+ translate_infobar_delegate_->SetTargetLanguage(command_id_size_t);
}
diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc
index c803b19..0d9b688 100644
--- a/chrome/browser/translate/translate_infobar_delegate.cc
+++ b/chrome/browser/translate/translate_infobar_delegate.cc
@@ -19,6 +19,9 @@
#include "ui/base/resource/resource_bundle.h"
// static
+const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1);
+
+// static
TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateDelegate(
Type type,
TabContents* tab_contents,
@@ -37,7 +40,7 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateDelegate(
TranslateInfoBarDelegate* delegate =
new TranslateInfoBarDelegate(type, TranslateErrors::NONE, tab_contents,
original_language, target_language);
- DCHECK_NE(-1, delegate->target_language_index());
+ DCHECK_NE(kNoIndex, delegate->target_language_index());
return delegate;
}
@@ -53,19 +56,19 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateErrorDelegate(
TranslateInfoBarDelegate::~TranslateInfoBarDelegate() {
}
-std::string TranslateInfoBarDelegate::GetLanguageCodeAt(int index) const {
- DCHECK(index >= 0 && index < GetLanguageCount());
+std::string TranslateInfoBarDelegate::GetLanguageCodeAt(size_t index) const {
+ DCHECK_LT(index, GetLanguageCount());
return languages_[index].first;
}
string16 TranslateInfoBarDelegate::GetLanguageDisplayableNameAt(
- int index) const {
- DCHECK(index >= 0 && index < GetLanguageCount());
+ size_t index) const {
+ DCHECK_LT(index, GetLanguageCount());
return languages_[index].second;
}
std::string TranslateInfoBarDelegate::GetOriginalLanguageCode() const {
- return (original_language_index() == -1) ?
+ return (original_language_index() == kNoIndex) ?
chrome::kUnknownLanguageCode :
GetLanguageCodeAt(original_language_index());
}
@@ -74,7 +77,7 @@ std::string TranslateInfoBarDelegate::GetTargetLanguageCode() const {
return GetLanguageCodeAt(target_language_index());
}
-void TranslateInfoBarDelegate::SetOriginalLanguage(int language_index) {
+void TranslateInfoBarDelegate::SetOriginalLanguage(size_t language_index) {
DCHECK_LT(language_index, GetLanguageCount());
original_language_index_ = language_index;
if (infobar_view_)
@@ -83,7 +86,7 @@ void TranslateInfoBarDelegate::SetOriginalLanguage(int language_index) {
Translate();
}
-void TranslateInfoBarDelegate::SetTargetLanguage(int language_index) {
+void TranslateInfoBarDelegate::SetTargetLanguage(size_t language_index) {
DCHECK_LT(language_index, GetLanguageCount());
target_language_index_ = language_index;
if (infobar_view_)
@@ -306,9 +309,9 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
type_(type),
background_animation_(NONE),
tab_contents_(tab_contents),
- original_language_index_(-1),
- initial_original_language_index_(-1),
- target_language_index_(-1),
+ original_language_index_(kNoIndex),
+ initial_original_language_index_(kNoIndex),
+ target_language_index_(kNoIndex),
error_(error),
infobar_view_(NULL),
prefs_(tab_contents_->profile()->GetPrefs()) {
@@ -362,7 +365,7 @@ SkBitmap* TranslateInfoBarDelegate::GetIcon() const {
}
InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const {
- return InfoBarDelegate::PAGE_ACTION_TYPE;
+ return PAGE_ACTION_TYPE;
}
TranslateInfoBarDelegate*
diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/chrome/browser/translate/translate_infobar_delegate.h
index 1bc8a98..5dd2e73 100644
--- a/chrome/browser/translate/translate_infobar_delegate.h
+++ b/chrome/browser/translate/translate_infobar_delegate.h
@@ -33,6 +33,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
ERROR_TO_NORMAL
};
+ static const size_t kNoIndex;
+
// Factory method to create a non-error translate infobar.
// The original and target language specified are the ASCII language codes
// (ex: en, fr...).
@@ -54,13 +56,13 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
virtual ~TranslateInfoBarDelegate();
// Returns the number of languages supported.
- int GetLanguageCount() const { return static_cast<int>(languages_.size()); }
+ size_t GetLanguageCount() const { return languages_.size(); }
// Returns the ISO code for the language at |index|.
- std::string GetLanguageCodeAt(int index) const;
+ std::string GetLanguageCodeAt(size_t index) const;
// Returns the displayable name for the language at |index|.
- string16 GetLanguageDisplayableNameAt(int index) const;
+ string16 GetLanguageDisplayableNameAt(size_t index) const;
TabContents* tab_contents() const { return tab_contents_; }
@@ -68,8 +70,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
TranslateErrors::Type error() const { return error_; }
- int original_language_index() const { return original_language_index_; }
- int target_language_index() const { return target_language_index_; }
+ size_t original_language_index() const { return original_language_index_; }
+ size_t target_language_index() const { return target_language_index_; }
// Convenience methods.
std::string GetOriginalLanguageCode() const;
@@ -77,8 +79,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
// Called by the InfoBar to notify that the original/target language has
// changed and is now the language at |language_index|.
- virtual void SetOriginalLanguage(int language_index);
- virtual void SetTargetLanguage(int language_index);
+ virtual void SetOriginalLanguage(size_t language_index);
+ virtual void SetTargetLanguage(size_t language_index);
// Returns true if the current infobar indicates an error (in which case it
// should get a yellow background instead of a blue one).
@@ -156,7 +158,7 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
private:
typedef std::pair<std::string, string16> LanguageNamePair;
- // InfoBarDelegate implementation:
+ // InfoBarDelegate:
virtual InfoBar* CreateInfoBar();
virtual void InfoBarDismissed();
virtual void InfoBarClosed();
@@ -181,17 +183,17 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
std::vector<LanguageNamePair> languages_;
// The index for language the page is originally in.
- int original_language_index_;
+ size_t original_language_index_;
// The index for language the page is originally in that was originally
// reported (original_language_index_ changes if the user selects a new
// original language, but this one does not). This is necessary to report
// language detection errors with the right original language even if the user
// changed the original language.
- int initial_original_language_index_;
+ size_t initial_original_language_index_;
// The index for language the page should be translated to.
- int target_language_index_;
+ size_t target_language_index_;
// The error that occurred when trying to translate (NONE if no error).
TranslateErrors::Type error_;
diff --git a/chrome/browser/translate/translate_infobar_view.h b/chrome/browser/translate/translate_infobar_view.h
index 2b4af28..e9b282f 100644
--- a/chrome/browser/translate/translate_infobar_view.h
+++ b/chrome/browser/translate/translate_infobar_view.h
@@ -1,4 +1,4 @@
-// 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.
@@ -10,8 +10,8 @@
// sense) of the TranslateInfoBarDelegate (which is the model).
class TranslateInfoBarView {
public:
- virtual void OriginalLanguageChanged() = 0;
- virtual void TargetLanguageChanged() = 0;
+ virtual void OriginalLanguageChanged() {}
+ virtual void TargetLanguageChanged() {}
protected:
virtual ~TranslateInfoBarView() {}
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index a07a52a..9146f3d 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -631,7 +631,7 @@ std::string TranslateManager::GetTargetLanguage() {
// static
TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate(
TabContents* tab) {
- for (int i = 0; i < tab->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab->infobar_count(); ++i) {
TranslateInfoBarDelegate* delegate =
tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate();
if (delegate)
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 11087f2..d093b38 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -86,7 +86,7 @@ class TranslateManagerTest : public RenderViewHostTestHarness,
// Returns the translate infobar if there is 1 infobar and it is a translate
// infobar.
TranslateInfoBarDelegate* GetTranslateInfoBar() {
- return (contents()->infobar_delegate_count() == 1) ?
+ return (contents()->infobar_count() == 1) ?
contents()->GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate() :
NULL;
}
@@ -545,21 +545,21 @@ TEST_F(TranslateManagerTest, MultipleOnPageContents) {
// Simulate clicking 'Nope' (don't translate).
EXPECT_TRUE(DenyTranslation());
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Send a new PageContents, we should not show an infobar.
SimulateOnPageContents(GURL("http://www.google.fr"), 0, "Le Google", "fr",
true);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Do the same steps but simulate closing the infobar this time.
SimulateNavigation(GURL("http://www.youtube.fr"), "Le YouTube", "fr",
true);
EXPECT_TRUE(CloseTranslateInfoBar());
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr",
true);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
}
// Test that reloading the page brings back the infobar.
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index d5bffbc..fa9a5cbb 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -3344,7 +3344,7 @@ void Browser::Observe(NotificationType type,
TabStripModel* model = tab_handler_->GetTabStripModel();
for (int m = 0; m < model->count(); ++m) {
TabContents* tab_contents = model->GetTabContentsAt(m)->tab_contents();
- for (int i = 0; i < tab_contents->infobar_delegate_count(); ) {
+ for (size_t i = 0; i < tab_contents->infobar_count(); ) {
CrashedExtensionInfoBarDelegate* delegate = tab_contents->
GetInfoBarDelegateAt(i)->AsCrashedExtensionInfoBarDelegate();
if (delegate && delegate->extension_id() == extension->id())
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index ed30dff..f062f37 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -148,7 +148,6 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual bool Accept();
virtual bool Cancel();
- private:
// The Profile that we restore sessions from.
Profile* profile_;
@@ -256,7 +255,7 @@ void NotifyNotDefaultBrowserTask::Run() {
// In ChromeBot tests, there might be a race. This line appears to get
// called during shutdown and |tab| can be NULL.
TabContents* tab = browser->GetSelectedTabContents();
- if (!tab || tab->infobar_delegate_count() > 0)
+ if (!tab || tab->infobar_count() > 0)
return;
tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab));
}
@@ -295,8 +294,7 @@ void CheckDefaultBrowserTask::Run() {
// SessionCrashedInfoBarDelegate ----------------------------------------------
-// A delegate for the InfoBar shown when the previous session has crashed. The
-// bar deletes itself automatically after it is closed.
+// A delegate for the InfoBar shown when the previous session has crashed.
class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
explicit SessionCrashedInfoBarDelegate(TabContents* contents);
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
index 68562a9..3d65217 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
+++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm
@@ -126,7 +126,7 @@ class InfoBarNotificationObserver : public NotificationObserver {
currentTabContents_ = contents;
if (currentTabContents_) {
- for (int i = 0; i < currentTabContents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) {
[self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i)
animate:NO];
}
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
index e14e0dd..aca76f9 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
+++ b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h
@@ -28,7 +28,7 @@ class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
static const char kLink[];
private:
- // LinkInfoBarDelegate
+ // LinkInfoBarDelegate:
virtual void InfoBarClosed();
virtual SkBitmap* GetIcon() const;
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const;
@@ -68,7 +68,7 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
static const char kMessage[];
private:
- // ConfirmInfoBarDelegate
+ // ConfirmInfoBarDelegate:
virtual void InfoBarClosed();
virtual SkBitmap* GetIcon() const;
virtual string16 GetMessageText() const;
diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm
index ff910bd..7b2c235 100644
--- a/chrome/browser/ui/cocoa/keystone_infobar.mm
+++ b/chrome/browser/ui/cocoa/keystone_infobar.mm
@@ -195,7 +195,7 @@ bool KeystonePromotionInfoBarDelegate::Cancel() {
// Only show if no other info bars are showing, because that's how the
// default browser info bar works.
- if (tabContents && tabContents->infobar_delegate_count() == 0) {
+ if (tabContents && tabContents->infobar_count() == 0) {
tabContents->AddInfoBar(
new KeystonePromotionInfoBarDelegate(tabContents));
}
diff --git a/chrome/browser/ui/cocoa/tabpose_window.mm b/chrome/browser/ui/cocoa/tabpose_window.mm
index 41283b8..22aa6ad 100644
--- a/chrome/browser/ui/cocoa/tabpose_window.mm
+++ b/chrome/browser/ui/cocoa/tabpose_window.mm
@@ -1,4 +1,4 @@
-// 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.
@@ -189,7 +189,7 @@ void ThumbnailLoader::LoadThumbnail() {
// means I need to create InfoBarControllers here. At that point, we can get
// the height from that controller. Until then, hardcode. :-/
const int kInfoBarHeight = 31;
- topOffset += contents_->infobar_delegate_count() * kInfoBarHeight;
+ topOffset += contents_->infobar_count() * kInfoBarHeight;
bool always_show_bookmark_bar =
contents_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
diff --git a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
index 4b94e89..5cac0a9 100644
--- a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
+++ b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm
@@ -216,20 +216,22 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
}
- (void)sourceLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->original_language_index())
+ size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
+ DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
+ if (newLanguageIdxSizeT == [self delegate]->original_language_index())
return;
- [self delegate]->SetOriginalLanguage(newLanguageIdx);
+ [self delegate]->SetOriginalLanguage(newLanguageIdxSizeT);
int commandId = IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE + newLanguageIdx;
int newMenuIdx = [fromLanguagePopUp_ indexOfItemWithTag:commandId];
[fromLanguagePopUp_ selectItemAtIndex:newMenuIdx];
}
- (void)targetLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->target_language_index())
+ size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
+ DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
+ if (newLanguageIdxSizeT == [self delegate]->target_language_index())
return;
- [self delegate]->SetTargetLanguage(newLanguageIdx);
+ [self delegate]->SetTargetLanguage(newLanguageIdxSizeT);
int commandId = IDC_TRANSLATE_TARGET_LANGUAGE_BASE + newLanguageIdx;
int newMenuIdx = [toLanguagePopUp_ indexOfItemWithTag:commandId];
[toLanguagePopUp_ selectItemAtIndex:newMenuIdx];
@@ -355,7 +357,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NSMenu* originalLanguageMenu = [fromLanguagePopUp_ menu];
[originalLanguageMenu setAutoenablesItems:NO];
int selectedMenuIndex = 0;
- int selectedLangIndex = [self delegate]->original_language_index();
+ int selectedLangIndex =
+ static_cast<int>([self delegate]->original_language_index());
for (int i = 0; i < originalLanguageMenuModel_->GetItemCount(); ++i) {
NSString* title = base::SysUTF16ToNSString(
originalLanguageMenuModel_->GetLabelAt(i));
@@ -377,7 +380,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NSMenu* targetLanguageMenu = [toLanguagePopUp_ menu];
[targetLanguageMenu setAutoenablesItems:NO];
- selectedLangIndex = [self delegate]->target_language_index();
+ selectedLangIndex =
+ static_cast<int>([self delegate]->target_language_index());
for (int i = 0; i < targetLanguageMenuModel_->GetItemCount(); ++i) {
NSString* title = base::SysUTF16ToNSString(
targetLanguageMenuModel_->GetLabelAt(i));
diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
index a0b7376..e1a3608 100644
--- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
+++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
@@ -139,7 +139,7 @@ void InfoBarContainerGtk::Observe(NotificationType type,
// InfoBarContainerGtk, private: -----------------------------------------------
void InfoBarContainerGtk::UpdateInfoBars() {
- for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
AddInfoBar(delegate, false);
}
@@ -201,7 +201,7 @@ void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate,
}
InfoBarDelegate* next_delegate = NULL;
- for (int i = 1; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 1; i < tab_contents_->infobar_count(); ++i) {
if (tab_contents_->GetInfoBarDelegateAt(i - 1) == delegate) {
next_delegate = tab_contents_->GetInfoBarDelegateAt(i);
break;
@@ -211,8 +211,8 @@ void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate,
ShowArrowForDelegate(next_delegate, animate);
}
-void InfoBarContainerGtk::UpdateToolbarInfoBarState(
- InfoBar* infobar, bool animate) {
+void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar,
+ bool animate) {
GtkWindow* parent = platform_util::GetTopLevel(widget());
BrowserWindowGtk* browser_window =
BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
diff --git a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
index 4b6f489..3eeec4e 100644
--- a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.cc
@@ -69,7 +69,7 @@ bool AfterTranslateInfoBar::ShowOptionsMenuButton() const {
}
void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->original_language_index())
return;
@@ -81,7 +81,7 @@ void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) {
}
void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->target_language_index())
return;
@@ -94,10 +94,10 @@ void AfterTranslateInfoBar::OnRevertPressed(GtkWidget* sender) {
GetDelegate()->RevertTranslation();
}
-void AfterTranslateInfoBar::SetOriginalLanguage(int language_index) {
+void AfterTranslateInfoBar::SetOriginalLanguage(size_t language_index) {
GetDelegate()->SetOriginalLanguage(language_index);
}
-void AfterTranslateInfoBar::SetTargetLanguage(int language_index) {
+void AfterTranslateInfoBar::SetTargetLanguage(size_t language_index) {
GetDelegate()->SetTargetLanguage(language_index);
}
diff --git a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
index 201a4c0..0f5d5fe 100644
--- a/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
+++ b/chrome/browser/ui/gtk/translate/after_translate_infobar_gtk.h
@@ -29,8 +29,8 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase {
// These methods set the original/target language on the
// TranslateInfobarDelegate.
- void SetOriginalLanguage(int language_index);
- void SetTargetLanguage(int language_index);
+ void SetOriginalLanguage(size_t language_index);
+ void SetTargetLanguage(size_t language_index);
ScopedRunnableMethodFactory<AfterTranslateInfoBar> method_factory_;
diff --git a/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
index 20a14c7..c3cdc12 100644
--- a/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/before_translate_infobar_gtk.cc
@@ -80,7 +80,7 @@ bool BeforeTranslateInfoBar::ShowOptionsMenuButton() const {
}
void BeforeTranslateInfoBar::OnLanguageModified(GtkWidget* sender) {
- int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
+ size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender));
if (index == GetDelegate()->original_language_index())
return;
diff --git a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
index 9457ae6..5b0182c 100644
--- a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
+++ b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc
@@ -134,14 +134,15 @@ GtkWidget* TranslateInfoBarBase::CreateLabel(const std::string& text) {
return label;
}
-GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(int selected_language,
- int exclude_language) {
+GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(
+ size_t selected_language,
+ size_t exclude_language) {
GtkListStore* model = gtk_list_store_new(LANGUAGE_COMBO_COLUMN_COUNT,
G_TYPE_INT, G_TYPE_STRING);
bool set_selection = false;
GtkTreeIter selected_iter;
TranslateInfoBarDelegate* delegate = GetDelegate();
- for (int i = 0; i < delegate->GetLanguageCount(); ++i) {
+ for (size_t i = 0; i < delegate->GetLanguageCount(); ++i) {
if (i == exclude_language)
continue;
GtkTreeIter tree_iter;
@@ -171,7 +172,7 @@ GtkWidget* TranslateInfoBarBase::CreateLanguageCombobox(int selected_language,
}
// static
-int TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
+size_t TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
GtkTreeIter iter;
if (!gtk_combo_box_get_active_iter(combo, &iter))
return 0;
@@ -180,7 +181,7 @@ int TranslateInfoBarBase::GetLanguageComboboxActiveId(GtkComboBox* combo) {
gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter,
LANGUAGE_COMBO_COLUMN_ID, &id,
-1);
- return id;
+ return static_cast<size_t>(id);
}
TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const {
@@ -234,8 +235,5 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
NOTREACHED();
}
infobar->Init();
- // Set |infobar_view_| so that the model can notify the infobar when it
- // changes.
- infobar_view_ = infobar;
return infobar;
}
diff --git a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
index 65b6488..f35ffd5 100644
--- a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
+++ b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.h
@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_GTK_TRANSLATE_TRANSLATE_INFOBAR_BASE_GTK_H_
#pragma once
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/gtk/infobars/infobar_gtk.h"
#include "ui/base/animation/animation_delegate.h"
@@ -16,8 +15,7 @@ class TranslateInfoBarDelegate;
// This class contains some of the base functionality that translate infobars
// use.
-class TranslateInfoBarBase : public TranslateInfoBarView,
- public InfoBar,
+class TranslateInfoBarBase : public InfoBar,
public ui::AnimationDelegate {
public:
explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate);
@@ -33,10 +31,6 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
virtual void GetBottomColor(InfoBarDelegate::Type type,
double* r, double* g, double *b);
- // Overridden from TranslateInfoBarView:
- virtual void OriginalLanguageChanged() {}
- virtual void TargetLanguageChanged() {}
-
// Overridden from ui::AnimationDelegate:
virtual void AnimationProgressed(const ui::Animation* animation);
@@ -53,13 +47,14 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
// |selected_language| is the language index (as used in the
// TranslateInfoBarDelegate) that should be selected initially.
// |exclude_language| is the language index of the language that should not be
- // included in the list (-1 means no language excluded).
- GtkWidget* CreateLanguageCombobox(int selected_language,
- int exclude_language);
+ // included in the list (TranslateInfoBarDelegate::kNoIndex means no language
+ // excluded).
+ GtkWidget* CreateLanguageCombobox(size_t selected_language,
+ size_t exclude_language);
// Given an above-constructed combobox, returns the currently selected
// language id.
- static int GetLanguageComboboxActiveId(GtkComboBox* combo);
+ static size_t GetLanguageComboboxActiveId(GtkComboBox* combo);
// Convenience to retrieve the TranslateInfoBarDelegate for this infobar.
TranslateInfoBarDelegate* GetDelegate() const;
diff --git a/chrome/browser/ui/views/extensions/extension_view.cc b/chrome/browser/ui/views/extensions/extension_view.cc
index 9fa7603..d6ff1c4 100644
--- a/chrome/browser/ui/views/extensions/extension_view.cc
+++ b/chrome/browser/ui/views/extensions/extension_view.cc
@@ -171,9 +171,8 @@ void ExtensionView::ViewHierarchyChanged(bool is_add,
void ExtensionView::PreferredSizeChanged() {
View::PreferredSizeChanged();
- if (container_) {
+ if (container_)
container_->OnExtensionPreferredSizeChanged(this);
- }
}
bool ExtensionView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
index b7eea3d..5a91252 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc
@@ -26,34 +26,34 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
options_menu_model_(delegate),
swapped_language_buttons_(false) {
std::vector<string16> strings;
- TranslateInfoBarDelegate::GetAfterTranslateStrings(
- &strings, &swapped_language_buttons_);
- DCHECK(strings.size() == 3U);
+ GetDelegate()->GetAfterTranslateStrings(&strings, &swapped_language_buttons_);
+ DCHECK_EQ(3U, strings.size());
label_1_ = CreateLabel(strings[0]);
AddChildView(label_1_);
+ original_language_menu_button_ = CreateMenuButton(string16(), true, this);
+ target_language_menu_button_ = CreateMenuButton(string16(), true, this);
+ AddChildView(swapped_language_buttons_ ?
+ target_language_menu_button_ : original_language_menu_button_);
+
label_2_ = CreateLabel(strings[1]);
AddChildView(label_2_);
+ AddChildView(swapped_language_buttons_ ?
+ original_language_menu_button_ : target_language_menu_button_);
+
label_3_ = CreateLabel(strings[2]);
AddChildView(label_3_);
- original_language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(original_language_menu_button_);
-
- target_language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(target_language_menu_button_);
-
- options_menu_button_ =
- CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS),
- false, this);
- AddChildView(options_menu_button_);
-
revert_button_ = InfoBarTextButton::Create(this,
l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_REVERT));
AddChildView(revert_button_);
+ options_menu_button_ = CreateMenuButton(
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), false, this);
+ AddChildView(options_menu_button_);
+
UpdateLanguageButtonText(LanguagesMenuModel::ORIGINAL);
UpdateLanguageButtonText(LanguagesMenuModel::TARGET);
}
@@ -61,51 +61,44 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
AfterTranslateInfoBar::~AfterTranslateInfoBar() {
}
-// Overridden from views::View:
void AfterTranslateInfoBar::Layout() {
- // Layout the icon and close button.
TranslateInfoBarBase::Layout();
- // Layout the options menu button on right of bar.
- int available_width = InfoBarView::GetAvailableWidth();
- gfx::Size pref_size = options_menu_button_->GetPreferredSize();
- options_menu_button_->SetBounds(available_width - pref_size.width(),
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- views::MenuButton* left_button = swapped_language_buttons_ ?
- target_language_menu_button_ : original_language_menu_button_;
- views::MenuButton* right_button = swapped_language_buttons_ ?
- original_language_menu_button_ : target_language_menu_button_;
-
- pref_size = label_1_->GetPreferredSize();
- label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing,
- InfoBarView::OffsetY(this, pref_size), pref_size.width(),
- pref_size.height());
-
- pref_size = left_button->GetPreferredSize();
- left_button->SetBounds(label_1_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_2_->GetPreferredSize();
- label_2_->SetBounds(left_button->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = right_button->GetPreferredSize();
- right_button->SetBounds(label_2_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_3_->GetPreferredSize();
- label_3_->SetBounds(right_button->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = revert_button_->GetPreferredSize();
- revert_button_->SetBounds(label_3_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
+ int available_width = GetAvailableWidth();
+ gfx::Size label_1_size = label_1_->GetPreferredSize();
+ label_1_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
+ OffsetY(this, label_1_size), label_1_size.width(), label_1_size.height());
+
+ views::MenuButton* first_button = original_language_menu_button_;
+ views::MenuButton* second_button = target_language_menu_button_;
+ if (swapped_language_buttons_)
+ std::swap(first_button, second_button);
+ gfx::Size first_button_size = first_button->GetPreferredSize();
+ first_button->SetBounds(label_1_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, first_button_size), first_button_size.width(),
+ first_button_size.height());
+
+ gfx::Size label_2_size = label_2_->GetPreferredSize();
+ label_2_->SetBounds(first_button->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_2_size), label_2_size.width(), label_2_size.height());
+
+ gfx::Size second_button_size = second_button->GetPreferredSize();
+ second_button->SetBounds(label_2_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, second_button_size), second_button_size.width(),
+ second_button_size.height());
+
+ gfx::Size label_3_size = label_3_->GetPreferredSize();
+ label_3_->SetBounds(second_button->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_3_size), label_3_size.width(), label_3_size.height());
+
+ gfx::Size revert_button_size = revert_button_->GetPreferredSize();
+ revert_button_->SetBounds(label_3_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, revert_button_size),
+ revert_button_size.width(), revert_button_size.height());
+
+ gfx::Size options_size = options_menu_button_->GetPreferredSize();
+ options_menu_button_->SetBounds(available_width - options_size.width(),
+ OffsetY(this, options_size), options_size.width(), options_size.height());
}
void AfterTranslateInfoBar::OriginalLanguageChanged() {
@@ -118,11 +111,10 @@ void AfterTranslateInfoBar::TargetLanguageChanged() {
void AfterTranslateInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
- if (sender == revert_button_) {
+ if (sender == revert_button_)
GetDelegate()->RevertTranslation();
- return;
- }
- TranslateInfoBarBase::ButtonPressed(sender, event);
+ else
+ TranslateInfoBarBase::ButtonPressed(sender, event);
}
void AfterTranslateInfoBar::RunMenu(views::View* source,
@@ -139,12 +131,11 @@ void AfterTranslateInfoBar::RunMenu(views::View* source,
new views::Menu2(&target_language_menu_model_));
}
target_language_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else if (source == options_menu_button_) {
+ } else {
+ DCHECK_EQ(options_menu_button_, source);
if (!options_menu_.get())
options_menu_.reset(new views::Menu2(&options_menu_model_));
options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else {
- NOTREACHED();
}
}
diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.h b/chrome/browser/ui/views/infobars/after_translate_infobar.h
index 0ee237a..977e629 100644
--- a/chrome/browser/ui/views/infobars/after_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/after_translate_infobar.h
@@ -8,15 +8,11 @@
#include "chrome/browser/translate/languages_menu_model.h"
#include "chrome/browser/translate/options_menu_model.h"
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
-#include "views/controls/button/button.h"
-#include "views/controls/link.h"
#include "views/controls/menu/view_menu_delegate.h"
class InfoBarTextButton;
class TranslateInfoBarDelegate;
-
namespace views {
class Menu2;
class MenuButton;
@@ -26,31 +22,27 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase,
public views::ViewMenuDelegate {
public:
explicit AfterTranslateInfoBar(TranslateInfoBarDelegate* delegate);
+
+ private:
virtual ~AfterTranslateInfoBar();
- // Overridden from views::View:
+ // TranslateInfoBarBase:
virtual void Layout();
-
- // Overridden from TranslateInfoBarView:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
virtual void OriginalLanguageChanged();
virtual void TargetLanguageChanged();
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- protected:
- // Overridden from views::ViewMenuDelegate:
+ // views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Sets the text of the original or target language menu buttons to reflect
// the current value from the delegate.
void UpdateLanguageButtonText(LanguagesMenuModel::LanguageType language);
// The text displayed in the infobar is something like:
- // "Translated from <lang1> to <lang2>"
- // Where <lang1> and <lang2> are displayed in a combobox.
- // So the text is split in 3 chunks, each one displayed in one of the label
+ // "Translated from <lang1> to <lang2> [more text in some languages]"
+ // ...where <lang1> and <lang2> are comboboxes.
+ // So the text is split in 3 chunks, each one displayed in one of the labels
// below.
views::Label* label_1_;
views::Label* label_2_;
@@ -58,8 +50,8 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase,
views::MenuButton* original_language_menu_button_;
views::MenuButton* target_language_menu_button_;
- views::MenuButton* options_menu_button_;
InfoBarTextButton* revert_button_;
+ views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> original_language_menu_;
LanguagesMenuModel original_language_menu_model_;
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
index cb35426..0159cb4 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc
@@ -12,6 +12,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/image_view.h"
+#include "views/controls/label.h"
#include "views/controls/menu/menu_2.h"
BeforeTranslateInfoBar::BeforeTranslateInfoBar(
@@ -22,118 +23,111 @@ BeforeTranslateInfoBar::BeforeTranslateInfoBar(
languages_menu_model_(delegate, LanguagesMenuModel::ORIGINAL),
options_menu_model_(delegate) {
size_t offset = 0;
- string16 text =
- l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
- string16(), &offset);
+ string16 text(l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
+ string16(), &offset));
label_1_ = CreateLabel(text.substr(0, offset));
AddChildView(label_1_);
+ language_menu_button_ = CreateMenuButton(string16(), true, this);
+ AddChildView(language_menu_button_);
+
label_2_ = CreateLabel(text.substr(offset));
AddChildView(label_2_);
- accept_button_ =
- InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_ACCEPT);
+ accept_button_ = InfoBarTextButton::CreateWithMessageID(this,
+ IDS_TRANSLATE_INFOBAR_ACCEPT);
AddChildView(accept_button_);
- deny_button_ =
- InfoBarTextButton::CreateWithMessageID(this,
- IDS_TRANSLATE_INFOBAR_DENY);
+ deny_button_ = InfoBarTextButton::CreateWithMessageID(this,
+ IDS_TRANSLATE_INFOBAR_DENY);
AddChildView(deny_button_);
- language_menu_button_ = CreateMenuButton(string16(), true, this);
- AddChildView(language_menu_button_);
-
- options_menu_button_ =
- CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS),
- false, this);
- AddChildView(options_menu_button_);
-
+ const string16& language(delegate->GetLanguageDisplayableNameAt(
+ delegate->original_language_index()));
if (delegate->ShouldShowNeverTranslateButton()) {
- const string16& language = delegate->GetLanguageDisplayableNameAt(
- delegate->original_language_index());
never_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
this, IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, language);
AddChildView(never_translate_button_);
- }
-
- if (delegate->ShouldShowAlwaysTranslateButton()) {
- const string16& language = delegate->GetLanguageDisplayableNameAt(
- delegate->original_language_index());
+ } else if (delegate->ShouldShowAlwaysTranslateButton()) {
always_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam(
this, IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language);
AddChildView(always_translate_button_);
}
+ options_menu_button_ = CreateMenuButton(
+ l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), false, this);
+ AddChildView(options_menu_button_);
+
UpdateOriginalButtonText();
}
BeforeTranslateInfoBar::~BeforeTranslateInfoBar() {
}
-// Overridden from views::View:
void BeforeTranslateInfoBar::Layout() {
- // Layout the icon and close button.
TranslateInfoBarBase::Layout();
- // Layout the options menu button on right of bar.
- int available_width = InfoBarView::GetAvailableWidth();
- gfx::Size pref_size = options_menu_button_->GetPreferredSize();
- options_menu_button_->SetBounds(available_width - pref_size.width(),
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- pref_size = label_1_->GetPreferredSize();
- label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing,
- InfoBarView::OffsetY(this, pref_size), pref_size.width(),
- pref_size.height());
-
- pref_size = language_menu_button_->GetPreferredSize();
- language_menu_button_->SetBounds(label_1_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = label_2_->GetPreferredSize();
- label_2_->SetBounds(language_menu_button_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size),
- pref_size.width(), pref_size.height());
-
- pref_size = accept_button_->GetPreferredSize();
- accept_button_->SetBounds(
- label_2_->bounds().right() + InfoBarView::kEndOfLabelSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
-
- pref_size = deny_button_->GetPreferredSize();
+ int available_width = GetAvailableWidth();
+ gfx::Size label_1_size = label_1_->GetPreferredSize();
+ label_1_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
+ OffsetY(this, label_1_size), label_1_size.width(), label_1_size.height());
+
+ gfx::Size language_button_size = language_menu_button_->GetPreferredSize();
+ language_menu_button_->SetBounds(
+ label_1_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, language_button_size), language_button_size.width(),
+ language_button_size.height());
+
+ gfx::Size label_2_size = label_2_->GetPreferredSize();
+ label_2_->SetBounds(
+ language_menu_button_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, label_2_size), label_2_size.width(), label_2_size.height());
+
+ gfx::Size accept_button_size = accept_button_->GetPreferredSize();
+ accept_button_->SetBounds(label_2_->bounds().right() + kEndOfLabelSpacing,
+ OffsetY(this, accept_button_size), accept_button_size.width(),
+ accept_button_size.height());
+
+ gfx::Size deny_button_size = deny_button_->GetPreferredSize();
deny_button_->SetBounds(
- accept_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ accept_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, deny_button_size), deny_button_size.width(),
+ deny_button_size.height());
if (never_translate_button_) {
- pref_size = never_translate_button_->GetPreferredSize();
+ gfx::Size never_button_size = never_translate_button_->GetPreferredSize();
never_translate_button_->SetBounds(
- deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ deny_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, never_button_size), never_button_size.width(),
+ never_button_size.height());
}
+
if (always_translate_button_) {
- DCHECK(!never_translate_button_);
- pref_size = always_translate_button_->GetPreferredSize();
+ gfx::Size always_button_size = always_translate_button_->GetPreferredSize();
always_translate_button_->SetBounds(
- deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing,
- OffsetY(this, pref_size), pref_size.width(), pref_size.height());
+ deny_button_->bounds().right() + kButtonButtonSpacing,
+ OffsetY(this, always_button_size), always_button_size.width(),
+ always_button_size.height());
}
+
+ gfx::Size options_size = options_menu_button_->GetPreferredSize();
+ options_menu_button_->SetBounds(available_width - options_size.width(),
+ OffsetY(this, options_size), options_size.width(), options_size.height());
}
void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
+ TranslateInfoBarDelegate* delegate = GetDelegate();
if (sender == accept_button_) {
- GetDelegate()->Translate();
+ delegate->Translate();
} else if (sender == deny_button_) {
+ delegate->TranslationDeclined();
RemoveInfoBar();
- GetDelegate()->TranslationDeclined();
} else if (sender == never_translate_button_) {
- GetDelegate()->NeverTranslatePageLanguage();
+ delegate->NeverTranslatePageLanguage();
} else if (sender == always_translate_button_) {
- GetDelegate()->AlwaysTranslatePageLanguage();
+ delegate->AlwaysTranslatePageLanguage();
} else {
TranslateInfoBarBase::ButtonPressed(sender, event);
}
@@ -143,22 +137,17 @@ void BeforeTranslateInfoBar::OriginalLanguageChanged() {
UpdateOriginalButtonText();
}
-void BeforeTranslateInfoBar::TargetLanguageChanged() {
- NOTREACHED();
-}
-
void BeforeTranslateInfoBar::RunMenu(views::View* source,
const gfx::Point& pt) {
if (source == language_menu_button_) {
if (!languages_menu_.get())
languages_menu_.reset(new views::Menu2(&languages_menu_model_));
languages_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else if (source == options_menu_button_) {
+ } else {
+ DCHECK_EQ(options_menu_button_, source);
if (!options_menu_.get())
options_menu_.reset(new views::Menu2(&options_menu_model_));
options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
- } else {
- NOTREACHED();
}
}
diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h
index 2f2c538..c0beea7 100644
--- a/chrome/browser/ui/views/infobars/before_translate_infobar.h
+++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h
@@ -8,15 +8,11 @@
#include "chrome/browser/translate/languages_menu_model.h"
#include "chrome/browser/translate/options_menu_model.h"
-#include "chrome/browser/translate/translate_infobar_view.h"
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
-#include "views/controls/button/button.h"
-#include "views/controls/link.h"
#include "views/controls/menu/view_menu_delegate.h"
class InfoBarTextButton;
class TranslateInfoBarDelegate;
-
namespace views {
class Menu2;
class MenuButton;
@@ -26,41 +22,35 @@ class BeforeTranslateInfoBar : public TranslateInfoBarBase,
public views::ViewMenuDelegate {
public:
explicit BeforeTranslateInfoBar(TranslateInfoBarDelegate* delegate);
+
+ private:
virtual ~BeforeTranslateInfoBar();
- // Overridden from views::View:
+ // TranslateInfoBarBase:
virtual void Layout();
-
- // Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from TranslateInfoBarView:
virtual void OriginalLanguageChanged();
- virtual void TargetLanguageChanged();
- protected:
// Overridden from views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Sets the text of the original language menu button to reflect the current
// value from the delegate.
void UpdateOriginalButtonText();
// The text displayed in the infobar is something like:
// "The page is in <lang>. Would you like to translate it?"
- // Where <lang> is displayed in a combobox.
- // So the text is split in 2 chunks, each one displayed in one of the label
- // below.
+ // ...where <lang> is a combobox. So the text is split in 2 chunks, each
+ // displayed in one of the labels below.
views::Label* label_1_;
views::Label* label_2_;
views::MenuButton* language_menu_button_;
- views::MenuButton* options_menu_button_;
InfoBarTextButton* accept_button_;
InfoBarTextButton* deny_button_;
InfoBarTextButton* never_translate_button_;
InfoBarTextButton* always_translate_button_;
+ views::MenuButton* options_menu_button_;
scoped_ptr<views::Menu2> languages_menu_;
LanguagesMenuModel languages_menu_model_;
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc
index 427beda..bfc306b 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.cc
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc
@@ -39,25 +39,24 @@ void AlertInfoBar::Layout() {
InfoBarView::Layout();
// Layout the icon and text.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(),
- icon_ps.height());
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
- gfx::Size text_ps = label_->GetPreferredSize();
- int text_width = std::min(
- text_ps.width(),
+ gfx::Size text_size = label_->GetPreferredSize();
+ int text_width = std::min(text_size.width(),
GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing);
label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
- OffsetY(this, text_ps), text_width, text_ps.height());
+ OffsetY(this, text_size), text_width, text_size.height());
}
-// ConfirmInfoBarDelegate, InfoBarDelegate overrides: --------------------------
+// ConfirmInfoBarDelegate -----------------------------------------------------
InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
return new ConfirmInfoBar(this);
}
-// ConfirmInfoBar, public: -----------------------------------------------------
+// ConfirmInfoBar -------------------------------------------------------------
ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
: AlertInfoBar(delegate),
@@ -94,101 +93,87 @@ ConfirmInfoBar::~ConfirmInfoBar() {
}
}
-// ConfirmInfoBar, views::LinkController implementation: -----------------------
-
-void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
- DCHECK(source == link_);
- DCHECK(link_->IsVisible());
- DCHECK(!link_->GetText().empty());
- if (GetDelegate()->LinkClicked(
- event_utils::DispositionFromEventFlags(event_flags))) {
- RemoveInfoBar();
- }
-}
-
-// ConfirmInfoBar, views::View overrides: --------------------------------------
-
void ConfirmInfoBar::Layout() {
- // First layout right aligned items (from right to left) in order to determine
- // the space avalable, then layout the left aligned items.
-
- // Layout the close button.
InfoBarView::Layout();
- // Layout the cancel and OK buttons.
int available_width = AlertInfoBar::GetAvailableWidth();
int ok_button_width = 0;
int cancel_button_width = 0;
- gfx::Size ok_ps = ok_button_->GetPreferredSize();
- gfx::Size cancel_ps = cancel_button_->GetPreferredSize();
+ gfx::Size ok_size = ok_button_->GetPreferredSize();
+ gfx::Size cancel_size = cancel_button_->GetPreferredSize();
if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) {
- ok_button_width = ok_ps.width();
+ ok_button_width = ok_size.width();
} else {
ok_button_->SetVisible(false);
}
if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
- cancel_button_width = cancel_ps.width();
+ cancel_button_width = cancel_size.width();
} else {
cancel_button_->SetVisible(false);
}
cancel_button_->SetBounds(available_width - cancel_button_width,
- OffsetY(this, cancel_ps), cancel_ps.width(),
- cancel_ps.height());
+ OffsetY(this, cancel_size), cancel_size.width(), cancel_size.height());
int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0;
ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width,
- OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height());
+ OffsetY(this, ok_size), ok_size.width(), ok_size.height());
// Layout the icon and label.
AlertInfoBar::Layout();
// Now append the link to the label's right edge.
link_->SetVisible(!link_->GetText().empty());
- gfx::Size link_ps = link_->GetPreferredSize();
+ gfx::Size link_size = link_->GetPreferredSize();
int link_x = label()->bounds().right() + kEndOfLabelSpacing;
- int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width());
- link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height());
+ int link_w = std::min(GetAvailableWidth() - link_x, link_size.width());
+ link_->SetBounds(link_x, OffsetY(this, link_size), link_w,
+ link_size.height());
}
void ConfirmInfoBar::ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child) {
if (is_add && child == this && !initialized_) {
- Init();
+ AddChildView(ok_button_);
+ AddChildView(cancel_button_);
+ AddChildView(link_);
initialized_ = true;
}
+
+ // This must happen after adding all other children so InfoBarView can ensure
+ // the close button is the last child.
InfoBarView::ViewHierarchyChanged(is_add, parent, child);
}
-// ConfirmInfoBar, views::ButtonListener implementation: ---------------
+int ConfirmInfoBar::GetAvailableWidth() const {
+ return ok_button_->x() - kEndOfLabelSpacing;
+}
-void ConfirmInfoBar::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- InfoBarView::ButtonPressed(sender, event);
+void ConfirmInfoBar::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ ConfirmInfoBarDelegate* delegate = GetDelegate();
if (sender == ok_button_) {
- if (GetDelegate()->Accept())
+ if (delegate->Accept())
RemoveInfoBar();
} else if (sender == cancel_button_) {
- if (GetDelegate()->Cancel())
+ if (delegate->Cancel())
RemoveInfoBar();
+ } else {
+ InfoBarView::ButtonPressed(sender, event);
}
}
-// ConfirmInfoBar, InfoBar overrides: ------------------------------------------
-
-int ConfirmInfoBar::GetAvailableWidth() const {
- return ok_button_->x() - kEndOfLabelSpacing;
+void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
+ DCHECK_EQ(link_, source);
+ DCHECK(link_->IsVisible());
+ DCHECK(!link_->GetText().empty());
+ if (GetDelegate()->LinkClicked(
+ event_utils::DispositionFromEventFlags(event_flags))) {
+ RemoveInfoBar();
+ }
}
-// ConfirmInfoBar, private: ----------------------------------------------------
-
ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
return delegate()->AsConfirmInfoBarDelegate();
}
-
-void ConfirmInfoBar::Init() {
- AddChildView(ok_button_);
- AddChildView(cancel_button_);
- AddChildView(link_);
-}
diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h
index de9afb2..0905bcc 100644
--- a/chrome/browser/ui/views/infobars/confirm_infobar.h
+++ b/chrome/browser/ui/views/infobars/confirm_infobar.h
@@ -11,7 +11,6 @@
class ConfirmInfoBarDelegate;
class InfoBarTextButton;
-
namespace views {
class Label;
}
@@ -42,31 +41,23 @@ class AlertInfoBar : public InfoBarView {
// TODO(pkasting): The above layout is the desired, but not current, layout; fix
// coming in a future patch.
class ConfirmInfoBar : public AlertInfoBar,
- public views::LinkController {
+ public views::LinkController {
public:
explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate);
- virtual ~ConfirmInfoBar();
- // Overridden from views::LinkController:
- virtual void LinkActivated(views::Link* source, int event_flags);
+ private:
+ virtual ~ConfirmInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
-
- protected:
- // Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from InfoBar:
virtual int GetAvailableWidth() const;
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- private:
- void Init();
+ // views::LinkController:
+ virtual void LinkActivated(views::Link* source, int event_flags);
ConfirmInfoBarDelegate* GetDelegate();
diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc
index 53663f8..7d5a404 100644
--- a/chrome/browser/ui/views/infobars/extension_infobar.cc
+++ b/chrome/browser/ui/views/infobars/extension_infobar.cc
@@ -5,9 +5,10 @@
#include "chrome/browser/ui/views/infobars/extension_infobar.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
-#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/platform_util.h"
+#include "chrome/browser/ui/views/infobars/infobar_background.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_icon_set.h"
@@ -20,120 +21,116 @@
#include "views/controls/menu/menu_2.h"
#include "views/widget/widget.h"
+// ExtensionInfoBarDelegate ---------------------------------------------------
+
+InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
+ return new ExtensionInfoBar(this);
+}
+
+// ExtensionInfoBar -----------------------------------------------------------
+
+namespace {
// The horizontal margin between the menu and the Extension (HTML) view.
static const int kMenuHorizontalMargin = 1;
// The amount of space to the right of the Extension (HTML) view (to avoid
// overlapping the close button for the InfoBar).
static const int kFarRightMargin = 30;
-
-// The margin between the extension icon and the drop-down arrow bitmap.
-static const int kDropArrowLeftMargin = 3;
+};
ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate)
: InfoBarView(delegate),
delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
- delegate_->set_observer(this);
-
- ExtensionHost* extension_host = delegate_->extension_host();
+ delegate->set_observer(this);
- // We set the target height for the InfoBar to be the height of the
- // ExtensionView it contains (plus 1 because the view should not overlap the
- // separator line at the bottom). When the InfoBar is first created, however,
- // this value is 0 but becomes positive after the InfoBar has been shown. See
- // function: OnExtensionPreferredSizeChanged.
- gfx::Size sz = extension_host->view()->GetPreferredSize();
- if (sz.height() > 0)
- sz.set_height(sz.height() + 1);
- set_target_height(sz.height());
+ ExtensionView* extension_view = delegate->extension_host()->view();
+ int height = extension_view->GetPreferredSize().height();
+ set_target_height((height > 0) ?
+ (height + InfoBarBackground::kSeparatorLineHeight) : height);
// Setup the extension icon and its associated drop down menu.
SetupIconAndMenu();
// Get notified of resize events for the ExtensionView.
- extension_host->view()->SetContainer(this);
+ extension_view->SetContainer(this);
// We show the ExtensionView, but we don't want it deleted when we get
// destroyed, which happens on tab switching (for example).
- extension_host->view()->set_parent_owned(false);
- AddChildView(extension_host->view());
+ extension_view->set_parent_owned(false);
+ AddChildView(extension_view);
}
ExtensionInfoBar::~ExtensionInfoBar() {
- if (delegate_) {
- delegate_->extension_host()->view()->SetContainer(NULL);
- delegate_->set_observer(NULL);
+ if (GetDelegate()) {
+ GetDelegate()->extension_host()->view()->SetContainer(NULL);
+ GetDelegate()->set_observer(NULL);
}
}
+void ExtensionInfoBar::Layout() {
+ InfoBarView::Layout();
+
+ gfx::Size menu_size = menu_->GetPreferredSize();
+ menu_->SetBounds(0, (height() - menu_size.height()) / 2, menu_size.width(),
+ menu_size.height());
+
+ int x = menu_->bounds().right() + kMenuHorizontalMargin;
+ GetDelegate()->extension_host()->view()->SetBounds(x, 0,
+ width() - x - kFarRightMargin - 1, height() - 1);
+}
+
+void ExtensionInfoBar::OnExtensionMouseMove(ExtensionView* view) {
+}
+
+void ExtensionInfoBar::OnExtensionMouseLeave(ExtensionView* view) {
+}
+
void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) {
- DCHECK(view == delegate_->extension_host()->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())
+ if (delegate->closing())
return;
- delegate_->extension_host()->view()->SetVisible(true);
-
- gfx::Size sz = view->GetPreferredSize();
- // Clamp height to a min and a max size of between 1 and 2 InfoBars.
- int default_height = static_cast<int>(InfoBarView::kDefaultTargetHeight);
- sz.set_height(std::max(default_height, sz.height()));
- sz.set_height(std::min(2 * default_height, sz.height()));
+ view->SetVisible(true);
if (height() == 0)
animation()->Reset(0.0);
- set_target_height(sz.height());
- animation()->Show();
-}
-void ExtensionInfoBar::Layout() {
- // Layout the close button and the background.
- InfoBarView::Layout();
+ // Clamp height to a min and a max size of between 1 and 2 InfoBars.
+ set_target_height(std::min(2 * kDefaultTargetHeight,
+ std::max(kDefaultTargetHeight, view->GetPreferredSize().height())));
- // Layout the extension icon + drop down menu.
- int x = 0;
- gfx::Size sz = menu_->GetPreferredSize();
- menu_->SetBounds(x,
- (height() - sz.height()) / 2,
- sz.width(), sz.height());
- x += sz.width() + kMenuHorizontalMargin;
-
- // Layout the ExtensionView, showing the HTML InfoBar.
- ExtensionView* view = delegate_->extension_host()->view();
- view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1);
+ animation()->Show();
}
-void ExtensionInfoBar::OnImageLoaded(
- SkBitmap* image, ExtensionResource resource, int index) {
- if (!delegate_)
+void ExtensionInfoBar::OnImageLoaded(SkBitmap* image,
+ ExtensionResource resource,
+ int index) {
+ if (!GetDelegate())
return; // The delegate can go away while we asynchronously load images.
+ SkBitmap* icon = image;
+ // Fall back on the default extension icon on failure.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
- // We fall back on the default extension icon on failure.
- SkBitmap* icon;
if (!image || image->empty())
icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
- else
- icon = image;
SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW);
int image_size = Extension::EXTENSION_ICON_BITTY;
- scoped_ptr<gfx::CanvasSkia> canvas(
- new gfx::CanvasSkia(
- image_size + kDropArrowLeftMargin + drop_image->width(),
- image_size, false));
- canvas->DrawBitmapInt(*icon,
- 0, 0, icon->width(), icon->height(),
- 0, 0, image_size, image_size,
- false);
- canvas->DrawBitmapInt(*drop_image,
- image_size + kDropArrowLeftMargin,
+ // The margin between the extension icon and the drop-down arrow bitmap.
+ static const int kDropArrowLeftMargin = 3;
+ scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia(
+ image_size + kDropArrowLeftMargin + drop_image->width(), image_size,
+ false));
+ canvas->DrawBitmapInt(*icon, 0, 0, icon->width(), icon->height(), 0, 0,
+ image_size, image_size, false);
+ canvas->DrawBitmapInt(*drop_image, image_size + kDropArrowLeftMargin,
image_size / 2);
menu_->SetIcon(canvas->ExtractBitmap());
menu_->SetVisible(true);
@@ -142,12 +139,12 @@ void ExtensionInfoBar::OnImageLoaded(
}
void ExtensionInfoBar::OnDelegateDeleted() {
- delegate_->extension_host()->view()->SetContainer(NULL);
+ GetDelegate()->extension_host()->view()->SetContainer(NULL);
delegate_ = NULL;
}
void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) {
- const Extension* extension = delegate_->extension_host()->extension();
+ const Extension* extension = GetDelegate()->extension_host()->extension();
if (!extension->ShowConfigureContextMenus())
return;
@@ -155,8 +152,8 @@ void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) {
Browser* browser = BrowserView::GetBrowserViewForNativeWindow(
platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))->
browser();
- options_menu_contents_ = new ExtensionContextMenuModel(
- extension, browser, NULL);
+ options_menu_contents_ = new ExtensionContextMenuModel(extension, browser,
+ NULL);
}
options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get()));
@@ -168,20 +165,18 @@ void ExtensionInfoBar::SetupIconAndMenu() {
menu_->SetVisible(false);
AddChildView(menu_);
- const Extension* extension = delegate_->extension_host()->extension();
+ const Extension* extension = GetDelegate()->extension_host()->extension();
+ int image_size = Extension::EXTENSION_ICON_BITTY;
ExtensionResource icon_resource = extension->GetIconResource(
- Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY);
+ image_size, 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);
+ gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE);
} else {
- OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|.
+ OnImageLoaded(NULL, icon_resource, 0);
}
}
-InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
- return new ExtensionInfoBar(this);
+ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() {
+ return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL;
}
diff --git a/chrome/browser/ui/views/infobars/extension_infobar.h b/chrome/browser/ui/views/infobars/extension_infobar.h
index aaa2729..9a7068a 100644
--- a/chrome/browser/ui/views/infobars/extension_infobar.h
+++ b/chrome/browser/ui/views/infobars/extension_infobar.h
@@ -6,19 +6,16 @@
#define CHROME_BROWSER_UI_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_
#pragma once
-#include "chrome/browser/ui/views/infobars/infobar_view.h"
-
#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"
class ExtensionContextMenuModel;
-class ExtensionInfoBarDelegate;
-
namespace views {
- class MenuButton;
- class Menu2;
+class MenuButton;
+class Menu2;
}
// This class implements InfoBars for Extensions.
@@ -29,34 +26,41 @@ class ExtensionInfoBar : public InfoBarView,
public views::ViewMenuDelegate {
public:
explicit ExtensionInfoBar(ExtensionInfoBarDelegate* delegate);
- virtual ~ExtensionInfoBar();
- // Overridden from ExtensionView::Container:
- virtual void OnExtensionMouseMove(ExtensionView* view) {}
- virtual void OnExtensionMouseLeave(ExtensionView* view) {}
- virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
+ private:
+ virtual ~ExtensionInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
- // Overridden from ImageLoadingTracker::Observer:
- virtual void OnImageLoaded(
- SkBitmap* image, ExtensionResource resource, int index);
+ // ExtensionView::Container:
+ virtual void OnExtensionMouseMove(ExtensionView* view);
+ virtual void OnExtensionMouseLeave(ExtensionView* view);
+ virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
+
+ // ImageLoadingTracker::Observer:
+ virtual void OnImageLoaded(SkBitmap* image,
+ ExtensionResource resource,
+ int index);
- // Overridden from ExtensionInfoBarDelegate::DelegateObserver:
+ // ExtensionInfoBarDelegate::DelegateObserver:
virtual void OnDelegateDeleted();
- // Overridden from views::ViewMenuDelegate:
+ // views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
- private:
// Setup the menu button showing the small extension icon and its dropdown
// menu.
void SetupIconAndMenu();
+ ExtensionInfoBarDelegate* GetDelegate();
+
NotificationRegistrar notification_registrar_;
- ExtensionInfoBarDelegate* delegate_;
+ // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once
+ // InfoBars own their delegates (and thus we don't need the DelegateObserver
+ // functionality). For now, almost everyone should use GetDelegate() instead.
+ InfoBarDelegate* delegate_;
// The dropdown menu for accessing the contextual extension actions.
scoped_refptr<ExtensionContextMenuModel> options_menu_contents_;
diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc
index 0af9149..71fa45c 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.cc
+++ b/chrome/browser/ui/views/infobars/infobar_background.cc
@@ -8,18 +8,8 @@
#include "ui/gfx/canvas.h"
#include "views/view.h"
-static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183);
-static const SkColor kWarningBackgroundColorBottom =
- SkColorSetRGB(250, 230, 145);
-
-static const SkColor kPageActionBackgroundColorTop =
- SkColorSetRGB(218, 231, 249);
-static const SkColor kPageActionBackgroundColorBottom =
- SkColorSetRGB(179, 202, 231);
-
-static const int kSeparatorLineHeight = 1;
-
-// InfoBarBackground, public: --------------------------------------------------
+// static
+const int InfoBarBackground::kSeparatorLineHeight = 1;
InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) {
gradient_background_.reset(
@@ -28,23 +18,31 @@ InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) {
GetBottomColor(infobar_type)));
}
+InfoBarBackground::~InfoBarBackground() {
+}
+
SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) {
+ static const SkColor kWarningBackgroundColorTop =
+ SkColorSetRGB(255, 242, 183);
+ static const SkColor kPageActionBackgroundColorTop =
+ SkColorSetRGB(218, 231, 249);
+
return (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
kWarningBackgroundColorTop : kPageActionBackgroundColorTop;
}
SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) {
+ static const SkColor kWarningBackgroundColorBottom =
+ SkColorSetRGB(250, 230, 145);
+ static const SkColor kPageActionBackgroundColorBottom =
+ SkColorSetRGB(179, 202, 231);
+
return (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom;
}
-// InfoBarBackground, views::Background overrides: -----------------------------
-
void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
- // First paint the gradient background.
gradient_background_->Paint(canvas, view);
-
- // Now paint the separator line.
canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0,
view->height() - kSeparatorLineHeight, view->width(),
kSeparatorLineHeight);
diff --git a/chrome/browser/ui/views/infobars/infobar_background.h b/chrome/browser/ui/views/infobars/infobar_background.h
index 9b967c0..1849588 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.h
+++ b/chrome/browser/ui/views/infobars/infobar_background.h
@@ -12,15 +12,18 @@
class InfoBarBackground : public views::Background {
public:
- explicit InfoBarBackground(InfoBarDelegate::Type infobar_type);
+ static const int kSeparatorLineHeight;
- // Overridden from views::Background:
- virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
+ explicit InfoBarBackground(InfoBarDelegate::Type infobar_type);
+ virtual ~InfoBarBackground();
static SkColor GetTopColor(InfoBarDelegate::Type infobar_type);
static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type);
private:
+ // views::Background:
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
+
scoped_ptr<views::Background> gradient_background_;
DISALLOW_COPY_AND_ASSIGN(InfoBarBackground);
diff --git a/chrome/browser/ui/views/infobars/infobar_button_border.cc b/chrome/browser/ui/views/infobars/infobar_button_border.cc
index 84a3bd9..981f3d5 100644
--- a/chrome/browser/ui/views/infobars/infobar_button_border.cc
+++ b/chrome/browser/ui/views/infobars/infobar_button_border.cc
@@ -5,19 +5,13 @@
#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "views/controls/button/text_button.h"
-// Preferred padding between text and edge
-static const int kPreferredPaddingHorizontal = 6;
-static const int kPreferredPaddingVertical = 5;
-
-// InfoBarButtonBorder, public: ----------------------------------------------
-
InfoBarButtonBorder::InfoBarButtonBorder() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
normal_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_N);
normal_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_N);
normal_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_N);
@@ -54,9 +48,9 @@ InfoBarButtonBorder::InfoBarButtonBorder() {
InfoBarButtonBorder::~InfoBarButtonBorder() {
}
-// InfoBarButtonBorder, Border overrides: ------------------------------------
-
void InfoBarButtonBorder::GetInsets(gfx::Insets* insets) const {
+ static const int kPreferredPaddingHorizontal = 6;
+ static const int kPreferredPaddingVertical = 5;
insets->Set(kPreferredPaddingVertical, kPreferredPaddingHorizontal,
kPreferredPaddingVertical, kPreferredPaddingHorizontal);
}
@@ -65,25 +59,19 @@ void InfoBarButtonBorder::Paint(const views::View& view,
gfx::Canvas* canvas) const {
const views::TextButton* mb = static_cast<const views::TextButton*>(&view);
int state = mb->state();
-
- // TextButton takes care of deciding when to call Paint.
const MBBImageSet* set = &normal_set_;
if (state == views::TextButton::BS_HOT)
set = &hot_set_;
else if (state == views::TextButton::BS_PUSHED)
set = &pushed_set_;
- gfx::Rect bounds = view.bounds();
-
// Draw top left image.
canvas->DrawBitmapInt(*set->top_left, 0, 0);
// Stretch top image.
- canvas->DrawBitmapInt(
- *set->top,
- 0, 0, set->top->width(), set->top->height(),
- set->top_left->width(),
- 0,
+ const gfx::Rect& bounds = view.bounds();
+ canvas->DrawBitmapInt(*set->top, 0, 0, set->top->width(), set->top->height(),
+ set->top_left->width(), 0,
bounds.width() - set->top_right->width() - set->top_left->width(),
set->top->height(), false);
@@ -92,46 +80,32 @@ void InfoBarButtonBorder::Paint(const views::View& view,
bounds.width() - set->top_right->width(), 0);
// Stretch left image.
- canvas->DrawBitmapInt(
- *set->left,
- 0, 0, set->left->width(), set->left->height(),
- 0,
- set->top_left->height(),
- set->top_left->width(),
+ canvas->DrawBitmapInt(*set->left, 0, 0, set->left->width(),
+ set->left->height(), 0, set->top_left->height(), set->top_left->width(),
bounds.height() - set->top->height() - set->bottom_left->height(), false);
// Stretch center image.
- canvas->DrawBitmapInt(
- *set->center,
- 0, 0, set->center->width(), set->center->height(),
- set->left->width(),
- set->top->height(),
+ canvas->DrawBitmapInt(*set->center, 0, 0, set->center->width(),
+ set->center->height(), set->left->width(), set->top->height(),
bounds.width() - set->right->width() - set->left->width(),
bounds.height() - set->bottom->height() - set->top->height(), false);
// Stretch right image.
- canvas->DrawBitmapInt(
- *set->right,
- 0, 0, set->right->width(), set->right->height(),
- bounds.width() - set->right->width(),
- set->top_right->height(),
- set->right->width(),
- bounds.height() - set->bottom_right->height() -
- set->top_right->height(), false);
+ canvas->DrawBitmapInt(*set->right, 0, 0, set->right->width(),
+ set->right->height(), bounds.width() - set->right->width(),
+ set->top_right->height(), set->right->width(),
+ bounds.height() - set->bottom_right->height() - set->top_right->height(),
+ false);
// Draw bottom left image.
- canvas->DrawBitmapInt(*set->bottom_left,
- 0,
+ canvas->DrawBitmapInt(*set->bottom_left, 0,
bounds.height() - set->bottom_left->height());
// Stretch bottom image.
- canvas->DrawBitmapInt(
- *set->bottom,
- 0, 0, set->bottom->width(), set->bottom->height(),
- set->bottom_left->width(),
+ canvas->DrawBitmapInt(*set->bottom, 0, 0, set->bottom->width(),
+ set->bottom->height(), set->bottom_left->width(),
bounds.height() - set->bottom->height(),
- bounds.width() - set->bottom_right->width() -
- set->bottom_left->width(),
+ bounds.width() - set->bottom_right->width() - set->bottom_left->width(),
set->bottom->height(), false);
// Draw bottom right image.
diff --git a/chrome/browser/ui/views/infobars/infobar_button_border.h b/chrome/browser/ui/views/infobars/infobar_button_border.h
index c8cfa83..fccdd87 100644
--- a/chrome/browser/ui/views/infobars/infobar_button_border.h
+++ b/chrome/browser/ui/views/infobars/infobar_button_border.h
@@ -1,4 +1,4 @@
-// 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,8 +8,7 @@
#include "views/border.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-
+class SkBitmap;
namespace gfx {
class Canvas;
}
@@ -19,18 +18,17 @@ class View;
// A TextButtonBorder that is dark and also paints the button frame in the
// normal state.
-
class InfoBarButtonBorder : public views::Border {
public:
InfoBarButtonBorder();
+
+ private:
virtual ~InfoBarButtonBorder();
- // Overriden from Border:
+ // views::Border:
virtual void GetInsets(gfx::Insets* insets) const;
virtual void Paint(const views::View& view, gfx::Canvas* canvas) const;
- private:
- // Images
struct MBBImageSet {
SkBitmap* top_left;
SkBitmap* top;
diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc
index c829c14..b0c7f37 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.cc
+++ b/chrome/browser/ui/views/infobars/infobar_container.cc
@@ -14,8 +14,6 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
-// InfoBarContainer, public: ---------------------------------------------------
-
InfoBarContainer::InfoBarContainer(Delegate* delegate)
: delegate_(delegate),
tab_contents_(NULL) {
@@ -62,14 +60,12 @@ void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas,
views::View* outer_view,
int arrow_center_x) {
- for(int i = 0; i < GetChildViewCount(); ++i) {
+ for (int i = 0; i < GetChildViewCount(); ++i) {
InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i));
infobar->PaintArrow(canvas, outer_view, arrow_center_x);
}
}
-// InfoBarContainer, views::View overrides: ------------------------------------
-
gfx::Size InfoBarContainer::GetPreferredSize() {
// We do not have a preferred width (we will expand to fit the available width
// of the delegate). Our preferred height is the sum of the preferred
@@ -106,8 +102,6 @@ void InfoBarContainer::ViewHierarchyChanged(bool is_add,
}
}
-// InfoBarContainer, NotificationObserver implementation: ----------------------
-
void InfoBarContainer::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -124,10 +118,8 @@ void InfoBarContainer::Observe(NotificationType type,
}
}
-// InfoBarContainer, private: --------------------------------------------------
-
void InfoBarContainer::UpdateInfoBars() {
- for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
InfoBarView* infobar = static_cast<InfoBarView*>(delegate->CreateInfoBar());
infobar->set_container(this);
diff --git a/chrome/browser/ui/views/infobars/infobar_container.h b/chrome/browser/ui/views/infobars/infobar_container.h
index 9a02bc8..6b82b5f 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.h
+++ b/chrome/browser/ui/views/infobars/infobar_container.h
@@ -51,18 +51,16 @@ class InfoBarContainer : public AccessiblePaneView,
views::View* outer_view,
int arrow_center_x);
- // Overridden from views::View:
+ private:
+ // AccessiblePaneView:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
virtual AccessibilityTypes::Role GetAccessibleRole();
-
- protected:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
- private:
- // Overridden from NotificationObserver:
+ // NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc
index 5e90a16..5871c96 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view.cc
@@ -27,7 +27,7 @@
#endif
// static
-const double InfoBarView::kDefaultTargetHeight = 36.0;
+const int InfoBarView::kDefaultTargetHeight = 36;
const int InfoBarView::kHorizontalPadding = 6;
const int InfoBarView::kIconLabelSpacing = 6;
const int InfoBarView::kButtonButtonSpacing = 10;
@@ -35,8 +35,6 @@ const int InfoBarView::kEndOfLabelSpacing = 16;
const int InfoBarView::kCloseButtonSpacing = 12;
const int InfoBarView::kButtonInLabelSpacing = 5;
-// InfoBarView, public: -------------------------------------------------------
-
InfoBarView::InfoBarView(InfoBarDelegate* delegate)
: InfoBar(delegate),
delegate_(delegate),
@@ -44,24 +42,14 @@ InfoBarView::InfoBarView(InfoBarDelegate* delegate)
close_button_(new views::ImageButton(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)),
target_height_(kDefaultTargetHeight) {
- // We delete ourselves when we're removed from the view hierarchy.
+ // InfoBar deletes itself at the appropriate time.
set_parent_owned(false);
- set_background(new InfoBarBackground(delegate->GetInfoBarType()));
-
- switch (delegate->GetInfoBarType()) {
- case InfoBarDelegate::WARNING_TYPE:
- SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_WARNING));
- break;
- case InfoBarDelegate::PAGE_ACTION_TYPE:
- SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_PAGE_ACTION));
- break;
- default:
- NOTREACHED();
- break;
- }
+ InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType();
+ set_background(new InfoBarBackground(infobar_type));
+ SetAccessibleName(l10n_util::GetStringUTF16(
+ (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
+ IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION));
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
close_button_->SetImage(views::CustomButton::BS_NORMAL,
@@ -72,13 +60,48 @@ InfoBarView::InfoBarView(InfoBarDelegate* delegate)
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
+ close_button_->SetFocusable(true);
AddChildView(close_button_);
animation_.reset(new ui::SlideAnimation(this));
animation_->SetTweenType(ui::Tween::LINEAR);
}
-InfoBarView::~InfoBarView() {
+void InfoBarView::AnimateOpen() {
+ animation_->Show();
+}
+
+void InfoBarView::Open() {
+ // Set the animation value to 1.0 so that GetPreferredSize() returns the right
+ // size.
+ animation_->Reset(1.0);
+ if (container_)
+ container_->InfoBarAnimated(false);
+}
+
+void InfoBarView::AnimateClose() {
+ bool restore_focus = true;
+#if defined(OS_WIN)
+ // Do not restore focus (and active state with it) on Windows if some other
+ // top-level window became active.
+ if (GetWidget() &&
+ !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) {
+ restore_focus = false;
+ }
+#endif // defined(OS_WIN)
+ DestroyFocusTracker(restore_focus);
+ animation_->Hide();
+}
+
+void InfoBarView::Close() {
+ GetParent()->RemoveChildView(this);
+ // Note that we only tell the delegate we're closed here, and not when we're
+ // simply destroyed (by virtue of a tab switch or being moved from window to
+ // window), since this action can cause the delegate to destroy itself.
+ if (delegate_) {
+ delegate_->InfoBarClosed();
+ delegate_ = NULL;
+ }
}
void InfoBarView::PaintArrow(gfx::Canvas* canvas,
@@ -133,22 +156,14 @@ void InfoBarView::PaintArrow(gfx::Canvas* canvas,
canvas_skia->drawPath(border_path, paint);
}
-// InfoBarView, views::View overrides: ----------------------------------------
-
-AccessibilityTypes::Role InfoBarView::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_ALERT;
-}
-
-gfx::Size InfoBarView::GetPreferredSize() {
- int height = static_cast<int>(target_height_ * animation_->GetCurrentValue());
- return gfx::Size(0, height);
+InfoBarView::~InfoBarView() {
}
void InfoBarView::Layout() {
- gfx::Size button_ps = close_button_->GetPreferredSize();
- close_button_->SetBounds(width() - kHorizontalPadding - button_ps.width(),
- OffsetY(this, button_ps), button_ps.width(),
- button_ps.height());
+ gfx::Size button_size = close_button_->GetPreferredSize();
+ close_button_->SetBounds(width() - kHorizontalPadding - button_size.width(),
+ OffsetY(this, button_size), button_size.width(),
+ button_size.height());
}
void InfoBarView::ViewHierarchyChanged(bool is_add,
@@ -156,27 +171,58 @@ void InfoBarView::ViewHierarchyChanged(bool is_add,
views::View* child) {
if (child == this) {
if (is_add) {
- InfoBarAdded();
+ // The container_ pointer must be set before adding to the view hierarchy.
+ DCHECK(container_);
+#if defined(OS_WIN)
+ // When we're added to a view hierarchy within a widget, we create an
+ // external focus tracker to track what was focused in case we obtain
+ // focus so that we can restore focus when we're removed.
+ views::Widget* widget = GetWidget();
+ if (widget) {
+ focus_tracker_.reset(
+ new views::ExternalFocusTracker(this, GetFocusManager()));
+ }
+#endif
+ if (GetFocusManager())
+ GetFocusManager()->AddFocusChangeListener(this);
+ NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
} else {
- InfoBarRemoved();
+ DestroyFocusTracker(false);
+ // NULL our container_ pointer so that if Animation::Stop results in
+ // AnimationEnded being called, we do not try and delete ourselves twice.
+ container_ = NULL;
+ animation_->Stop();
+ // Finally, clean ourselves up when we're removed from the view hierarchy
+ // since no-one refers to us now.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
+ if (GetFocusManager())
+ GetFocusManager()->RemoveFocusChangeListener(this);
}
}
- if (GetWidget() && GetWidget()->IsAccessibleWidget()) {
- // For accessibility, make the close button the last child view.
- if (parent == this && child != close_button_ &&
- HasChildView(close_button_) &&
- GetChildViewAt(GetChildViewCount() - 1) != close_button_) {
- RemoveChildView(close_button_);
- AddChildView(close_button_);
- }
+ // For accessibility, ensure the close button is the last child view.
+ if ((parent == this) && (child != close_button_) &&
+ HasChildView(close_button_) &&
+ (GetChildViewAt(GetChildViewCount() - 1) != close_button_)) {
+ RemoveChildView(close_button_);
+ AddChildView(close_button_);
+ }
+}
- // Allow screen reader users to focus the close button.
- close_button_->SetFocusable(true);
+void InfoBarView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == close_button_) {
+ if (delegate_)
+ delegate_->InfoBarDismissed();
+ RemoveInfoBar();
}
}
-// InfoBarView, protected: ----------------------------------------------------
+void InfoBarView::AnimationProgressed(const ui::Animation* animation) {
+ if (container_)
+ container_->InfoBarAnimated(true);
+}
int InfoBarView::GetAvailableWidth() const {
return close_button_->x() - kCloseButtonSpacing;
@@ -187,43 +233,29 @@ void InfoBarView::RemoveInfoBar() const {
container_->RemoveDelegate(delegate());
}
-int InfoBarView::CenterY(const gfx::Size prefsize) {
- return std::max((static_cast<int>(target_height_) -
- prefsize.height()) / 2, 0);
+int InfoBarView::CenterY(const gfx::Size prefsize) const {
+ return std::max((target_height_ - prefsize.height()) / 2, 0);
}
-int InfoBarView::OffsetY(views::View* parent, const gfx::Size prefsize) {
- return CenterY(prefsize) -
- (static_cast<int>(target_height_) - parent->height());
+int InfoBarView::OffsetY(views::View* parent, const gfx::Size prefsize) const {
+ return CenterY(prefsize) - (target_height_ - parent->height());
}
-// InfoBarView, views::ButtonListener implementation: -------------------------
-
-void InfoBarView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- if (sender == close_button_) {
- if (delegate_)
- delegate_->InfoBarDismissed();
- RemoveInfoBar();
- }
+AccessibilityTypes::Role InfoBarView::GetAccessibleRole() {
+ return AccessibilityTypes::ROLE_ALERT;
}
-// InfoBarView, views::FocusChangeListener implementation: --------------------
+gfx::Size InfoBarView::GetPreferredSize() {
+ int height = static_cast<int>(target_height_ * animation_->GetCurrentValue());
+ return gfx::Size(0, height);
+}
void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
// This will trigger some screen readers to read the entire contents of this
// infobar.
- if (focused_before && focused_now &&
- !this->IsParentOf(focused_before) && this->IsParentOf(focused_now)) {
+ if (focused_before && focused_now && !this->IsParentOf(focused_before) &&
+ this->IsParentOf(focused_now))
NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
- }
-}
-
-// InfoBarView, ui::AnimationDelegate implementation: -------------------------
-
-void InfoBarView::AnimationProgressed(const ui::Animation* animation) {
- if (container_)
- container_->InfoBarAnimated(true);
}
void InfoBarView::AnimationEnded(const ui::Animation* animation) {
@@ -235,86 +267,12 @@ void InfoBarView::AnimationEnded(const ui::Animation* animation) {
}
}
-// InfoBarView, private: ------------------------------------------------------
-
-void InfoBarView::AnimateOpen() {
- animation_->Show();
-}
-
-void InfoBarView::Open() {
- // Set the animation value to 1.0 so that GetPreferredSize() returns the right
- // size.
- animation_->Reset(1.0);
- if (container_)
- container_->InfoBarAnimated(false);
-}
-
-void InfoBarView::AnimateClose() {
- bool restore_focus = true;
-#if defined(OS_WIN)
- // Do not restore focus (and active state with it) on Windows if some other
- // top-level window became active.
- if (GetWidget() &&
- !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) {
- restore_focus = false;
- }
-#endif // defined(OS_WIN)
- DestroyFocusTracker(restore_focus);
- animation_->Hide();
-}
-
-void InfoBarView::Close() {
- GetParent()->RemoveChildView(this);
- // Note that we only tell the delegate we're closed here, and not when we're
- // simply destroyed (by virtue of a tab switch or being moved from window to
- // window), since this action can cause the delegate to destroy itself.
- if (delegate_) {
- delegate_->InfoBarClosed();
- delegate_ = NULL;
- }
-}
-
-void InfoBarView::InfoBarAdded() {
- // The container_ pointer must be set before adding to the view hierarchy.
- DCHECK(container_);
-#if defined(OS_WIN)
- // When we're added to a view hierarchy within a widget, we create an
- // external focus tracker to track what was focused in case we obtain
- // focus so that we can restore focus when we're removed.
- views::Widget* widget = GetWidget();
- if (widget) {
- focus_tracker_.reset(new views::ExternalFocusTracker(this,
- GetFocusManager()));
- }
-#endif
-
- if (GetFocusManager())
- GetFocusManager()->AddFocusChangeListener(this);
-
- NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
-}
-
-void InfoBarView::InfoBarRemoved() {
- DestroyFocusTracker(false);
- // NULL our container_ pointer so that if Animation::Stop results in
- // AnimationEnded being called, we do not try and delete ourselves twice.
- container_ = NULL;
- animation_->Stop();
- // Finally, clean ourselves up when we're removed from the view hierarchy
- // since no-one refers to us now.
- MessageLoop::current()->PostTask(FROM_HERE,
- delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
-
- if (GetFocusManager())
- GetFocusManager()->RemoveFocusChangeListener(this);
-}
-
void InfoBarView::DestroyFocusTracker(bool restore_focus) {
- if (focus_tracker_.get()) {
+ if (focus_tracker_ != NULL) {
if (restore_focus)
focus_tracker_->FocusLastFocusedExternalView();
focus_tracker_->SetFocusManager(NULL);
- focus_tracker_.reset(NULL);
+ focus_tracker_.reset();
}
}
diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h
index b52e64f..b3d5606 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.h
+++ b/chrome/browser/ui/views/infobars/infobar_view.h
@@ -46,7 +46,6 @@ class InfoBarView : public InfoBar,
public ui::AnimationDelegate {
public:
explicit InfoBarView(InfoBarDelegate* delegate);
- virtual ~InfoBarView();
InfoBarDelegate* delegate() const { return delegate_; }
@@ -54,21 +53,20 @@ class InfoBarView : public InfoBar,
// InfoBar is added to the view hierarchy.
void set_container(InfoBarContainer* container) { container_ = container; }
- // The target height of the InfoBar, regardless of what its current height
- // is (due to animation).
- static const double kDefaultTargetHeight;
+ // Starts animating the InfoBar open.
+ void AnimateOpen();
- static const int kHorizontalPadding;
- static const int kIconLabelSpacing;
- static const int kButtonButtonSpacing;
- static const int kEndOfLabelSpacing;
- static const int kCloseButtonSpacing;
- static const int kButtonInLabelSpacing;
+ // Opens the InfoBar immediately.
+ void Open();
- // Overridden from views::View:
- virtual AccessibilityTypes::Role GetAccessibleRole();
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
+ // Starts animating the InfoBar closed. It will not be closed until the
+ // animation has completed, when |Close| will be called.
+ void AnimateClose();
+
+ // Closes the InfoBar immediately and removes it from its container. Notifies
+ // the delegate that it has closed. The InfoBar is deleted after this function
+ // is called.
+ void Close();
// Paint the arrow on |canvas|. |arrow_center_x| indicates the
// desired location of the center of the arrow in the |outer_view|
@@ -78,11 +76,31 @@ class InfoBarView : public InfoBar,
int arrow_center_x);
protected:
- // Overridden from views::View:
+ // The target height of the InfoBar, regardless of what its current height
+ // is (due to animation).
+ static const int kDefaultTargetHeight;
+
+ static const int kHorizontalPadding;
+ static const int kIconLabelSpacing;
+ static const int kButtonButtonSpacing;
+ static const int kEndOfLabelSpacing;
+ static const int kCloseButtonSpacing;
+ static const int kButtonInLabelSpacing;
+
+ virtual ~InfoBarView();
+
+ // views::View:
+ virtual void Layout();
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
+ // ui::AnimationDelegate:
+ virtual void AnimationProgressed(const ui::Animation* animation);
+
// Returns the available width of the View for use by child view layout,
// excluding the close button.
virtual int GetAvailableWidth() const;
@@ -91,53 +109,31 @@ class InfoBarView : public InfoBar,
// (Will lead to this InfoBar being closed).
void RemoveInfoBar() const;
- void set_target_height(double height) { target_height_ = height; }
+ void set_target_height(int height) { target_height_ = height; }
ui::SlideAnimation* animation() { return animation_.get(); }
// Returns a centered y-position of a control of height specified in
// |prefsize| within the standard InfoBar height. Stable during an animation.
- int CenterY(const gfx::Size prefsize);
+ int CenterY(const gfx::Size prefsize) const;
// Returns a centered y-position of a control of height specified in
// |prefsize| within the standard InfoBar height, adjusted according to the
// current amount of animation offset the |parent| InfoBar currently has.
// Changes during an animation.
- int OffsetY(views::View* parent, const gfx::Size prefsize);
+ int OffsetY(views::View* parent, const gfx::Size prefsize) const;
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+ private:
+ // views::View:
+ virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual gfx::Size GetPreferredSize();
- // Overridden from views::FocusChangeListener:
+ // views::FocusChangeListener:
virtual void FocusWillChange(View* focused_before, View* focused_now);
- // Overridden from ui::AnimationDelegate:
- virtual void AnimationProgressed(const ui::Animation* animation);
+ // ui::AnimationDelegate:
virtual void AnimationEnded(const ui::Animation* animation);
- private:
- friend class InfoBarContainer;
-
- // Starts animating the InfoBar open.
- void AnimateOpen();
-
- // Opens the InfoBar immediately.
- void Open();
-
- // Starts animating the InfoBar closed. It will not be closed until the
- // animation has completed, when |Close| will be called.
- void AnimateClose();
-
- // Closes the InfoBar immediately and removes it from its container. Notifies
- // the delegate that it has closed. The InfoBar is deleted after this function
- // is called.
- void Close();
-
- // Called when an InfoBar is added or removed from a view hierarchy to do
- // setup and shutdown.
- void InfoBarAdded();
- void InfoBarRemoved();
-
// Destroys the external focus tracker, if present. If |restore_focus| is
// true, restores focus to the view tracked by the focus tracker before doing
// so.
@@ -153,7 +149,7 @@ class InfoBarView : public InfoBar,
// The InfoBar's delegate.
InfoBarDelegate* delegate_;
- // The Close Button at the right edge of the InfoBar.
+ // The close button at the right edge of the InfoBar.
views::ImageButton* close_button_;
// The animation that runs when the InfoBar is opened or closed.
@@ -166,8 +162,8 @@ class InfoBarView : public InfoBar,
// Used to delete this object after a return to the message loop.
ScopedRunnableMethodFactory<InfoBarView> delete_factory_;
- // The target height for the InfoBar.
- double target_height_;
+ // The target height for the InfoBarView.
+ int target_height_;
DISALLOW_COPY_AND_ASSIGN(InfoBarView);
};
diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc
index 973b977..7049e3d 100644
--- a/chrome/browser/ui/views/infobars/link_infobar.cc
+++ b/chrome/browser/ui/views/infobars/link_infobar.cc
@@ -10,20 +10,20 @@
#include "ui/base/resource/resource_bundle.h"
#include "views/controls/image_view.h"
-// LinkInfoBarDelegate, InfoBarDelegate overrides: -----------------------------
+// LinkInfoBarDelegate --------------------------------------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
return new LinkInfoBar(this);
}
-// LinkInfoBar, public: --------------------------------------------------------
+// LinkInfoBar ----------------------------------------------------------------
LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
: InfoBarView(delegate),
icon_(new views::ImageView),
label_1_(new views::Label),
- label_2_(new views::Label),
- link_(new views::Link) {
+ link_(new views::Link),
+ label_2_(new views::Label) {
// Set up the icon.
if (delegate->GetIcon())
icon_->SetImage(delegate->GetIcon());
@@ -60,26 +60,13 @@ LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
LinkInfoBar::~LinkInfoBar() {
}
-// LinkInfoBar, views::LinkController implementation: --------------------------
-
-void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
- DCHECK(source == link_);
- if (GetDelegate()->LinkClicked(
- event_utils::DispositionFromEventFlags(event_flags))) {
- RemoveInfoBar();
- }
-}
-
-// LinkInfoBar, views::View overrides: -----------------------------------------
-
void LinkInfoBar::Layout() {
- // Layout the close button.
InfoBarView::Layout();
// Layout the icon.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(),
- icon_ps.height());
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
int label_1_x = icon_->bounds().right() + kIconLabelSpacing;
@@ -88,32 +75,37 @@ void LinkInfoBar::Layout() {
int available_width = GetAvailableWidth() - label_1_x;
// Layout the left label.
- gfx::Size label_1_ps = label_1_->GetPreferredSize();
- label_1_->SetBounds(label_1_x, OffsetY(this, label_1_ps), label_1_ps.width(),
- label_1_ps.height());
+ gfx::Size label_1_size = label_1_->GetPreferredSize();
+ label_1_->SetBounds(label_1_x, OffsetY(this, label_1_size),
+ label_1_size.width(), label_1_size.height());
// Layout the link.
- gfx::Size link_ps = link_->GetPreferredSize();
+ gfx::Size link_size = link_->GetPreferredSize();
bool has_second_label = !label_2_->GetText().empty();
if (has_second_label) {
// Embed the link in the text string between the two labels.
- link_->SetBounds(label_1_->bounds().right(),
- OffsetY(this, link_ps), link_ps.width(), link_ps.height());
+ link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
+ link_size.width(), link_size.height());
} else {
// Right-align the link toward the edge of the InfoBar.
- link_->SetBounds(label_1_x + available_width - link_ps.width(),
- OffsetY(this, link_ps), link_ps.width(), link_ps.height());
+ link_->SetBounds(label_1_x + available_width - link_size.width(),
+ OffsetY(this, link_size), link_size.width(), link_size.height());
}
// Layout the right label (we do this regardless of whether or not it has
// text).
- gfx::Size label_2_ps = label_2_->GetPreferredSize();
- label_2_->SetBounds(link_->bounds().right(),
- OffsetY(this, label_2_ps), label_2_ps.width(),
- label_2_ps.height());
+ gfx::Size label_2_size = label_2_->GetPreferredSize();
+ label_2_->SetBounds(link_->bounds().right(), OffsetY(this, label_2_size),
+ label_2_size.width(), label_2_size.height());
}
-// LinkInfoBar, private: -------------------------------------------------------
+void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
+ DCHECK(source == link_);
+ if (GetDelegate()->LinkClicked(
+ event_utils::DispositionFromEventFlags(event_flags))) {
+ RemoveInfoBar();
+ }
+}
LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
return delegate()->AsLinkInfoBarDelegate();
diff --git a/chrome/browser/ui/views/infobars/link_infobar.h b/chrome/browser/ui/views/infobars/link_infobar.h
index 1ca6bb7..6e8be356 100644
--- a/chrome/browser/ui/views/infobars/link_infobar.h
+++ b/chrome/browser/ui/views/infobars/link_infobar.h
@@ -16,21 +16,22 @@ class LinkInfoBar : public InfoBarView,
public views::LinkController {
public:
explicit LinkInfoBar(LinkInfoBarDelegate* delegate);
- virtual ~LinkInfoBar();
- // Overridden from views::LinkController:
- virtual void LinkActivated(views::Link* source, int event_flags);
+ private:
+ virtual ~LinkInfoBar();
- // Overridden from views::View:
+ // InfoBarView:
virtual void Layout();
- private:
+ // views::LinkController:
+ virtual void LinkActivated(views::Link* source, int event_flags);
+
LinkInfoBarDelegate* GetDelegate();
views::ImageView* icon_;
views::Label* label_1_;
- views::Label* label_2_;
views::Link* link_;
+ views::Label* label_2_;
DISALLOW_COPY_AND_ASSIGN(LinkInfoBar);
};
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
index 4162401..2dbdacb 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc
@@ -16,9 +16,33 @@
#include "ui/gfx/canvas_skia.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/image_view.h"
+#include "views/controls/label.h"
-TranslateInfoBarBase::TranslateInfoBarBase(
- TranslateInfoBarDelegate* delegate)
+// TranslateInfoBarDelegate ---------------------------------------------------
+
+InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
+ TranslateInfoBarBase* infobar = NULL;
+ switch (type_) {
+ case BEFORE_TRANSLATE:
+ infobar = new BeforeTranslateInfoBar(this);
+ break;
+ case AFTER_TRANSLATE:
+ infobar = new AfterTranslateInfoBar(this);
+ break;
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
+ infobar = new TranslateMessageInfoBar(this);
+ break;
+ default:
+ NOTREACHED();
+ }
+ infobar_view_ = infobar;
+ return infobar;
+}
+
+// TranslateInfoBarBase -------------------------------------------------------
+
+TranslateInfoBarBase::TranslateInfoBarBase(TranslateInfoBarDelegate* delegate)
: InfoBarView(delegate),
normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE),
error_background_(InfoBarDelegate::WARNING_TYPE) {
@@ -28,37 +52,24 @@ TranslateInfoBarBase::TranslateInfoBarBase(
icon_->SetImage(image);
AddChildView(icon_);
+ background_color_animation_.reset(new ui::SlideAnimation(this));
+ background_color_animation_->SetTweenType(ui::Tween::LINEAR);
+ background_color_animation_->SetSlideDuration(500);
TranslateInfoBarDelegate::BackgroundAnimationType animation =
- delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate::NONE) {
- background_color_animation_.reset(new ui::SlideAnimation(this));
- background_color_animation_->SetTweenType(ui::Tween::LINEAR);
- background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
- background_color_animation_->Show();
- } else {
- DCHECK_EQ(TranslateInfoBarDelegate::ERROR_TO_NORMAL, animation);
- // Hide() runs the animation in reverse.
- background_color_animation_->Reset(1.0);
- background_color_animation_->Hide();
- }
+ GetDelegate()->background_animation_type();
+ if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
+ background_color_animation_->Show();
+ } else if (animation == TranslateInfoBarDelegate::ERROR_TO_NORMAL) {
+ // Hide() runs the animation in reverse.
+ background_color_animation_->Reset(1.0);
+ background_color_animation_->Hide();
}
}
TranslateInfoBarBase::~TranslateInfoBarBase() {
}
-// Overridden from views::View:
-void TranslateInfoBarBase::Layout() {
- // Layout the close button.
- InfoBarView::Layout();
-
- // Layout the icon on left of bar.
- gfx::Size icon_ps = icon_->GetPreferredSize();
- icon_->SetBounds(InfoBarView::kHorizontalPadding,
- InfoBarView::OffsetY(this, icon_ps), icon_ps.width(), icon_ps.height());
-}
-
+// static
views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) {
views::Label* label = new views::Label(UTF16ToWideHack(text),
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
@@ -67,27 +78,7 @@ views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) {
return label;
}
-void TranslateInfoBarBase::PaintBackground(gfx::Canvas* canvas) {
- // If we're not animating, simply paint the background for the current state.
- if (background_color_animation_ == NULL ||
- !background_color_animation_->is_animating()) {
- GetBackground().Paint(canvas, this);
- return;
- }
-
- FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
- normal_background_);
- FadeBackground(canvas, background_color_animation_->GetCurrentValue(),
- error_background_);
-}
-
-void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) {
- if (background_color_animation_.get() == animation)
- SchedulePaint(); // That'll trigger a PaintBackgroud.
- else
- InfoBarView::AnimationProgressed(animation);
-}
-
+// static
views::MenuButton* TranslateInfoBarBase::CreateMenuButton(
const string16& text,
bool normal_has_border,
@@ -118,34 +109,45 @@ views::MenuButton* TranslateInfoBarBase::CreateMenuButton(
return menu_button;
}
-gfx::Point TranslateInfoBarBase::DetermineMenuPosition(
- views::MenuButton* menu_button) {
- gfx::Rect lb = menu_button->GetContentsBounds();
- gfx::Point menu_position(lb.origin());
- menu_position.Offset(2, lb.height() - 3);
- if (base::i18n::IsRTL())
- menu_position.Offset(lb.width() - 4, 0);
-
- View::ConvertPointToScreen(menu_button, &menu_position);
-#if defined(OS_WIN)
- int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN);
- if (menu_position.x() < left_bound)
- menu_position.set_x(left_bound);
-#endif
- return menu_position;
+void TranslateInfoBarBase::Layout() {
+ InfoBarView::Layout();
+
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
+ icon_size.width(), icon_size.height());
}
-TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const {
- return static_cast<TranslateInfoBarDelegate*>(delegate());
+TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() {
+ return delegate()->AsTranslateInfoBarDelegate();
+}
+
+void TranslateInfoBarBase::PaintBackground(gfx::Canvas* canvas) {
+ // If we're not animating, simply paint the background for the current state.
+ if (!background_color_animation_->is_animating()) {
+ GetBackground().Paint(canvas, this);
+ return;
+ }
+
+ FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
+ normal_background_);
+ FadeBackground(canvas, background_color_animation_->GetCurrentValue(),
+ error_background_);
}
-const InfoBarBackground& TranslateInfoBarBase::GetBackground() const {
+void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) {
+ if (animation == background_color_animation_.get())
+ SchedulePaint(); // That'll trigger a PaintBackgroud.
+ else
+ InfoBarView::AnimationProgressed(animation);
+}
+
+const views::Background& TranslateInfoBarBase::GetBackground() {
return GetDelegate()->IsError() ? error_background_ : normal_background_;
}
void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
double animation_value,
- const InfoBarBackground& background) {
+ const views::Background& background) {
// Draw the background into an offscreen buffer with alpha value per animation
// value, then blend it back into the current canvas.
canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255));
@@ -153,26 +155,3 @@ void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
background.Paint(canvas, this);
canvas->Restore();
}
-
-// TranslateInfoBarDelegate views specific method:
-InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
- TranslateInfoBarBase* infobar = NULL;
- switch (type_) {
- case BEFORE_TRANSLATE:
- infobar = new BeforeTranslateInfoBar(this);
- break;
- case AFTER_TRANSLATE:
- infobar = new AfterTranslateInfoBar(this);
- break;
- case TRANSLATING:
- case TRANSLATION_ERROR:
- infobar = new TranslateMessageInfoBar(this);
- break;
- default:
- NOTREACHED();
- }
- // Set |infobar_view_| so that the model can notify the infobar when it
- // changes.
- infobar_view_ = infobar;
- return infobar;
-}
diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h
index 16daf32..d6d8255 100644
--- a/chrome/browser/ui/views/infobars/translate_infobar_base.h
+++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h
@@ -25,50 +25,43 @@ class TranslateInfoBarBase : public TranslateInfoBarView,
explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate);
virtual ~TranslateInfoBarBase();
- // TranslateInfoBarView implementation:
- virtual void OriginalLanguageChanged() {}
- virtual void TargetLanguageChanged() {}
-
- // Overridden from views::View:
- virtual void Layout();
- virtual void PaintBackground(gfx::Canvas* canvas);
-
protected:
- // Overridden from ui::AnimationDelegate:
- virtual void AnimationProgressed(const ui::Animation* animation);
-
// Creates a label with the appropriate font and color for the translate
// infobars.
- views::Label* CreateLabel(const string16& text);
+ static views::Label* CreateLabel(const string16& text);
// Creates a menu-button with a custom appearance for the translate infobars.
- views::MenuButton* CreateMenuButton(const string16& text,
- bool normal_has_border,
- views::ViewMenuDelegate* menu_delegate);
+ static views::MenuButton* CreateMenuButton(
+ const string16& text,
+ bool normal_has_border,
+ views::ViewMenuDelegate* menu_delegate);
- // Returns the location at which the menu triggered by |menu_button| should be
- // positioned.
- gfx::Point DetermineMenuPosition(views::MenuButton* menu_button);
+ // InfoBarView:
+ virtual void Layout();
// Convenience to retrieve the TranslateInfoBarDelegate for this infobar.
- TranslateInfoBarDelegate* GetDelegate() const;
+ TranslateInfoBarDelegate* GetDelegate();
// The translate icon.
views::ImageView* icon_;
- InfoBarBackground normal_background_;
- InfoBarBackground error_background_;
- scoped_ptr<ui::SlideAnimation> background_color_animation_;
-
private:
+ // InfoBarView:
+ virtual void PaintBackground(gfx::Canvas* canvas);
+ virtual void AnimationProgressed(const ui::Animation* animation);
+
// Returns the background that should be displayed when not animating.
- const InfoBarBackground& GetBackground() const;
+ const views::Background& GetBackground();
// Paints |background| to |canvas| with the opacity level based on
// |animation_value|.
void FadeBackground(gfx::Canvas* canvas,
double animation_value,
- const InfoBarBackground& background);
+ const views::Background& background);
+
+ InfoBarBackground normal_background_;
+ InfoBarBackground error_background_;
+ scoped_ptr<ui::SlideAnimation> background_color_animation_;
DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase);
};
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
index 7abff8f..47ead3c 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc
@@ -11,48 +11,45 @@
TranslateMessageInfoBar::TranslateMessageInfoBar(
TranslateInfoBarDelegate* delegate)
- : TranslateInfoBarBase(delegate) {
+ : TranslateInfoBarBase(delegate),
+ button_(NULL) {
label_ = CreateLabel(delegate->GetMessageInfoBarText());
AddChildView(label_);
string16 button_text = delegate->GetMessageInfoBarButtonText();
- if (button_text.empty()) {
- button_ = NULL;
- } else {
+ if (!button_text.empty()) {
button_ = InfoBarTextButton::Create(this, button_text);
AddChildView(button_);
}
}
+TranslateMessageInfoBar::~TranslateMessageInfoBar() {
+}
+
void TranslateMessageInfoBar::Layout() {
TranslateInfoBarBase::Layout();
- int x = icon_->bounds().right() + InfoBarView::kIconLabelSpacing;
- gfx::Size label_pref_size = label_->GetPreferredSize();
+ int x = icon_->bounds().right() + kIconLabelSpacing;
+ gfx::Size label_size = label_->GetPreferredSize();
int available_width = GetAvailableWidth() - x;
- gfx::Size button_pref_size;
+ gfx::Size button_size;
if (button_) {
- button_pref_size = button_->GetPreferredSize();
- available_width -=
- (button_pref_size.width() + InfoBarView::kButtonInLabelSpacing);
+ button_size = button_->GetPreferredSize();
+ available_width -= (button_size.width() + kButtonInLabelSpacing);
}
- label_->SetBounds(x, InfoBarView::OffsetY(this, label_pref_size),
- std::min(label_pref_size.width(), available_width),
- label_pref_size.height());
+ label_->SetBounds(x, OffsetY(this, label_size),
+ std::min(label_size.width(), available_width), label_size.height());
if (button_) {
- button_->SetBounds(label_->bounds().right() +
- InfoBarView::kButtonInLabelSpacing,
- InfoBarView::OffsetY(this, button_pref_size),
- button_pref_size.width(), button_pref_size.height());
+ button_->SetBounds(label_->bounds().right() + kButtonInLabelSpacing,
+ OffsetY(this, button_size), button_size.width(), button_size.height());
}
}
void TranslateMessageInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
- if (sender == button_) {
+ if (sender == button_)
GetDelegate()->MessageInfoBarButtonPressed();
- return;
- }
- TranslateInfoBarBase::ButtonPressed(sender, event);
+ else
+ TranslateInfoBarBase::ButtonPressed(sender, event);
}
diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.h b/chrome/browser/ui/views/infobars/translate_message_infobar.h
index 6f5fa72..a29122d 100644
--- a/chrome/browser/ui/views/infobars/translate_message_infobar.h
+++ b/chrome/browser/ui/views/infobars/translate_message_infobar.h
@@ -14,12 +14,13 @@ class TranslateMessageInfoBar : public TranslateInfoBarBase {
public:
explicit TranslateMessageInfoBar(TranslateInfoBarDelegate* delegate);
- virtual void Layout();
+ private:
+ virtual ~TranslateMessageInfoBar();
- // views::ButtonListener implementation:
+ // TranslateInfoBarBase:
+ virtual void Layout();
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- private:
views::Label* label_;
InfoBarTextButton* button_;
diff --git a/chrome/common/automation_messages_internal.h b/chrome/common/automation_messages_internal.h
index f3abe90..8ff405d 100644
--- a/chrome/common/automation_messages_internal.h
+++ b/chrome/common/automation_messages_internal.h
@@ -755,14 +755,14 @@ IPC_SYNC_MESSAGE_CONTROL1_2(AutomationMsg_BookmarkBarVisibility,
// returns -1 if an error occurred.
IPC_SYNC_MESSAGE_CONTROL1_1(AutomationMsg_GetInfoBarCount,
int /* tab_handle */,
- int /* info bar count */)
+ size_t /* info bar count */)
// This message triggers the action associated with the "accept" button in
// the info-bar at the specified index. If |wait for navigation| is true, it
// won't return until a navigation has occurred.
IPC_SYNC_MESSAGE_CONTROL3_1(AutomationMsg_ClickInfoBarAccept,
int /* tab_handle */,
- int /* info bar index */,
+ size_t /* info bar index */,
bool /* wait for navigation */,
// This line blank on purpose, see comment atop file about __LINE__.
/* navigation result */
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index 5625c40..e04c039 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -1,4 +1,4 @@
-// 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.
@@ -638,14 +638,14 @@ bool TabProxy::SavePage(const FilePath& file_name,
return succeeded;
}
-bool TabProxy::GetInfoBarCount(int* count) {
+bool TabProxy::GetInfoBarCount(size_t* count) {
if (!is_valid())
return false;
return sender_->Send(new AutomationMsg_GetInfoBarCount(handle_, count));
}
-bool TabProxy::WaitForInfoBarCount(int target_count) {
+bool TabProxy::WaitForInfoBarCount(size_t target_count) {
if (!is_valid())
return false;
@@ -654,7 +654,7 @@ bool TabProxy::WaitForInfoBarCount(int target_count) {
handle_, target_count, &success)) && success;
}
-bool TabProxy::ClickInfoBarAccept(int info_bar_index,
+bool TabProxy::ClickInfoBarAccept(size_t info_bar_index,
bool wait_for_navigation) {
if (!is_valid())
return false;
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 0aa0cff..e8dc599 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -1,4 +1,4 @@
-// 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.
@@ -338,16 +338,16 @@ class TabProxy : public AutomationResourceProxy,
SavePackage::SavePackageType type) WARN_UNUSED_RESULT;
// Retrieves the number of info-bars currently showing in |count|.
- bool GetInfoBarCount(int* count) WARN_UNUSED_RESULT;
+ bool GetInfoBarCount(size_t* count) WARN_UNUSED_RESULT;
// Waits until the infobar count is |count|.
// Returns true on success.
- bool WaitForInfoBarCount(int count) WARN_UNUSED_RESULT;
+ bool WaitForInfoBarCount(size_t count) WARN_UNUSED_RESULT;
// Causes a click on the "accept" button of the info-bar at |info_bar_index|.
// If |wait_for_navigation| is true, this call does not return until a
// navigation has occurred.
- bool ClickInfoBarAccept(int info_bar_index,
+ bool ClickInfoBarAccept(size_t info_bar_index,
bool wait_for_navigation) WARN_UNUSED_RESULT;
// Retrieves the time at which the last navigation occurred. This is intended