diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 21:00:54 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-26 21:00:54 +0000 |
commit | a592615a53d4c9a75f9dfa07b18b64039eebac48 (patch) | |
tree | 7f459015fc3f6eb7b17c7a2c2fb3557bc6359da1 | |
parent | 7b0f8e41468fb9cccf9d5304258e6cbe91ccea38 (diff) | |
download | chromium_src-a592615a53d4c9a75f9dfa07b18b64039eebac48.zip chromium_src-a592615a53d4c9a75f9dfa07b18b64039eebac48.tar.gz chromium_src-a592615a53d4c9a75f9dfa07b18b64039eebac48.tar.bz2 |
Content Settings dialog and related Options UI changes.
BUG=32719
TEST=none
Review URL: http://codereview.chromium.org/554045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37153 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 1729 insertions, 346 deletions
diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd index 4af4560..3584702 100644 --- a/chrome/app/resources/locale_settings.grd +++ b/chrome/app/resources/locale_settings.grd @@ -271,6 +271,18 @@ 80 </message> + <!-- The width of the Content Settings dialog box, in characters (character width = --> + <!-- average character width for default dialog box font) --> + <message name="IDS_CONTENT_SETTINGS_DIALOG_WIDTH_CHARS" use_name_for_id="true"> + 72 + </message> + + <!-- The height of the Content Settings dialog box, in lines (line height = character --> + <!-- height for default dialog box font) --> + <message name="IDS_CONTENT_SETTINGS_DIALOG_HEIGHT_LINES" use_name_for_id="true"> + 23 + </message> + <!-- The width and height of the URL picker dialog box in characters and lines --> <!-- (See above). --> <message name="IDS_URLPICKER_DIALOG_WIDTH_CHARS" use_name_for_id="true"> @@ -395,6 +407,15 @@ <!-- The width and height of the Cookies dialog box in characters and lines --> <!-- (See above). --> + <message name="IDS_COOKIES_PROMPT_WIDTH_CHARS" use_name_for_id="true"> + 82 + </message> + <message name="IDS_COOKIES_PROMPT_HEIGHT_LINES" use_name_for_id="true"> + 25 + </message> + + <!-- The width and height of the Cookies dialog box in characters and lines --> + <!-- (See above). --> <message name="IDS_COOKIES_DIALOG_WIDTH_CHARS" use_name_for_id="true"> 80 </message> diff --git a/chrome/browser/content_settings_window.h b/chrome/browser/content_settings_window.h new file mode 100644 index 0000000..a77a579 --- /dev/null +++ b/chrome/browser/content_settings_window.h @@ -0,0 +1,36 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CONTENT_SETTINGS_WINDOW_H_ +#define CHROME_BROWSER_CONTENT_SETTINGS_WINDOW_H_ + +class PrefService; +class Profile; + +// A particular tab within the Content Settings dialog. When passed to +// ShowContentSettingsWindow(), CONTENT_SETTINGS_TAB_DEFAULT means select the +// last. +enum ContentSettingsTab { + CONTENT_SETTINGS_TAB_DEFAULT = -1, + CONTENT_SETTINGS_TAB_COOKIES, + CONTENT_SETTINGS_TAB_IMAGES, + CONTENT_SETTINGS_TAB_JAVASCRIPT, + CONTENT_SETTINGS_TAB_PLUGINS, + CONTENT_SETTINGS_PAGE_POPUPS, + CONTENT_SETTINGS_NUM_TABS +}; + +class ContentSettings { + public: + // Show the Content Settings window selecting the specified page. + // If a Content Settings window is currently open, this just activates it + // instead of opening a new one. + static void ShowContentSettingsWindow(ContentSettingsTab page, + Profile* profile); + + static void RegisterPrefs(PrefService* prefs); +}; + +#endif // CHROME_BROWSER_CONTENT_SETTINGS_WINDOW_H_ + diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc index 2916886..94732ea 100644 --- a/chrome/browser/options_util.cc +++ b/chrome/browser/options_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -77,7 +77,6 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { // don't reset it. const wchar_t* kLocalStatePrefs[] = { prefs::kApplicationLocale, - prefs::kOptionsWindowLastTabIndex, }; for (size_t i = 0; i < arraysize(kLocalStatePrefs); ++i) local_state->ClearPref(kLocalStatePrefs[i]); diff --git a/chrome/browser/views/cookie_info_view.cc b/chrome/browser/views/cookie_info_view.cc new file mode 100644 index 0000000..a0cfb3e --- /dev/null +++ b/chrome/browser/views/cookie_info_view.cc @@ -0,0 +1,269 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/cookie_info_view.h" + +#include <algorithm> + +#include "app/gfx/canvas.h" +#include "app/gfx/color_utils.h" +#include "app/l10n_util.h" +#include "base/i18n/time_formatting.h" +#include "base/message_loop.h" +#include "base/string_util.h" +#include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/profile.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "net/base/cookie_monster.h" +#include "views/border.h" +#include "views/grid_layout.h" +#include "views/controls/label.h" +#include "views/controls/button/native_button.h" +#include "views/controls/tree/tree_view.h" +#include "views/controls/textfield/textfield.h" +#include "views/standard_layout.h" + +static const int kCookieInfoViewBorderSize = 1; +static const int kCookieInfoViewInsetSize = 3; + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView, public: + +CookieInfoView::CookieInfoView(bool editable_expiration_date) + : name_label_(NULL), + name_value_field_(NULL), + content_label_(NULL), + content_value_field_(NULL), + domain_label_(NULL), + domain_value_field_(NULL), + path_label_(NULL), + path_value_field_(NULL), + send_for_label_(NULL), + send_for_value_field_(NULL), + created_label_(NULL), + created_value_field_(NULL), + expires_label_(NULL), + expires_value_field_(NULL), + expires_value_combobox_(NULL), + expire_view_(NULL), + editable_expiration_date_(editable_expiration_date), + delegate_(NULL) { +} + +CookieInfoView::~CookieInfoView() { +} + +void CookieInfoView::SetCookie( + const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie) { + name_value_field_->SetText(UTF8ToWide(cookie.Name())); + content_value_field_->SetText(UTF8ToWide(cookie.Value())); + domain_value_field_->SetText(UTF8ToWide(domain)); + path_value_field_->SetText(UTF8ToWide(cookie.Path())); + created_value_field_->SetText( + base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())); + + std::wstring expire_text = cookie.DoesExpire() ? + base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate()) : + l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION); + + if (editable_expiration_date_) { + expire_combo_values_.clear(); + if (cookie.DoesExpire()) + expire_combo_values_.push_back(expire_text); + expire_combo_values_.push_back( + l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION)); + expires_value_combobox_->ModelChanged(); + expires_value_combobox_->SetSelectedItem(0); + expires_value_combobox_->SetEnabled(true); + } else { + expires_value_field_->SetText(expire_text); + } + + send_for_value_field_->SetText(cookie.IsSecure() ? + l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_SECURE) : + l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_ANY)); + EnableCookieDisplay(true); + Layout(); +} + + +void CookieInfoView::ClearCookieDisplay() { + std::wstring no_cookie_string = + l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); + name_value_field_->SetText(no_cookie_string); + content_value_field_->SetText(no_cookie_string); + domain_value_field_->SetText(no_cookie_string); + path_value_field_->SetText(no_cookie_string); + send_for_value_field_->SetText(no_cookie_string); + created_value_field_->SetText(no_cookie_string); + if (expires_value_field_) + expires_value_field_->SetText(no_cookie_string); + EnableCookieDisplay(false); +} + +void CookieInfoView::EnableCookieDisplay(bool enabled) { + name_value_field_->SetEnabled(enabled); + content_value_field_->SetEnabled(enabled); + domain_value_field_->SetEnabled(enabled); + path_value_field_->SetEnabled(enabled); + send_for_value_field_->SetEnabled(enabled); + created_value_field_->SetEnabled(enabled); + if (expires_value_field_) + expires_value_field_->SetEnabled(enabled); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView, views::View overrides. + +void CookieInfoView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this) + Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView, views::Combobox::Listener overrides. + +void CookieInfoView::ItemChanged(views::Combobox* combo_box, + int prev_index, + int new_index) { + DCHECK(combo_box == expires_value_combobox_); + if (delegate_) + delegate_->ModifyExpireDate(new_index != 0); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView, ComboboxModel overrides. +int CookieInfoView::GetItemCount() { + return static_cast<int>(expire_combo_values_.size()); +} + +std::wstring CookieInfoView::GetItemAt(int index) { + return expire_combo_values_[index]; +} + +void CookieInfoView::AddLabelRow(int layout_id, views::GridLayout* layout, + views::View* label, views::View* value) { + layout->StartRow(0, layout_id); + layout->AddView(label); + layout->AddView(value, 2, 1, views::GridLayout::FILL, + views::GridLayout::CENTER); + layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); +} + +void CookieInfoView::AddControlRow(int layout_id, views::GridLayout* layout, + views::View* label, views::View* control) { + layout->StartRow(0, layout_id); + layout->AddView(label); + layout->AddView(control, 1, 1); + layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView, private: + +void CookieInfoView::Init() { + // Ensure we don't run this more than once and leak memory. + DCHECK(!name_label_); + + SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); + views::Border* border = views::Border::CreateSolidBorder( + kCookieInfoViewBorderSize, border_color); + set_border(border); + + name_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); + name_value_field_ = new views::Textfield; + content_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_CONTENT_LABEL)); + content_value_field_ = new views::Textfield; + domain_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); + domain_value_field_ = new views::Textfield; + path_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_PATH_LABEL)); + path_value_field_ = new views::Textfield; + send_for_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); + send_for_value_field_ = new views::Textfield; + created_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_CREATED_LABEL)); + created_value_field_ = new views::Textfield; + expires_label_ = new views::Label( + l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); + if (editable_expiration_date_) + expires_value_combobox_ = new views::Combobox(this); + else + expires_value_field_ = new views::Textfield; + + using views::GridLayout; + using views::ColumnSet; + + GridLayout* layout = new GridLayout(this); + layout->SetInsets(kCookieInfoViewInsetSize, + kCookieInfoViewInsetSize, + kCookieInfoViewInsetSize, + kCookieInfoViewInsetSize); + SetLayoutManager(layout); + + int three_column_layout_id = 0; + ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); + column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + + AddLabelRow(three_column_layout_id, layout, name_label_, name_value_field_); + AddLabelRow(three_column_layout_id, layout, content_label_, + content_value_field_); + AddLabelRow(three_column_layout_id, layout, domain_label_, + domain_value_field_); + AddLabelRow(three_column_layout_id, layout, path_label_, path_value_field_); + AddLabelRow(three_column_layout_id, layout, send_for_label_, + send_for_value_field_); + AddLabelRow(three_column_layout_id, layout, created_label_, + created_value_field_); + + if (editable_expiration_date_) { + AddControlRow(three_column_layout_id, layout, expires_label_, + expires_value_combobox_); + } else { + AddLabelRow(three_column_layout_id, layout, expires_label_, + expires_value_field_); + } + + // Color these borderless text areas the same as the containing dialog. + SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); + // Now that the Textfields are in the view hierarchy, we can initialize them. + name_value_field_->SetReadOnly(true); + name_value_field_->RemoveBorder(); + name_value_field_->SetBackgroundColor(text_area_background); + content_value_field_->SetReadOnly(true); + content_value_field_->RemoveBorder(); + content_value_field_->SetBackgroundColor(text_area_background); + domain_value_field_->SetReadOnly(true); + domain_value_field_->RemoveBorder(); + domain_value_field_->SetBackgroundColor(text_area_background); + path_value_field_->SetReadOnly(true); + path_value_field_->RemoveBorder(); + path_value_field_->SetBackgroundColor(text_area_background); + send_for_value_field_->SetReadOnly(true); + send_for_value_field_->RemoveBorder(); + send_for_value_field_->SetBackgroundColor(text_area_background); + created_value_field_->SetReadOnly(true); + created_value_field_->RemoveBorder(); + created_value_field_->SetBackgroundColor(text_area_background); + if (expires_value_field_) { + expires_value_field_->SetReadOnly(true); + expires_value_field_->RemoveBorder(); + expires_value_field_->SetBackgroundColor(text_area_background); + } +} + diff --git a/chrome/browser/views/cookie_info_view.h b/chrome/browser/views/cookie_info_view.h new file mode 100644 index 0000000..5846146 --- /dev/null +++ b/chrome/browser/views/cookie_info_view.h @@ -0,0 +1,118 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_COOKIE_INFO_VIEW_H_ +#define CHROME_BROWSER_VIEWS_COOKIE_INFO_VIEW_H_ + +#include <string> +#include <vector> + +#include "app/combobox_model.h" +#include "net/base/cookie_monster.h" +#include "views/controls/combobox/combobox.h" +#include "views/view.h" + +namespace views { +class GridLayout; +class Label; +class NativeButton; +class Textfield; +} + + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoViewDelegate +// +class CookieInfoViewDelegate { + public: + virtual void ModifyExpireDate(bool session_expire) = 0; + + protected: + virtual ~CookieInfoViewDelegate() {} +}; + +/////////////////////////////////////////////////////////////////////////////// +// CookieInfoView +// +// Responsible for displaying a tabular grid of Cookie information. +class CookieInfoView : public views::View, + public views::Combobox::Listener, + public ComboboxModel { + public: + explicit CookieInfoView(bool editable_expiration_date); + virtual ~CookieInfoView(); + + // Update the display from the specified CookieNode. + void SetCookie(const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie_node); + + // Clears the cookie display to indicate that no or multiple cookies are + // selected. + void ClearCookieDisplay(); + + // Enables or disables the cookie property text fields. + void EnableCookieDisplay(bool enabled); + + void set_delegate(CookieInfoViewDelegate* delegate) { delegate_ = delegate; } + + protected: + // views::View overrides: + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + + // views::Combobox::Listener override. + virtual void ItemChanged(views::Combobox* combo_box, + int prev_index, + int new_index); + + // ComboboxModel overrides for expires_value_combobox_. + virtual int GetItemCount(); + virtual std::wstring GetItemAt(int index); + + private: + // Layout helper routines. + void AddLabelRow(int layout_id, views::GridLayout* layout, + views::View* label, views::View* value); + void AddControlRow(int layout_id, views::GridLayout* layout, + views::View* label, views::View* control); + + // Sets up the view layout. + void Init(); + + // Individual property labels + views::Label* name_label_; + views::Textfield* name_value_field_; + views::Label* content_label_; + views::Textfield* content_value_field_; + views::Label* domain_label_; + views::Textfield* domain_value_field_; + views::Label* path_label_; + views::Textfield* path_value_field_; + views::Label* send_for_label_; + views::Textfield* send_for_value_field_; + views::Label* created_label_; + views::Textfield* created_value_field_; + views::Label* expires_label_; + views::Textfield* expires_value_field_; + views::Combobox* expires_value_combobox_; + views::View* expire_view_; + + // Option values for expires_value_combobox_. + std::vector<std::wstring> expire_combo_values_; + + // True if expiration date can be edited. In this case we will show + // expires_value_combobox_ instead of expires_value_field_. The cookie's + // expiration date is editable only this class is used in + // CookiesPromptView (alert before cookie is set), in all other cases we + // don't let user directly change cookie setting. + bool editable_expiration_date_; + + CookieInfoViewDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(CookieInfoView); +}; + +#endif // CHROME_BROWSER_VIEWS_COOKIE_INFO_VIEW_H_ + diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc new file mode 100644 index 0000000..0adf262 --- /dev/null +++ b/chrome/browser/views/cookie_prompt_view.cc @@ -0,0 +1,291 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/cookie_prompt_view.h" + +#include <algorithm> + +#include "app/gfx/canvas.h" +#include "app/gfx/color_utils.h" +#include "app/l10n_util.h" +#include "base/i18n/time_formatting.h" +#include "base/message_loop.h" +#include "base/string_util.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/content_settings_window.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "net/base/cookie_monster.h" +#include "views/controls/label.h" +#include "views/controls/button/native_button.h" +#include "views/controls/button/radio_button.h" +#include "views/controls/textfield/textfield.h" +#include "views/grid_layout.h" +#include "views/standard_layout.h" +#include "views/window/non_client_view.h" + +static const int kCookiePromptViewInsetSize = 5; + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, public: + +// static +void CookiesPromptView::ShowCookiePromptWindow( + gfx::NativeWindow parent, + Profile* profile, + const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie, + CookiesPromptViewDelegate* delegate) { + + CookiesPromptView* cookies_view = new CookiesPromptView(profile, delegate); + cookies_view->SetCookie(domain, cookie); + + views::Window::CreateChromeWindow(parent, + gfx::Rect(), + cookies_view)->Show(); +} + +CookiesPromptView::~CookiesPromptView() { +} + +void CookiesPromptView::SetCookie( + const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie) { + + domain_ = domain; + std::string display_domain = domain; + if (!domain.empty() && domain[0] == '.') + display_domain = display_domain.substr(1); + display_domain_ = UTF8ToWide(display_domain); + title_ = l10n_util::GetStringF(IDS_COOKIE_ALERT_TITLE, + display_domain_); + cookie_.reset(new net::CookieMonster::CanonicalCookie( + cookie.Name(), + cookie.Value(), + cookie.Path(), + cookie.IsSecure(), + cookie.IsHttpOnly(), + cookie.CreationDate(), + cookie.LastAccessDate(), + cookie.DoesExpire(), + cookie.ExpiryDate())); +} + + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, views::View overrides: + +gfx::Size CookiesPromptView::GetPreferredSize() { + gfx::Size client_size = views::View::GetPreferredSize(); + return gfx::Size(client_size.width(), + client_size.height() + GetExtendedViewHeight()); +} + + +void CookiesPromptView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this) + Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, views::DialogDelegate implementation: + +std::wstring CookiesPromptView::GetWindowTitle() const { + return title_; +} + +void CookiesPromptView::WindowClosing() { + if (!signaled_ && delegate_) + delegate_->BlockCookie(false); +} + +views::View* CookiesPromptView::GetContentsView() { + return this; +} + +// CookieInfoViewDelegate overrides: +void CookiesPromptView::ModifyExpireDate(bool session_expire) { + session_expire_ = session_expire; +} + + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, views::ButtonListener implementation: + +void CookiesPromptView::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == allow_button_) { + if (delegate_) { + delegate_->AllowCookie(remember_radio_->checked(), session_expire_); + signaled_ = true; + } + GetWindow()->Close(); + } else if (sender == block_button_) { + if (delegate_) { + delegate_->BlockCookie(remember_radio_->checked()); + signaled_ = true; + } + GetWindow()->Close(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, views::LinkController implementation: +void CookiesPromptView::LinkActivated(views::Link* source, int event_flags) { + if (source == show_cookie_link_) + ToggleCookieViewExpand(); + else if (source == manage_cookies_link_) + ContentSettings::ShowContentSettingsWindow(CONTENT_SETTINGS_TAB_COOKIES, + profile_); + else + NOTREACHED(); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookiesPromptView, private: + +CookiesPromptView::CookiesPromptView(Profile* profile, + CookiesPromptViewDelegate* delegate) + : description_label_(NULL), + 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 CookiesPromptView::Init() { + DCHECK(cookie_.get()); + // Ensure we don't run twice and leak memory. + DCHECK(!description_label_); + + int radio_group_id = 1; + description_label_ = new views::Label( + l10n_util::GetStringF(IDS_COOKIE_ALERT_LABEL, display_domain_)); + remember_radio_ = new views::RadioButton( + l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, + display_domain_), + radio_group_id); + remember_radio_->set_listener(this); + ask_radio_ = new views::RadioButton( + l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id); + ask_radio_->set_listener(this); + allow_button_ = new views::NativeButton( + this, l10n_util::GetString(IDS_COOKIE_ALERT_ALLOW_BUTTON)); + block_button_ = new views::NativeButton( + this, l10n_util::GetString(IDS_COOKIE_ALERT_BLOCK_BUTTON)); + 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); + + info_view_ = new CookieInfoView(true); + info_view_->set_delegate(this); + + using views::GridLayout; + using views::ColumnSet; + + GridLayout* layout = CreatePanelGridLayout(this); + layout->SetInsets(kCookiePromptViewInsetSize, kCookiePromptViewInsetSize, + kCookiePromptViewInsetSize, kCookiePromptViewInsetSize); + SetLayoutManager(layout); + + const int one_column_layout_id = 0; + ColumnSet* one_column_set = layout->AddColumnSet(one_column_layout_id); + one_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + one_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + one_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, one_column_layout_id); + layout->AddView(description_label_); + layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); + layout->StartRow(0, one_column_layout_id); + layout->AddView(remember_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, one_column_layout_id); + layout->AddView(ask_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + View* button_container = new View(); + GridLayout* button_layout = new GridLayout(button_container); + button_container->SetLayoutManager(button_layout); + const int inner_column_layout_id = 1; + ColumnSet* inner_column_set = button_layout->AddColumnSet( + inner_column_layout_id); + inner_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + inner_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + inner_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + button_layout->StartRow(0, inner_column_layout_id); + button_layout->AddView(allow_button_); + button_layout->AddView(block_button_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + int button_column_layout_id = 2; + ColumnSet* button_column_set = layout->AddColumnSet(button_column_layout_id); + button_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + button_column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, + GridLayout::USE_PREF, 0, 0); + button_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + layout->StartRow(0, one_column_layout_id); + layout->AddView(button_container, 1, 1, + GridLayout::TRAILING, GridLayout::CENTER); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + int link_column_layout_id = 3; + ColumnSet* link_column_set = layout->AddColumnSet(link_column_layout_id); + link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + link_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + link_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + 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); + layout->AddView(info_view_, 1, 1, GridLayout::FILL, GridLayout::CENTER); + info_view_->SetVisible(false); + + // Set default values. + ask_radio_->SetChecked(true); +} + +int CookiesPromptView::GetExtendedViewHeight() { + DCHECK(info_view_); + return expanded_view_ ? kRelatedControlVerticalSpacing : + -info_view_->GetPreferredSize().height(); +} + +void CookiesPromptView::ToggleCookieViewExpand() { + expanded_view_ = !expanded_view_; + if (expanded_view_) + info_view_->SetCookie(domain_, *cookie_.get()); + 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); + + info_view_->SetVisible(expanded_view_); + Layout(); +} + diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h new file mode 100644 index 0000000..a83c33d --- /dev/null +++ b/chrome/browser/views/cookie_prompt_view.h @@ -0,0 +1,143 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ +#define CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ + +#include <string> + +#include "base/task.h" +#include "chrome/browser/views/cookie_info_view.h" +#include "net/base/cookie_monster.h" +#include "views/controls/button/button.h" +#include "views/controls/link.h" +#include "views/view.h" +#include "views/window/dialog_delegate.h" +#include "views/window/window.h" + +namespace views { +class Label; +class NativeButton; +class RadioButton; +} + +class CookieInfoView; +class Profile; +class Timer; + +class CookiesPromptViewDelegate { + public: + // Allow cookie to be set. If |remember| is true, record this decision + // for this host. + virtual void AllowCookie(bool remember, bool session_expire) = 0; + + // Block cookie from being stored. If |remember| is true, record this + // decision for this host. + virtual void BlockCookie(bool remember) = 0; + + protected: + virtual ~CookiesPromptViewDelegate() {} +}; + +// Cookie alert dialog UI. +class CookiesPromptView : public views::View, + public views::DialogDelegate, + public views::ButtonListener, + public views::LinkController, + public CookieInfoViewDelegate { + public: + // Show the Cookies Window, creating one if necessary. + static void ShowCookiePromptWindow( + gfx::NativeWindow parent, + Profile* profile, + const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie, + CookiesPromptViewDelegate* delegate); + + virtual ~CookiesPromptView(); + + void SetCookie(const std::string& domain, + const net::CookieMonster::CanonicalCookie& cookie_node); + + protected: + // views::View overrides. + virtual gfx::Size GetPreferredSize(); + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + + // views::DialogDelegate overrides. + virtual bool CanResize() const { return false; } + virtual std::wstring GetWindowTitle() const; + virtual void WindowClosing(); + virtual views::View* GetContentsView(); + + // views::ButtonListener overrides. + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // views::LinkController overrides. + virtual void LinkActivated(views::Link* source, int event_flags); + + // views::WindowDelegate overrides. + virtual int GetDialogButtons() const { + return MessageBoxFlags::DIALOGBUTTON_NONE; + } + + // CookieInfoViewDelegate overrides: + virtual void ModifyExpireDate(bool session_expire); + + private: + // Use the static factory method to show. + explicit CookiesPromptView(Profile* profile, + CookiesPromptViewDelegate* delegate); + + // Initialize the dialog layout. + void Init(); + + // Shows or hides cooke info view and changes parent. + void ToggleCookieViewExpand(); + + // Calculates view size offset depending on visibility of cookie details. + int GetExtendedViewHeight(); + + views::Label* description_label_; + views::RadioButton* remember_radio_; + views::RadioButton* ask_radio_; + views::NativeButton* allow_button_; + views::NativeButton* block_button_; + views::Link* show_cookie_link_; + views::Link* manage_cookies_link_; + CookieInfoView* info_view_; + + // True if cookie should expire with this session. + bool session_expire_; + + // True if cookie info view is currently shown and window expanded. + bool expanded_view_; + + // True if the outcome of this dialog has been signaled to the delegate. + bool signaled_; + + // Cookie prompt window title. + std::wstring title_; + + CookiesPromptViewDelegate* delegate_; + + // Cookie domain. + std::string domain_; + + // Cookie domain formatted for displaying (removed leading '.'). + std::wstring display_domain_; + + // Displayed cookie. + scoped_ptr<net::CookieMonster::CanonicalCookie> cookie_; + + // The Profile for which Cookies are displayed. + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(CookiesPromptView); +}; + +#endif // CHROME_BROWSER_VIEWS_COOKIE_PROMPT_VIEW_H_ + diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index dd6b992..aefb93d 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,6 +24,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/content_settings_window.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/gears_integration.h" #include "chrome/browser/net/dns_global.h" @@ -32,7 +33,7 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/shell_dialogs.h" -#include "chrome/browser/views/options/cookies_view.h" +#include "chrome/browser/views/clear_browsing_data.h" #include "chrome/browser/views/options/fonts_languages_window_view.h" #include "chrome/browser/views/restart_message_box.h" #include "chrome/common/pref_member.h" @@ -54,6 +55,7 @@ #include "views/grid_layout.h" #include "views/standard_layout.h" #include "views/widget/widget.h" +#include "views/window/window.h" using views::GridLayout; using views::ColumnSet; @@ -248,9 +250,15 @@ class AdvancedSection : public OptionsPageView { views::Label* label, int id, bool related_follows); + void AddLabeledTwoColumnRow(views::GridLayout* layout, + views::Label* label, + views::View* control, + bool control_stretches, + int id, + bool related_follows); void AddTwoColumnRow(views::GridLayout* layout, - views::Label* label, - views::View* control, + views::View* first, + views::View* second, bool control_stretches, // Whether or not the control // expands to fill the width. int id, @@ -361,19 +369,29 @@ void AdvancedSection::AddWrappingLabelRow(views::GridLayout* layout, AddSpacing(layout, related_follows); } +void AdvancedSection::AddLabeledTwoColumnRow(views::GridLayout* layout, + views::Label* label, + views::View* control, + bool control_stretches, + int id, + bool related_follows) { + label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddTwoColumnRow(layout, label, control, control_stretches, id, + related_follows); +} + void AdvancedSection::AddTwoColumnRow(views::GridLayout* layout, - views::Label* label, - views::View* control, + views::View* first, + views::View* second, bool control_stretches, int id, bool related_follows) { - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); layout->StartRow(0, id); - layout->AddView(label); + layout->AddView(first); if (control_stretches) { - layout->AddView(control); + layout->AddView(second); } else { - layout->AddView(control, 1, 1, views::GridLayout::LEADING, + layout->AddView(second, 1, 1, views::GridLayout::LEADING, views::GridLayout::CENTER); } AddSpacing(layout, related_follows); @@ -463,7 +481,6 @@ class CookieBehaviorComboModel : public ComboboxModel { class PrivacySection : public AdvancedSection, public views::ButtonListener, - public views::Combobox::Listener, public views::LinkController { public: explicit PrivacySection(Profile* profile); @@ -472,11 +489,6 @@ class PrivacySection : public AdvancedSection, // Overridden from views::ButtonListener: virtual void ButtonPressed(views::Button* sender, const views::Event& event); - // Overridden from views::Combobox::Listener: - virtual void ItemChanged(views::Combobox* sender, - int prev_index, - int new_index); - // Overridden from views::LinkController: virtual void LinkActivated(views::Link* source, int event_flags); @@ -490,6 +502,8 @@ class PrivacySection : public AdvancedSection, private: // Controls for this section: + views::NativeButton* content_settings_button_; + views::NativeButton* clear_data_button_; views::Label* section_description_label_; views::Checkbox* enable_link_doctor_checkbox_; views::Checkbox* enable_suggest_checkbox_; @@ -497,9 +511,6 @@ class PrivacySection : public AdvancedSection, views::Checkbox* enable_safe_browsing_checkbox_; views::Checkbox* reporting_enabled_checkbox_; views::Link* learn_more_link_; - views::Label* cookie_behavior_label_; - views::Combobox* cookie_behavior_combobox_; - views::NativeButton* show_cookies_button_; // Dummy for now. Used to populate cookies models. scoped_ptr<CookieBehaviorComboModel> allow_cookies_model_; @@ -510,7 +521,6 @@ class PrivacySection : public AdvancedSection, BooleanPrefMember dns_prefetch_enabled_; BooleanPrefMember safe_browsing_; BooleanPrefMember enable_metrics_recording_; - IntegerPrefMember cookie_behavior_; void ResolveMetricsReportingEnabled(); @@ -518,16 +528,15 @@ class PrivacySection : public AdvancedSection, }; PrivacySection::PrivacySection(Profile* profile) - : section_description_label_(NULL), + : content_settings_button_(NULL), + clear_data_button_(NULL), + section_description_label_(NULL), enable_link_doctor_checkbox_(NULL), enable_suggest_checkbox_(NULL), enable_dns_prefetching_checkbox_(NULL), enable_safe_browsing_checkbox_(NULL), reporting_enabled_checkbox_(NULL), learn_more_link_(NULL), - cookie_behavior_label_(NULL), - cookie_behavior_combobox_(NULL), - show_cookies_button_(NULL), AdvancedSection(profile, l10n_util::GetString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY)) { } @@ -577,9 +586,16 @@ void PrivacySection::ButtonPressed( if (enabled == reporting_enabled_checkbox_->checked()) RestartMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow()); enable_metrics_recording_.SetValue(enabled); - } else if (sender == show_cookies_button_) { - UserMetricsRecordAction("Options_ShowCookies", NULL); - CookiesView::ShowCookiesWindow(profile()); + } else if (sender == content_settings_button_) { + UserMetricsRecordAction("Options_ContentSettings", NULL); + ContentSettings::ShowContentSettingsWindow(CONTENT_SETTINGS_TAB_DEFAULT, + profile()); + } else if (sender == clear_data_button_) { + UserMetricsRecordAction("Options_ClearData", NULL); + views::Window::CreateChromeWindow( + GetWindow()->GetNativeWindow(), + gfx::Rect(), + new ClearBrowsingDataView(profile()))->Show(); } } @@ -607,26 +623,13 @@ void PrivacySection::Layout() { View::Layout(); } -void PrivacySection::ItemChanged(views::Combobox* sender, - int prev_index, - int new_index) { - if (sender == cookie_behavior_combobox_) { - net::CookiePolicy::Type cookie_policy = - CookieBehaviorComboModel::IndexToCookiePolicy(new_index); - const char* kUserMetrics[] = { - "Options_AllowAllCookies", - "Options_BlockThirdPartyCookies", - "Options_BlockAllCookies" - }; - DCHECK(cookie_policy >= 0 && cookie_policy < arraysize(kUserMetrics)); - UserMetricsRecordAction(kUserMetrics[cookie_policy], profile()->GetPrefs()); - this->cookie_behavior_.SetValue(cookie_policy); - } -} - void PrivacySection::InitControlLayout() { AdvancedSection::InitControlLayout(); + content_settings_button_ = new views::NativeButton( + this, l10n_util::GetString(IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON)); + clear_data_button_ = new views::NativeButton( + this, l10n_util::GetString(IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON)); section_description_label_ = new views::Label( l10n_util::GetString(IDS_OPTIONS_DISABLE_SERVICES)); enable_link_doctor_checkbox_ = new views::Checkbox( @@ -652,28 +655,24 @@ void PrivacySection::InitControlLayout() { #endif learn_more_link_ = new views::Link(l10n_util::GetString(IDS_LEARN_MORE)); learn_more_link_->SetController(this); - cookie_behavior_label_ = new views::Label( - l10n_util::GetString(IDS_OPTIONS_COOKIES_ACCEPT_LABEL)); - allow_cookies_model_.reset(new CookieBehaviorComboModel); - cookie_behavior_combobox_ = new views::Combobox( - allow_cookies_model_.get()); - cookie_behavior_combobox_->set_listener(this); - show_cookies_button_ = new views::NativeButton( - this, l10n_util::GetString( - IDS_OPTIONS_COOKIES_SHOWCOOKIES_WEBSITE_PERMISSIONS)); GridLayout* layout = new GridLayout(contents_); contents_->SetLayoutManager(layout); - const int single_column_view_set_id = 0; + const int leading_column_set_id = 0; + AddTwoColumnSet(layout, leading_column_set_id); + const int single_column_view_set_id = 1; AddWrappingColumnSet(layout, single_column_view_set_id); - const int dependent_labeled_field_set_id = 1; + const int dependent_labeled_field_set_id = 2; AddDependentTwoColumnSet(layout, dependent_labeled_field_set_id); - const int indented_view_set_id = 2; + const int indented_view_set_id = 3; AddIndentedColumnSet(layout, indented_view_set_id); - const int indented_column_set_id = 3; + const int indented_column_set_id = 4; AddIndentedColumnSet(layout, indented_column_set_id); + AddTwoColumnRow(layout, content_settings_button_, clear_data_button_, false, + leading_column_set_id, false); + // The description label at the top and label. section_description_label_->SetMultiLine(true); AddWrappingLabelRow(layout, section_description_label_, @@ -697,13 +696,6 @@ void PrivacySection::InitControlLayout() { // The "Help make Google Chrome better" checkbox. AddLeadingControl(layout, reporting_enabled_checkbox_, single_column_view_set_id, false); - // Cookies. - AddWrappingLabelRow(layout, cookie_behavior_label_, single_column_view_set_id, - true); - AddLeadingControl(layout, cookie_behavior_combobox_, indented_column_set_id, - true); - AddLeadingControl(layout, show_cookies_button_, indented_column_set_id, - false); // Init member prefs so we can update the controls if prefs change. alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled, @@ -715,7 +707,6 @@ void PrivacySection::InitControlLayout() { safe_browsing_.Init(prefs::kSafeBrowsingEnabled, profile()->GetPrefs(), this); enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, g_browser_process->local_state(), this); - cookie_behavior_.Init(prefs::kCookieBehavior, profile()->GetPrefs(), this); } void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { @@ -738,11 +729,6 @@ void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { enable_metrics_recording_.GetValue()); ResolveMetricsReportingEnabled(); } - if (!pref_name || *pref_name == prefs::kCookieBehavior) { - cookie_behavior_combobox_->SetSelectedItem( - CookieBehaviorComboModel::CookiePolicyToIndex( - net::CookiePolicy::FromInt(cookie_behavior_.GetValue()))); - } } void PrivacySection::ResolveMetricsReportingEnabled() { @@ -845,8 +831,8 @@ void WebContentSection::InitControlLayout() { false); // Gears. - AddTwoColumnRow(layout, gears_label_, gears_settings_button_, false, - single_double_column_set, false); + AddLabeledTwoColumnRow(layout, gears_label_, gears_settings_button_, false, + single_double_column_set, false); } //////////////////////////////////////////////////////////////////////////////// @@ -1361,10 +1347,10 @@ void AdvancedContentsView::InitControlLayout() { GridLayout::USE_PREF, 0, 0); layout->StartRow(0, single_column_view_set_id); - layout->AddView(new NetworkSection(profile())); - layout->StartRow(0, single_column_view_set_id); layout->AddView(new PrivacySection(profile())); layout->StartRow(0, single_column_view_set_id); + layout->AddView(new NetworkSection(profile())); + layout->StartRow(0, single_column_view_set_id); layout->AddView(new DownloadSection(profile())); layout->StartRow(0, single_column_view_set_id); layout->AddView(new WebContentSection(profile())); diff --git a/chrome/browser/views/options/content_filter_page_view.cc b/chrome/browser/views/options/content_filter_page_view.cc new file mode 100644 index 0000000..09a0f09 --- /dev/null +++ b/chrome/browser/views/options/content_filter_page_view.cc @@ -0,0 +1,124 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/options/content_filter_page_view.h" + +#include "app/gfx/canvas.h" +#include "app/gfx/native_theme_win.h" +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "chrome/common/pref_names.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "views/controls/button/radio_button.h" +#include "views/grid_layout.h" +#include "views/standard_layout.h" +#include "views/widget/widget.h" +#include "views/window/window.h" + +static const int kAllowRadioGroup = 1; + +ContentFilterPageView::ContentFilterPageView(Profile* profile, + int label_message_id, + int allow_radio_message_id, + int block_radio_message_id) + : label_message_id_(label_message_id), + allow_radio_message_id_(allow_radio_message_id), + block_radio_message_id_(block_radio_message_id), + caption_label_(NULL), + allow_radio_(NULL), + block_radio_(NULL), + exceptions_button_(NULL), + OptionsPageView(profile) { +} + +ContentFilterPageView::~ContentFilterPageView() { +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentFilterPageView, views::ButtonListener implementation: + +void ContentFilterPageView::ButtonPressed( + views::Button* sender, const views::Event& event) { + if (sender == allow_radio_ || sender == block_radio_) + OnAllowedChanged(allow_radio_->checked()); + else if (sender == exceptions_button_) + OnShowExceptionsDialog(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ContentFilterPageView, OptionsPageView implementation: +void ContentFilterPageView::InitControlLayout() { + // Make sure we don't leak memory by calling this more than once. + DCHECK(!exceptions_button_); + using views::GridLayout; + using views::ColumnSet; + + exceptions_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON)); + caption_label_ = new views::Label( + l10n_util::GetString(label_message_id_)); + caption_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + caption_label_->SetMultiLine(true); + + allow_radio_ = new views::RadioButton( + l10n_util::GetString(allow_radio_message_id_), + kAllowRadioGroup); + allow_radio_->set_listener(this); + allow_radio_->SetMultiLine(true); + block_radio_ = new views::RadioButton( + l10n_util::GetString(block_radio_message_id_), + kAllowRadioGroup); + block_radio_->set_listener(this); + block_radio_->SetMultiLine(true); + + + GridLayout* layout = new GridLayout(this); + layout->SetInsets(5, 5, 5, 5); + SetLayoutManager(layout); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int label_view_set_id = 0; + ColumnSet* label_column_set = layout->AddColumnSet(label_view_set_id); + label_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + label_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, label_view_set_id); + layout->AddView(caption_label_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int radio_view_set_id = 1; + ColumnSet* radio_column_set = layout->AddColumnSet(radio_view_set_id); + radio_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + radio_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, radio_view_set_id); + layout->AddView(allow_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, radio_view_set_id); + layout->AddView(block_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int button_view_set_id = 2; + ColumnSet* button_column_set = layout->AddColumnSet(button_view_set_id); + button_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + button_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, button_view_set_id); + layout->AddView(exceptions_button_); +} + +void ContentFilterPageView::Layout() { + views::View* parent = GetParent(); + if (parent && parent->width()) { + const int width = parent->width(); + const int height = GetHeightForWidth(width); + SetBounds(0, 0, width, height); + } else { + gfx::Size prefsize = GetPreferredSize(); + SetBounds(0, 0, prefsize.width(), prefsize.height()); + } + View::Layout(); +} + diff --git a/chrome/browser/views/options/content_filter_page_view.h b/chrome/browser/views/options/content_filter_page_view.h new file mode 100644 index 0000000..862b796 --- /dev/null +++ b/chrome/browser/views/options/content_filter_page_view.h @@ -0,0 +1,66 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ +#define CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ + +#include "chrome/browser/views/options/options_page_view.h" +#include "chrome/common/pref_member.h" +#include "views/controls/button/button.h" +#include "views/view.h" + +namespace views { +class Label; +class NativeButton; +class RadioButton; +} +class PrefService; + +//////////////////////////////////////////////////////////////////////////////// +// ContentFilterPageView class is used to render Images, JavaScript and +// Plug-ins page in Content Settings dialog + +class ContentFilterPageView : public OptionsPageView, + public views::ButtonListener { + public: + ContentFilterPageView(Profile* profile, + int label_message_id, + int allow_radio_message_id, + int block_radio_message_id); + virtual ~ContentFilterPageView(); + + protected: + // views::ButtonListener implementation: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // OptionsPageView implementation: + virtual void InitControlLayout(); + virtual void NotifyPrefChanged(const std::wstring* pref_name) {} + + // views::View overrides: + virtual void Layout(); + + // Signals that allowed radio button state has changed. + virtual void OnAllowedChanged(bool allowed) {} + + // Signals that exceptions dialog should be shown. + virtual void OnShowExceptionsDialog() {} + + private: + // Controls for the content filter tab page. + views::Label* caption_label_; + views::RadioButton* allow_radio_; + views::RadioButton* block_radio_; + views::NativeButton* exceptions_button_; + + // Message ids for above UI controls. + int label_message_id_; + int allow_radio_message_id_; + int block_radio_message_id_; + + DISALLOW_COPY_AND_ASSIGN(ContentFilterPageView); +}; + +#endif // CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_FILTER_PAGE_VIEW_H_ + diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc index 686d6498..c00e1be 100644 --- a/chrome/browser/views/options/content_page_view.cc +++ b/chrome/browser/views/options/content_page_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,7 +18,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/sync/sync_ui_util.h" -#include "chrome/browser/views/clear_browsing_data.h" #include "chrome/browser/views/importer_view.h" #include "chrome/browser/views/options/options_group_view.h" #include "chrome/browser/views/options/passwords_exceptions_window_view.h" @@ -58,7 +57,6 @@ ContentPageView::ContentPageView(Profile* profile) browsing_data_label_(NULL), browsing_data_group_(NULL), import_button_(NULL), - clear_data_button_(NULL), sync_group_(NULL), sync_status_label_(NULL), sync_action_link_(NULL), @@ -114,11 +112,6 @@ void ContentPageView::ButtonPressed( GetWindow()->GetNativeWindow(), gfx::Rect(), new ImporterView(profile(), ALL))->Show(); - } else if (sender == clear_data_button_) { - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new ClearBrowsingDataView(profile()))->Show(); } else if (sender == sync_start_stop_button_) { DCHECK(sync_service_); @@ -369,8 +362,6 @@ void ContentPageView::InitThemesGroup() { } void ContentPageView::InitBrowsingDataGroup() { - clear_data_button_ = new views::NativeButton(this, - l10n_util::GetString(IDS_OPTIONS_CLEAR_DATA_BUTTON)); import_button_ = new views::NativeButton(this, l10n_util::GetString(IDS_OPTIONS_IMPORT_DATA_BUTTON)); browsing_data_label_ = new views::Label( @@ -389,24 +380,15 @@ void ContentPageView::InitBrowsingDataGroup() { const int single_column_view_set_id = 0; ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); + GridLayout::USE_PREF, 0, 0); layout->StartRow(0, single_column_view_set_id); layout->AddView(browsing_data_label_); // Add some padding for not making the next component close together. layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - // Add double column layout for import and clear browsing buttons. - const int double_column_view_set_id = 1; - ColumnSet* double_col_set = layout->AddColumnSet(double_column_view_set_id); - double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - double_col_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, double_column_view_set_id); + layout->StartRow(0, single_column_view_set_id); layout->AddView(import_button_); - layout->AddView(clear_data_button_); browsing_data_group_ = new OptionsGroupView( contents, l10n_util::GetString(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME), diff --git a/chrome/browser/views/options/content_page_view.h b/chrome/browser/views/options/content_page_view.h index d79ede6..c70fa2a 100644 --- a/chrome/browser/views/options/content_page_view.h +++ b/chrome/browser/views/options/content_page_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -94,7 +94,6 @@ class ContentPageView : public OptionsPageView, OptionsGroupView* browsing_data_group_; views::Label* browsing_data_label_; views::NativeButton* import_button_; - views::NativeButton* clear_data_button_; // Controls for the Sync group. OptionsGroupView* sync_group_; diff --git a/chrome/browser/views/options/content_settings_window_view.cc b/chrome/browser/views/options/content_settings_window_view.cc new file mode 100644 index 0000000..2e327df --- /dev/null +++ b/chrome/browser/views/options/content_settings_window_view.cc @@ -0,0 +1,199 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/options/content_settings_window_view.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/views/options/advanced_page_view.h" +#include "chrome/browser/views/options/content_filter_page_view.h" +#include "chrome/browser/views/options/cookie_filter_page_view.h" +#include "chrome/browser/views/options/general_page_view.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/widget/root_view.h" +#include "views/window/dialog_delegate.h" +#include "views/window/window.h" + +static ContentSettingsWindowView* instance_ = NULL; +// Content setting dialog bounds padding. +static const int kDialogPadding = 7; + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView, public: + +ContentSettingsWindowView::ContentSettingsWindowView(Profile* profile) + // Always show preferences for the original profile. Most state when off + // the record comes from the original profile, but we explicitly use + // the original profile to avoid potential problems. + : tabs_(NULL), + profile_(profile->GetOriginalProfile()) { + // We don't need to observe changes in this value. + last_selected_page_.Init(prefs::kContentSettingsWindowLastTabIndex, + g_browser_process->local_state(), NULL); +} + +ContentSettingsWindowView::~ContentSettingsWindowView() { +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView, views::DialogDelegate implementation: + +std::wstring ContentSettingsWindowView::GetWindowTitle() const { + return l10n_util::GetString(IDS_CONTENT_SETTINGS_TITLE); +} + +void ContentSettingsWindowView::WindowClosing() { + instance_ = NULL; +} + +bool ContentSettingsWindowView::Cancel() { + return GetCurrentContentSettingsTabView()->CanClose(); +} + +views::View* ContentSettingsWindowView::GetContentsView() { + return this; +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView, views::TabbedPane::Listener implementation: + +void ContentSettingsWindowView::TabSelectedAt(int index) { +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView, views::View overrides: + +void ContentSettingsWindowView::Layout() { + tabs_->SetBounds(kDialogPadding, kDialogPadding, + width() - (2 * kDialogPadding), + height() - (2 * kDialogPadding)); +} + +gfx::Size ContentSettingsWindowView::GetPreferredSize() { + return gfx::Size(views::Window::GetLocalizedContentsSize( + IDS_CONTENT_SETTINGS_DIALOG_WIDTH_CHARS, + IDS_CONTENT_SETTINGS_DIALOG_HEIGHT_LINES)); +} + +void ContentSettingsWindowView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + // Can't init before we're inserted into a Container, because we require a + // HWND to parent native child controls to. + if (is_add && child == this) + Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView, private: + +void ContentSettingsWindowView::Init() { + // Make sure we don't leak memory by calling this twice. + DCHECK(!tabs_); + tabs_ = new views::TabbedPane; + tabs_->SetListener(this); + AddChildView(tabs_); + int tab_index = 0; + + CookieFilterPageView* cookie_page = new CookieFilterPageView(profile_); + tabs_->AddTabAtIndex(tab_index++, + l10n_util::GetString(IDS_COOKIES_TAB_LABEL), + cookie_page, false); + + ContentFilterPageView* image_page = + new ContentFilterPageView(profile_, + IDS_IMAGES_SETTING_LABEL, + IDS_IMAGES_LOAD_RADIO, + IDS_IMAGES_NOLOAD_RADIO); + tabs_->AddTabAtIndex(tab_index++, + l10n_util::GetString(IDS_IMAGES_TAB_LABEL), + image_page, false); + + ContentFilterPageView* javascript_page = + new ContentFilterPageView(profile_, + IDS_JS_SETTING_LABEL, + IDS_JS_ALLOW_RADIO, + IDS_JS_DONOTALLOW_RADIO); + tabs_->AddTabAtIndex(tab_index++, + l10n_util::GetString(IDS_JAVASCRIPT_TAB_LABEL), + javascript_page, false); + + ContentFilterPageView* plugin_page = + new ContentFilterPageView(profile_, + IDS_PLUGIN_SETTING_LABEL, + IDS_PLUGIN_LOAD_RADIO, + IDS_PLUGIN_NOLOAD_RADIO); + tabs_->AddTabAtIndex(tab_index++, + l10n_util::GetString(IDS_PLUGIN_TAB_LABEL), + plugin_page, false); + + ContentFilterPageView* popup_page = + new ContentFilterPageView(profile_, + IDS_POPUP_SETTING_LABEL, + IDS_POPUP_ALLOW_RADIO, + IDS_POPUP_BLOCK_RADIO); + tabs_->AddTabAtIndex(tab_index++, + l10n_util::GetString(IDS_POPUP_TAB_LABEL), + popup_page, false); + + DCHECK(tabs_->GetTabCount() == CONTENT_SETTINGS_NUM_TABS); +} + +const OptionsPageView* + ContentSettingsWindowView::GetCurrentContentSettingsTabView() const { + return static_cast<OptionsPageView*>(tabs_->GetSelectedTab()); +} + + +void ContentSettingsWindowView::ShowContentSettingsTab( + ContentSettingsTab page) { + // If the window is not yet visible, we need to show it (it will become + // active), otherwise just bring it to the front. + if (!window()->IsVisible()) + window()->Show(); + else + window()->Activate(); + + if (page == CONTENT_SETTINGS_TAB_DEFAULT) { + // Remember the last visited page from local state. + page = static_cast<ContentSettingsTab>(last_selected_page_.GetValue()); + if (page == CONTENT_SETTINGS_TAB_DEFAULT) + page = CONTENT_SETTINGS_TAB_COOKIES; + } + // If the page number is out of bounds, reset to the first tab. + if (page < 0 || page >= tabs_->GetTabCount()) + page = CONTENT_SETTINGS_TAB_COOKIES; + + tabs_->SelectTabAt(static_cast<int>(page)); +} + +/////////////////////////////////////////////////////////////////////////////// +// Factory/finder method: +void ContentSettings::ShowContentSettingsWindow(ContentSettingsTab page, + Profile* profile) { + DCHECK(profile); + // If there's already an existing options window, activate it and switch to + // the specified page. + // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care + // about this case this will have to be fixed. + if (!instance_) { + instance_ = new ContentSettingsWindowView(profile); + views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); + // The window is alive by itself now... + } + instance_->ShowContentSettingsTab(page); +} + +void ContentSettings::RegisterPrefs(PrefService* prefs) { + prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); +} + diff --git a/chrome/browser/views/options/content_settings_window_view.h b/chrome/browser/views/options/content_settings_window_view.h new file mode 100644 index 0000000..4cd606e --- /dev/null +++ b/chrome/browser/views/options/content_settings_window_view.h @@ -0,0 +1,73 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ +#define CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ + +#include "chrome/common/pref_member.h" +#include "chrome/browser/content_settings_window.h" +#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/view.h" +#include "views/window/dialog_delegate.h" + +class Profile; +class MessageLoop; +class OptionsPageView; + +/////////////////////////////////////////////////////////////////////////////// +// ContentSettingsWindowView +// +// The contents of the Options dialog window. +// +class ContentSettingsWindowView : public views::View, + public views::DialogDelegate, + public views::TabbedPane::Listener { + public: + explicit ContentSettingsWindowView(Profile* profile); + virtual ~ContentSettingsWindowView(); + + // Shows the Tab corresponding to the specified Content Settings page. + void ShowContentSettingsTab(ContentSettingsTab page); + + protected: + // views::View overrides: + virtual void Layout(); + virtual gfx::Size GetPreferredSize(); + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + + // views::DialogDelegate implementation: + virtual int GetDialogButtons() const { + return MessageBoxFlags::DIALOGBUTTON_CANCEL; + } + virtual std::wstring GetWindowTitle() const; + virtual void WindowClosing(); + virtual bool Cancel(); + virtual views::View* GetContentsView(); + + // views::TabbedPane::Listener implementation: + virtual void TabSelectedAt(int index); + + private: + // Initializes the view. + void Init(); + + // Returns the currently selected OptionsPageView. + const OptionsPageView* GetCurrentContentSettingsTabView() const; + + // The Tab view that contains all of the options pages. + views::TabbedPane* tabs_; + + // The Profile associated with these options. + Profile* profile_; + + // The last page the user was on when they opened the Options window. + IntegerPrefMember last_selected_page_; + + DISALLOW_EVIL_CONSTRUCTORS(ContentSettingsWindowView); +}; + +#endif // CHROME_BROWSER_VIEWS_OPTIONS_CONTENT_SETTINGS_WINDOW_VIEW_H_ + diff --git a/chrome/browser/views/options/cookie_filter_page_view.cc b/chrome/browser/views/options/cookie_filter_page_view.cc new file mode 100644 index 0000000..36486c0 --- /dev/null +++ b/chrome/browser/views/options/cookie_filter_page_view.cc @@ -0,0 +1,212 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/options/cookie_filter_page_view.h" + +#include "app/gfx/canvas.h" +#include "app/gfx/native_theme_win.h" +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "chrome/browser/views/options/cookies_view.h" +#include "chrome/common/pref_names.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "views/controls/button/checkbox.h" +#include "views/controls/button/radio_button.h" +#include "views/grid_layout.h" +#include "views/standard_layout.h" +#include "views/widget/widget.h" +#include "views/window/window.h" + +static const int kAllowRadioGroup = 1; +static const int kFilterPageInset = 5; + +CookieFilterPageView::CookieFilterPageView(Profile* profile) + : caption_label_(NULL), + allow_radio_(NULL), + ask_radio_(NULL), + block_radio_(NULL), + exceptions_button_(NULL), + block_3rdparty_check_(NULL), + clear_on_close_check_(NULL), + show_cookies_button_(NULL), + flash_settings_link_(NULL), + OptionsPageView(profile) { +} + +CookieFilterPageView::~CookieFilterPageView() { +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieFilterPageView, views::ButtonListener implementation: + +void CookieFilterPageView::ButtonPressed( + views::Button* sender, const views::Event& event) { + if (sender == allow_radio_) { + SetAllowCookies(COOKIES_ALLOWED_ALLOW); + } else if (sender == ask_radio_) { + SetAllowCookies(COOKIES_ALLOWED_ASK); + } else if (sender == block_radio_) { + SetAllowCookies(COOKIES_ALLOWED_BLOCK); + } else if (sender == exceptions_button_) { + ShowCookieExceptionsDialog(); + } else if (sender == block_3rdparty_check_) { + SetBlock3rdPartyCookies(block_3rdparty_check_->checked()); + } else if (sender == clear_on_close_check_) { + SetBlock3rdPartyCookies(block_3rdparty_check_->checked()); + } else if (sender == show_cookies_button_) { + ShowCookieManagerDialog(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieFilterPageView, views::LinkController implementation: +void CookieFilterPageView::LinkActivated(views::Link* source, + int event_flags) { + if (source == flash_settings_link_) + OpenFlashSettingsDialog(); +} + +// TODO(zelidrag): Hook setters for preference settings here: +void CookieFilterPageView::SetAllowCookies(CookiesAllowed allowed) { +} + +void CookieFilterPageView::ShowCookieExceptionsDialog() { +} + +void CookieFilterPageView::SetBlock3rdPartyCookies(bool block) { +} + +void CookieFilterPageView::SetClearCookiesOnClose(bool clear) { +} + +void CookieFilterPageView::OpenFlashSettingsDialog() { +} + +void CookieFilterPageView::ShowCookieManagerDialog() { + UserMetricsRecordAction("Options_ShowCookies", NULL); + CookiesView::ShowCookiesWindow(profile()); +} + +/////////////////////////////////////////////////////////////////////////////// +// CookieFilterPageView, OptionsPageView implementation: +void CookieFilterPageView::InitControlLayout() { + using views::GridLayout; + using views::ColumnSet; + + caption_label_ = new views::Label( + l10n_util::GetString(IDS_MODIFY_COOKIE_STORING_LABEL)); + caption_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + caption_label_->SetMultiLine(true); + + allow_radio_ = new views::RadioButton( + l10n_util::GetString(IDS_COOKIES_ALLOW_RADIO), + kAllowRadioGroup); + allow_radio_->set_listener(this); + allow_radio_->SetMultiLine(true); + + ask_radio_ = new views::RadioButton( + l10n_util::GetString(IDS_COOKIES_ASK_EVERY_TIME_RADIO), + kAllowRadioGroup); + ask_radio_->set_listener(this); + ask_radio_->SetMultiLine(true); + + block_radio_ = new views::RadioButton( + l10n_util::GetString(IDS_COOKIES_BLOCK_RADIO), + kAllowRadioGroup); + block_radio_->set_listener(this); + block_radio_->SetMultiLine(true); + + exceptions_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON)); + + block_3rdparty_check_ = new views::Checkbox( + l10n_util::GetString(IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX)); + block_3rdparty_check_->set_listener(this); + + clear_on_close_check_ = new views::Checkbox( + l10n_util::GetString(IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX)); + clear_on_close_check_->set_listener(this); + + show_cookies_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_COOKIES_SHOW_COOKIES_BUTTON)); + + flash_settings_link_ = new views::Link( + l10n_util::GetString(IDS_FLASH_STORAGE_SETTINGS)); + flash_settings_link_->SetController(this); + + GridLayout* layout = new GridLayout(this); + layout->SetInsets(kFilterPageInset, kFilterPageInset, kFilterPageInset, + kFilterPageInset); + SetLayoutManager(layout); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int label_view_set_id = 0; + ColumnSet* label_column_set = layout->AddColumnSet(label_view_set_id); + label_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + label_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, label_view_set_id); + layout->AddView(caption_label_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int radio_view_set_id = 1; + ColumnSet* radio_column_set = layout->AddColumnSet(radio_view_set_id); + radio_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + radio_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, radio_view_set_id); + layout->AddView(allow_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, radio_view_set_id); + layout->AddView(ask_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, radio_view_set_id); + layout->AddView(block_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int exceptions_button_view_set_id = 2; + ColumnSet* button_column_set = layout->AddColumnSet( + exceptions_button_view_set_id); + button_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + button_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, exceptions_button_view_set_id); + layout->AddView(exceptions_button_); + layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); + layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); + + const int check_view_set_id = 3; + ColumnSet* check_column_set = layout->AddColumnSet(check_view_set_id); + check_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + check_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, check_view_set_id); + layout->AddView(block_3rdparty_check_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, check_view_set_id); + layout->AddView(clear_on_close_check_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int mgr_button_view_set_id = 4; + ColumnSet* mgr_button_column_set = + layout->AddColumnSet(mgr_button_view_set_id); + mgr_button_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + mgr_button_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, mgr_button_view_set_id); + layout->AddView(show_cookies_button_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + const int link_view_set_id = 5; + ColumnSet* link_column_set = layout->AddColumnSet(link_view_set_id); + link_column_set->AddPaddingColumn(0, kRelatedControlVerticalSpacing); + link_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, link_view_set_id); + layout->AddView(flash_settings_link_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); +} + + diff --git a/chrome/browser/views/options/cookie_filter_page_view.h b/chrome/browser/views/options/cookie_filter_page_view.h new file mode 100644 index 0000000..7bcc909 --- /dev/null +++ b/chrome/browser/views/options/cookie_filter_page_view.h @@ -0,0 +1,85 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ +#define CHROME_BROWSER_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ + +#include "chrome/browser/views/options/options_page_view.h" +#include "chrome/common/pref_member.h" +#include "views/controls/button/button.h" +#include "views/view.h" + +namespace views { +class Checkbox; +class Label; +class NativeButton; +class RadioButton; +} + +class PrefService; + +//////////////////////////////////////////////////////////////////////////////// +// CookieFilterPageView class is used to render the cookie content settings +// tab. + +class CookieFilterPageView : public OptionsPageView, + public views::ButtonListener, + public views::LinkController { + public: + explicit CookieFilterPageView(Profile* profile); + virtual ~CookieFilterPageView(); + + // views::ButtonListener implementation: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // Overridden from views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + + private: + typedef enum { + COOKIES_ALLOWED_DEFAULT = 0, + COOKIES_ALLOWED_ALLOW = 0, + COOKIES_ALLOWED_ASK, + COOKIES_ALLOWED_BLOCK, + } CookiesAllowed; + + // OptionsPageView implementation: + virtual void InitControlLayout(); + virtual void NotifyPrefChanged(const std::wstring* pref_name) {} + + // Handles that allowed radio button state has changed. + void SetAllowCookies(CookiesAllowed allowed); + + // Handles click on exceptions dialog. + void ShowCookieExceptionsDialog(); + + // Handles change in block 3rd party cookies checkbox. + void SetBlock3rdPartyCookies(bool block); + + // Handles change in clean on close checkbox. + void SetClearCookiesOnClose(bool clear); + + // Handles click on flash settings link. + void OpenFlashSettingsDialog(); + + // Opens cookie manager dialog. + void ShowCookieManagerDialog(); + + private: + // Controls for the cookie filter tab page view. + views::Label* caption_label_; + views::RadioButton* allow_radio_; + views::RadioButton* ask_radio_; + views::RadioButton* block_radio_; + views::NativeButton* exceptions_button_; + views::Checkbox* block_3rdparty_check_; + views::Checkbox* clear_on_close_check_; + views::NativeButton* show_cookies_button_; + views::Link* flash_settings_link_; + + DISALLOW_COPY_AND_ASSIGN(CookieFilterPageView); +}; + +#endif // CHROME_BROWSER_VIEWS_OPTIONS_COOKIE_FILTER_PAGE_VIEW_H_ + diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 2500e7e..809e455 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -14,6 +14,7 @@ #include "base/string_util.h" #include "chrome/browser/cookies_tree_model.h" #include "chrome/browser/profile.h" +#include "chrome/browser/views/cookie_info_view.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "net/base/cookie_monster.h" @@ -27,8 +28,8 @@ // static views::Window* CookiesView::instance_ = NULL; -static const int kCookieInfoViewBorderSize = 1; -static const int kCookieInfoViewInsetSize = 3; +static const int kLocalStorageInfoViewBorderSize = 1; +static const int kLocalStorageInfoViewInsetSize = 3; static const int kSearchFilterDelayMs = 500; /////////////////////////////////////////////////////////////////////////////// @@ -62,195 +63,6 @@ void CookiesTreeView::RemoveSelectedItems() { } /////////////////////////////////////////////////////////////////////////////// -// CookieInfoView, public: - -CookieInfoView::CookieInfoView() - : name_label_(NULL), - name_value_field_(NULL), - content_label_(NULL), - content_value_field_(NULL), - domain_label_(NULL), - domain_value_field_(NULL), - path_label_(NULL), - path_value_field_(NULL), - send_for_label_(NULL), - send_for_value_field_(NULL), - created_label_(NULL), - created_value_field_(NULL), - expires_label_(NULL), - expires_value_field_(NULL) { -} - -CookieInfoView::~CookieInfoView() { -} - -void CookieInfoView::SetCookie( - const std::string& domain, - const net::CookieMonster::CanonicalCookie& cookie) { - name_value_field_->SetText(UTF8ToWide(cookie.Name())); - content_value_field_->SetText(UTF8ToWide(cookie.Value())); - domain_value_field_->SetText(UTF8ToWide(domain)); - path_value_field_->SetText(UTF8ToWide(cookie.Path())); - created_value_field_->SetText( - base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())); - - if (cookie.DoesExpire()) { - expires_value_field_->SetText( - base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())); - } else { - // TODO(deanm) need a string that the average user can understand - // "When you quit or restart your browser" ? - expires_value_field_->SetText( - l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION)); - } - - std::wstring sendfor_text; - if (cookie.IsSecure()) { - sendfor_text = l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_SECURE); - } else { - sendfor_text = l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_ANY); - } - send_for_value_field_->SetText(sendfor_text); - EnableCookieDisplay(true); -} - -void CookieInfoView::EnableCookieDisplay(bool enabled) { - name_value_field_->SetEnabled(enabled); - content_value_field_->SetEnabled(enabled); - domain_value_field_->SetEnabled(enabled); - path_value_field_->SetEnabled(enabled); - send_for_value_field_->SetEnabled(enabled); - created_value_field_->SetEnabled(enabled); - expires_value_field_->SetEnabled(enabled); -} - -void CookieInfoView::ClearCookieDisplay() { - std::wstring no_cookie_string = - l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); - name_value_field_->SetText(no_cookie_string); - content_value_field_->SetText(no_cookie_string); - domain_value_field_->SetText(no_cookie_string); - path_value_field_->SetText(no_cookie_string); - send_for_value_field_->SetText(no_cookie_string); - created_value_field_->SetText(no_cookie_string); - expires_value_field_->SetText(no_cookie_string); - EnableCookieDisplay(false); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieInfoView, views::View overrides: - -void CookieInfoView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieInfoView, private: - -void CookieInfoView::Init() { - SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); - views::Border* border = views::Border::CreateSolidBorder( - kCookieInfoViewBorderSize, border_color); - set_border(border); - - name_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); - name_value_field_ = new views::Textfield; - content_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_CONTENT_LABEL)); - content_value_field_ = new views::Textfield; - domain_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); - domain_value_field_ = new views::Textfield; - path_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_PATH_LABEL)); - path_value_field_ = new views::Textfield; - send_for_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); - send_for_value_field_ = new views::Textfield; - created_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_CREATED_LABEL)); - created_value_field_ = new views::Textfield; - expires_label_ = new views::Label( - l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); - expires_value_field_ = new views::Textfield; - - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = new GridLayout(this); - layout->SetInsets(kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize); - SetLayoutManager(layout); - - int three_column_layout_id = 0; - ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); - column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, three_column_layout_id); - layout->AddView(name_label_); - layout->AddView(name_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(content_label_); - layout->AddView(content_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(domain_label_); - layout->AddView(domain_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(path_label_); - layout->AddView(path_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(send_for_label_); - layout->AddView(send_for_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(created_label_); - layout->AddView(created_value_field_); - layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); - layout->StartRow(0, three_column_layout_id); - layout->AddView(expires_label_); - layout->AddView(expires_value_field_); - - // Color these borderless text areas the same as the containing dialog. - SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); - // Now that the Textfields are in the view hierarchy, we can initialize them. - name_value_field_->SetReadOnly(true); - name_value_field_->RemoveBorder(); - name_value_field_->SetBackgroundColor(text_area_background); - content_value_field_->SetReadOnly(true); - content_value_field_->RemoveBorder(); - content_value_field_->SetBackgroundColor(text_area_background); - domain_value_field_->SetReadOnly(true); - domain_value_field_->RemoveBorder(); - domain_value_field_->SetBackgroundColor(text_area_background); - path_value_field_->SetReadOnly(true); - path_value_field_->RemoveBorder(); - path_value_field_->SetBackgroundColor(text_area_background); - send_for_value_field_->SetReadOnly(true); - send_for_value_field_->RemoveBorder(); - send_for_value_field_->SetBackgroundColor(text_area_background); - created_value_field_->SetReadOnly(true); - created_value_field_->RemoveBorder(); - created_value_field_->SetBackgroundColor(text_area_background); - expires_value_field_->SetReadOnly(true); - expires_value_field_->RemoveBorder(); - expires_value_field_->SetBackgroundColor(text_area_background); -} - -/////////////////////////////////////////////////////////////////////////////// // LocalStorageInfoView, public: LocalStorageInfoView::LocalStorageInfoView() @@ -309,7 +121,7 @@ void LocalStorageInfoView::ViewHierarchyChanged(bool is_add, void LocalStorageInfoView::Init() { SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); views::Border* border = views::Border::CreateSolidBorder( - kCookieInfoViewBorderSize, border_color); + kLocalStorageInfoViewBorderSize, border_color); set_border(border); origin_label_ = new views::Label( @@ -326,10 +138,10 @@ void LocalStorageInfoView::Init() { using views::ColumnSet; GridLayout* layout = new GridLayout(this); - layout->SetInsets(kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize, - kCookieInfoViewInsetSize); + layout->SetInsets(kLocalStorageInfoViewInsetSize, + kLocalStorageInfoViewInsetSize, + kLocalStorageInfoViewInsetSize, + kLocalStorageInfoViewInsetSize); SetLayoutManager(layout); int three_column_layout_id = 0; @@ -545,7 +357,7 @@ void CookiesView::Init() { description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); cookies_tree_model_.reset(new CookiesTreeModel( profile_, new BrowsingDataLocalStorageHelper(profile_))); - cookie_info_view_ = new CookieInfoView; + cookie_info_view_ = new CookieInfoView(false); local_storage_info_view_ = new LocalStorageInfoView; cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); remove_button_ = new views::NativeButton( diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h index 91d6cf4a..5adee37 100644 --- a/chrome/browser/views/options/cookies_view.h +++ b/chrome/browser/views/options/cookies_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -137,55 +137,6 @@ class CookiesView : public views::View, }; /////////////////////////////////////////////////////////////////////////////// -// CookieInfoView -// -// Responsible for displaying a tabular grid of Cookie information. -class CookieInfoView : public views::View { - public: - CookieInfoView(); - virtual ~CookieInfoView(); - - // Update the display from the specified CookieNode. - void SetCookie(const std::string& domain, - const net::CookieMonster::CanonicalCookie& cookie_node); - - // Clears the cookie display to indicate that no or multiple cookies are - // selected. - void ClearCookieDisplay(); - - // Enables or disables the cookie proerty text fields. - void EnableCookieDisplay(bool enabled); - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - // Set up the view layout - void Init(); - - // Individual property labels - views::Label* name_label_; - views::Textfield* name_value_field_; - views::Label* content_label_; - views::Textfield* content_value_field_; - views::Label* domain_label_; - views::Textfield* domain_value_field_; - views::Label* path_label_; - views::Textfield* path_value_field_; - views::Label* send_for_label_; - views::Textfield* send_for_value_field_; - views::Label* created_label_; - views::Textfield* created_value_field_; - views::Label* expires_label_; - views::Textfield* expires_value_field_; - - DISALLOW_COPY_AND_ASSIGN(CookieInfoView); -}; - -/////////////////////////////////////////////////////////////////////////////// // LocalStorageInfoView // // Responsible for displaying a tabular grid of Local Storage information. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 3fc3a1e..04c9712 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -603,6 +603,7 @@ 'browser/cocoa/window_size_autosaver.mm', 'browser/command_updater.cc', 'browser/command_updater.h', + 'browser/content_settings_window.h', 'browser/cookies_tree_model.cc', 'browser/cookies_tree_model.h', 'browser/cross_site_request_manager.cc', @@ -1681,6 +1682,10 @@ 'browser/views/constrained_window_win.h', 'browser/views/confirm_message_box_dialog.cc', 'browser/views/confirm_message_box_dialog.h', + 'browser/views/cookie_info_view.cc', + 'browser/views/cookie_info_view.h', + 'browser/views/cookie_prompt_view.cc', + 'browser/views/cookie_prompt_view.h', 'browser/views/create_application_shortcut_view.cc', 'browser/views/create_application_shortcut_view.h', 'browser/views/detachable_toolbar_view.cc', @@ -1790,6 +1795,12 @@ 'browser/views/options/advanced_page_view.h', 'browser/views/options/content_page_view.cc', 'browser/views/options/content_page_view.h', + 'browser/views/options/content_filter_page_view.cc', + 'browser/views/options/content_filter_page_view.h', + 'browser/views/options/content_settings_window_view.cc', + 'browser/views/options/content_settings_window_view.h', + 'browser/views/options/cookie_filter_page_view.cc', + 'browser/views/options/cookie_filter_page_view.h', 'browser/views/options/cookies_view.cc', 'browser/views/options/cookies_view.h', 'browser/views/options/exceptions_page_view.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index d2cca53d..3824985 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -514,6 +514,11 @@ const wchar_t kSafeBrowsingWrappedKey[] = L"safe_browsing.wrapped_key"; // last visited the options window. const wchar_t kOptionsWindowLastTabIndex[] = L"options_window.last_tab_index"; +// Integer that specifies the index of the tab the user was on when they +// last visited the content settings window. +const wchar_t kContentSettingsWindowLastTabIndex[] = + L"content_settings_window.last_tab_index"; + // The mere fact that this pref is registered signals that we should show the // First Run Search Information bubble when the first browser window appears. // This preference is only registered by the first-run procedure. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 1627d31..e81dd00 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -192,6 +192,7 @@ extern const wchar_t kSafeBrowsingClientKey[]; extern const wchar_t kSafeBrowsingWrappedKey[]; extern const wchar_t kOptionsWindowLastTabIndex[]; +extern const wchar_t kContentSettingsWindowLastTabIndex[]; extern const wchar_t kShouldShowFirstRunBubble[]; extern const wchar_t kShouldUseOEMFirstRunBubble[]; extern const wchar_t kShouldShowWelcomePage[]; |