| 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/page_info/page_info_bubble_view.h" | 5 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 std::vector<size_t> offsets; | 264 std::vector<size_t> offsets; |
| 265 | 265 |
| 266 base::string16 text = base::ReplaceStringPlaceholders( | 266 base::string16 text = base::ReplaceStringPlaceholders( |
| 267 base::ASCIIToUTF16("$1 $2"), subst, &offsets); | 267 base::ASCIIToUTF16("$1 $2"), subst, &offsets); |
| 268 security_details_label_->SetText(text); | 268 security_details_label_->SetText(text); |
| 269 gfx::Range details_range(offsets[1], text.length()); | 269 gfx::Range details_range(offsets[1], text.length()); |
| 270 | 270 |
| 271 views::StyledLabel::RangeStyleInfo link_style = | 271 views::StyledLabel::RangeStyleInfo link_style = |
| 272 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 272 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 273 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) | 273 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 274 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; | 274 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; |
| 275 } |
| 275 link_style.disable_line_wrapping = false; | 276 link_style.disable_line_wrapping = false; |
| 276 | 277 |
| 277 security_details_label_->AddStyleRange(details_range, link_style); | 278 security_details_label_->AddStyleRange(details_range, link_style); |
| 278 } | 279 } |
| 279 | 280 |
| 280 void BubbleHeaderView::AddResetDecisionsLabel() { | 281 void BubbleHeaderView::AddResetDecisionsLabel() { |
| 281 std::vector<base::string16> subst; | 282 std::vector<base::string16> subst; |
| 282 subst.push_back( | 283 subst.push_back( |
| 283 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INVALID_CERTIFICATE_DESCRIPTION)); | 284 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INVALID_CERTIFICATE_DESCRIPTION)); |
| 284 subst.push_back(l10n_util::GetStringUTF16( | 285 subst.push_back(l10n_util::GetStringUTF16( |
| 285 IDS_PAGE_INFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); | 286 IDS_PAGE_INFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); |
| 286 | 287 |
| 287 std::vector<size_t> offsets; | 288 std::vector<size_t> offsets; |
| 288 | 289 |
| 289 base::string16 text = base::ReplaceStringPlaceholders( | 290 base::string16 text = base::ReplaceStringPlaceholders( |
| 290 base::ASCIIToUTF16("$1 $2"), subst, &offsets); | 291 base::ASCIIToUTF16("$1 $2"), subst, &offsets); |
| 291 reset_cert_decisions_label_ = | 292 reset_cert_decisions_label_ = |
| 292 new views::StyledLabel(text, styled_label_listener_); | 293 new views::StyledLabel(text, styled_label_listener_); |
| 293 reset_cert_decisions_label_->set_id( | 294 reset_cert_decisions_label_->set_id( |
| 294 VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS); | 295 VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS); |
| 295 gfx::Range link_range(offsets[1], text.length()); | 296 gfx::Range link_range(offsets[1], text.length()); |
| 296 | 297 |
| 297 views::StyledLabel::RangeStyleInfo link_style = | 298 views::StyledLabel::RangeStyleInfo link_style = |
| 298 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 299 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 299 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) | 300 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 300 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; | 301 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; |
| 302 } |
| 301 link_style.disable_line_wrapping = false; | 303 link_style.disable_line_wrapping = false; |
| 302 | 304 |
| 303 reset_cert_decisions_label_->AddStyleRange(link_range, link_style); | 305 reset_cert_decisions_label_->AddStyleRange(link_range, link_style); |
| 304 // Fit the styled label to occupy available width. | 306 // Fit the styled label to occupy available width. |
| 305 reset_cert_decisions_label_->SizeToFit(0); | 307 reset_cert_decisions_label_->SizeToFit(0); |
| 306 reset_decisions_label_container_->AddChildView(reset_cert_decisions_label_); | 308 reset_decisions_label_container_->AddChildView(reset_cert_decisions_label_); |
| 307 | 309 |
| 308 // Now that it contains a label, the container needs padding at the top. | 310 // Now that it contains a label, the container needs padding at the top. |
| 309 reset_decisions_label_container_->SetBorder( | 311 reset_decisions_label_container_->SetBorder( |
| 310 views::CreateEmptyBorder(8, 0, 0, 0)); | 312 views::CreateEmptyBorder(8, 0, 0, 0)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 const security_state::SecurityInfo& security_info) { | 392 const security_state::SecurityInfo& security_info) { |
| 391 gfx::NativeView parent_window = | 393 gfx::NativeView parent_window = |
| 392 anchor_view ? nullptr : web_contents->GetNativeView(); | 394 anchor_view ? nullptr : web_contents->GetNativeView(); |
| 393 if (url.SchemeIs(content::kChromeUIScheme) || | 395 if (url.SchemeIs(content::kChromeUIScheme) || |
| 394 url.SchemeIs(content::kChromeDevToolsScheme) || | 396 url.SchemeIs(content::kChromeDevToolsScheme) || |
| 395 url.SchemeIs(extensions::kExtensionScheme) || | 397 url.SchemeIs(extensions::kExtensionScheme) || |
| 396 url.SchemeIs(content::kViewSourceScheme)) { | 398 url.SchemeIs(content::kViewSourceScheme)) { |
| 397 // Use the concrete type so that |SetAnchorRect| can be called as a friend. | 399 // Use the concrete type so that |SetAnchorRect| can be called as a friend. |
| 398 InternalPageInfoBubbleView* bubble = | 400 InternalPageInfoBubbleView* bubble = |
| 399 new InternalPageInfoBubbleView(anchor_view, parent_window, url); | 401 new InternalPageInfoBubbleView(anchor_view, parent_window, url); |
| 400 if (!anchor_view) | 402 if (!anchor_view) { |
| 401 bubble->SetAnchorRect(anchor_rect); | 403 bubble->SetAnchorRect(anchor_rect); |
| 402 if (widget_observer) | 404 } |
| 405 if (widget_observer) { |
| 403 bubble->GetWidget()->AddObserver(widget_observer); | 406 bubble->GetWidget()->AddObserver(widget_observer); |
| 407 } |
| 404 bubble->GetWidget()->Show(); | 408 bubble->GetWidget()->Show(); |
| 405 return bubble; | 409 return bubble; |
| 406 } | 410 } |
| 407 PageInfoBubbleView* bubble = new PageInfoBubbleView( | 411 PageInfoBubbleView* bubble = new PageInfoBubbleView( |
| 408 anchor_view, parent_window, profile, web_contents, url, security_info); | 412 anchor_view, parent_window, profile, web_contents, url, security_info); |
| 409 if (!anchor_view) | 413 if (!anchor_view) { |
| 410 bubble->SetAnchorRect(anchor_rect); | 414 bubble->SetAnchorRect(anchor_rect); |
| 411 if (widget_observer) | 415 } |
| 416 if (widget_observer) { |
| 412 bubble->GetWidget()->AddObserver(widget_observer); | 417 bubble->GetWidget()->AddObserver(widget_observer); |
| 418 } |
| 413 bubble->GetWidget()->Show(); | 419 bubble->GetWidget()->Show(); |
| 414 return bubble; | 420 return bubble; |
| 415 } | 421 } |
| 416 | 422 |
| 417 // static | 423 // static |
| 418 PageInfoBubbleView::BubbleType PageInfoBubbleView::GetShownBubbleType() { | 424 PageInfoBubbleView::BubbleType PageInfoBubbleView::GetShownBubbleType() { |
| 419 return g_shown_bubble_type; | 425 return g_shown_bubble_type; |
| 420 } | 426 } |
| 421 | 427 |
| 422 // static | 428 // static |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 499 } |
| 494 views::BubbleDialogDelegateView::CreateBubble(this); | 500 views::BubbleDialogDelegateView::CreateBubble(this); |
| 495 | 501 |
| 496 presenter_.reset(new PageInfo( | 502 presenter_.reset(new PageInfo( |
| 497 this, profile, TabSpecificContentSettings::FromWebContents(web_contents), | 503 this, profile, TabSpecificContentSettings::FromWebContents(web_contents), |
| 498 web_contents, url, security_info)); | 504 web_contents, url, security_info)); |
| 499 } | 505 } |
| 500 | 506 |
| 501 void PageInfoBubbleView::RenderFrameDeleted( | 507 void PageInfoBubbleView::RenderFrameDeleted( |
| 502 content::RenderFrameHost* render_frame_host) { | 508 content::RenderFrameHost* render_frame_host) { |
| 503 if (render_frame_host == web_contents()->GetMainFrame()) | 509 if (render_frame_host == web_contents()->GetMainFrame()) { |
| 504 GetWidget()->Close(); | 510 GetWidget()->Close(); |
| 511 } |
| 505 } | 512 } |
| 506 | 513 |
| 507 void PageInfoBubbleView::WebContentsDestroyed() { | 514 void PageInfoBubbleView::WebContentsDestroyed() { |
| 508 weak_factory_.InvalidateWeakPtrs(); | 515 weak_factory_.InvalidateWeakPtrs(); |
| 509 } | 516 } |
| 510 | 517 |
| 511 void PageInfoBubbleView::WasHidden() { | 518 void PageInfoBubbleView::WasHidden() { |
| 512 GetWidget()->Close(); | 519 GetWidget()->Close(); |
| 513 } | 520 } |
| 514 | 521 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 // The bubble closes automatically when the collected cookies dialog or the | 570 // The bubble closes automatically when the collected cookies dialog or the |
| 564 // certificate viewer opens. So delay handling of the link clicked to avoid | 571 // certificate viewer opens. So delay handling of the link clicked to avoid |
| 565 // a crash in the base class which needs to complete the mouse event handling. | 572 // a crash in the base class which needs to complete the mouse event handling. |
| 566 content::BrowserThread::PostTask( | 573 content::BrowserThread::PostTask( |
| 567 content::BrowserThread::UI, FROM_HERE, | 574 content::BrowserThread::UI, FROM_HERE, |
| 568 base::BindOnce(&PageInfoBubbleView::HandleLinkClickedAsync, | 575 base::BindOnce(&PageInfoBubbleView::HandleLinkClickedAsync, |
| 569 weak_factory_.GetWeakPtr(), source)); | 576 weak_factory_.GetWeakPtr(), source)); |
| 570 } | 577 } |
| 571 | 578 |
| 572 gfx::Size PageInfoBubbleView::CalculatePreferredSize() const { | 579 gfx::Size PageInfoBubbleView::CalculatePreferredSize() const { |
| 573 if (header_ == nullptr && site_settings_view_ == nullptr) | 580 if (header_ == nullptr && site_settings_view_ == nullptr) { |
| 574 return views::View::CalculatePreferredSize(); | 581 return views::View::CalculatePreferredSize(); |
| 582 } |
| 575 | 583 |
| 576 int height = 0; | 584 int height = 0; |
| 577 if (header_) | 585 if (header_) { |
| 578 height += header_->GetPreferredSize().height() + kHeaderMarginBottom; | 586 height += header_->GetPreferredSize().height() + kHeaderMarginBottom; |
| 579 if (separator_) | 587 } |
| 588 if (separator_) { |
| 580 height += separator_->GetPreferredSize().height(); | 589 height += separator_->GetPreferredSize().height(); |
| 590 } |
| 581 | 591 |
| 582 if (site_settings_view_) | 592 if (site_settings_view_) { |
| 583 height += site_settings_view_->GetPreferredSize().height(); | 593 height += site_settings_view_->GetPreferredSize().height(); |
| 594 } |
| 584 | 595 |
| 585 int width = kMinBubbleWidth; | 596 int width = kMinBubbleWidth; |
| 586 if (site_settings_view_) | 597 if (site_settings_view_) { |
| 587 width = std::max(width, site_settings_view_->GetPreferredSize().width()); | 598 width = std::max(width, site_settings_view_->GetPreferredSize().width()); |
| 599 } |
| 588 width = std::min(width, kMaxBubbleWidth); | 600 width = std::min(width, kMaxBubbleWidth); |
| 589 return gfx::Size(width, height); | 601 return gfx::Size(width, height); |
| 590 } | 602 } |
| 591 | 603 |
| 592 void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) { | 604 void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) { |
| 593 // |cookie_info_list| should only ever have 2 items: first- and third-party | 605 // |cookie_info_list| should only ever have 2 items: first- and third-party |
| 594 // cookies. | 606 // cookies. |
| 595 DCHECK_EQ(cookie_info_list.size(), 2u); | 607 DCHECK_EQ(cookie_info_list.size(), 2u); |
| 596 int total_allowed = 0; | 608 int total_allowed = 0; |
| 597 for (const auto& i : cookie_info_list) | 609 for (const auto& i : cookie_info_list) { |
| 598 total_allowed += i.allowed; | 610 total_allowed += i.allowed; |
| 611 } |
| 599 base::string16 label_text = l10n_util::GetPluralStringFUTF16( | 612 base::string16 label_text = l10n_util::GetPluralStringFUTF16( |
| 600 IDS_PAGE_INFO_NUM_COOKIES, total_allowed); | 613 IDS_PAGE_INFO_NUM_COOKIES, total_allowed); |
| 601 | 614 |
| 602 cookie_dialog_link_->SetText(label_text); | 615 cookie_dialog_link_->SetText(label_text); |
| 603 Layout(); | 616 Layout(); |
| 604 SizeToContents(); | 617 SizeToContents(); |
| 605 } | 618 } |
| 606 | 619 |
| 607 void PageInfoBubbleView::SetPermissionInfo( | 620 void PageInfoBubbleView::SetPermissionInfo( |
| 608 const PermissionInfoList& permission_info_list, | 621 const PermissionInfoList& permission_info_list, |
| 609 ChosenObjectInfoList chosen_object_info_list) { | 622 ChosenObjectInfoList chosen_object_info_list) { |
| 610 // When a permission is changed, PageInfo::OnSitePermissionChanged() | 623 // When a permission is changed, PageInfo::OnSitePermissionChanged() |
| 611 // calls this method with updated permissions. However, PermissionSelectorRow | 624 // calls this method with updated permissions. However, PermissionSelectorRow |
| 612 // will have already updated its state, so it's already reflected in the UI. | 625 // will have already updated its state, so it's already reflected in the UI. |
| 613 // In addition, if a permission is set to the default setting, PageInfo | 626 // In addition, if a permission is set to the default setting, PageInfo |
| 614 // removes it from |permission_info_list|, but the button should remain. | 627 // removes it from |permission_info_list|, but the button should remain. |
| 615 if (permissions_view_) | 628 if (permissions_view_) { |
| 616 return; | 629 return; |
| 630 } |
| 617 | 631 |
| 618 permissions_view_ = new views::View(); | 632 permissions_view_ = new views::View(); |
| 619 views::GridLayout* layout = new views::GridLayout(permissions_view_); | 633 views::GridLayout* layout = new views::GridLayout(permissions_view_); |
| 620 permissions_view_->SetLayoutManager(layout); | 634 permissions_view_->SetLayoutManager(layout); |
| 621 | 635 |
| 622 site_settings_view_->AddChildView(permissions_view_); | 636 site_settings_view_->AddChildView(permissions_view_); |
| 623 | 637 |
| 624 const int content_column = 0; | 638 const int content_column = 0; |
| 625 views::ColumnSet* column_set = layout->AddColumnSet(content_column); | 639 views::ColumnSet* column_set = layout->AddColumnSet(content_column); |
| 626 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 640 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 void PageInfoBubbleView::SetIdentityInfo(const IdentityInfo& identity_info) { | 694 void PageInfoBubbleView::SetIdentityInfo(const IdentityInfo& identity_info) { |
| 681 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = | 695 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = |
| 682 identity_info.GetSecurityDescription(); | 696 identity_info.GetSecurityDescription(); |
| 683 | 697 |
| 684 summary_text_ = security_description->summary; | 698 summary_text_ = security_description->summary; |
| 685 GetWidget()->UpdateWindowTitle(); | 699 GetWidget()->UpdateWindowTitle(); |
| 686 | 700 |
| 687 if (identity_info.certificate) { | 701 if (identity_info.certificate) { |
| 688 certificate_ = identity_info.certificate; | 702 certificate_ = identity_info.certificate; |
| 689 | 703 |
| 690 if (identity_info.show_ssl_decision_revoke_button) | 704 if (identity_info.show_ssl_decision_revoke_button) { |
| 691 header_->AddResetDecisionsLabel(); | 705 header_->AddResetDecisionsLabel(); |
| 706 } |
| 692 | 707 |
| 693 if (PageInfoUI::ShouldShowCertificateLink()) { | 708 if (PageInfoUI::ShouldShowCertificateLink()) { |
| 694 // The text of link to the Certificate Viewer varies depending on the | 709 // The text of link to the Certificate Viewer varies depending on the |
| 695 // validity of the Certificate. | 710 // validity of the Certificate. |
| 696 const bool valid_identity = (identity_info.identity_status != | 711 const bool valid_identity = (identity_info.identity_status != |
| 697 PageInfo::SITE_IDENTITY_STATUS_ERROR); | 712 PageInfo::SITE_IDENTITY_STATUS_ERROR); |
| 698 const base::string16 link_title = l10n_util::GetStringUTF16( | 713 const base::string16 link_title = l10n_util::GetStringUTF16( |
| 699 valid_identity ? IDS_PAGE_INFO_CERTIFICATE_VALID_LINK | 714 valid_identity ? IDS_PAGE_INFO_CERTIFICATE_VALID_LINK |
| 700 : IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK); | 715 : IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK); |
| 701 | 716 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 const gfx::ImageSkia icon = PageInfoUI::GetPermissionIcon(info).AsImageSkia(); | 764 const gfx::ImageSkia icon = PageInfoUI::GetPermissionIcon(info).AsImageSkia(); |
| 750 // Add the Cookies section. | 765 // Add the Cookies section. |
| 751 site_settings_view->AddChildView(CreateInspectLinkSection( | 766 site_settings_view->AddChildView(CreateInspectLinkSection( |
| 752 icon, IDS_PAGE_INFO_COOKIES, cookie_dialog_link_)); | 767 icon, IDS_PAGE_INFO_COOKIES, cookie_dialog_link_)); |
| 753 | 768 |
| 754 return site_settings_view; | 769 return site_settings_view; |
| 755 } | 770 } |
| 756 | 771 |
| 757 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { | 772 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { |
| 758 // All switch cases require accessing web_contents(), so we check it here. | 773 // All switch cases require accessing web_contents(), so we check it here. |
| 759 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) | 774 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) { |
| 760 return; | 775 return; |
| 776 } |
| 761 switch (source->id()) { | 777 switch (source->id()) { |
| 762 case VIEW_ID_PAGE_INFO_LINK_SITE_SETTINGS: | 778 case VIEW_ID_PAGE_INFO_LINK_SITE_SETTINGS: |
| 763 presenter_->OpenSiteSettingsView(); | 779 presenter_->OpenSiteSettingsView(); |
| 764 break; | 780 break; |
| 765 case VIEW_ID_PAGE_INFO_LINK_COOKIE_DIALOG: | 781 case VIEW_ID_PAGE_INFO_LINK_COOKIE_DIALOG: |
| 766 // Count how often the Collected Cookies dialog is opened. | 782 // Count how often the Collected Cookies dialog is opened. |
| 767 presenter_->RecordPageInfoAction( | 783 presenter_->RecordPageInfoAction( |
| 768 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); | 784 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); |
| 769 new CollectedCookiesViews(web_contents()); | 785 new CollectedCookiesViews(web_contents()); |
| 770 break; | 786 break; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 795 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); | 811 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); |
| 796 break; | 812 break; |
| 797 case VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS: | 813 case VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS: |
| 798 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | 814 presenter_->OnRevokeSSLErrorBypassButtonPressed(); |
| 799 GetWidget()->Close(); | 815 GetWidget()->Close(); |
| 800 break; | 816 break; |
| 801 default: | 817 default: |
| 802 NOTREACHED(); | 818 NOTREACHED(); |
| 803 } | 819 } |
| 804 } | 820 } |
| OLD | NEW |