summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 00:34:06 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 00:34:06 +0000
commitd4c755d3917ec20b811d4b868c18cb40cae6713b (patch)
treeab2fa1b64c4a0cacd379ef0950f381be12eeb810 /chrome/browser/cocoa
parentcf07e5608a8712bea53666d2ee3adbf3d182899c (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.h5
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm9
-rw-r--r--chrome/browser/cocoa/page_info_window_controller.h5
-rw-r--r--chrome/browser/cocoa/page_info_window_controller.mm6
-rw-r--r--chrome/browser/cocoa/page_info_window_mac.h47
-rw-r--r--chrome/browser/cocoa/page_info_window_mac.mm217
6 files changed, 96 insertions, 193 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h
index 4d5da19..74eab33 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/cocoa/browser_window_cocoa.h
@@ -77,6 +77,11 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual void UserChangedTheme();
virtual int GetExtraRenderViewHeight() const;
virtual void TabContentsFocused(TabContents* tab_contents);
+ virtual void ShowPageInfo(gfx::NativeView parent,
+ Profile* profile,
+ const GURL& url,
+ const NavigationEntry::SSLStatus& ssl,
+ bool show_history);
// Overridden from NotificationObserver
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index 2493a93..7e72184 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -10,6 +10,7 @@
#import "chrome/browser/cocoa/browser_window_controller.h"
#import "chrome/browser/cocoa/clear_browsing_data_controller.h"
#import "chrome/browser/cocoa/download_shelf_controller.h"
+#include "chrome/browser/cocoa/page_info_window_mac.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/common/notification_service.h"
@@ -268,6 +269,14 @@ void BrowserWindowCocoa::TabContentsFocused(TabContents* tab_contents) {
NOTIMPLEMENTED();
}
+void BrowserWindowCocoa::ShowPageInfo(gfx::NativeView parent,
+ Profile* profile,
+ const GURL& url,
+ const NavigationEntry::SSLStatus& ssl,
+ bool show_history) {
+ PageInfoWindowMac::ShowPageInfo(parent, profile, url, ssl, show_history);
+}
+
void BrowserWindowCocoa::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/cocoa/page_info_window_controller.h b/chrome/browser/cocoa/page_info_window_controller.h
index 7c8fce5..132c684 100644
--- a/chrome/browser/cocoa/page_info_window_controller.h
+++ b/chrome/browser/cocoa/page_info_window_controller.h
@@ -7,7 +7,6 @@
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
-class PageInfoWindow;
class PageInfoWindowMac;
// This NSWindowController subclass implements the Cocoa window for
@@ -44,8 +43,8 @@ class PageInfoWindowMac;
@property(readwrite, copy) NSString* historyMsg;
@property(readwrite) BOOL enableCertButton;
-// Returns the bridge between Cocoa and Chromium.
-- (PageInfoWindow*)pageInfo;
+// Sets the bridge between Cocoa and Chromium.
+- (void)setPageInfo:(PageInfoWindowMac*)pageInfo;
// Returns the good and bad image refs.
- (NSImage*)goodImg;
diff --git a/chrome/browser/cocoa/page_info_window_controller.mm b/chrome/browser/cocoa/page_info_window_controller.mm
index 0e895e1..a14d8b9 100644
--- a/chrome/browser/cocoa/page_info_window_controller.mm
+++ b/chrome/browser/cocoa/page_info_window_controller.mm
@@ -20,8 +20,6 @@
NSBundle* bundle = mac_util::MainAppBundle();
NSString* nibpath = [bundle pathForResource:@"PageInfo" ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
- pageInfo_.reset(new PageInfoWindowMac(self));
-
// Load the image refs.
NSImage* img = [[NSImage alloc] initByReferencingFile:
[bundle pathForResource:@"pageinfo_good" ofType:@"png"]];
@@ -49,8 +47,8 @@
[super dealloc];
}
-- (PageInfoWindow*)pageInfo {
- return pageInfo_.get();
+- (void)setPageInfo:(PageInfoWindowMac*)pageInfo {
+ pageInfo_.reset(pageInfo);
}
- (NSImage*)goodImg {
diff --git a/chrome/browser/cocoa/page_info_window_mac.h b/chrome/browser/cocoa/page_info_window_mac.h
index 1665b79..0d1d660 100644
--- a/chrome/browser/cocoa/page_info_window_mac.h
+++ b/chrome/browser/cocoa/page_info_window_mac.h
@@ -5,46 +5,49 @@
#ifndef CHROME_BROWSER_COCOA_PAGE_INFO_WINDOW_MAC_H_
#define CHROME_BROWSER_COCOA_PAGE_INFO_WINDOW_MAC_H_
-#include "chrome/browser/history/history.h"
+#include "chrome/browser/page_info_model.h"
#include "chrome/browser/page_info_window.h"
-class CancelableRequestConsumerBase;
class Profile;
@class PageInfoWindowController;
-namespace base {
-class Time;
-}
-
-class PageInfoWindowMac : public PageInfoWindow {
+class PageInfoWindowMac : public PageInfoModel::PageInfoModelObserver {
public:
- PageInfoWindowMac(PageInfoWindowController* controller);
virtual ~PageInfoWindowMac();
- // This is the main initializer that creates the window.
- virtual void Init(Profile* profile,
- const GURL& url,
- const NavigationEntry::SSLStatus& ssl,
- NavigationEntry::PageType page_type,
- bool show_history,
- gfx::NativeView parent);
-
- virtual void Show();
+ // Creates and shows the page info.
+ static void ShowPageInfo(gfx::NativeView parent,
+ Profile* profile,
+ const GURL& url,
+ const NavigationEntry::SSLStatus& ssl,
+ bool show_history);
// Shows various information for the specified certificate in a new dialog.
// The argument is ignored here and we use the |cert_id_| member that was
// passed to us in Init().
virtual void ShowCertDialog(int);
+ // PageInfoModelObserver implementation.
+ virtual void ModelChanged();
+
private:
- void OnGotVisitCountToHost(HistoryService::Handle handle,
- bool found_visits,
- int count,
- base::Time first_visit);
+ PageInfoWindowMac(PageInfoWindowController* controller,
+ Profile* profile,
+ const GURL& url,
+ const NavigationEntry::SSLStatus& ssl,
+ bool show_history);
+
+ void LayoutSections();
+
+ void Show();
- CancelableRequestConsumer request_consumer_; // Used for getting visit count.
PageInfoWindowController* controller_; // WEAK, owns us.
+ PageInfoModel model_;
+
+ // The certificate ID for the page, 0 if the page is not over HTTPS.
+ int cert_id_;
+
DISALLOW_COPY_AND_ASSIGN(PageInfoWindowMac);
};
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();
}
+