| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/views/cookie_prompt_view.h" | 5 #include "chrome/browser/views/cookie_prompt_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/color_utils.h" | 10 #include "app/gfx/color_utils.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/cookie_modal_dialog.h" | 16 #include "chrome/browser/cookie_modal_dialog.h" |
| 17 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 18 #include "chrome/browser/views/browser_dialogs.h" | 18 #include "chrome/browser/views/browser_dialogs.h" |
| 19 #include "chrome/browser/views/cookie_info_view.h" | 19 #include "chrome/browser/views/cookie_info_view.h" |
| 20 #include "chrome/browser/views/local_storage_info_view.h" | 20 #include "chrome/browser/views/local_storage_set_item_info_view.h" |
| 21 #include "chrome/browser/views/options/content_settings_window_view.h" | 21 #include "chrome/browser/views/options/content_settings_window_view.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "grit/locale_settings.h" | 25 #include "grit/locale_settings.h" |
| 26 #include "net/base/cookie_monster.h" | 26 #include "net/base/cookie_monster.h" |
| 27 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
| 28 #include "views/controls/button/native_button.h" | 28 #include "views/controls/button/native_button.h" |
| 29 #include "views/controls/button/radio_button.h" | 29 #include "views/controls/button/radio_button.h" |
| 30 #include "views/controls/textfield/textfield.h" | 30 #include "views/controls/textfield/textfield.h" |
| 31 #include "views/grid_layout.h" | 31 #include "views/grid_layout.h" |
| 32 #include "views/standard_layout.h" | 32 #include "views/standard_layout.h" |
| 33 #include "views/window/non_client_view.h" | 33 #include "views/window/non_client_view.h" |
| 34 | 34 |
| 35 static const int kCookiePromptViewInsetSize = 5; | 35 static const int kCookiePromptViewInsetSize = 5; |
| 36 | 36 |
| 37 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
| 38 // CookiePromptView, public: | 38 // CookiePromptView, public: |
| 39 | 39 |
| 40 CookiePromptView::CookiePromptView( | 40 CookiePromptView::CookiePromptView( |
| 41 CookiePromptModalDialog* parent, | 41 CookiePromptModalDialog* parent, |
| 42 gfx::NativeWindow root_window, | 42 gfx::NativeWindow root_window, |
| 43 Profile* profile, | 43 Profile* profile) |
| 44 const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info, | |
| 45 const std::string& host, | |
| 46 const std::string& cookie_line, | |
| 47 CookiePromptModalDialogDelegate* delegate, | |
| 48 bool cookie_ui) | |
| 49 : remember_radio_(NULL), | 44 : remember_radio_(NULL), |
| 50 ask_radio_(NULL), | 45 ask_radio_(NULL), |
| 51 allow_button_(NULL), | 46 allow_button_(NULL), |
| 52 block_button_(NULL), | 47 block_button_(NULL), |
| 53 show_cookie_link_(NULL), | 48 show_cookie_link_(NULL), |
| 54 info_view_(NULL), | 49 info_view_(NULL), |
| 55 session_expire_(false), | 50 session_expire_(false), |
| 56 expanded_view_(false), | 51 expanded_view_(false), |
| 57 signaled_(false), | 52 signaled_(false), |
| 58 cookie_ui_(cookie_ui), | |
| 59 parent_(parent), | 53 parent_(parent), |
| 60 root_window_(root_window), | 54 root_window_(root_window) { |
| 61 host_(host), | 55 InitializeViewResources(parent_->host()); |
| 62 cookie_line_(cookie_line), | |
| 63 local_storage_info_(storage_info), | |
| 64 delegate_(delegate) { | |
| 65 InitializeViewResources(host); | |
| 66 expanded_view_ = g_browser_process->local_state()-> | 56 expanded_view_ = g_browser_process->local_state()-> |
| 67 GetBoolean(prefs::kCookiePromptExpanded); | 57 GetBoolean(prefs::kCookiePromptExpanded); |
| 68 } | 58 } |
| 69 | 59 |
| 70 CookiePromptView::~CookiePromptView() { | 60 CookiePromptView::~CookiePromptView() { |
| 71 } | 61 } |
| 72 | 62 |
| 73 /////////////////////////////////////////////////////////////////////////////// | 63 /////////////////////////////////////////////////////////////////////////////// |
| 74 // CookiePromptView, views::View overrides: | 64 // CookiePromptView, views::View overrides: |
| 75 | 65 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 95 } | 85 } |
| 96 | 86 |
| 97 /////////////////////////////////////////////////////////////////////////////// | 87 /////////////////////////////////////////////////////////////////////////////// |
| 98 // CookiePromptView, views::DialogDelegate implementation: | 88 // CookiePromptView, views::DialogDelegate implementation: |
| 99 | 89 |
| 100 std::wstring CookiePromptView::GetWindowTitle() const { | 90 std::wstring CookiePromptView::GetWindowTitle() const { |
| 101 return title_; | 91 return title_; |
| 102 } | 92 } |
| 103 | 93 |
| 104 void CookiePromptView::WindowClosing() { | 94 void CookiePromptView::WindowClosing() { |
| 105 if (!signaled_ && delegate_) | 95 if (!signaled_ && parent_->GetDelegate()) |
| 106 delegate_->BlockSiteData(false); | 96 parent_->GetDelegate()->BlockSiteData(false); |
| 107 parent_->CompleteDialog(); | 97 parent_->CompleteDialog(); |
| 108 } | 98 } |
| 109 | 99 |
| 110 views::View* CookiePromptView::GetContentsView() { | 100 views::View* CookiePromptView::GetContentsView() { |
| 111 return this; | 101 return this; |
| 112 } | 102 } |
| 113 | 103 |
| 114 // CookieInfoViewDelegate overrides: | 104 // CookieInfoViewDelegate overrides: |
| 115 void CookiePromptView::ModifyExpireDate(bool session_expire) { | 105 void CookiePromptView::ModifyExpireDate(bool session_expire) { |
| 116 session_expire_ = session_expire; | 106 session_expire_ = session_expire; |
| 117 } | 107 } |
| 118 | 108 |
| 119 | 109 |
| 120 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
| 121 // CookiePromptView, views::ButtonListener implementation: | 111 // CookiePromptView, views::ButtonListener implementation: |
| 122 | 112 |
| 123 void CookiePromptView::ButtonPressed(views::Button* sender, | 113 void CookiePromptView::ButtonPressed(views::Button* sender, |
| 124 const views::Event& event) { | 114 const views::Event& event) { |
| 125 if (sender == allow_button_) { | 115 if (sender == allow_button_) { |
| 126 if (delegate_) { | 116 if (parent_->GetDelegate()) { |
| 127 delegate_->AllowSiteData(remember_radio_->checked(), session_expire_); | 117 parent_->GetDelegate()->AllowSiteData(remember_radio_->checked(), |
| 118 session_expire_); |
| 128 signaled_ = true; | 119 signaled_ = true; |
| 129 } | 120 } |
| 130 GetWindow()->Close(); | 121 GetWindow()->Close(); |
| 131 } else if (sender == block_button_) { | 122 } else if (sender == block_button_) { |
| 132 if (delegate_) { | 123 if (parent_->GetDelegate()) { |
| 133 delegate_->BlockSiteData(remember_radio_->checked()); | 124 parent_->GetDelegate()->BlockSiteData(remember_radio_->checked()); |
| 134 signaled_ = true; | 125 signaled_ = true; |
| 135 } | 126 } |
| 136 GetWindow()->Close(); | 127 GetWindow()->Close(); |
| 137 } | 128 } |
| 138 } | 129 } |
| 139 | 130 |
| 140 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 141 // CookiePromptView, views::LinkController implementation: | 132 // CookiePromptView, views::LinkController implementation: |
| 142 void CookiePromptView::LinkActivated(views::Link* source, int event_flags) { | 133 void CookiePromptView::LinkActivated(views::Link* source, int event_flags) { |
| 143 DCHECK_EQ(source, show_cookie_link_); | 134 DCHECK_EQ(source, show_cookie_link_); |
| 144 ToggleDetailsViewExpand(); | 135 ToggleDetailsViewExpand(); |
| 145 } | 136 } |
| 146 | 137 |
| 147 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
| 148 // CookiePromptView, private: | 139 // CookiePromptView, private: |
| 149 | 140 |
| 150 void CookiePromptView::Init() { | 141 void CookiePromptView::Init() { |
| 151 std::wstring display_host = UTF8ToWide(host_); | 142 CookiePromptModalDialog::DialogType type = parent_->dialog_type(); |
| 143 std::wstring display_host = UTF8ToWide(parent_->host()); |
| 152 views::Label* description_label = new views::Label(l10n_util::GetStringF( | 144 views::Label* description_label = new views::Label(l10n_util::GetStringF( |
| 153 cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, | 145 type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? |
| 146 IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, |
| 154 display_host)); | 147 display_host)); |
| 155 int radio_group_id = 0; | 148 int radio_group_id = 0; |
| 156 remember_radio_ = new views::RadioButton( | 149 remember_radio_ = new views::RadioButton( |
| 157 l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_host), | 150 l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_host), |
| 158 radio_group_id); | 151 radio_group_id); |
| 159 remember_radio_->set_listener(this); | 152 remember_radio_->set_listener(this); |
| 160 ask_radio_ = new views::RadioButton( | 153 ask_radio_ = new views::RadioButton( |
| 161 l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id); | 154 l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id); |
| 162 ask_radio_->set_listener(this); | 155 ask_radio_->set_listener(this); |
| 163 allow_button_ = new views::NativeButton( | 156 allow_button_ = new views::NativeButton( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 222 link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 230 link_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 223 link_column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 231 GridLayout::USE_PREF, 0, 0); | 224 GridLayout::USE_PREF, 0, 0); |
| 232 link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 225 link_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 233 layout->StartRow(0, link_column_layout_id); | 226 layout->StartRow(0, link_column_layout_id); |
| 234 layout->AddView(show_cookie_link_); | 227 layout->AddView(show_cookie_link_); |
| 235 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 228 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 236 | 229 |
| 237 layout->StartRow(0, one_column_layout_id); | 230 layout->StartRow(0, one_column_layout_id); |
| 238 | 231 |
| 239 if (cookie_ui_) { | 232 if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { |
| 240 CookieInfoView* cookie_info_view = new CookieInfoView(true); | 233 CookieInfoView* cookie_info_view = new CookieInfoView(true); |
| 241 cookie_info_view->set_delegate(this); | 234 cookie_info_view->set_delegate(this); |
| 242 layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL, | 235 layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL, |
| 243 GridLayout::CENTER); | 236 GridLayout::CENTER); |
| 244 | 237 |
| 245 cookie_info_view->SetCookieString(host_, cookie_line_); | 238 cookie_info_view->SetCookieString(parent_->host(), parent_->cookie_line()); |
| 246 info_view_ = cookie_info_view; | 239 info_view_ = cookie_info_view; |
| 240 } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { |
| 241 LocalStorageSetItemInfoView* view = new LocalStorageSetItemInfoView(); |
| 242 layout->AddView(view, 1, 1, GridLayout::FILL, GridLayout::CENTER); |
| 243 view->SetFields(parent_->host(), |
| 244 parent_->local_storage_key(), |
| 245 parent_->local_storage_value()); |
| 246 info_view_ = view; |
| 247 } else { | 247 } else { |
| 248 LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView(); | 248 NOTIMPLEMENTED(); |
| 249 layout->AddView(local_storage_info_view, 1, 1, GridLayout::FILL, | |
| 250 GridLayout::CENTER); | |
| 251 local_storage_info_view->SetLocalStorageInfo(local_storage_info_); | |
| 252 info_view_ = local_storage_info_view; | |
| 253 } | 249 } |
| 254 | 250 |
| 255 info_view_->SetVisible(expanded_view_); | 251 info_view_->SetVisible(expanded_view_); |
| 256 | 252 |
| 257 // Set default values. | 253 // Set default values. |
| 258 remember_radio_->SetChecked(true); | 254 remember_radio_->SetChecked(true); |
| 259 } | 255 } |
| 260 | 256 |
| 261 int CookiePromptView::GetExtendedViewHeight() { | 257 int CookiePromptView::GetExtendedViewHeight() { |
| 262 DCHECK(info_view_); | 258 DCHECK(info_view_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 277 info_view_->SetVisible(expanded_view_); | 273 info_view_->SetVisible(expanded_view_); |
| 278 int extended_height_delta = GetExtendedViewHeight() - old_extended_height; | 274 int extended_height_delta = GetExtendedViewHeight() - old_extended_height; |
| 279 views::Window* window = GetWindow(); | 275 views::Window* window = GetWindow(); |
| 280 gfx::Rect bounds = window->GetBounds(); | 276 gfx::Rect bounds = window->GetBounds(); |
| 281 bounds.set_height(bounds.height() + extended_height_delta); | 277 bounds.set_height(bounds.height() + extended_height_delta); |
| 282 window->SetBounds(bounds, NULL); | 278 window->SetBounds(bounds, NULL); |
| 283 } | 279 } |
| 284 | 280 |
| 285 void CookiePromptView::InitializeViewResources(const std::string& host) { | 281 void CookiePromptView::InitializeViewResources(const std::string& host) { |
| 286 DCHECK(host.empty() || host[0] != '.'); | 282 DCHECK(host.empty() || host[0] != '.'); |
| 287 host_ = host; | 283 DCHECK(host == parent_->host()); |
| 284 CookiePromptModalDialog::DialogType type = parent_->dialog_type(); |
| 288 title_ = l10n_util::GetStringF( | 285 title_ = l10n_util::GetStringF( |
| 289 cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, | 286 type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? |
| 290 UTF8ToWide(host_)); | 287 IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, |
| 288 UTF8ToWide(parent_->host())); |
| 291 } | 289 } |
| 292 | 290 |
| OLD | NEW |