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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "views/controls/tree/tree_view.h" | 24 #include "views/controls/tree/tree_view.h" |
25 #include "views/controls/textfield/textfield.h" | 25 #include "views/controls/textfield/textfield.h" |
26 #include "views/standard_layout.h" | 26 #include "views/standard_layout.h" |
27 | 27 |
28 // static | 28 // static |
29 views::Window* CookiesView::instance_ = NULL; | 29 views::Window* CookiesView::instance_ = NULL; |
30 static const int kCookieInfoViewBorderSize = 1; | 30 static const int kCookieInfoViewBorderSize = 1; |
31 static const int kCookieInfoViewInsetSize = 3; | 31 static const int kCookieInfoViewInsetSize = 3; |
32 static const int kSearchFilterDelayMs = 500; | 32 static const int kSearchFilterDelayMs = 500; |
33 | 33 |
34 | |
35 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
36 // CookiesTreeView | 35 // CookiesTreeView |
37 // Overridden to handle Delete key presses | 36 // Overridden to handle Delete key presses |
38 | 37 |
39 class CookiesTreeView : public views::TreeView { | 38 class CookiesTreeView : public views::TreeView { |
40 public: | 39 public: |
41 explicit CookiesTreeView(CookiesTreeModel* cookies_model); | 40 explicit CookiesTreeView(CookiesTreeModel* cookies_model); |
42 virtual ~CookiesTreeView() {} | 41 virtual ~CookiesTreeView() {} |
43 | 42 |
44 // Removes the items associated with the selected node in the TreeView | 43 // Removes the items associated with the selected node in the TreeView |
45 void RemoveSelectedItems(); | 44 void RemoveSelectedItems(); |
46 | 45 |
47 private: | 46 private: |
48 DISALLOW_COPY_AND_ASSIGN(CookiesTreeView); | 47 DISALLOW_COPY_AND_ASSIGN(CookiesTreeView); |
49 }; | 48 }; |
50 | 49 |
51 CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) { | 50 CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) { |
52 SetModel(cookies_model); | 51 SetModel(cookies_model); |
53 SetRootShown(false); | 52 SetRootShown(false); |
54 SetEditable(false); | 53 SetEditable(false); |
55 } | 54 } |
56 | 55 |
57 void CookiesTreeView::RemoveSelectedItems() { | 56 void CookiesTreeView::RemoveSelectedItems() { |
58 TreeModelNode* selected_node = GetSelectedNode(); | 57 TreeModelNode* selected_node = GetSelectedNode(); |
59 if (selected_node) { | 58 if (selected_node) { |
60 static_cast<CookiesTreeModel*>(model())->DeleteCookieNode( | 59 static_cast<CookiesTreeModel*>(model())->DeleteCookieNode( |
61 static_cast<CookieTreeCookieNode*>(GetSelectedNode())); | 60 static_cast<CookieTreeNode*>(GetSelectedNode())); |
62 } | 61 } |
63 } | 62 } |
64 | 63 |
65 | |
66 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
67 // CookieInfoView, public: | 65 // CookieInfoView, public: |
68 | 66 |
69 CookieInfoView::CookieInfoView() | 67 CookieInfoView::CookieInfoView() |
70 : name_label_(NULL), | 68 : name_label_(NULL), |
71 name_value_field_(NULL), | 69 name_value_field_(NULL), |
72 content_label_(NULL), | 70 content_label_(NULL), |
73 content_value_field_(NULL), | 71 content_value_field_(NULL), |
74 domain_label_(NULL), | 72 domain_label_(NULL), |
75 domain_value_field_(NULL), | 73 domain_value_field_(NULL), |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 send_for_value_field_->SetBackgroundColor(text_area_background); | 244 send_for_value_field_->SetBackgroundColor(text_area_background); |
247 created_value_field_->SetReadOnly(true); | 245 created_value_field_->SetReadOnly(true); |
248 created_value_field_->RemoveBorder(); | 246 created_value_field_->RemoveBorder(); |
249 created_value_field_->SetBackgroundColor(text_area_background); | 247 created_value_field_->SetBackgroundColor(text_area_background); |
250 expires_value_field_->SetReadOnly(true); | 248 expires_value_field_->SetReadOnly(true); |
251 expires_value_field_->RemoveBorder(); | 249 expires_value_field_->RemoveBorder(); |
252 expires_value_field_->SetBackgroundColor(text_area_background); | 250 expires_value_field_->SetBackgroundColor(text_area_background); |
253 } | 251 } |
254 | 252 |
255 /////////////////////////////////////////////////////////////////////////////// | 253 /////////////////////////////////////////////////////////////////////////////// |
| 254 // LocalStorageInfoView, public: |
| 255 |
| 256 LocalStorageInfoView::LocalStorageInfoView() |
| 257 : origin_label_(NULL), |
| 258 origin_value_field_(NULL), |
| 259 size_label_(NULL), |
| 260 size_value_field_(NULL), |
| 261 last_modified_label_(NULL), |
| 262 last_modified_value_field_(NULL) { |
| 263 } |
| 264 |
| 265 LocalStorageInfoView::~LocalStorageInfoView() { |
| 266 } |
| 267 |
| 268 void LocalStorageInfoView::SetLocalStorageInfo( |
| 269 const BrowsingDataLocalStorageHelper::LocalStorageInfo& |
| 270 local_storage_info) { |
| 271 origin_value_field_->SetText(UTF8ToWide(local_storage_info.origin)); |
| 272 size_value_field_->SetText( |
| 273 FormatBytes(local_storage_info.size, |
| 274 GetByteDisplayUnits(local_storage_info.size), |
| 275 true)); |
| 276 last_modified_value_field_->SetText( |
| 277 base::TimeFormatFriendlyDateAndTime(local_storage_info.last_modified)); |
| 278 EnableLocalStorageDisplay(true); |
| 279 } |
| 280 |
| 281 void LocalStorageInfoView::EnableLocalStorageDisplay(bool enabled) { |
| 282 origin_value_field_->SetEnabled(enabled); |
| 283 size_value_field_->SetEnabled(enabled); |
| 284 last_modified_value_field_->SetEnabled(enabled); |
| 285 } |
| 286 |
| 287 void LocalStorageInfoView::ClearLocalStorageDisplay() { |
| 288 std::wstring no_cookie_string = |
| 289 l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); |
| 290 origin_value_field_->SetText(no_cookie_string); |
| 291 size_value_field_->SetText(no_cookie_string); |
| 292 last_modified_value_field_->SetText(no_cookie_string); |
| 293 EnableLocalStorageDisplay(false); |
| 294 } |
| 295 |
| 296 /////////////////////////////////////////////////////////////////////////////// |
| 297 // LocalStorageInfoView, views::View overrides: |
| 298 |
| 299 void LocalStorageInfoView::ViewHierarchyChanged(bool is_add, |
| 300 views::View* parent, |
| 301 views::View* child) { |
| 302 if (is_add && child == this) |
| 303 Init(); |
| 304 } |
| 305 |
| 306 /////////////////////////////////////////////////////////////////////////////// |
| 307 // LocalStorageInfoView, private: |
| 308 |
| 309 void LocalStorageInfoView::Init() { |
| 310 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); |
| 311 views::Border* border = views::Border::CreateSolidBorder( |
| 312 kCookieInfoViewBorderSize, border_color); |
| 313 set_border(border); |
| 314 |
| 315 origin_label_ = new views::Label( |
| 316 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL)); |
| 317 origin_value_field_ = new views::Textfield; |
| 318 size_label_ = new views::Label( |
| 319 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); |
| 320 size_value_field_ = new views::Textfield; |
| 321 last_modified_label_ = new views::Label( |
| 322 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); |
| 323 last_modified_value_field_ = new views::Textfield; |
| 324 |
| 325 using views::GridLayout; |
| 326 using views::ColumnSet; |
| 327 |
| 328 GridLayout* layout = new GridLayout(this); |
| 329 layout->SetInsets(kCookieInfoViewInsetSize, |
| 330 kCookieInfoViewInsetSize, |
| 331 kCookieInfoViewInsetSize, |
| 332 kCookieInfoViewInsetSize); |
| 333 SetLayoutManager(layout); |
| 334 |
| 335 int three_column_layout_id = 0; |
| 336 ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); |
| 337 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 338 GridLayout::USE_PREF, 0, 0); |
| 339 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 340 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 341 GridLayout::USE_PREF, 0, 0); |
| 342 |
| 343 layout->StartRow(0, three_column_layout_id); |
| 344 layout->AddView(origin_label_); |
| 345 layout->AddView(origin_value_field_); |
| 346 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 347 layout->StartRow(0, three_column_layout_id); |
| 348 layout->AddView(size_label_); |
| 349 layout->AddView(size_value_field_); |
| 350 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 351 layout->StartRow(0, three_column_layout_id); |
| 352 layout->AddView(last_modified_label_); |
| 353 layout->AddView(last_modified_value_field_); |
| 354 |
| 355 // Color these borderless text areas the same as the containing dialog. |
| 356 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); |
| 357 // Now that the Textfields are in the view hierarchy, we can initialize them. |
| 358 origin_value_field_->SetReadOnly(true); |
| 359 origin_value_field_->RemoveBorder(); |
| 360 origin_value_field_->SetBackgroundColor(text_area_background); |
| 361 size_value_field_->SetReadOnly(true); |
| 362 size_value_field_->RemoveBorder(); |
| 363 size_value_field_->SetBackgroundColor(text_area_background); |
| 364 last_modified_value_field_->SetReadOnly(true); |
| 365 last_modified_value_field_->RemoveBorder(); |
| 366 last_modified_value_field_->SetBackgroundColor(text_area_background); |
| 367 } |
| 368 |
| 369 |
| 370 /////////////////////////////////////////////////////////////////////////////// |
256 // CookiesView, public: | 371 // CookiesView, public: |
257 | 372 |
258 // static | 373 // static |
259 void CookiesView::ShowCookiesWindow(Profile* profile) { | 374 void CookiesView::ShowCookiesWindow(Profile* profile) { |
260 if (!instance_) { | 375 if (!instance_) { |
261 CookiesView* cookies_view = new CookiesView(profile); | 376 CookiesView* cookies_view = new CookiesView(profile); |
262 instance_ = views::Window::CreateChromeWindow( | 377 instance_ = views::Window::CreateChromeWindow( |
263 NULL, gfx::Rect(), cookies_view); | 378 NULL, gfx::Rect(), cookies_view); |
264 } | 379 } |
265 if (!instance_->IsVisible()) { | 380 if (!instance_->IsVisible()) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 479 } |
365 | 480 |
366 /////////////////////////////////////////////////////////////////////////////// | 481 /////////////////////////////////////////////////////////////////////////////// |
367 // CookiesView, views::TreeViewController overrides: | 482 // CookiesView, views::TreeViewController overrides: |
368 | 483 |
369 void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) { | 484 void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) { |
370 CookieTreeNode::DetailedInfo detailed_info = | 485 CookieTreeNode::DetailedInfo detailed_info = |
371 static_cast<CookieTreeNode*>(tree_view->GetSelectedNode())-> | 486 static_cast<CookieTreeNode*>(tree_view->GetSelectedNode())-> |
372 GetDetailedInfo(); | 487 GetDetailedInfo(); |
373 if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { | 488 if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { |
374 info_view_->SetCookie(detailed_info.cookie->first, | 489 UpdateVisibleDetailedInfo(cookie_info_view_); |
375 detailed_info.cookie->second); | 490 cookie_info_view_->SetCookie(detailed_info.cookie->first, |
| 491 detailed_info.cookie->second); |
| 492 } else if (detailed_info.node_type == |
| 493 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { |
| 494 UpdateVisibleDetailedInfo(local_storage_info_view_); |
| 495 local_storage_info_view_->SetLocalStorageInfo( |
| 496 *detailed_info.local_storage_info); |
376 } else { | 497 } else { |
377 info_view_->ClearCookieDisplay(); | 498 UpdateVisibleDetailedInfo(cookie_info_view_); |
| 499 cookie_info_view_->ClearCookieDisplay(); |
378 } | 500 } |
379 } | 501 } |
380 | 502 |
381 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) { | 503 void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) { |
382 if (keycode == base::VKEY_DELETE) | 504 if (keycode == base::VKEY_DELETE) |
383 cookies_tree_->RemoveSelectedItems(); | 505 cookies_tree_->RemoveSelectedItems(); |
384 } | 506 } |
385 | 507 |
386 /////////////////////////////////////////////////////////////////////////////// | 508 /////////////////////////////////////////////////////////////////////////////// |
387 // CookiesView, private: | 509 // CookiesView, private: |
388 | 510 |
389 CookiesView::CookiesView(Profile* profile) | 511 CookiesView::CookiesView(Profile* profile) |
390 : | 512 : |
391 search_label_(NULL), | 513 search_label_(NULL), |
392 search_field_(NULL), | 514 search_field_(NULL), |
393 clear_search_button_(NULL), | 515 clear_search_button_(NULL), |
394 description_label_(NULL), | 516 description_label_(NULL), |
395 cookies_tree_(NULL), | 517 cookies_tree_(NULL), |
396 info_view_(NULL), | 518 cookie_info_view_(NULL), |
| 519 local_storage_info_view_(NULL), |
397 remove_button_(NULL), | 520 remove_button_(NULL), |
398 remove_all_button_(NULL), | 521 remove_all_button_(NULL), |
399 profile_(profile), | 522 profile_(profile), |
400 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { | 523 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { |
401 } | 524 } |
402 | 525 |
403 | 526 |
404 void CookiesView::UpdateSearchResults() { | 527 void CookiesView::UpdateSearchResults() { |
405 cookies_tree_model_->UpdateSearchResults(search_field_->text()); | 528 cookies_tree_model_->UpdateSearchResults(search_field_->text()); |
406 remove_button_->SetEnabled(cookies_tree_model_->GetRoot()-> | 529 remove_button_->SetEnabled(cookies_tree_model_->GetRoot()-> |
407 GetTotalNodeCount() > 1); | 530 GetTotalNodeCount() > 1); |
408 remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()-> | 531 remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()-> |
409 GetTotalNodeCount() > 1); | 532 GetTotalNodeCount() > 1); |
410 } | 533 } |
411 | 534 |
412 void CookiesView::Init() { | 535 void CookiesView::Init() { |
413 search_label_ = new views::Label( | 536 search_label_ = new views::Label( |
414 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); | 537 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); |
415 search_field_ = new views::Textfield; | 538 search_field_ = new views::Textfield; |
416 search_field_->SetController(this); | 539 search_field_->SetController(this); |
417 clear_search_button_ = new views::NativeButton( | 540 clear_search_button_ = new views::NativeButton( |
418 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); | 541 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); |
419 clear_search_button_->SetEnabled(false); | 542 clear_search_button_->SetEnabled(false); |
420 description_label_ = new views::Label( | 543 description_label_ = new views::Label( |
421 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); | 544 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); |
422 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 545 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
423 cookies_tree_model_.reset(new CookiesTreeModel(profile_)); | 546 cookies_tree_model_.reset(new CookiesTreeModel( |
424 info_view_ = new CookieInfoView; | 547 profile_, new BrowsingDataLocalStorageHelper(profile_))); |
| 548 cookie_info_view_ = new CookieInfoView; |
| 549 local_storage_info_view_ = new LocalStorageInfoView; |
425 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); | 550 cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); |
426 remove_button_ = new views::NativeButton( | 551 remove_button_ = new views::NativeButton( |
427 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL)); | 552 this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL)); |
428 remove_all_button_ = new views::NativeButton( | 553 remove_all_button_ = new views::NativeButton( |
429 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL)); | 554 this, l10n_util::GetString(IDS_COOKIES_REMOVE_ALL_LABEL)); |
430 | 555 |
431 using views::GridLayout; | 556 using views::GridLayout; |
432 using views::ColumnSet; | 557 using views::ColumnSet; |
433 | 558 |
434 GridLayout* layout = CreatePanelGridLayout(this); | 559 GridLayout* layout = CreatePanelGridLayout(this); |
(...skipping 27 matching lines...) Expand all Loading... |
462 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 587 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
463 layout->StartRow(1, single_column_layout_id); | 588 layout->StartRow(1, single_column_layout_id); |
464 cookies_tree_->set_lines_at_root(true); | 589 cookies_tree_->set_lines_at_root(true); |
465 cookies_tree_->set_auto_expand_children(true); | 590 cookies_tree_->set_auto_expand_children(true); |
466 layout->AddView(cookies_tree_); | 591 layout->AddView(cookies_tree_); |
467 | 592 |
468 cookies_tree_->SetController(this); | 593 cookies_tree_->SetController(this); |
469 | 594 |
470 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 595 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
471 layout->StartRow(0, single_column_layout_id); | 596 layout->StartRow(0, single_column_layout_id); |
472 layout->AddView(info_view_); | 597 layout->AddView(cookie_info_view_, 1, 2); |
| 598 |
| 599 layout->StartRow(0, single_column_layout_id); |
| 600 layout->AddView(local_storage_info_view_); |
473 | 601 |
474 // Add the Remove/Remove All buttons to the ClientView | 602 // Add the Remove/Remove All buttons to the ClientView |
475 View* parent = GetParent(); | 603 View* parent = GetParent(); |
476 parent->AddChildView(remove_button_); | 604 parent->AddChildView(remove_button_); |
477 parent->AddChildView(remove_all_button_); | 605 parent->AddChildView(remove_all_button_); |
478 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) | 606 if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) |
479 UpdateForEmptyState(); | 607 UpdateForEmptyState(); |
| 608 else |
| 609 UpdateVisibleDetailedInfo(cookie_info_view_); |
480 } | 610 } |
481 | 611 |
482 void CookiesView::ResetSearchQuery() { | 612 void CookiesView::ResetSearchQuery() { |
483 search_field_->SetText(std::wstring()); | 613 search_field_->SetText(std::wstring()); |
484 clear_search_button_->SetEnabled(false); | 614 clear_search_button_->SetEnabled(false); |
485 UpdateSearchResults(); | 615 UpdateSearchResults(); |
486 } | 616 } |
487 | 617 |
488 void CookiesView::UpdateForEmptyState() { | 618 void CookiesView::UpdateForEmptyState() { |
489 info_view_->ClearCookieDisplay(); | 619 cookie_info_view_->ClearCookieDisplay(); |
490 remove_button_->SetEnabled(false); | 620 remove_button_->SetEnabled(false); |
491 remove_all_button_->SetEnabled(false); | 621 remove_all_button_->SetEnabled(false); |
| 622 UpdateVisibleDetailedInfo(cookie_info_view_); |
492 } | 623 } |
| 624 |
| 625 void CookiesView::UpdateVisibleDetailedInfo(views::View* view) { |
| 626 view->SetVisible(true); |
| 627 views::View* other = local_storage_info_view_; |
| 628 if (view == local_storage_info_view_) other = cookie_info_view_; |
| 629 other->SetVisible(false); |
| 630 } |
OLD | NEW |