diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-02 02:41:34 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-02 02:41:34 +0000 |
commit | eb9ba19258bbd0cd7e66a85ad42d58642103c1f0 (patch) | |
tree | a04a04fd467de8a251e7b2136cca65021300ea77 /chrome | |
parent | c85d1211431897484d49d3cbc640f30362a53e44 (diff) | |
download | chromium_src-eb9ba19258bbd0cd7e66a85ad42d58642103c1f0.zip chromium_src-eb9ba19258bbd0cd7e66a85ad42d58642103c1f0.tar.gz chromium_src-eb9ba19258bbd0cd7e66a85ad42d58642103c1f0.tar.bz2 |
Convert SSL info bars to use the new system.
http://crbug.com/4620
Review URL: http://codereview.chromium.org/12847
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6196 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 18 | ||||
-rw-r--r-- | chrome/browser/ssl_manager.cc | 130 | ||||
-rw-r--r-- | chrome/browser/ssl_manager.h | 36 |
3 files changed, 56 insertions, 128 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 800e5fb..b51eb54 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2366,10 +2366,8 @@ void AutomationProvider::GetSSLInfoBarCount(const IPC::Message& message, int count = -1; // -1 means error. if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); - if (nav_controller) { - count = static_cast<int>(nav_controller->ssl_manager()-> - visible_info_bars_.size()); - } + if (nav_controller) + count = nav_controller->active_contents()->infobar_delegate_count(); } Send(new AutomationMsg_GetSSLInfoBarCountResponse(message.routing_id(), count)); @@ -2383,8 +2381,7 @@ void AutomationProvider::ClickSSLInfoBarLink(const IPC::Message& message, if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); if (nav_controller) { - int count = static_cast<int>(nav_controller->ssl_manager()-> - visible_info_bars_.size()); + int count = nav_controller->active_contents()->infobar_delegate_count(); if (info_bar_index >= 0 && info_bar_index < count) { if (wait_for_navigation) { AddNavigationStatusListener(nav_controller, @@ -2393,10 +2390,11 @@ void AutomationProvider::ClickSSLInfoBarLink(const IPC::Message& message, new AutomationMsg_ClickSSLInfoBarLinkResponse( message.routing_id(), true)); } - SSLManager::SSLInfoBar* info_bar = - nav_controller->ssl_manager()->visible_info_bars_. - GetElementAt(info_bar_index); - info_bar->LinkActivated(NULL, 0); // Parameters are not used. + InfoBarDelegate* delegate = + nav_controller->active_contents()->GetInfoBarDelegateAt( + info_bar_index); + if (delegate->AsConfirmInfoBarDelegate()) + delegate->AsConfirmInfoBarDelegate()->Accept(); success = true; } } diff --git a/chrome/browser/ssl_manager.cc b/chrome/browser/ssl_manager.cc index 08ab798..46a5546 100644 --- a/chrome/browser/ssl_manager.cc +++ b/chrome/browser/ssl_manager.cc @@ -9,6 +9,7 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/provisional_load_details.h" +#include "chrome/browser/infobar_delegate.h" #include "chrome/browser/load_notification_details.h" #include "chrome/browser/load_from_memory_cache_details.h" #include "chrome/browser/navigation_controller.h" @@ -36,55 +37,55 @@ #include "webkit/glue/resource_type.h" #include "generated_resources.h" -SSLManager::SSLInfoBar::SSLInfoBar(SSLManager* manager, - const std::wstring& message, - const std::wstring& link_text, - Task* task) - : label_(NULL), - link_(NULL), - manager_(manager), - task_(task) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - if (!message.empty()) { - label_ = new views::Label(message); - label_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddChildViewLeading(label_); +class SSLInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + SSLInfoBarDelegate(TabContents* contents, + const std::wstring message, + const std::wstring& button_label, + Task* task) + : message_(message), + button_label_(button_label), + task_(task), + ConfirmInfoBarDelegate(contents) { } + virtual ~SSLInfoBarDelegate() {} - if (!link_text.empty()) { - DCHECK(task) << L"Link and no task"; // What do you want to do when users - // click the link?? - link_ = new views::Link(link_text); - link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - link_->SetController(this); - AddChildViewTrailing(link_); + // Overridden from ConfirmInfoBarDelegate: + virtual void InfoBarClosed() { + delete this; } + virtual std::wstring GetMessageText() const { + return message_; + } + virtual SkBitmap* GetIcon() const { + return ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_INFOBAR_SSL_WARNING); + } + virtual int GetButtons() const { + return !button_label_.empty() ? BUTTON_OK : BUTTON_NONE; + } + virtual std::wstring GetButtonLabel(InfoBarButton button) const { + return button_label_; + } + virtual bool Accept() { + if (task_.get()) { + task_->Run(); + task_.reset(); // Ensures we won't run the task again. + } + return true; + } + - SetIcon(*rb.GetBitmapNamed(IDR_INFOBAR_SSL_WARNING)); - DCHECK(manager); -} - -SSLManager::SSLInfoBar::~SSLInfoBar() { - // Notify our manager that we no longer exist. - manager_->OnInfoBarClose(this); -} - -const std::wstring SSLManager::SSLInfoBar::GetMessageText() const { - if (!label_) - return std::wstring(); + private: + // Labels for the InfoBar's message and button. + std::wstring message_; + std::wstring button_label_; - return label_->GetText(); -} + // A task to run when the InfoBar is accepted. + scoped_ptr<Task> task_; -void SSLManager::SSLInfoBar::LinkActivated(views::Link* source, - int event_flags) { - if (task_.get()) { - task_->Run(); - task_.reset(); // Ensures we won't run the task again. - } - Close(); -} + DISALLOW_COPY_AND_ASSIGN(SSLInfoBarDelegate); +}; //////////////////////////////////////////////////////////////////////////////// // SSLManager @@ -118,8 +119,6 @@ SSLManager::SSLManager(NavigationController* controller, Delegate* delegate) } SSLManager::~SSLManager() { - // Close any of our info bars that are still left. - FOR_EACH_OBSERVER(SSLInfoBar, visible_info_bars_, Close()); } // Delegate API method. @@ -149,29 +148,10 @@ void SSLManager::ShowMessageWithLink(const std::wstring& msg, if (entry->ssl().security_style() <= SECURITY_STYLE_UNAUTHENTICATED) return; - // TODO(brettw) have a more general way to deal with info bars. - if (controller_->active_contents()->AsWebContents()) { - InfoBarView* info_bar_view = controller_->active_contents()-> - AsWebContents()->view()->GetInfoBarView(); - DCHECK(info_bar_view); - - if (!info_bar_view) - return; - - // Check if we are already displaying this message. - ObserverList<SSLInfoBar>::Iterator it(visible_info_bars_); - SSLInfoBar* info_bar; - while (info_bar = it.GetNext()) { - if (info_bar->GetMessageText() == msg) - return; - } - - // Show the message. - info_bar = new SSLInfoBar(this, msg, link_text, task); - visible_info_bars_.AddObserver(info_bar); - - // false indicates info_bar is not automatically removed. - info_bar_view->AppendInfoBarItem(info_bar, false); + if (controller_->active_contents()) { + controller_->active_contents()->AddInfoBar( + new SSLInfoBarDelegate(controller_->active_contents(), msg, link_text, + task)); } } @@ -237,11 +217,6 @@ void SSLManager::AllowShowInsecureContentForURL(const GURL& url) { can_show_insecure_content_for_host_.insert(url.host()); } -void SSLManager::OnInfoBarClose(SSLInfoBar* info_bar) { - // |info_bar| is no longer visible. No need to track it any more. - visible_info_bars_.RemoveObserver(info_bar); -} - bool SSLManager::ProcessedSSLErrorFromRequest() const { NavigationEntry* entry = controller_->GetActiveEntry(); if (!entry) { @@ -586,15 +561,6 @@ void SSLManager::DidCommitProvisionalLoad( bool changed = false; if (details->is_main_frame) { - // We are navigating to a new page, it's time to close the info bars. They - // will automagically disappear from the visible_info_bars_ list (when - // OnInfoBarClose is invoked). - // TODO(jcampan): if we are navigating to an interstitial page, we close - // the info-bars. That is unfortunate as if you decide to go back to the - // original page, the info-bars are now gone. We would need a way to - // restore them in that case. - FOR_EACH_OBSERVER(SSLInfoBar, visible_info_bars_, Close()); - // Update the SSL states of the pending entry. NavigationEntry* entry = controller_->GetActiveEntry(); if (entry) { diff --git a/chrome/browser/ssl_manager.h b/chrome/browser/ssl_manager.h index adf58f3..0610403 100644 --- a/chrome/browser/ssl_manager.h +++ b/chrome/browser/ssl_manager.h @@ -27,7 +27,6 @@ #include "webkit/glue/resource_type.h" class AutomationProvider; -class InfoBarItemView; class NavigationEntry; class LoadFromMemoryCacheDetails; class LoadNotificationDetails; @@ -262,32 +261,6 @@ class SSLManager : public NotificationObserver { virtual SecurityStyle GetDefaultStyle(const GURL& url) = 0; }; - // An info bar with a message and an optional link that runs a task when - // clicked. - class SSLInfoBar : public InfoBarItemView, - public views::LinkController { - public: - SSLInfoBar(SSLManager* manager, - const std::wstring& message, - const std::wstring& link_text, - Task* task); - - virtual ~SSLInfoBar(); - - const std::wstring GetMessageText() const; - - // views::LinkController method. - virtual void LinkActivated(views::Link* source, int event_flags); - - private: - views::Label* label_; - views::Link* link_; - SSLManager* manager_; - scoped_ptr<Task> task_; - - DISALLOW_COPY_AND_ASSIGN(SSLInfoBar); - }; - static void RegisterUserPrefs(PrefService* prefs); // Construct an SSLManager for the specified tab. @@ -402,9 +375,6 @@ class SSLManager : public NotificationObserver { // Called on the UI thread. void NavigationStateChanged(); - // Called when one of our infobars closes. - void OnInfoBarClose(SSLInfoBar* info_bar); - // Called to determine if there were any processed SSL errors from request. bool ProcessedSSLErrorFromRequest() const; @@ -427,9 +397,6 @@ class SSLManager : public NotificationObserver { std::wstring* ca_name); private: - // The AutomationProvider needs to access the InfoBars. - friend class AutomationProvider; - // SSLMessageInfo contains the information necessary for displaying a message // in an info-bar. struct SSLMessageInfo { @@ -480,9 +447,6 @@ class SSLManager : public NotificationObserver { // for the security UI of this tab. NavigationController* controller_; - // The list of currently visible SSL InfoBars. - ObserverList<SSLInfoBar> visible_info_bars_; - // Handles registering notifications with the NotificationService. NotificationRegistrar registrar_; |