OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/collected_cookies_views.h" | 5 #include "chrome/browser/ui/views/collected_cookies_views.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 8 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
9 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 9 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
10 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 10 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
23 #include "chrome/browser/ui/views/constrained_window_views.h" | 23 #include "chrome/browser/ui/views/constrained_window_views.h" |
24 #include "chrome/browser/ui/views/cookie_info_view.h" | 24 #include "chrome/browser/ui/views/cookie_info_view.h" |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "components/web_modal/web_contents_modal_dialog_host.h" | 26 #include "components/web_modal/web_contents_modal_dialog_host.h" |
27 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 27 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
28 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 28 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
29 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_contents_view.h" | |
33 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
34 #include "grit/locale_settings.h" | 33 #include "grit/locale_settings.h" |
35 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
36 #include "net/cookies/canonical_cookie.h" | 35 #include "net/cookies/canonical_cookie.h" |
37 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/gfx/color_utils.h" | 38 #include "ui/gfx/color_utils.h" |
40 #include "ui/views/border.h" | 39 #include "ui/views/border.h" |
41 #include "ui/views/controls/button/label_button.h" | 40 #include "ui/views/controls/button/label_button.h" |
42 #include "ui/views/controls/image_view.h" | 41 #include "ui/views/controls/image_view.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 TabSpecificContentSettings* content_settings = | 207 TabSpecificContentSettings* content_settings = |
209 TabSpecificContentSettings::FromWebContents(web_contents); | 208 TabSpecificContentSettings::FromWebContents(web_contents); |
210 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 209 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
211 content::Source<TabSpecificContentSettings>(content_settings)); | 210 content::Source<TabSpecificContentSettings>(content_settings)); |
212 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 211 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
213 WebContentsModalDialogManager::FromWebContents(web_contents); | 212 WebContentsModalDialogManager::FromWebContents(web_contents); |
214 WebContentsModalDialogManagerDelegate* modal_delegate = | 213 WebContentsModalDialogManagerDelegate* modal_delegate = |
215 web_contents_modal_dialog_manager->delegate(); | 214 web_contents_modal_dialog_manager->delegate(); |
216 DCHECK(modal_delegate); | 215 DCHECK(modal_delegate); |
217 window_ = views::Widget::CreateWindowAsFramelessChild( | 216 window_ = views::Widget::CreateWindowAsFramelessChild( |
218 this, | 217 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
219 web_contents->GetView()->GetNativeView(), | |
220 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | |
221 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); | 218 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); |
222 } | 219 } |
223 | 220 |
224 /////////////////////////////////////////////////////////////////////////////// | 221 /////////////////////////////////////////////////////////////////////////////// |
225 // CollectedCookiesViews, views::DialogDelegate implementation: | 222 // CollectedCookiesViews, views::DialogDelegate implementation: |
226 | 223 |
227 string16 CollectedCookiesViews::GetWindowTitle() const { | 224 string16 CollectedCookiesViews::GetWindowTitle() const { |
228 return l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_DIALOG_TITLE); | 225 return l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_DIALOG_TITLE); |
229 } | 226 } |
230 | 227 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 321 |
325 GridLayout* layout = GridLayout::CreatePanel(this); | 322 GridLayout* layout = GridLayout::CreatePanel(this); |
326 SetLayoutManager(layout); | 323 SetLayoutManager(layout); |
327 | 324 |
328 const int single_column_layout_id = 0; | 325 const int single_column_layout_id = 0; |
329 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); | 326 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); |
330 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 327 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
331 GridLayout::USE_PREF, 0, 0); | 328 GridLayout::USE_PREF, 0, 0); |
332 | 329 |
333 layout->StartRow(0, single_column_layout_id); | 330 layout->StartRow(0, single_column_layout_id); |
334 views::TabbedPane* tabbed_pane = NULL; | 331 views::TabbedPane* tabbed_pane = new views::TabbedPane(); |
335 if (DialogDelegate::UseNewStyle()) { | 332 layout->SetInsets(gfx::Insets(kTabbedPaneTopPadding, 0, 0, 0)); |
336 tabbed_pane = new views::TabbedPane(false); | |
337 layout->SetInsets(gfx::Insets(kTabbedPaneTopPadding, 0, 0, 0)); | |
338 } else { | |
339 tabbed_pane = new views::TabbedPane(true); | |
340 } | |
341 | 333 |
342 layout->AddView(tabbed_pane); | 334 layout->AddView(tabbed_pane); |
343 // NOTE: Panes must be added after |tabbed_pane| has been added to its parent. | 335 // NOTE: Panes must be added after |tabbed_pane| has been added to its parent. |
344 string16 label_allowed = l10n_util::GetStringUTF16( | 336 string16 label_allowed = l10n_util::GetStringUTF16( |
345 IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_TAB_LABEL); | 337 IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_TAB_LABEL); |
346 string16 label_blocked = l10n_util::GetStringUTF16( | 338 string16 label_blocked = l10n_util::GetStringUTF16( |
347 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_TAB_LABEL); | 339 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_TAB_LABEL); |
348 tabbed_pane->AddTab(label_allowed, CreateAllowedPane()); | 340 tabbed_pane->AddTab(label_allowed, CreateAllowedPane()); |
349 tabbed_pane->AddTab(label_blocked, CreateBlockedPane()); | 341 tabbed_pane->AddTab(label_blocked, CreateBlockedPane()); |
350 tabbed_pane->SelectTabAt(0); | 342 tabbed_pane->SelectTabAt(0); |
351 tabbed_pane->set_listener(this); | 343 tabbed_pane->set_listener(this); |
352 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 344 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
353 | 345 |
354 layout->StartRow(0, single_column_layout_id); | 346 layout->StartRow(0, single_column_layout_id); |
355 cookie_info_view_ = new CookieInfoView(); | 347 cookie_info_view_ = new CookieInfoView(); |
356 layout->AddView(cookie_info_view_); | 348 layout->AddView(cookie_info_view_); |
357 layout->AddPaddingRow(0, DialogDelegate::UseNewStyle() ? | 349 layout->AddPaddingRow(0, kCookieInfoBottomPadding); |
358 kCookieInfoBottomPadding : | |
359 views::kRelatedControlVerticalSpacing); | |
360 | 350 |
361 layout->StartRow(0, single_column_layout_id); | 351 layout->StartRow(0, single_column_layout_id); |
362 infobar_ = new InfobarView(); | 352 infobar_ = new InfobarView(); |
363 layout->AddView(infobar_); | 353 layout->AddView(infobar_); |
364 | 354 |
365 EnableControls(); | 355 EnableControls(); |
366 ShowCookieInfo(); | 356 ShowCookieInfo(); |
367 } | 357 } |
368 | 358 |
369 views::View* CollectedCookiesViews::CreateAllowedPane() { | 359 views::View* CollectedCookiesViews::CreateAllowedPane() { |
(...skipping 17 matching lines...) Expand all Loading... |
387 block_allowed_button_ = new views::LabelButton(this, | 377 block_allowed_button_ = new views::LabelButton(this, |
388 l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_BLOCK_BUTTON)); | 378 l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_BLOCK_BUTTON)); |
389 block_allowed_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 379 block_allowed_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
390 | 380 |
391 // Create the view that holds all the controls together. This will be the | 381 // Create the view that holds all the controls together. This will be the |
392 // pane added to the tabbed pane. | 382 // pane added to the tabbed pane. |
393 using views::GridLayout; | 383 using views::GridLayout; |
394 | 384 |
395 views::View* pane = new views::View(); | 385 views::View* pane = new views::View(); |
396 GridLayout* layout = GridLayout::CreatePanel(pane); | 386 GridLayout* layout = GridLayout::CreatePanel(pane); |
397 if (DialogDelegate::UseNewStyle()) { | 387 layout->SetInsets(kVPanelPadding, views::kButtonHEdgeMarginNew, |
398 layout->SetInsets(kVPanelPadding, views::kButtonHEdgeMarginNew, | 388 kVPanelPadding, views::kButtonHEdgeMarginNew); |
399 kVPanelPadding, views::kButtonHEdgeMarginNew); | |
400 } | |
401 pane->SetLayoutManager(layout); | 389 pane->SetLayoutManager(layout); |
402 | 390 |
403 const int single_column_layout_id = 0; | 391 const int single_column_layout_id = 0; |
404 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); | 392 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); |
405 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 393 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
406 GridLayout::USE_PREF, 0, 0); | 394 GridLayout::USE_PREF, 0, 0); |
407 | 395 |
408 layout->StartRow(0, single_column_layout_id); | 396 layout->StartRow(0, single_column_layout_id); |
409 layout->AddView(allowed_label_); | 397 layout->AddView(allowed_label_); |
410 layout->AddPaddingRow(0, DialogDelegate::UseNewStyle() ? | 398 layout->AddPaddingRow(0, kLabelBottomPadding); |
411 kLabelBottomPadding : | |
412 views::kRelatedControlVerticalSpacing); | |
413 | 399 |
414 layout->StartRow(1, single_column_layout_id); | 400 layout->StartRow(1, single_column_layout_id); |
415 layout->AddView(CreateScrollView(allowed_cookies_tree_), 1, 1, | 401 layout->AddView(CreateScrollView(allowed_cookies_tree_), 1, 1, |
416 GridLayout::FILL, GridLayout::FILL, kTreeViewWidth, | 402 GridLayout::FILL, GridLayout::FILL, kTreeViewWidth, |
417 kTreeViewHeight); | 403 kTreeViewHeight); |
418 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 404 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
419 | 405 |
420 layout->StartRow(0, single_column_layout_id); | 406 layout->StartRow(0, single_column_layout_id); |
421 layout->AddView(block_allowed_button_, 1, 1, GridLayout::LEADING, | 407 layout->AddView(block_allowed_button_, 1, 1, GridLayout::LEADING, |
422 GridLayout::CENTER); | 408 GridLayout::CENTER); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 for_session_blocked_button_ = new views::LabelButton(this, | 442 for_session_blocked_button_ = new views::LabelButton(this, |
457 l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON)); | 443 l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON)); |
458 for_session_blocked_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 444 for_session_blocked_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
459 | 445 |
460 // Create the view that holds all the controls together. This will be the | 446 // Create the view that holds all the controls together. This will be the |
461 // pane added to the tabbed pane. | 447 // pane added to the tabbed pane. |
462 using views::GridLayout; | 448 using views::GridLayout; |
463 | 449 |
464 views::View* pane = new views::View(); | 450 views::View* pane = new views::View(); |
465 GridLayout* layout = GridLayout::CreatePanel(pane); | 451 GridLayout* layout = GridLayout::CreatePanel(pane); |
466 if (DialogDelegate::UseNewStyle()) { | 452 layout->SetInsets(kVPanelPadding, views::kButtonHEdgeMarginNew, |
467 layout->SetInsets(kVPanelPadding, views::kButtonHEdgeMarginNew, | 453 kVPanelPadding, views::kButtonHEdgeMarginNew); |
468 kVPanelPadding, views::kButtonHEdgeMarginNew); | |
469 } | |
470 pane->SetLayoutManager(layout); | 454 pane->SetLayoutManager(layout); |
471 | 455 |
472 const int single_column_layout_id = 0; | 456 const int single_column_layout_id = 0; |
473 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); | 457 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); |
474 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 458 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
475 GridLayout::USE_PREF, 0, 0); | 459 GridLayout::USE_PREF, 0, 0); |
476 | 460 |
477 const int three_columns_layout_id = 1; | 461 const int three_columns_layout_id = 1; |
478 column_set = layout->AddColumnSet(three_columns_layout_id); | 462 column_set = layout->AddColumnSet(three_columns_layout_id); |
479 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 463 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
480 GridLayout::USE_PREF, 0, 0); | 464 GridLayout::USE_PREF, 0, 0); |
481 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 465 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
482 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 466 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
483 GridLayout::USE_PREF, 0, 0); | 467 GridLayout::USE_PREF, 0, 0); |
484 | 468 |
485 layout->StartRow(0, single_column_layout_id); | 469 layout->StartRow(0, single_column_layout_id); |
486 layout->AddView(blocked_label_, 1, 1, GridLayout::FILL, GridLayout::FILL); | 470 layout->AddView(blocked_label_, 1, 1, GridLayout::FILL, GridLayout::FILL); |
487 layout->AddPaddingRow(0, DialogDelegate::UseNewStyle() ? | 471 layout->AddPaddingRow(0, kLabelBottomPadding); |
488 kLabelBottomPadding : | |
489 views::kRelatedControlVerticalSpacing); | |
490 | 472 |
491 layout->StartRow(1, single_column_layout_id); | 473 layout->StartRow(1, single_column_layout_id); |
492 layout->AddView( | 474 layout->AddView( |
493 CreateScrollView(blocked_cookies_tree_), 1, 1, | 475 CreateScrollView(blocked_cookies_tree_), 1, 1, |
494 GridLayout::FILL, GridLayout::FILL, kTreeViewWidth, kTreeViewHeight); | 476 GridLayout::FILL, GridLayout::FILL, kTreeViewWidth, kTreeViewHeight); |
495 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 477 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
496 | 478 |
497 layout->StartRow(0, three_columns_layout_id); | 479 layout->StartRow(0, three_columns_layout_id); |
498 layout->AddView(allow_blocked_button_); | 480 layout->AddView(allow_blocked_button_); |
499 layout->AddView(for_session_blocked_button_); | 481 layout->AddView(for_session_blocked_button_); |
500 | 482 |
501 return pane; | 483 return pane; |
502 } | 484 } |
503 | 485 |
504 views::View* CollectedCookiesViews::CreateScrollView(views::TreeView* pane) { | 486 views::View* CollectedCookiesViews::CreateScrollView(views::TreeView* pane) { |
505 if (DialogDelegate::UseNewStyle()) { | 487 views::ScrollView* scroll_view = new views::ScrollView(); |
506 views::ScrollView* scroll_view = new views::ScrollView(); | 488 scroll_view->SetContents(pane); |
507 scroll_view->SetContents(pane); | 489 scroll_view->set_border( |
508 scroll_view->set_border( | 490 views::Border::CreateSolidBorder(1, kCookiesBorderColor)); |
509 views::Border::CreateSolidBorder(1, kCookiesBorderColor)); | 491 return scroll_view; |
510 return scroll_view; | |
511 } else { | |
512 return pane->CreateParentIfNecessary(); | |
513 } | |
514 } | 492 } |
515 | 493 |
516 void CollectedCookiesViews::EnableControls() { | 494 void CollectedCookiesViews::EnableControls() { |
517 bool enable_allowed_buttons = false; | 495 bool enable_allowed_buttons = false; |
518 ui::TreeModelNode* node = allowed_cookies_tree_->GetSelectedNode(); | 496 ui::TreeModelNode* node = allowed_cookies_tree_->GetSelectedNode(); |
519 if (node) { | 497 if (node) { |
520 CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node); | 498 CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node); |
521 if (cookie_node->GetDetailedInfo().node_type == | 499 if (cookie_node->GetDetailedInfo().node_type == |
522 CookieTreeNode::DetailedInfo::TYPE_HOST) { | 500 CookieTreeNode::DetailedInfo::TYPE_HOST) { |
523 enable_allowed_buttons = static_cast<CookieTreeHostNode*>( | 501 enable_allowed_buttons = static_cast<CookieTreeHostNode*>( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 /////////////////////////////////////////////////////////////////////////////// | 554 /////////////////////////////////////////////////////////////////////////////// |
577 // CollectedCookiesViews, content::NotificationObserver implementation: | 555 // CollectedCookiesViews, content::NotificationObserver implementation: |
578 | 556 |
579 void CollectedCookiesViews::Observe( | 557 void CollectedCookiesViews::Observe( |
580 int type, | 558 int type, |
581 const content::NotificationSource& source, | 559 const content::NotificationSource& source, |
582 const content::NotificationDetails& details) { | 560 const content::NotificationDetails& details) { |
583 DCHECK_EQ(chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, type); | 561 DCHECK_EQ(chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, type); |
584 window_->Close(); | 562 window_->Close(); |
585 } | 563 } |
OLD | NEW |