| 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_bubble_view.h" | 5 #include "chrome/browser/ui/views/page_info_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/certificate_viewer.h" | 10 #include "chrome/browser/certificate_viewer.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "chrome/browser/ui/views/toolbar_view.h" | 14 #include "chrome/browser/ui/views/toolbar_view.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/cert_store.h" | 16 #include "content/public/browser/cert_store.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/ssl_status.h" | 18 #include "content/public/common/ssl_status.h" |
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 18 #include "grit/locale_settings.h" | 20 #include "grit/locale_settings.h" |
| 19 #include "net/base/x509_certificate.h" | 21 #include "net/base/x509_certificate.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 23 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 24 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
| 25 #include "ui/views/controls/link.h" | 27 #include "ui/views/controls/link.h" |
| 26 #include "ui/views/controls/separator.h" | 28 #include "ui/views/controls/separator.h" |
| 27 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
| 28 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 29 | 31 |
| 30 using content::OpenURLParams; | 32 using content::OpenURLParams; |
| 31 using content::Referrer; | 33 using content::Referrer; |
| 32 using content::SSLStatus; | 34 using content::SSLStatus; |
| 35 using content::WebContents; |
| 33 | 36 |
| 34 namespace { | 37 namespace { |
| 35 | 38 |
| 36 // Layout constants. | 39 // Layout constants. |
| 37 const int kHGapToBorder = 11; | 40 const int kHGapToBorder = 11; |
| 38 const int kVerticalSectionPadding = 8; | 41 const int kVerticalSectionPadding = 8; |
| 39 const int kVGapToHeadline = 5; | 42 const int kVGapToHeadline = 5; |
| 40 const int kHGapImageToDescription = 6; | 43 const int kHGapImageToDescription = 6; |
| 41 const int kTextPaddingRight = 10; | 44 const int kTextPaddingRight = 10; |
| 42 const int kPaddingBelowSeparator = 6; | 45 const int kPaddingBelowSeparator = 6; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 98 |
| 96 DISALLOW_COPY_AND_ASSIGN(Section); | 99 DISALLOW_COPY_AND_ASSIGN(Section); |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 } // namespace | 102 } // namespace |
| 100 | 103 |
| 101 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
| 102 // PageInfoBubbleView | 105 // PageInfoBubbleView |
| 103 | 106 |
| 104 PageInfoBubbleView::PageInfoBubbleView(views::View* anchor_view, | 107 PageInfoBubbleView::PageInfoBubbleView(views::View* anchor_view, |
| 105 Profile* profile, | 108 WebContents* web_contents, |
| 106 const GURL& url, | 109 const GURL& url, |
| 107 const SSLStatus& ssl, | 110 const SSLStatus& ssl, |
| 108 bool show_history, | 111 bool show_history, |
| 109 content::PageNavigator* navigator) | 112 content::PageNavigator* navigator) |
| 110 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 113 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
| 111 ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl, | 114 ALLOW_THIS_IN_INITIALIZER_LIST(model_( |
| 112 show_history, this)), | 115 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url, |
| 116 ssl, show_history, this)), |
| 113 cert_id_(ssl.cert_id), | 117 cert_id_(ssl.cert_id), |
| 114 help_center_link_(NULL), | 118 help_center_link_(NULL), |
| 115 ALLOW_THIS_IN_INITIALIZER_LIST(resize_animation_(this)), | 119 ALLOW_THIS_IN_INITIALIZER_LIST(resize_animation_(this)), |
| 116 animation_start_height_(0), | 120 animation_start_height_(0), |
| 117 navigator_(navigator) { | 121 navigator_(navigator), |
| 118 | 122 web_contents_(web_contents) { |
| 119 if (cert_id_ > 0) { | 123 if (cert_id_ > 0) { |
| 120 scoped_refptr<net::X509Certificate> cert; | 124 scoped_refptr<net::X509Certificate> cert; |
| 121 content::CertStore::GetInstance()->RetrieveCert(cert_id_, &cert); | 125 content::CertStore::GetInstance()->RetrieveCert(cert_id_, &cert); |
| 122 // When running with fake certificate (Chrome Frame), we have no os | 126 // When running with fake certificate (Chrome Frame), we have no os |
| 123 // certificate, so there is no cert to show. Don't bother showing the cert | 127 // certificate, so there is no cert to show. Don't bother showing the cert |
| 124 // info link in that case. | 128 // info link in that case. |
| 125 if (!cert.get() || !cert->os_cert_handle()) | 129 if (!cert.get() || !cert->os_cert_handle()) |
| 126 cert_id_ = 0; | 130 cert_id_ = 0; |
| 127 } | 131 } |
| 128 LayoutSections(); | 132 LayoutSections(); |
| 129 } | 133 } |
| 130 | 134 |
| 131 PageInfoBubbleView::~PageInfoBubbleView() { | 135 PageInfoBubbleView::~PageInfoBubbleView() { |
| 132 resize_animation_.Reset(); | 136 resize_animation_.Reset(); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void PageInfoBubbleView::ShowCertDialog() { | 139 void PageInfoBubbleView::ShowCertDialog() { |
| 136 gfx::NativeWindow parent = | 140 gfx::NativeWindow parent = |
| 137 anchor_view() ? anchor_view()->GetWidget()->GetNativeWindow() : NULL; | 141 anchor_view() ? anchor_view()->GetWidget()->GetNativeWindow() : NULL; |
| 138 ShowCertificateViewerByID(parent, cert_id_); | 142 ShowCertificateViewerByID(web_contents_, parent, cert_id_); |
| 139 } | 143 } |
| 140 | 144 |
| 141 gfx::Size PageInfoBubbleView::GetSeparatorSize() { | 145 gfx::Size PageInfoBubbleView::GetSeparatorSize() { |
| 142 // Calculate how much space the separators take up (with padding). | 146 // Calculate how much space the separators take up (with padding). |
| 143 views::Separator separator; | 147 views::Separator separator; |
| 144 gfx::Size separator_size = separator.GetPreferredSize(); | 148 gfx::Size separator_size = separator.GetPreferredSize(); |
| 145 gfx::Size separator_plus_padding(0, separator_size.height() + | 149 gfx::Size separator_plus_padding(0, separator_size.height() + |
| 146 kPaddingAboveSeparator + | 150 kPaddingAboveSeparator + |
| 147 kPaddingBelowSeparator); | 151 kPaddingBelowSeparator); |
| 148 return separator_plus_padding; | 152 return separator_plus_padding; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 450 } |
| 447 | 451 |
| 448 // Make sure the image is not truncated if the text doesn't contain much. | 452 // Make sure the image is not truncated if the text doesn't contain much. |
| 449 y = std::max(y, (2 * kVerticalSectionPadding) + image_height); | 453 y = std::max(y, (2 * kVerticalSectionPadding) + image_height); |
| 450 return gfx::Size(width, y); | 454 return gfx::Size(width, y); |
| 451 } | 455 } |
| 452 | 456 |
| 453 namespace browser { | 457 namespace browser { |
| 454 | 458 |
| 455 void ShowPageInfoBubble(views::View* anchor_view, | 459 void ShowPageInfoBubble(views::View* anchor_view, |
| 456 Profile* profile, | 460 WebContents* web_contents, |
| 457 const GURL& url, | 461 const GURL& url, |
| 458 const SSLStatus& ssl, | 462 const SSLStatus& ssl, |
| 459 bool show_history, | 463 bool show_history, |
| 460 content::PageNavigator* navigator) { | 464 content::PageNavigator* navigator) { |
| 461 PageInfoBubbleView* page_info_bubble = | 465 PageInfoBubbleView* page_info_bubble = |
| 462 new PageInfoBubbleView(anchor_view, | 466 new PageInfoBubbleView(anchor_view, |
| 463 profile, | 467 web_contents, |
| 464 url, | 468 url, |
| 465 ssl, | 469 ssl, |
| 466 show_history, | 470 show_history, |
| 467 navigator); | 471 navigator); |
| 468 views::BubbleDelegateView::CreateBubble(page_info_bubble); | 472 views::BubbleDelegateView::CreateBubble(page_info_bubble); |
| 469 page_info_bubble->Show(); | 473 page_info_bubble->Show(); |
| 470 } | 474 } |
| 471 | 475 |
| 472 } | 476 } |
| OLD | NEW |