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/options/cookies_view.h" | 5 #include "chrome/browser/views/options/cookies_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/cookies_tree_model.h" | 15 #include "chrome/browser/cookies_tree_model.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/views/appcache_info_view.h" |
17 #include "chrome/browser/views/cookie_info_view.h" | 18 #include "chrome/browser/views/cookie_info_view.h" |
18 #include "chrome/browser/views/database_info_view.h" | 19 #include "chrome/browser/views/database_info_view.h" |
19 #include "chrome/browser/views/local_storage_info_view.h" | 20 #include "chrome/browser/views/local_storage_info_view.h" |
20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
21 #include "grit/locale_settings.h" | 22 #include "grit/locale_settings.h" |
22 #include "net/base/cookie_monster.h" | 23 #include "net/base/cookie_monster.h" |
23 #include "views/border.h" | 24 #include "views/border.h" |
24 #include "views/grid_layout.h" | 25 #include "views/grid_layout.h" |
25 #include "views/controls/label.h" | 26 #include "views/controls/label.h" |
26 #include "views/controls/button/native_button.h" | 27 #include "views/controls/button/native_button.h" |
(...skipping 29 matching lines...) Expand all Loading... |
56 | 57 |
57 void CookiesTreeView::RemoveSelectedItems() { | 58 void CookiesTreeView::RemoveSelectedItems() { |
58 TreeModelNode* selected_node = GetSelectedNode(); | 59 TreeModelNode* selected_node = GetSelectedNode(); |
59 if (selected_node) { | 60 if (selected_node) { |
60 static_cast<CookiesTreeModel*>(model())->DeleteCookieNode( | 61 static_cast<CookiesTreeModel*>(model())->DeleteCookieNode( |
61 static_cast<CookieTreeNode*>(GetSelectedNode())); | 62 static_cast<CookieTreeNode*>(GetSelectedNode())); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
| 67 // CookiesView::InfoPanelView |
| 68 // Overridden to handle layout of the various info views. |
| 69 // |
| 70 // This view is a child of the CookiesView and participates |
| 71 // in its GridLayout. The various info views are all children |
| 72 // of this view. Only one child is expected to be visible at a time. |
| 73 |
| 74 class CookiesView::InfoPanelView : public views::View { |
| 75 public: |
| 76 virtual void Layout() { |
| 77 int child_count = GetChildViewCount(); |
| 78 for (int i = 0; i < child_count; ++i) |
| 79 GetChildViewAt(i)->SetBounds(0, 0, width(), height()); |
| 80 } |
| 81 |
| 82 virtual gfx::Size GetPreferredSize() { |
| 83 DCHECK(GetChildViewCount() > 0); |
| 84 return GetChildViewAt(0)->GetPreferredSize(); |
| 85 } |
| 86 }; |
| 87 |
| 88 /////////////////////////////////////////////////////////////////////////////// |
66 // CookiesView, public: | 89 // CookiesView, public: |
67 | 90 |
68 // static | 91 // static |
69 void CookiesView::ShowCookiesWindow(Profile* profile) { | 92 void CookiesView::ShowCookiesWindow(Profile* profile) { |
70 if (!instance_) { | 93 if (!instance_) { |
71 CookiesView* cookies_view = new CookiesView(profile); | 94 CookiesView* cookies_view = new CookiesView(profile); |
72 instance_ = views::Window::CreateChromeWindow( | 95 instance_ = views::Window::CreateChromeWindow( |
73 NULL, gfx::Rect(), cookies_view); | 96 NULL, gfx::Rect(), cookies_view); |
74 } | 97 } |
75 if (!instance_->IsVisible()) { | 98 if (!instance_->IsVisible()) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 detailed_info.cookie->second); | 220 detailed_info.cookie->second); |
198 } else if (detailed_info.node_type == | 221 } else if (detailed_info.node_type == |
199 CookieTreeNode::DetailedInfo::TYPE_DATABASE) { | 222 CookieTreeNode::DetailedInfo::TYPE_DATABASE) { |
200 UpdateVisibleDetailedInfo(database_info_view_); | 223 UpdateVisibleDetailedInfo(database_info_view_); |
201 database_info_view_->SetDatabaseInfo(*detailed_info.database_info); | 224 database_info_view_->SetDatabaseInfo(*detailed_info.database_info); |
202 } else if (detailed_info.node_type == | 225 } else if (detailed_info.node_type == |
203 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { | 226 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { |
204 UpdateVisibleDetailedInfo(local_storage_info_view_); | 227 UpdateVisibleDetailedInfo(local_storage_info_view_); |
205 local_storage_info_view_->SetLocalStorageInfo( | 228 local_storage_info_view_->SetLocalStorageInfo( |
206 *detailed_info.local_storage_info); | 229 *detailed_info.local_storage_info); |
| 230 } else if (detailed_info.node_type == |
| 231 CookieTreeNode::DetailedInfo::TYPE_APPCACHE) { |
| 232 UpdateVisibleDetailedInfo(appcache_info_view_); |
| 233 appcache_info_view_->SetAppCacheInfo(detailed_info.appcache_info); |
207 } else { | 234 } else { |
208 UpdateVisibleDetailedInfo(cookie_info_view_); | 235 UpdateVisibleDetailedInfo(cookie_info_view_); |
209 cookie_info_view_->ClearCookieDisplay(); | 236 cookie_info_view_->ClearCookieDisplay(); |
210 } | 237 } |
211 } | 238 } |
212 | 239 |
213 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) { | 240 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) { |
214 if (keycode == base::VKEY_DELETE) | 241 if (keycode == base::VKEY_DELETE) |
215 cookies_tree_->RemoveSelectedItems(); | 242 cookies_tree_->RemoveSelectedItems(); |
216 } | 243 } |
(...skipping 12 matching lines...) Expand all Loading... |
229 /////////////////////////////////////////////////////////////////////////////// | 256 /////////////////////////////////////////////////////////////////////////////// |
230 // CookiesView, private: | 257 // CookiesView, private: |
231 | 258 |
232 CookiesView::CookiesView(Profile* profile) | 259 CookiesView::CookiesView(Profile* profile) |
233 : | 260 : |
234 search_label_(NULL), | 261 search_label_(NULL), |
235 search_field_(NULL), | 262 search_field_(NULL), |
236 clear_search_button_(NULL), | 263 clear_search_button_(NULL), |
237 description_label_(NULL), | 264 description_label_(NULL), |
238 cookies_tree_(NULL), | 265 cookies_tree_(NULL), |
| 266 info_panel_(NULL), |
239 cookie_info_view_(NULL), | 267 cookie_info_view_(NULL), |
240 database_info_view_(NULL), | 268 database_info_view_(NULL), |
241 local_storage_info_view_(NULL), | 269 local_storage_info_view_(NULL), |
| 270 appcache_info_view_(NULL), |
242 remove_button_(NULL), | 271 remove_button_(NULL), |
243 remove_all_button_(NULL), | 272 remove_all_button_(NULL), |
244 profile_(profile), | 273 profile_(profile), |
245 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { | 274 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { |
246 } | 275 } |
247 | 276 |
248 void CookiesView::Init() { | 277 void CookiesView::Init() { |
249 search_label_ = new views::Label( | 278 search_label_ = new views::Label( |
250 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); | 279 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); |
251 search_field_ = new views::Textfield; | 280 search_field_ = new views::Textfield; |
252 search_field_->SetController(this); | 281 search_field_->SetController(this); |
253 clear_search_button_ = new views::NativeButton( | 282 clear_search_button_ = new views::NativeButton( |
254 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); | 283 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); |
255 clear_search_button_->SetEnabled(false); | 284 clear_search_button_->SetEnabled(false); |
256 description_label_ = new views::Label( | 285 description_label_ = new views::Label( |
257 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); | 286 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); |
258 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 287 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
259 cookies_tree_model_.reset(new CookiesTreeModel(profile_, | 288 cookies_tree_model_.reset(new CookiesTreeModel(profile_, |
260 new BrowsingDataDatabaseHelper(profile_), | 289 new BrowsingDataDatabaseHelper(profile_), |
261 new BrowsingDataLocalStorageHelper(profile_))); | 290 new BrowsingDataLocalStorageHelper(profile_), |
| 291 new BrowsingDataAppCacheHelper(profile_))); |
262 cookies_tree_model_->AddObserver(this); | 292 cookies_tree_model_->AddObserver(this); |
| 293 |
| 294 info_panel_ = new InfoPanelView; |
263 cookie_info_view_ = new CookieInfoView(false); | 295 cookie_info_view_ = new CookieInfoView(false); |
264 database_info_view_ = new DatabaseInfoView; | 296 database_info_view_ = new DatabaseInfoView; |
265 local_storage_info_view_ = new LocalStorageInfoView; | 297 local_storage_info_view_ = new LocalStorageInfoView; |
| 298 appcache_info_view_ = new AppCacheInfoView; |
| 299 info_panel_->AddChildView(cookie_info_view_); |
| 300 info_panel_->AddChildView(database_info_view_); |
| 301 info_panel_->AddChildView(local_storage_info_view_); |
| 302 info_panel_->AddChildView(appcache_info_view_); |
| 303 |
266 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); | 304 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); |
267 remove_button_ = new views::NativeButton( | 305 remove_button_ = new views::NativeButton( |
268 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL)); | 306 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL)); |
269 remove_all_button_ = new views::NativeButton( | 307 remove_all_button_ = new views::NativeButton( |
270 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL)); | 308 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL)); |
271 | 309 |
272 using views::GridLayout; | 310 using views::GridLayout; |
273 using views::ColumnSet; | 311 using views::ColumnSet; |
274 | 312 |
275 GridLayout* layout = CreatePanelGridLayout(this); | 313 GridLayout* layout = CreatePanelGridLayout(this); |
(...skipping 27 matching lines...) Expand all Loading... |
303 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 341 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
304 layout->StartRow(1, single_column_layout_id); | 342 layout->StartRow(1, single_column_layout_id); |
305 cookies_tree_->set_lines_at_root(true); | 343 cookies_tree_->set_lines_at_root(true); |
306 cookies_tree_->set_auto_expand_children(true); | 344 cookies_tree_->set_auto_expand_children(true); |
307 layout->AddView(cookies_tree_); | 345 layout->AddView(cookies_tree_); |
308 | 346 |
309 cookies_tree_->SetController(this); | 347 cookies_tree_->SetController(this); |
310 | 348 |
311 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 349 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
312 layout->StartRow(0, single_column_layout_id); | 350 layout->StartRow(0, single_column_layout_id); |
313 layout->AddView(cookie_info_view_, 1, 2); | 351 layout->AddView(info_panel_); |
314 | |
315 layout->StartRow(0, single_column_layout_id); | |
316 layout->AddView(database_info_view_); | |
317 | |
318 layout->StartRow(0, single_column_layout_id); | |
319 layout->AddView(local_storage_info_view_); | |
320 | 352 |
321 // Add the Remove/Remove All buttons to the ClientView | 353 // Add the Remove/Remove All buttons to the ClientView |
322 View* parent = GetParent(); | 354 View* parent = GetParent(); |
323 parent->AddChildView(remove_button_); | 355 parent->AddChildView(remove_button_); |
324 parent->AddChildView(remove_all_button_); | 356 parent->AddChildView(remove_all_button_); |
325 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) | 357 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) |
326 UpdateForEmptyState(); | 358 UpdateForEmptyState(); |
327 else | 359 else |
328 UpdateVisibleDetailedInfo(cookie_info_view_); | 360 UpdateVisibleDetailedInfo(cookie_info_view_); |
329 } | 361 } |
(...skipping 15 matching lines...) Expand all Loading... |
345 remove_button_->SetEnabled(cookies_tree_model_->GetRoot()-> | 377 remove_button_->SetEnabled(cookies_tree_model_->GetRoot()-> |
346 GetTotalNodeCount() > 1 && cookies_tree_->GetSelectedNode()); | 378 GetTotalNodeCount() > 1 && cookies_tree_->GetSelectedNode()); |
347 remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()-> | 379 remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()-> |
348 GetTotalNodeCount() > 1 && cookies_tree_->GetSelectedNode()); | 380 GetTotalNodeCount() > 1 && cookies_tree_->GetSelectedNode()); |
349 } | 381 } |
350 | 382 |
351 void CookiesView::UpdateVisibleDetailedInfo(views::View* view) { | 383 void CookiesView::UpdateVisibleDetailedInfo(views::View* view) { |
352 cookie_info_view_->SetVisible(view == cookie_info_view_); | 384 cookie_info_view_->SetVisible(view == cookie_info_view_); |
353 database_info_view_->SetVisible(view == database_info_view_); | 385 database_info_view_->SetVisible(view == database_info_view_); |
354 local_storage_info_view_->SetVisible(view == local_storage_info_view_); | 386 local_storage_info_view_->SetVisible(view == local_storage_info_view_); |
| 387 appcache_info_view_->SetVisible(view == appcache_info_view_); |
355 } | 388 } |
OLD | NEW |