diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-18 00:34:06 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-18 00:34:06 +0000 |
commit | d4c755d3917ec20b811d4b868c18cb40cae6713b (patch) | |
tree | ab2fa1b64c4a0cacd379ef0950f381be12eeb810 /chrome/browser/cocoa/page_info_window_mac.mm | |
parent | cf07e5608a8712bea53666d2ee3adbf3d182899c (diff) | |
download | chromium_src-d4c755d3917ec20b811d4b868c18cb40cae6713b.zip chromium_src-d4c755d3917ec20b811d4b868c18cb40cae6713b.tar.gz chromium_src-d4c755d3917ec20b811d4b868c18cb40cae6713b.tar.bz2 |
Refactoring the page info to have a model.BUG=NoneTEST=Make sure clicking the lock/warning icon when visiting a HTTPS page brings the page info and that it reports the correct info. Also check that the "Page/Frame info" right click menu works as well.
Review URL: http://codereview.chromium.org/155336
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/page_info_window_mac.mm')
-rw-r--r-- | chrome/browser/cocoa/page_info_window_mac.mm | 217 |
1 files changed, 53 insertions, 164 deletions
diff --git a/chrome/browser/cocoa/page_info_window_mac.mm b/chrome/browser/cocoa/page_info_window_mac.mm index b76d74d..f7dfaca 100644 --- a/chrome/browser/cocoa/page_info_window_mac.mm +++ b/chrome/browser/cocoa/page_info_window_mac.mm @@ -18,18 +18,33 @@ #include "net/base/cert_status_flags.h" #include "net/base/x509_certificate.h" -using base::Time; - -PageInfoWindow* PageInfoWindow::Factory() { +void PageInfoWindowMac::ShowPageInfo(gfx::NativeView parent, + Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history) { // The controller will clean itself up after the NSWindow it manages closes. // We do not manage it as it owns us. PageInfoWindowController* controller = [[PageInfoWindowController alloc] init]; - return [controller pageInfo]; + PageInfoWindowMac* page_info = new PageInfoWindowMac(controller, + profile, + url, + ssl, + show_history); + [controller setPageInfo:page_info]; + page_info->LayoutSections(); + page_info->Show(); } -PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller) - : PageInfoWindow(), controller_(controller) { +PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, + Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history) + : controller_(controller), + model_(profile, url, ssl, show_history, this), + cert_id_(ssl.cert_id()) { } PageInfoWindowMac::~PageInfoWindowMac() { @@ -67,149 +82,51 @@ void PageInfoWindowMac::ShowCertDialog(int) { ]; } -void PageInfoWindowMac::Init(Profile* profile, - const GURL& url, - const NavigationEntry::SSLStatus& ssl, - NavigationEntry::PageType page_type, - bool show_history, - gfx::NativeView parent) { +void PageInfoWindowMac::LayoutSections() { // These wstring's will be converted to NSString's and passed to the // window controller when we're done figuring out what text should go in them. std::wstring identity_msg; std::wstring connection_msg; - // Set all the images to "good" mode. - [controller_ setIdentityImg:[controller_ goodImg]]; - [controller_ setConnectionImg:[controller_ goodImg]]; - - cert_id_ = ssl.cert_id(); - scoped_refptr<net::X509Certificate> cert; - // Identity section - std::wstring identity_title; - std::wstring subject_name(UTF8ToWide(url.host())); - bool empty_subject_name = subject_name.empty(); - if (empty_subject_name) { - subject_name.assign( - l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); - } - if (page_type == NavigationEntry::NORMAL_PAGE && cert_id_ && - CertStore::GetSharedInstance()->RetrieveCert(cert_id_, &cert) && - !net::IsCertStatusError(ssl.cert_status())) { - // OK HTTPS page - if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) { - DCHECK(!cert->subject().organization_names.empty()); - identity_title = - l10n_util::GetStringF(IDS_PAGE_INFO_EV_IDENTITY_TITLE, - UTF8ToWide(cert->subject().organization_names[0]), - UTF8ToWide(url.host())); - // An EV cert is required to have a city (localityName) and country but - // state is "if any". - DCHECK(!cert->subject().locality_name.empty()); - DCHECK(!cert->subject().country_name.empty()); - std::wstring locality; - if (!cert->subject().state_or_province_name.empty()) { - locality = l10n_util::GetStringF( - IDS_PAGEINFO_ADDRESS, - UTF8ToWide(cert->subject().locality_name), - UTF8ToWide(cert->subject().state_or_province_name), - UTF8ToWide(cert->subject().country_name)); - } else { - locality = l10n_util::GetStringF( - IDS_PAGEINFO_PARTIAL_ADDRESS, - UTF8ToWide(cert->subject().locality_name), - UTF8ToWide(cert->subject().country_name)); - } - DCHECK(!cert->subject().organization_names.empty()); - identity_msg.assign(l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, - UTF8ToWide(cert->subject().organization_names[0]), - locality, - UTF8ToWide(PageInfoWindow::GetIssuerName(cert->issuer())))); - } else { - // Non EV OK HTTPS. - if (empty_subject_name) - identity_title.clear(); // Don't display any title. - else - identity_title.assign(subject_name); - std::wstring issuer_name(UTF8ToWide( - PageInfoWindow::GetIssuerName(cert->issuer()))); - if (issuer_name.empty()) { - issuer_name.assign( - l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); - } else { - identity_msg.assign( - l10n_util::GetStringF(IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, - issuer_name)); - } - } - } else { - // Bad HTTPS. - identity_msg.assign( - l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); + PageInfoModel::SectionInfo identity_section = + model_.GetSectionInfo(PageInfoModel::IDENTITY); + if (identity_section.state) + [controller_ setIdentityImg:[controller_ goodImg]]; + else [controller_ setIdentityImg:[controller_ badImg]]; - } + [controller_ setIdentityMsg:base::SysWideToNSString( + identity_section.description)]; // Connection section. - // We consider anything less than 80 bits encryption to be weak encryption. - // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and - // weakly encrypted connections. - if (ssl.security_bits() <= 0) { - [controller_ setConnectionImg:[controller_ badImg]]; - connection_msg.assign( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, - subject_name)); - } else if (ssl.security_bits() < 80) { + PageInfoModel::SectionInfo connection_section = + model_.GetSectionInfo(PageInfoModel::CONNECTION); + if (connection_section.state) + [controller_ setConnectionImg:[controller_ goodImg]]; + else [controller_ setConnectionImg:[controller_ badImg]]; - connection_msg.assign( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT, - subject_name)); - } else { - connection_msg.assign( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, - subject_name, - IntToWString(ssl.security_bits()))); - if (ssl.has_mixed_content()) { - [controller_ setConnectionImg:[controller_ badImg]]; - connection_msg.assign( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, - connection_msg, - l10n_util::GetString( - IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_MIXED_CONTENT_WARNING))); - } else if (ssl.has_unsafe_content()) { - [controller_ setConnectionImg:[controller_ badImg]]; - connection_msg.assign( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, - connection_msg, - l10n_util::GetString( - IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_BAD_HTTPS_WARNING))); - } - } + [controller_ setConnectionMsg: + base::SysWideToNSString(connection_section.description)]; + + if (model_.GetSectionCount() > 2) { + // We have the history info. + PageInfoModel::SectionInfo history_section = + model_.GetSectionInfo(PageInfoModel::HISTORY); + if (history_section.state) + [controller_ setHistoryImg:[controller_ goodImg]]; + else + [controller_ setHistoryImg:[controller_ badImg]]; - // We've figured out the messages that we want to appear in the page info - // window and we now hand them up to the NSWindowController, which binds them - // to the Cocoa view. - [controller_ setIdentityMsg:base::SysWideToNSString(identity_msg)]; - [controller_ setConnectionMsg:base::SysWideToNSString(connection_msg)]; - - // Request the number of visits. - HistoryService* history = profile->GetHistoryService( - Profile::EXPLICIT_ACCESS); - if (show_history && history) { - history->GetVisitCountToHost( - url, - &request_consumer_, - NewCallback(this, &PageInfoWindowMac::OnGotVisitCountToHost)); + [controller_ setHistoryMsg: + base::SysWideToNSString(history_section.description)]; } // By default, assume that we don't have certificate information to show. [controller_ setEnableCertButton:NO]; if (cert_id_) { + scoped_refptr<net::X509Certificate> cert; + CertStore::GetSharedInstance()->RetrieveCert(cert_id_, &cert); + // Don't bother showing certificates if there isn't one. Gears runs with no // os root certificate. if (cert.get() && cert->os_cert_handle()) { @@ -218,37 +135,9 @@ void PageInfoWindowMac::Init(Profile* profile, } } -void PageInfoWindowMac::OnGotVisitCountToHost(HistoryService::Handle handle, - bool found_visits, - int count, - Time first_visit) { - if (!found_visits) { - // This indicates an error, such as the page wasn't http/https; do nothing. - return; - } - +void PageInfoWindowMac::ModelChanged() { // We have history information, so show the box and extend the window frame. [controller_ setShowHistoryBox:YES]; - - bool visited_before_today = false; - if (count) { - Time today = Time::Now().LocalMidnight(); - Time first_visit_midnight = first_visit.LocalMidnight(); - visited_before_today = (first_visit_midnight < today); - } - - if (!visited_before_today) { - [controller_ setHistoryImg:[controller_ badImg]]; - [controller_ setHistoryMsg: - base::SysWideToNSString( - l10n_util::GetString( - IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY))]; - } else { - [controller_ setHistoryImg:[controller_ goodImg]]; - [controller_ setHistoryMsg: - base::SysWideToNSString( - l10n_util::GetStringF( - IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY, - base::TimeFormatShortDate(first_visit)))]; - } + LayoutSections(); } + |