| 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/cocoa/page_info_window_mac.h" | 5 #include "chrome/browser/cocoa/page_info_window_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/scoped_cftyperef.h" | 10 #include "base/scoped_cftyperef.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #import "chrome/browser/cocoa/page_info_window_controller.h" | 14 #import "chrome/browser/cocoa/page_info_window_controller.h" |
| 15 #include "chrome/browser/cert_store.h" | 15 #include "chrome/browser/cert_store.h" |
| 16 #include "chrome/browser/certificate_viewer.h" | 16 #include "chrome/browser/certificate_viewer.h" |
| 17 #include "chrome/browser/page_info_window.h" |
| 17 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "net/base/cert_status_flags.h" | 21 #include "net/base/cert_status_flags.h" |
| 21 #include "net/base/x509_certificate.h" | 22 #include "net/base/x509_certificate.h" |
| 22 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 23 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Spacing in between section boxes. | 27 // Spacing in between section boxes. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 const NSInteger kBoxBottomSpacing = 7; | 40 const NSInteger kBoxBottomSpacing = 7; |
| 40 | 41 |
| 41 // Spacing between the image and the text. | 42 // Spacing between the image and the text. |
| 42 const NSInteger kImageSpacing = 10; | 43 const NSInteger kImageSpacing = 10; |
| 43 | 44 |
| 44 // Square size of the image. | 45 // Square size of the image. |
| 45 const CGFloat kImageSize = 30; | 46 const CGFloat kImageSize = 30; |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 void PageInfoWindowMac::ShowPageInfo(Profile* profile, | 50 namespace browser { |
| 50 const GURL& url, | 51 |
| 51 const NavigationEntry::SSLStatus& ssl, | 52 void ShowPageInfo(gfx::NativeWindow parent, |
| 52 bool show_history) { | 53 Profile* profile, |
| 53 // The controller will clean itself up after the NSWindow it manages closes. | 54 const GURL& url, |
| 54 // We do not manage it as it owns us. | 55 const NavigationEntry::SSLStatus& ssl, |
| 55 PageInfoWindowController* controller = | 56 bool show_history) { |
| 56 [[PageInfoWindowController alloc] init]; | 57 PageInfoWindowMac::ShowPageInfo(parent, profile, url, ssl, show_history); |
| 57 PageInfoWindowMac* page_info = new PageInfoWindowMac(controller, | |
| 58 profile, | |
| 59 url, | |
| 60 ssl, | |
| 61 show_history); | |
| 62 [controller setPageInfo:page_info]; | |
| 63 page_info->LayoutSections(); | |
| 64 page_info->Show(); | |
| 65 } | 58 } |
| 66 | 59 |
| 60 void ShowPageInfoBubble(gfx::NativeWindow parent, |
| 61 Profile* profile, |
| 62 const GURL& url, |
| 63 const NavigationEntry::SSLStatus& ssl, |
| 64 bool show_history) { |
| 65 NOTIMPLEMENTED(); |
| 66 } |
| 67 |
| 68 } // namespace browser |
| 69 |
| 67 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, | 70 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, |
| 68 Profile* profile, | 71 Profile* profile, |
| 69 const GURL& url, | 72 const GURL& url, |
| 70 const NavigationEntry::SSLStatus& ssl, | 73 const NavigationEntry::SSLStatus& ssl, |
| 71 bool show_history) | 74 bool show_history) |
| 72 : controller_(controller), | 75 : controller_(controller), |
| 73 model_(new PageInfoModel(profile, url, ssl, show_history, this)), | 76 model_(new PageInfoModel(profile, url, ssl, show_history, this)), |
| 74 cert_id_(ssl.cert_id()) { | 77 cert_id_(ssl.cert_id()) { |
| 75 Init(); | 78 Init(); |
| 76 } | 79 } |
| 77 | 80 |
| 78 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, | 81 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, |
| 79 PageInfoModel* model) | 82 PageInfoModel* model) |
| 80 : controller_(controller), | 83 : controller_(controller), |
| 81 model_(model), | 84 model_(model), |
| 82 cert_id_(0) { | 85 cert_id_(0) { |
| 83 Init(); | 86 Init(); |
| 84 } | 87 } |
| 85 | 88 |
| 89 // static |
| 90 void PageInfoWindowMac::ShowPageInfo(gfx::NativeWindow parent, |
| 91 Profile* profile, |
| 92 const GURL& url, |
| 93 const NavigationEntry::SSLStatus& ssl, |
| 94 bool show_history) { |
| 95 // The controller will clean itself up after the NSWindow it manages closes. |
| 96 // We do not manage it as it owns us. |
| 97 PageInfoWindowController* controller = |
| 98 [[PageInfoWindowController alloc] init]; |
| 99 PageInfoWindowMac* page_info = new PageInfoWindowMac(controller, |
| 100 profile, |
| 101 url, |
| 102 ssl, |
| 103 show_history); |
| 104 [controller setPageInfo:page_info]; |
| 105 page_info->LayoutSections(); |
| 106 page_info->Show(); |
| 107 } |
| 108 |
| 86 void PageInfoWindowMac::Init() { | 109 void PageInfoWindowMac::Init() { |
| 87 // Load the image refs. | 110 // Load the image refs. |
| 88 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 111 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 89 good_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_GOOD) retain]); | 112 good_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_GOOD) retain]); |
| 90 DCHECK_GE(kImageSize, [good_image_ size].width); | 113 DCHECK_GE(kImageSize, [good_image_ size].width); |
| 91 DCHECK_GE(kImageSize, [good_image_ size].height); | 114 DCHECK_GE(kImageSize, [good_image_ size].height); |
| 92 bad_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_BAD) retain]); | 115 bad_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_BAD) retain]); |
| 93 DCHECK_GE(kImageSize, [bad_image_ size].width); | 116 DCHECK_GE(kImageSize, [bad_image_ size].width); |
| 94 DCHECK_GE(kImageSize, [bad_image_ size].height); | 117 DCHECK_GE(kImageSize, [bad_image_ size].height); |
| 95 } | 118 } |
| 96 | 119 |
| 97 PageInfoWindowMac::~PageInfoWindowMac() { | 120 PageInfoWindowMac::~PageInfoWindowMac() { |
| 98 } | 121 } |
| 99 | 122 |
| 100 void PageInfoWindowMac::Show() { | |
| 101 [[controller_ window] makeKeyAndOrderFront:nil]; | |
| 102 } | |
| 103 | |
| 104 void PageInfoWindowMac::ShowCertDialog(int) { | 123 void PageInfoWindowMac::ShowCertDialog(int) { |
| 105 DCHECK(cert_id_ != 0); | 124 DCHECK(cert_id_ != 0); |
| 106 ShowCertificateViewerByID([controller_ window], cert_id_); | 125 ShowCertificateViewerByID([controller_ window], cert_id_); |
| 107 } | 126 } |
| 108 | 127 |
| 128 void PageInfoWindowMac::ModelChanged() { |
| 129 LayoutSections(); |
| 130 } |
| 131 |
| 132 void PageInfoWindowMac::Show() { |
| 133 [[controller_ window] makeKeyAndOrderFront:nil]; |
| 134 } |
| 135 |
| 109 // This will create the subviews for the page info window. The general layout | 136 // This will create the subviews for the page info window. The general layout |
| 110 // is 2 or 3 boxed and titled sections, each of which has a status image to | 137 // is 2 or 3 boxed and titled sections, each of which has a status image to |
| 111 // provide visual feedback and a description that explains it. The description | 138 // provide visual feedback and a description that explains it. The description |
| 112 // text is usually only 1 or 2 lines, but can be much longer. At the bottom of | 139 // text is usually only 1 or 2 lines, but can be much longer. At the bottom of |
| 113 // the window is a button to view the SSL certificate, which is disabled if | 140 // the window is a button to view the SSL certificate, which is disabled if |
| 114 // not using HTTPS. | 141 // not using HTTPS. |
| 115 void PageInfoWindowMac::LayoutSections() { | 142 void PageInfoWindowMac::LayoutSections() { |
| 116 NSRect window_frame = [[controller_ window] frame]; | 143 NSRect window_frame = [[controller_ window] frame]; |
| 117 CGFloat window_width = NSWidth(window_frame); | 144 CGFloat window_width = NSWidth(window_frame); |
| 118 // |offset| is the Y position that should be drawn at next. | 145 // |offset| is the Y position that should be drawn at next. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 [cert_button setEnabled:YES]; | 250 [cert_button setEnabled:YES]; |
| 224 } | 251 } |
| 225 } | 252 } |
| 226 | 253 |
| 227 // Resize the window. Only animate if the window is visible, otherwise it | 254 // Resize the window. Only animate if the window is visible, otherwise it |
| 228 // could be "growing" while it's opening, looking awkward. | 255 // could be "growing" while it's opening, looking awkward. |
| 229 [[controller_ window] setFrame:window_frame | 256 [[controller_ window] setFrame:window_frame |
| 230 display:YES | 257 display:YES |
| 231 animate:[[controller_ window] isVisible]]; | 258 animate:[[controller_ window] isVisible]]; |
| 232 } | 259 } |
| 233 | |
| 234 void PageInfoWindowMac::ModelChanged() { | |
| 235 LayoutSections(); | |
| 236 } | |
| OLD | NEW |