diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-17 19:21:56 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-17 19:21:56 +0000 |
commit | 3c46b15df4004309cce51688337b43d5af2722c4 (patch) | |
tree | 6b5f81d68fa9e2af81a3e78275ee0eeadeb70d50 /chrome/browser | |
parent | b55530cc5f175911fac5803367fcb1194a935da8 (diff) | |
download | chromium_src-3c46b15df4004309cce51688337b43d5af2722c4.zip chromium_src-3c46b15df4004309cce51688337b43d5af2722c4.tar.gz chromium_src-3c46b15df4004309cce51688337b43d5af2722c4.tar.bz2 |
Implements the Page Info window on Mac.
- Splits out the code that was in chrome/browser/views/page_info_window.{cc,h}
into a platform-independent class PageInfoWindow in
chrome/browser/page_info_window.{cc,h}
- The Windows implementation now lives in
chrome/browser/views/page_info_window_win.{cc,h}
- Created a Mac implemenation PageInfoWindowMac in
chrome/browser/cocoa/page_info_window_mac.{h,mm} to bridge to a Cocoa
NSWindowController
- Created a new NSWindowController subclass PageInfoWindowController that is in
chrome/browser/cocoa/page_info_window_controller.{h,mm}
- Created a XIB for the page info window in
chrome/app/nibs/en.lproj/PageInfo.xib
Patch by Robert Sesek <rsesek@bluestatic.org>
Review URL: http://codereview.chromium.org/115116
Review URL: http://codereview.chromium.org/125266
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rwxr-xr-x | chrome/browser/browser_prefs.cc | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/page_info_window_controller.h | 61 | ||||
-rw-r--r-- | chrome/browser/cocoa/page_info_window_controller.mm | 88 | ||||
-rw-r--r-- | chrome/browser/cocoa/page_info_window_mac.h | 51 | ||||
-rw-r--r-- | chrome/browser/cocoa/page_info_window_mac.mm | 254 | ||||
-rw-r--r-- | chrome/browser/page_info_window.cc | 63 | ||||
-rw-r--r-- | chrome/browser/page_info_window.h | 80 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/page_info_window_win.cc (renamed from chrome/browser/views/page_info_window.cc) | 105 | ||||
-rw-r--r-- | chrome/browser/views/page_info_window_win.h (renamed from chrome/browser/views/page_info_window.h) | 60 |
11 files changed, 652 insertions, 126 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 24ff76f..f8c5f7f 100755 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -15,6 +15,7 @@ #include "chrome/browser/google_url_tracker.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" +#include "chrome/browser/page_info_window.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" #include "chrome/browser/renderer_host/web_cache_manager.h" @@ -28,7 +29,6 @@ #include "chrome/browser/task_manager.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/keyword_editor_view.h" -#include "chrome/browser/views/page_info_window.h" #endif namespace browser { @@ -45,9 +45,9 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { browser_shutdown::RegisterPrefs(local_state); chrome_browser_net::RegisterPrefs(local_state); bookmark_utils::RegisterPrefs(local_state); + PageInfoWindow::RegisterPrefs(local_state); #if defined(OS_WIN) // TODO(port): whittle this down as we port BrowserView::RegisterBrowserViewPrefs(local_state); - PageInfoWindow::RegisterPrefs(local_state); TaskManager::RegisterPrefs(local_state); #endif diff --git a/chrome/browser/cocoa/page_info_window_controller.h b/chrome/browser/cocoa/page_info_window_controller.h new file mode 100644 index 0000000..7c8fce5 --- /dev/null +++ b/chrome/browser/cocoa/page_info_window_controller.h @@ -0,0 +1,61 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsobject.h" +#include "base/scoped_ptr.h" + +class PageInfoWindow; +class PageInfoWindowMac; + +// This NSWindowController subclass implements the Cocoa window for +// PageInfoWindow. This creates and owns the PageInfoWindowMac subclass. + +@interface PageInfoWindowController : NSWindowController { + @private + // We load both images and then we share the refs with our UI elements. + scoped_nsobject<NSImage> goodImg_; + scoped_nsobject<NSImage> badImg_; + + // User interface item values. The NIB uses KVO to get these, so the values + // are not explicitly set in the view by the controller. + NSImage* identityImg_; + NSImage* connectionImg_; + NSImage* historyImg_; + NSString* identityMsg_; + NSString* connectionMsg_; + NSString* historyMsg_; + BOOL enableCertButton_; + + // Box that allows us to show/hide the history information. + IBOutlet NSBox* historyBox_; + + // Bridge to Chromium that we own. + scoped_ptr<PageInfoWindowMac> pageInfo_; +} + +@property(readwrite, retain) NSImage* identityImg; +@property(readwrite, retain) NSImage* connectionImg; +@property(readwrite, retain) NSImage* historyImg; +@property(readwrite, copy) NSString* identityMsg; +@property(readwrite, copy) NSString* connectionMsg; +@property(readwrite, copy) NSString* historyMsg; +@property(readwrite) BOOL enableCertButton; + +// Returns the bridge between Cocoa and Chromium. +- (PageInfoWindow*)pageInfo; + +// Returns the good and bad image refs. +- (NSImage*)goodImg; +- (NSImage*)badImg; + +// Shows the certificate display window +- (IBAction)showCertWindow:(id)sender; + +// Sets whether or not to show or hide the history box. This will resize the +// frame of the window. +- (void)setShowHistoryBox:(BOOL)show; + +@end diff --git a/chrome/browser/cocoa/page_info_window_controller.mm b/chrome/browser/cocoa/page_info_window_controller.mm new file mode 100644 index 0000000..0e895e1 --- /dev/null +++ b/chrome/browser/cocoa/page_info_window_controller.mm @@ -0,0 +1,88 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/page_info_window_controller.h" + +#include "base/mac_util.h" +#include "chrome/browser/cocoa/page_info_window_mac.h" + +@implementation PageInfoWindowController +@synthesize identityImg = identityImg_; +@synthesize connectionImg = connectionImg_; +@synthesize historyImg = historyImg_; +@synthesize identityMsg = identityMsg_; +@synthesize connectionMsg = connectionMsg_; +@synthesize historyMsg = historyMsg_; +@synthesize enableCertButton = enableCertButton_; + +- (id)init { + 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"]]; + goodImg_.reset(img); + + img = [[NSImage alloc] initByReferencingFile: + [bundle pathForResource:@"pageinfo_bad" ofType:@"png"]]; + badImg_.reset(img); + } + return self; +} + +- (void)awakeFromNib { + // By default, assume we have no history information. + [self setShowHistoryBox:NO]; +} + +- (void)dealloc { + [identityImg_ release]; + [connectionImg_ release]; + [historyImg_ release]; + [identityMsg_ release]; + [connectionMsg_ release]; + [historyMsg_ release]; + [super dealloc]; +} + +- (PageInfoWindow*)pageInfo { + return pageInfo_.get(); +} + +- (NSImage*)goodImg { + return goodImg_.get(); +} + +- (NSImage*)badImg { + return badImg_.get(); +} + +- (IBAction)showCertWindow:(id)sender { + pageInfo_->ShowCertDialog(0); // Pass it any int because it's ignored. +} + +- (void)setShowHistoryBox:(BOOL)show { + [historyBox_ setHidden:!show]; + + NSWindow* window = [self window]; + NSRect frame = [window frame]; + + const NSSize kPageInfoWindowSize = NSMakeSize(460, 235); + const NSSize kPageInfoWindowWithHistorySize = NSMakeSize(460, 310); + + frame.size = (show ? kPageInfoWindowWithHistorySize : kPageInfoWindowSize); + + [window setFrame:frame display:YES animate:YES]; +} + +// If the page info window gets closed, we have nothing left to manage and we +// can clean ourselves up. +- (void)windowWillClose:(NSNotification*)notif { + [self autorelease]; +} + +@end diff --git a/chrome/browser/cocoa/page_info_window_mac.h b/chrome/browser/cocoa/page_info_window_mac.h new file mode 100644 index 0000000..1665b79 --- /dev/null +++ b/chrome/browser/cocoa/page_info_window_mac.h @@ -0,0 +1,51 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#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_window.h" + +class CancelableRequestConsumerBase; +class Profile; +@class PageInfoWindowController; + +namespace base { +class Time; +} + +class PageInfoWindowMac : public PageInfoWindow { + 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(); + + // 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); + + private: + void OnGotVisitCountToHost(HistoryService::Handle handle, + bool found_visits, + int count, + base::Time first_visit); + + CancelableRequestConsumer request_consumer_; // Used for getting visit count. + PageInfoWindowController* controller_; // WEAK, owns us. + + DISALLOW_COPY_AND_ASSIGN(PageInfoWindowMac); +}; + +#endif // CHROME_BROWSER_COCOA_PAGE_INFO_WINDOW_MAC_H_ diff --git a/chrome/browser/cocoa/page_info_window_mac.mm b/chrome/browser/cocoa/page_info_window_mac.mm new file mode 100644 index 0000000..b76d74d --- /dev/null +++ b/chrome/browser/cocoa/page_info_window_mac.mm @@ -0,0 +1,254 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/page_info_window_mac.h" + +#include <Security/Security.h> +#include <SecurityInterface/SFCertificatePanel.h> + +#include "app/l10n_util.h" +#include "base/string_util.h" +#include "base/time_format.h" +#include "base/sys_string_conversions.h" +#import "chrome/browser/cocoa/page_info_window_controller.h" +#include "chrome/browser/cert_store.h" +#include "chrome/browser/profile.h" +#include "grit/generated_resources.h" +#include "net/base/cert_status_flags.h" +#include "net/base/x509_certificate.h" + +using base::Time; + +PageInfoWindow* PageInfoWindow::Factory() { + // 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::PageInfoWindowMac(PageInfoWindowController* controller) + : PageInfoWindow(), controller_(controller) { +} + +PageInfoWindowMac::~PageInfoWindowMac() { +} + +void PageInfoWindowMac::Show() { + [[controller_ window] makeKeyAndOrderFront:nil]; +} + +void PageInfoWindowMac::ShowCertDialog(int) { + DCHECK(cert_id_ != 0); + scoped_refptr<net::X509Certificate> cert; + CertStore::GetSharedInstance()->RetrieveCert(cert_id_, &cert); + if (!cert.get()) { + // The certificate was not found. Could be that the renderer crashed before + // we displayed the page info. + return; + } + + SecCertificateRef cert_mac = cert->os_cert_handle(); + if (!cert_mac) + return; + + [[SFCertificatePanel sharedCertificatePanel] + beginSheetForWindow:[controller_ window] + modalDelegate:nil + didEndSelector:NULL + contextInfo:NULL + // This is cast to id because we get compiler errors about an + // OpaqueSecCertificateRef* being converted to an ObjC class. + // It's a CF-type so it's toll-free bridged and casting to id + // is OK. + certificates:[NSArray arrayWithObject:(id)cert_mac] + showGroup:YES + ]; +} + +void PageInfoWindowMac::Init(Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + NavigationEntry::PageType page_type, + bool show_history, + gfx::NativeView parent) { + // 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)); + [controller_ setIdentityImg:[controller_ badImg]]; + } + + // 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) { + [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))); + } + } + + // 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)); + } + + // By default, assume that we don't have certificate information to show. + [controller_ setEnableCertButton:NO]; + if (cert_id_) { + // Don't bother showing certificates if there isn't one. Gears runs with no + // os root certificate. + if (cert.get() && cert->os_cert_handle()) { + [controller_ setEnableCertButton:YES]; + } + } +} + +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; + } + + // 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)))]; + } +} diff --git a/chrome/browser/page_info_window.cc b/chrome/browser/page_info_window.cc new file mode 100644 index 0000000..c18ef06 --- /dev/null +++ b/chrome/browser/page_info_window.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/page_info_window.h" + +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" + +PageInfoWindow::PageInfoWindow() : cert_id_(0) { +} + +PageInfoWindow::~PageInfoWindow() { +} + +#if defined(OS_LINUX) +// TODO(rsesek): Remove once we have a PageInfoWindowLinux implementation +PageInfoWindow* PageInfoWindow::Factory() { + NOTIMPLEMENTED(); + return NULL; +} +#endif + +// static +void PageInfoWindow::CreatePageInfo(Profile* profile, + NavigationEntry* nav_entry, + gfx::NativeView parent, + PageInfoWindow::TabID tab) { + PageInfoWindow* window = Factory(); + window->Init(profile, nav_entry->url(), nav_entry->ssl(), + nav_entry->page_type(), true, parent); + window->Show(); +} + +// static +void PageInfoWindow::CreateFrameInfo(Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + gfx::NativeView parent, + TabID tab) { + PageInfoWindow* window = Factory(); + window->Init(profile, url, ssl, NavigationEntry::NORMAL_PAGE, + false, parent); + window->Show(); +} + +// static +void PageInfoWindow::RegisterPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement); +} + +// static +std::string PageInfoWindow::GetIssuerName( + const net::X509Certificate::Principal& issuer) { + if (!issuer.common_name.empty()) + return issuer.common_name; + if (!issuer.organization_names.empty()) + return issuer.organization_names[0]; + if (!issuer.organization_unit_names.empty()) + return issuer.organization_unit_names[0]; + + return std::string(); +} diff --git a/chrome/browser/page_info_window.h b/chrome/browser/page_info_window.h new file mode 100644 index 0000000..c39bd38 --- /dev/null +++ b/chrome/browser/page_info_window.h @@ -0,0 +1,80 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PAGE_INFO_WINDOW_H__ +#define CHROME_BROWSER_PAGE_INFO_WINDOW_H__ + +#include "base/gfx/native_widget_types.h" +#include "chrome/browser/tab_contents/navigation_entry.h" +#include "googleurl/src/gurl.h" +#include "net/base/x509_certificate.h" + +// The page info window displays information regarding the current page, +// including security information. + +class NavigationEntry; +class PageInfoContentView; +class PrefService; +class Profile; + +class PageInfoWindow { + public: + enum TabID { + GENERAL = 0, + SECURITY, + }; + + // Factory method to get a new platform impl of PageInfoWindow + static PageInfoWindow* Factory(); + + // Creates and shows a new page info window for the main page. + static void CreatePageInfo(Profile* profile, + NavigationEntry* nav_entry, + gfx::NativeView parent, + TabID tab); + + // Creates and shows a new page info window for the frame at |url| with the + // specified SSL information. + static void CreateFrameInfo(Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + gfx::NativeView parent, + TabID tab); + + static void RegisterPrefs(PrefService* prefs); + + PageInfoWindow(); + virtual ~PageInfoWindow(); + + // 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) = 0; + + // Brings the page info window to the foreground. + virtual void Show() = 0; + + // Shows various information for the specified certificate in a new dialog. + // This can be implemented as an individual window (like on Windows), or as + // a modal dialog/sheet (on Mac). Either will work since we're only expecting + // one certificate per page. + virtual void ShowCertDialog(int cert_id) = 0; + + protected: + // Returns a name that can be used to represent the issuer. It tries in this + // order CN, O and OU and returns the first non-empty one found. + static std::string GetIssuerName( + const net::X509Certificate::Principal& issuer); + + // The id of the server cert for this page (0 means no cert). + int cert_id_; + + private: + DISALLOW_COPY_AND_ASSIGN(PageInfoWindow); +}; + +#endif // #define CHROME_BROWSER_PAGE_INFO_WINDOW_H__ diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 581598d..4926481 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -12,6 +12,7 @@ #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/page_info_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/spellchecker.h" @@ -27,7 +28,6 @@ #if defined(OS_WIN) #include "chrome/browser/views/options/fonts_languages_window_view.h" -#include "chrome/browser/views/page_info_window.h" #endif RenderViewContextMenu::RenderViewContextMenu( @@ -429,7 +429,7 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { break; case IDS_CONTENT_CONTEXT_VIEWPAGEINFO: { -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_MACOSX) NavigationEntry* nav_entry = source_tab_contents_->controller().GetActiveEntry(); PageInfoWindow::CreatePageInfo( @@ -484,7 +484,7 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { ssl.set_cert_status(cert_status); ssl.set_security_bits(security_bits); } -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_MACOSX) PageInfoWindow::CreateFrameInfo( profile_, params_.frame_url, diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 3f00588..59fbe37 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -26,6 +26,7 @@ #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/page_info_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -45,7 +46,6 @@ #if defined(OS_WIN) #include "app/win_util.h" #include "chrome/browser/views/first_run_bubble.h" -#include "chrome/browser/views/page_info_window.h" #else #include "base/gfx/gtk_util.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" @@ -1115,14 +1115,10 @@ bool LocationBarView::SecurityImageView::OnMousePressed( NOTREACHED(); return true; } -#if defined(OS_WIN) PageInfoWindow::CreatePageInfo(profile_, nav_entry, GetRootView()->GetWidget()->GetNativeView(), PageInfoWindow::SECURITY); -#else - NOTIMPLEMENTED(); -#endif return true; } diff --git a/chrome/browser/views/page_info_window.cc b/chrome/browser/views/page_info_window_win.cc index d05aabb..1d75602 100644 --- a/chrome/browser/views/page_info_window.cc +++ b/chrome/browser/views/page_info_window_win.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/views/page_info_window.h" +#include "chrome/browser/views/page_info_window_win.h" #if defined(OS_WIN) #include <cryptuiapi.h> @@ -29,6 +29,7 @@ #include "views/background.h" #include "views/grid_layout.h" #include "views/controls/button/native_button.h" +#include "views/controls/button/button.h" #include "views/controls/image_view.h" #include "views/controls/label.h" #include "views/controls/separator.h" @@ -101,11 +102,6 @@ class SecurityTabView : public views::View { DISALLOW_EVIL_CONSTRUCTORS(Section); }; - // Returns a name that can be used to represent the issuer. It tries in this - // order CN, O and OU and returns the first non-empty one found. - static std::string GetIssuerName( - const net::X509Certificate::Principal& issuer); - // Callback from history service with number of visits to url. void OnGotVisitCountToHost(HistoryService::Handle handle, bool found_visits, @@ -282,14 +278,15 @@ SecurityTabView::SecurityTabView(Profile* profile, IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, UTF8ToWide(cert->subject().organization_names[0]), locality, - UTF8ToWide(GetIssuerName(cert->issuer())))); + 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(GetIssuerName(cert->issuer()))); + 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)); @@ -390,19 +387,6 @@ void SecurityTabView::Layout() { } } -// static -std::string SecurityTabView::GetIssuerName( - const net::X509Certificate::Principal& issuer) { - if (!issuer.common_name.empty()) - return issuer.common_name; - if (!issuer.organization_names.empty()) - return issuer.organization_names[0]; - if (!issuer.organization_unit_names.empty()) - return issuer.organization_unit_names[0]; - - return std::string(); -} - void SecurityTabView::OnGotVisitCountToHost(HistoryService::Handle handle, bool found_visits, int count, @@ -472,52 +456,29 @@ class PageInfoContentView : public views::View { }; //////////////////////////////////////////////////////////////////////////////// -// PageInfoWindow - -int PageInfoWindow::opened_window_count_ = 0; - -// static -void PageInfoWindow::CreatePageInfo(Profile* profile, - NavigationEntry* nav_entry, - HWND parent_hwnd, - PageInfoWindow::TabID tab) { - PageInfoWindow* window = new PageInfoWindow(); - window->Init(profile, nav_entry->url(), nav_entry->ssl(), - nav_entry->page_type(), true, parent_hwnd); - window->Show(); -} +// PageInfoWindowWin -// static -void PageInfoWindow::CreateFrameInfo(Profile* profile, - const GURL& url, - const NavigationEntry::SSLStatus& ssl, - HWND parent_hwnd, - TabID tab) { - PageInfoWindow* window = new PageInfoWindow(); - window->Init(profile, url, ssl, NavigationEntry::NORMAL_PAGE, - false, parent_hwnd); - window->Show(); -} +int PageInfoWindowWin::opened_window_count_ = 0; -// static -void PageInfoWindow::RegisterPrefs(PrefService* prefs) { - prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement); +PageInfoWindow* PageInfoWindow::Factory() { + return new PageInfoWindowWin(); } -PageInfoWindow::PageInfoWindow() : cert_id_(0), contents_(NULL) { +PageInfoWindowWin::PageInfoWindowWin() + : PageInfoWindow() { } -PageInfoWindow::~PageInfoWindow() { +PageInfoWindowWin::~PageInfoWindowWin() { DCHECK(opened_window_count_ > 0); opened_window_count_--; } -void PageInfoWindow::Init(Profile* profile, - const GURL& url, - const NavigationEntry::SSLStatus& ssl, - NavigationEntry::PageType page_type, - bool show_history, - HWND parent) { +void PageInfoWindowWin::Init(Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + NavigationEntry::PageType page_type, + bool show_history, + gfx::NativeView parent) { cert_id_ = ssl.cert_id(); cert_info_button_ = new views::NativeButton( @@ -582,11 +543,11 @@ void PageInfoWindow::Init(Profile* profile, } } -views::View* PageInfoWindow::CreateGeneralTabView() { +views::View* PageInfoWindowWin::CreateGeneralTabView() { return new views::View(); } -views::View* PageInfoWindow::CreateSecurityTabView( +views::View* PageInfoWindowWin::CreateSecurityTabView( Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, @@ -595,28 +556,28 @@ views::View* PageInfoWindow::CreateSecurityTabView( return new SecurityTabView(profile, url, ssl, page_type, show_history); } -void PageInfoWindow::Show() { +void PageInfoWindowWin::Show() { window()->Show(); opened_window_count_++; } -int PageInfoWindow::GetDialogButtons() const { +int PageInfoWindowWin::GetDialogButtons() const { return MessageBoxFlags::DIALOGBUTTON_CANCEL; } -std::wstring PageInfoWindow::GetWindowTitle() const { +std::wstring PageInfoWindowWin::GetWindowTitle() const { return l10n_util::GetString(IDS_PAGEINFO_WINDOW_TITLE); } -std::wstring PageInfoWindow::GetWindowName() const { +std::wstring PageInfoWindowWin::GetWindowName() const { return prefs::kPageInfoWindowPlacement; } -views::View* PageInfoWindow::GetContentsView() { +views::View* PageInfoWindowWin::GetContentsView() { return contents_; } -void PageInfoWindow::ButtonPressed(views::Button* sender) { +void PageInfoWindowWin::ButtonPressed(views::Button* sender) { if (sender == cert_info_button_) { DCHECK(cert_id_ != 0); ShowCertDialog(cert_id_); @@ -625,16 +586,10 @@ void PageInfoWindow::ButtonPressed(views::Button* sender) { } } -void PageInfoWindow::CalculateWindowBounds(gfx::Rect* bounds) { +void PageInfoWindowWin::CalculateWindowBounds(gfx::Rect* bounds) { const int kDefaultOffset = 15; -#if defined(OS_WIN) gfx::Rect monitor_bounds(win_util::GetMonitorBoundsForRect(*bounds)); -#else - gfx::Rect monitor_bounds; - NOTIMPLEMENTED(); -#endif - if (monitor_bounds.IsEmpty()) return; @@ -666,8 +621,7 @@ void PageInfoWindow::CalculateWindowBounds(gfx::Rect* bounds) { bounds->Offset(x_offset, y_offset); } -void PageInfoWindow::ShowCertDialog(int cert_id) { -#if defined(OS_WIN) +void PageInfoWindowWin::ShowCertDialog(int cert_id) { scoped_refptr<net::X509Certificate> cert; CertStore::GetSharedInstance()->RetrieveCert(cert_id, &cert); if (!cert.get()) { @@ -693,5 +647,4 @@ void PageInfoWindow::ShowCertDialog(int cert_id) { // This next call blocks but keeps processing windows messages, making it // modal to the browser window. BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed); -#endif } diff --git a/chrome/browser/views/page_info_window.h b/chrome/browser/views/page_info_window_win.h index a7d1ca1..fba4a48 100644 --- a/chrome/browser/views/page_info_window.h +++ b/chrome/browser/views/page_info_window_win.h @@ -1,10 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H_ -#define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H_ +#ifndef CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_WIN_H__ +#define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_WIN_H__ +#include "chrome/browser/page_info_window.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "googleurl/src/gurl.h" #include "views/controls/button/button.h" @@ -23,44 +24,29 @@ class PageInfoContentView; class PrefService; class Profile; class X509Certificate; +class SecurityTabView; -class PageInfoWindow : public views::DialogDelegate, - public views::ButtonListener { +class PageInfoWindowWin : public PageInfoWindow, + public views::DialogDelegate, + public views::ButtonListener { public: - enum TabID { - GENERAL = 0, - SECURITY, + // We need access to PageInfoWindow::GetIssuerName() which is protected + friend class SecurityTabView; - }; - - // Creates and shows a new page info window for the main page. - static void CreatePageInfo(Profile* profile, - NavigationEntry* nav_entry, - HWND parent_hwnd, - TabID tab); - - // Creates and shows a new page info window for the frame at |url| with the - // specified SSL information. - static void CreateFrameInfo(Profile* profile, - const GURL& url, - const NavigationEntry::SSLStatus& ssl, - HWND parent_hwnd, - TabID tab); - - static void RegisterPrefs(PrefService* prefs); - - PageInfoWindow(); - virtual ~PageInfoWindow(); + PageInfoWindowWin(); + virtual ~PageInfoWindowWin(); + // 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, - HWND parent); + gfx::NativeView parent); // views::Window overridden method. - void Show(); + virtual void Show(); + virtual void ShowCertDialog(int cert_id); // views::ButtonListener method. virtual void ButtonPressed(views::Button* sender); @@ -72,8 +58,8 @@ class PageInfoWindow : public views::DialogDelegate, virtual views::View* GetContentsView(); private: - views::View* CreateGeneralTabView(); - views::View* CreateSecurityTabView( + virtual views::View* CreateGeneralTabView(); + virtual views::View* CreateSecurityTabView( Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, @@ -84,21 +70,15 @@ class PageInfoWindow : public views::DialogDelegate, // from its original location. void CalculateWindowBounds(gfx::Rect* bounds); - // Shows various information for the specified certificate in a new dialog. - void ShowCertDialog(int cert_id); - views::NativeButton* cert_info_button_; - // The id of the server cert for this page (0 means no cert). - int cert_id_; - // The page info contents. PageInfoContentView* contents_; // A counter of how many page info windows are currently opened. static int opened_window_count_; - DISALLOW_COPY_AND_ASSIGN(PageInfoWindow); + DISALLOW_COPY_AND_ASSIGN(PageInfoWindowWin); }; -#endif // #define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H_ +#endif // #define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_WIN_H__ |