diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 17:00:51 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 17:00:51 +0000 |
commit | be6354f978d56dd8237d3ac9bcf8bb76cdd0cb57 (patch) | |
tree | 09cda907cbfecc852b92e68017bd833156e332a4 | |
parent | 86b3ea336404f6248e3d8b63be219c5ba100f9d4 (diff) | |
download | chromium_src-be6354f978d56dd8237d3ac9bcf8bb76cdd0cb57.zip chromium_src-be6354f978d56dd8237d3ac9bcf8bb76cdd0cb57.tar.gz chromium_src-be6354f978d56dd8237d3ac9bcf8bb76cdd0cb57.tar.bz2 |
Couple of tweaks to the cookie prompt dialog:
. Fixes bug that lead to randomly expanding and not (expanded_view_
wasn't in the member initializer list).
. Fixed bug where expanding/collapsing would result in dialog changing
to wrong size.
. Persist expanded state to prefs.
BUG=35092, 35165
TEST=see bugs
Review URL: http://codereview.chromium.org/595014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38622 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_prefs.cc | 8 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog.cc | 7 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog.h | 3 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog_views.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.cc | 90 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.h | 22 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 3 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
8 files changed, 66 insertions, 82 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 5d918c8..551c323 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -48,6 +48,11 @@ #include "chrome/browser/chromeos/preferences.h" #endif +#if defined(OS_WIN) +// TODO: port me. +#include "chrome/browser/cookie_modal_dialog.h" +#endif + namespace browser { void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { @@ -74,6 +79,9 @@ void RegisterLocalState(PrefService* local_state) { BrowserView::RegisterBrowserViewPrefs(local_state); #endif TaskManager::RegisterPrefs(local_state); +#if defined(OS_WIN) + CookiePromptModalDialog::RegisterPrefs(local_state); +#endif } void RegisterUserPrefs(PrefService* user_prefs) { diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc index eea617d..5bd46fa 100644 --- a/chrome/browser/cookie_modal_dialog.cc +++ b/chrome/browser/cookie_modal_dialog.cc @@ -5,6 +5,8 @@ #include "chrome/browser/cookie_modal_dialog.h" #include "chrome/browser/views/cookie_prompt_view.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, @@ -29,4 +31,7 @@ CookiePromptModalDialog::CookiePromptModalDialog( delegate_(delegate) { } - +// static +void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) { + prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false); +} diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h index df70f0a..d36bb93 100644 --- a/chrome/browser/cookie_modal_dialog.h +++ b/chrome/browser/cookie_modal_dialog.h @@ -12,6 +12,7 @@ #include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" #include "googleurl/src/gurl.h" +class PrefService; // A controller+model class for cookie and local storage warning prompt. // |NativeDialog| is a platform specific view. @@ -29,6 +30,8 @@ class CookiePromptModalDialog : public AppModalDialog { CookiePromptModalDialogDelegate* delegate); virtual ~CookiePromptModalDialog() {} + static void RegisterPrefs(PrefService* prefs); + // AppModalDialog overrides. virtual int GetDialogButtons(); virtual void AcceptWindow(); diff --git a/chrome/browser/cookie_modal_dialog_views.cc b/chrome/browser/cookie_modal_dialog_views.cc index 1cf3ac5..6e9027a 100644 --- a/chrome/browser/cookie_modal_dialog_views.cc +++ b/chrome/browser/cookie_modal_dialog_views.cc @@ -39,16 +39,12 @@ void CookiePromptModalDialog::CancelWindow() { NativeDialog CookiePromptModalDialog::CreateNativeDialog() { #if defined(OS_WIN) - if (cookie_ui_) { - return new CookiePromptView(this, - tab_contents_->GetMessageBoxRootWindow(), - tab_contents_->profile(), - host_, cookie_line_, delegate_); - } return new CookiePromptView(this, - tab_contents_->GetMessageBoxRootWindow(), - tab_contents_->profile(), - storage_info_, delegate_); + tab_contents_->GetMessageBoxRootWindow(), + tab_contents_->profile(), + storage_info_, + host_, cookie_line_, delegate_, + cookie_ui_); #else return NULL; #endif diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc index 80619b2..001efbc 100644 --- a/chrome/browser/views/cookie_prompt_view.cc +++ b/chrome/browser/views/cookie_prompt_view.cc @@ -12,12 +12,15 @@ #include "base/i18n/time_formatting.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/cookie_modal_dialog.h" #include "chrome/browser/profile.h" #include "chrome/browser/views/browser_dialogs.h" #include "chrome/browser/views/cookie_info_view.h" #include "chrome/browser/views/local_storage_info_view.h" #include "chrome/browser/views/options/content_settings_window_view.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "net/base/cookie_monster.h" @@ -38,31 +41,30 @@ CookiePromptView::CookiePromptView( CookiePromptModalDialog* parent, gfx::NativeWindow root_window, Profile* profile, + const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, const std::string& host, const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate) - : cookie_ui_(true), + CookiePromptModalDialogDelegate* delegate, + bool cookie_ui) + : remember_radio_(NULL), + ask_radio_(NULL), + allow_button_(NULL), + block_button_(NULL), + show_cookie_link_(NULL), + info_view_(NULL), + session_expire_(false), + expanded_view_(false), + signaled_(false), + cookie_ui_(cookie_ui), parent_(parent), root_window_(root_window), - profile_(profile), + host_(host), cookie_line_(cookie_line), - delegate_(delegate) { - InitializeViewResources(host); -} - -CookiePromptView::CookiePromptView( - CookiePromptModalDialog* parent, - gfx::NativeWindow root_window, - Profile* profile, - const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, - CookiePromptModalDialogDelegate* delegate) - : cookie_ui_(false), - parent_(parent), - root_window_(root_window), - profile_(profile), local_storage_info_(storage_info), delegate_(delegate) { - InitializeViewResources(storage_info.host); + InitializeViewResources(host); + expanded_view_ = g_browser_process->local_state()-> + GetBoolean(prefs::kCookiePromptExpanded); } CookiePromptView::~CookiePromptView() { @@ -138,35 +140,13 @@ void CookiePromptView::ButtonPressed(views::Button* sender, /////////////////////////////////////////////////////////////////////////////// // CookiePromptView, views::LinkController implementation: void CookiePromptView::LinkActivated(views::Link* source, int event_flags) { - if (source == show_cookie_link_) { - ToggleDetailsViewExpand(); - return; - } - - DCHECK_EQ(source, manage_cookies_link_); - browser::ShowContentSettingsWindow(root_window_, - CONTENT_SETTINGS_TYPE_COOKIES, profile_); + DCHECK_EQ(source, show_cookie_link_); + ToggleDetailsViewExpand(); } /////////////////////////////////////////////////////////////////////////////// // CookiePromptView, private: -CookiePromptView::CookiePromptView(Profile* profile, - CookiePromptModalDialogDelegate* delegate) - : remember_radio_(NULL), - ask_radio_(NULL), - allow_button_(NULL), - block_button_(NULL), - show_cookie_link_(NULL), - manage_cookies_link_(NULL), - info_view_(NULL), - session_expire_(false), - expanded_view_(false), - signaled_(false), - delegate_(delegate), - profile_(profile) { -} - void CookiePromptView::Init() { std::wstring display_host = UTF8ToWide(host_); views::Label* description_label = new views::Label(l10n_util::GetStringF( @@ -187,9 +167,6 @@ void CookiePromptView::Init() { show_cookie_link_ = new views::Link( l10n_util::GetString(IDS_COOKIE_SHOW_DETAILS_LABEL)); show_cookie_link_->SetController(this); - manage_cookies_link_ = new views::Link( - l10n_util::GetString(IDS_COOKIE_MANAGE_ALERTS_LABEL)); - manage_cookies_link_->SetController(this); using views::GridLayout; @@ -255,8 +232,6 @@ void CookiePromptView::Init() { link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); layout->StartRow(0, link_column_layout_id); layout->AddView(show_cookie_link_); - layout->AddView(manage_cookies_link_, 1, 1, - GridLayout::TRAILING, GridLayout::CENTER); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, one_column_layout_id); @@ -276,7 +251,8 @@ void CookiePromptView::Init() { local_storage_info_view->SetLocalStorageInfo(local_storage_info_); info_view_ = local_storage_info_view; } - info_view_->SetVisible(false); + + info_view_->SetVisible(expanded_view_); // Set default values. ask_radio_->SetChecked(true); @@ -289,15 +265,21 @@ int CookiePromptView::GetExtendedViewHeight() { } void CookiePromptView::ToggleDetailsViewExpand() { + int old_extended_height = GetExtendedViewHeight(); + expanded_view_ = !expanded_view_; - views::Window* parent = GetWindow(); - gfx::Size non_client_size = parent->GetNonClientView()->GetPreferredSize(); - gfx::Rect bounds = parent->GetBounds(); - bounds.set_height(non_client_size.height() + GetExtendedViewHeight()); - parent->SetBounds(bounds, NULL); + g_browser_process->local_state()->SetBoolean(prefs::kCookiePromptExpanded, + expanded_view_); + // We have to set the visbility before asking for the extended view height + // again as there is a bug in combobox that results in preferred height + // changing when visible and not visible. info_view_->SetVisible(expanded_view_); - Layout(); + int extended_height_delta = GetExtendedViewHeight() - old_extended_height; + views::Window* window = GetWindow(); + gfx::Rect bounds = window->GetBounds(); + bounds.set_height(bounds.height() + extended_height_delta); + window->SetBounds(bounds, NULL); } void CookiePromptView::InitializeViewResources(const std::string& host) { diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h index 14560bc..5f1e400 100644 --- a/chrome/browser/views/cookie_prompt_view.h +++ b/chrome/browser/views/cookie_prompt_view.h @@ -37,22 +37,16 @@ class CookiePromptView : public views::View, public views::LinkController, public CookieInfoViewDelegate { public: - // Show the Cookies Window, creating one if necessary. - CookiePromptView( - CookiePromptModalDialog* parent, - gfx::NativeWindow root_window, - Profile* profile, - const std::string& host, - const std::string& cookie_line, - CookiePromptModalDialogDelegate* delegate); - CookiePromptView( CookiePromptModalDialog* parent, gfx::NativeWindow root_window, Profile* profile, const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info, - CookiePromptModalDialogDelegate* delegate); + const std::string& host, + const std::string& cookie_line, + CookiePromptModalDialogDelegate* delegate, + bool cookie_ui); virtual ~CookiePromptView(); @@ -88,10 +82,6 @@ class CookiePromptView : public views::View, virtual void ModifyExpireDate(bool session_expire); private: - // Use the static factory method to show. - explicit CookiePromptView(Profile* profile, - CookiePromptModalDialogDelegate* delegate); - // Initialize the dialog layout. void Init(); @@ -109,7 +99,6 @@ class CookiePromptView : public views::View, views::NativeButton* allow_button_; views::NativeButton* block_button_; views::Link* show_cookie_link_; - views::Link* manage_cookies_link_; views::View* info_view_; // True if cookie should expire with this session. @@ -132,9 +121,6 @@ class CookiePromptView : public views::View, gfx::NativeWindow root_window_; - // The Profile for which Cookies are displayed. - Profile* profile_; - // Cookie / local storage host. std::string host_; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index b33045b..a742996 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -164,6 +164,9 @@ const wchar_t kDnsStartupPrefetchList[] = L"StartupDNSPrefetchList"; // This list is adaptively grown and pruned. extern const wchar_t kDnsHostReferralList[] = L"HostReferralList"; +// Is the cookie prompt expanded? +extern const wchar_t kCookiePromptExpanded[] = L"cookieprompt.expanded"; + #if defined(OS_LINUX) // Prefs for SSLConfigServicePref. Currently, these are only present on // and used by Linux. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 11faae7..6fecca6 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -59,6 +59,7 @@ extern const wchar_t kAlternateErrorPagesEnabled[]; extern const wchar_t kDnsPrefetchingEnabled[]; extern const wchar_t kDnsStartupPrefetchList[]; extern const wchar_t kDnsHostReferralList[]; +extern const wchar_t kCookiePromptExpanded[]; #if defined(OS_LINUX) extern const wchar_t kCertRevocationCheckingEnabled[]; extern const wchar_t kSSL2Enabled[]; |